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/>.
28 ;; For Emacs <22.2 and XEmacs.
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-hidden-properties '(invisible t intangible t)
261 "Property list to use for hiding text."
263 :group 'gnus-article-hiding)
265 ;; Fixme: This isn't the right thing for mixed graphical and non-graphical
266 ;; frames in a session.
267 (defcustom gnus-article-x-face-command
268 (if (featurep 'xemacs)
269 (if (or (gnus-image-type-available-p 'xface)
270 (gnus-image-type-available-p 'pbm))
271 'gnus-display-x-face-in-from
272 "{ echo '/* Width=48, Height=48 */'; uncompface; } | icontopbm | ee -")
273 (if (gnus-image-type-available-p 'pbm)
274 'gnus-display-x-face-in-from
275 "{ echo '/* Width=48, Height=48 */'; uncompface; } | icontopbm | \
277 "*String or function to be executed to display an X-Face header.
278 If it is a string, the command will be executed in a sub-shell
279 asynchronously. The compressed face will be piped to this command."
280 :type `(choice string
281 (function-item gnus-display-x-face-in-from)
285 :group 'gnus-article-washing)
287 (defcustom gnus-article-x-face-too-ugly nil
288 "Regexp matching posters whose face shouldn't be shown automatically."
289 :type '(choice regexp (const nil))
290 :group 'gnus-article-washing)
292 (defcustom gnus-article-banner-alist nil
293 "Banner alist for stripping.
295 ((egroups . \"^[ \\t\\n]*-------------------+\\\\( \\\\(e\\\\|Yahoo! \\\\)Groups Sponsor -+\\\\)?....\\n\\\\(.+\\n\\\\)+\"))"
297 :type '(repeat (cons symbol regexp))
298 :group 'gnus-article-washing)
300 (gnus-define-group-parameter
303 "Alist of regexps (to match group names) and banner."
304 :variable-group gnus-article-washing
306 '(choice :tag "Banner"
308 (const :tag "Remove signature" signature)
309 (symbol :tag "Item in `gnus-article-banner-alist'" none)
311 (const :tag "None" nil))
313 "If non-nil, specify how to remove `banners' from articles.
315 Symbol `signature' means to remove signatures delimited by
316 `gnus-signature-separator'. Any other symbol is used to look up a
317 regular expression to match the banner in `gnus-article-banner-alist'.
318 A string is used as a regular expression to match the banner
321 (defcustom gnus-article-address-banner-alist nil
322 "Alist of mail addresses and banners.
323 Each element has the form (ADDRESS . BANNER), where ADDRESS is a regexp
324 to match a mail address in the From: header, BANNER is one of a symbol
325 `signature', an item in `gnus-article-banner-alist', a regexp and nil.
326 If ADDRESS matches author's mail address, it will remove things like
327 advertisements. For example:
329 \((\"@yoo-hoo\\\\.co\\\\.jp\\\\'\" . \"\\n_+\\nDo You Yoo-hoo!\\\\?\\n.*\\n.*\\n\"))
333 (regexp :tag "Address")
334 (choice :tag "Banner" :value nil
335 (const :tag "Remove signature" signature)
336 (symbol :tag "Item in `gnus-article-banner-alist'" none)
338 (const :tag "None" nil))))
340 :group 'gnus-article-washing)
342 (defmacro gnus-emphasis-custom-with-format (&rest body)
344 \\(\\s-\\|^\\|\\=\\|[-\"]\\|\\s(\\)\\(%s\\(\\w+\\(\\s-+\\w+\\)*[.,]?\\)%s\\)\
345 \\(\\([-,.;:!?\"]\\|\\s)\\)+\\s-\\|[?!.]\\s-\\|\\s)\\|\\s-\\)"))
348 (defun gnus-emphasis-custom-value-to-external (value)
349 (gnus-emphasis-custom-with-format
350 (if (consp (car value))
351 (list (format format (car (car value)) (cdr (car value)))
353 (if (nth 1 value) 2 3)
357 (defun gnus-emphasis-custom-value-to-internal (value)
358 (gnus-emphasis-custom-with-format
359 (let ((regexp (concat "\\`"
360 (format (regexp-quote format)
361 "\\([^()]+\\)" "\\([^()]+\\)")
364 (if (string-match regexp (setq pattern (car value)))
365 (list (cons (match-string 1 pattern) (match-string 2 pattern))
370 (defcustom gnus-emphasis-alist
372 '(("\\*" "\\*" bold nil 2)
375 ("_/" "/_" underline-italic)
376 ("_\\*" "\\*_" underline-bold)
377 ("\\*/" "/\\*" bold-italic)
378 ("_\\*/" "/\\*_" underline-bold-italic))))
380 (gnus-emphasis-custom-with-format
381 (mapcar (lambda (spec)
382 (list (format format (car spec) (cadr spec))
385 (intern (format "gnus-emphasis-%s" (nth 2 spec)))))
387 '(;; I've never seen anyone use this strikethru convention whereas I've
388 ;; several times seen it triggered by normal text. --Stef
389 ;; Miles suggests that this form is sometimes used but for italics,
390 ;; so maybe we should map it to `italic'.
391 ;; ("\\(\\s-\\|^\\)\\(-\\(\\(\\w\\|-[^-]\\)+\\)-\\)\\(\\s-\\|[?!.,;]\\)"
392 ;; 2 3 gnus-emphasis-strikethru)
393 ("\\(\\s-\\|^\\)\\(_\\(\\(\\w\\|_[^_]\\)+\\)_\\)\\(\\s-\\|[?!.,;]\\)"
394 2 3 gnus-emphasis-underline))))
395 "*Alist that says how to fontify certain phrases.
396 Each item looks like this:
398 (\"_\\\\(\\\\w+\\\\)_\" 0 1 'underline)
400 The first element is a regular expression to be matched. The second
401 is a number that says what regular expression grouping used to find
402 the entire emphasized word. The third is a number that says what
403 regexp grouping should be displayed and highlighted. The fourth
404 is the face used for highlighting."
408 :format "%[Customizing Style%]\n%v"
410 (group :tag "Default"
411 :value ("" 0 0 default)
414 (let ((value (widget-get
415 (cadr (widget-get (widget-get widget :parent)
418 (if (not (eq (nth 2 value) 'default))
422 (gnus-emphasis-custom-value-to-external value))))
423 (widget-group-value-create widget))
425 (integer :format "Match group: %v")
426 (integer :format "Emphasize group: %v")
429 :value (("_" . "_") nil default)
431 (regexp :format "Start regexp: %v")
432 (regexp :format "End regexp: %v"))
433 (boolean :format "Show start and end patterns: %[%v%]\n"
434 :on " On " :off " Off ")
436 :get (lambda (symbol)
437 (mapcar 'gnus-emphasis-custom-value-to-internal
438 (default-value symbol)))
439 :set (lambda (symbol value)
440 (set-default symbol (mapcar 'gnus-emphasis-custom-value-to-external
442 :group 'gnus-article-emphasis)
444 (defcustom gnus-emphasize-whitespace-regexp "^[ \t]+\\|[ \t]*\n"
445 "A regexp to describe whitespace which should not be emphasized.
446 Typical values are \"^[ \\t]+\\\\|[ \\t]*\\n\" and \"[ \\t]+\\\\|[ \\t]*\\n\".
447 The former avoids underlining of leading and trailing whitespace,
448 and the latter avoids underlining any whitespace at all."
450 :group 'gnus-article-emphasis
453 (defface gnus-emphasis-bold '((t (:bold t)))
454 "Face used for displaying strong emphasized text (*word*)."
455 :group 'gnus-article-emphasis)
457 (defface gnus-emphasis-italic '((t (:italic t)))
458 "Face used for displaying italic emphasized text (/word/)."
459 :group 'gnus-article-emphasis)
461 (defface gnus-emphasis-underline '((t (:underline t)))
462 "Face used for displaying underlined emphasized text (_word_)."
463 :group 'gnus-article-emphasis)
465 (defface gnus-emphasis-underline-bold '((t (:bold t :underline t)))
466 "Face used for displaying underlined bold emphasized text (_*word*_)."
467 :group 'gnus-article-emphasis)
469 (defface gnus-emphasis-underline-italic '((t (:italic t :underline t)))
470 "Face used for displaying underlined italic emphasized text (_/word/_)."
471 :group 'gnus-article-emphasis)
473 (defface gnus-emphasis-bold-italic '((t (:bold t :italic t)))
474 "Face used for displaying bold italic emphasized text (/*word*/)."
475 :group 'gnus-article-emphasis)
477 (defface gnus-emphasis-underline-bold-italic
478 '((t (:bold t :italic t :underline t)))
479 "Face used for displaying underlined bold italic emphasized text.
480 Example: (_/*word*/_)."
481 :group 'gnus-article-emphasis)
483 (defface gnus-emphasis-strikethru (if (featurep 'xemacs)
484 '((t (:strikethru t)))
485 '((t (:strike-through t))))
486 "Face used for displaying strike-through text (-word-)."
487 :group 'gnus-article-emphasis)
489 (defface gnus-emphasis-highlight-words
490 '((t (:background "black" :foreground "yellow")))
491 "Face used for displaying highlighted words."
492 :group 'gnus-article-emphasis)
494 (defcustom gnus-article-time-format "%a, %d %b %Y %T %Z"
495 "Format for display of Date headers in article bodies.
496 See `format-time-string' for the possible values.
498 The variable can also be function, which should return a complete Date
499 header. The function is called with one argument, the time, which can
500 be fed to `format-time-string'."
501 :type '(choice string function)
502 :link '(custom-manual "(gnus)Article Date")
503 :group 'gnus-article-washing)
505 (defcustom gnus-save-all-headers t
506 "*If non-nil, don't remove any headers before saving.
507 This will be overridden by the `:headers' property that the symbol of
508 the saver function, which is specified by `gnus-default-article-saver',
510 :group 'gnus-article-saving
513 (defcustom gnus-prompt-before-saving 'always
514 "*This variable says how much prompting is to be done when saving articles.
515 If it is nil, no prompting will be done, and the articles will be
516 saved to the default files. If this variable is `always', each and
517 every article that is saved will be preceded by a prompt, even when
518 saving large batches of articles. If this variable is neither nil not
519 `always', there the user will be prompted once for a file name for
520 each invocation of the saving commands."
521 :group 'gnus-article-saving
522 :type '(choice (item always)
523 (item :tag "never" nil)
524 (sexp :tag "once" :format "%t\n" :value t)))
526 (defcustom gnus-saved-headers gnus-visible-headers
527 "Headers to keep if `gnus-save-all-headers' is nil.
528 If `gnus-save-all-headers' is non-nil, this variable will be ignored.
529 If that variable is nil, however, all headers that match this regexp
530 will be kept while the rest will be deleted before saving. This and
531 `gnus-save-all-headers' will be overridden by the `:headers' property
532 that the symbol of the saver function, which is specified by
533 `gnus-default-article-saver', might have."
534 :group 'gnus-article-saving
537 ;; Note that "Rmail format" is mbox since Emacs 23, but Babyl before.
538 (defcustom gnus-default-article-saver 'gnus-summary-save-in-rmail
539 "A function to save articles in your favourite format.
540 The function will be called by way of the `gnus-summary-save-article'
541 command, and friends such as `gnus-summary-save-article-rmail'.
543 Gnus provides the following functions:
545 * gnus-summary-save-in-rmail (Rmail format)
546 * gnus-summary-save-in-mail (Unix mail format)
547 * gnus-summary-save-in-folder (MH folder)
548 * gnus-summary-save-in-file (article format)
549 * gnus-summary-save-body-in-file (article body)
550 * gnus-summary-save-in-vm (use VM's folder format)
551 * gnus-summary-write-to-file (article format -- overwrite)
552 * gnus-summary-write-body-to-file (article body -- overwrite)
553 * gnus-summary-save-in-pipe (article format)
555 The symbol of each function may have the following properties:
558 The value non-nil means save decoded articles. This is meaningful
559 only with `gnus-summary-save-in-file', `gnus-summary-save-body-in-file',
560 `gnus-summary-write-to-file', `gnus-summary-write-body-to-file', and
561 `gnus-summary-save-in-pipe'.
564 The value specifies an alternative function which appends, not
565 overwrites, articles to a file. This implies that when saving many
566 articles at a time, `gnus-prompt-before-saving' is bound to t and all
567 articles are saved in a single file. This is meaningful only with
568 `gnus-summary-write-to-file' and `gnus-summary-write-body-to-file'.
571 The value specifies the symbol of a variable of which the value
572 specifies headers to be saved. If it is omitted,
573 `gnus-save-all-headers' and `gnus-saved-headers' control what
574 headers should be saved."
575 :group 'gnus-article-saving
576 :type '(radio (function-item gnus-summary-save-in-rmail)
577 (function-item gnus-summary-save-in-mail)
578 (function-item gnus-summary-save-in-folder)
579 (function-item gnus-summary-save-in-file)
580 (function-item gnus-summary-save-body-in-file)
581 (function-item gnus-summary-save-in-vm)
582 (function-item gnus-summary-write-to-file)
583 (function-item gnus-summary-write-body-to-file)
584 (function-item gnus-summary-save-in-pipe)
587 (defcustom gnus-article-save-coding-system
588 (or (and (mm-coding-system-p 'utf-8) 'utf-8)
589 (and (mm-coding-system-p 'iso-2022-7bit) 'iso-2022-7bit)
590 (and (mm-coding-system-p 'emacs-mule) 'emacs-mule)
591 (and (mm-coding-system-p 'escape-quoted) 'escape-quoted))
592 "Coding system used to save decoded articles to a file.
594 The recommended coding systems are `utf-8', `iso-2022-7bit' and so on,
595 which can safely encode any characters in text. This is used by the
598 * gnus-summary-save-article-file
599 * gnus-summary-save-article-body-file
600 * gnus-summary-write-article-file
601 * gnus-summary-write-article-body-file
603 and the functions to which you may set `gnus-default-article-saver':
605 * gnus-summary-save-in-file
606 * gnus-summary-save-body-in-file
607 * gnus-summary-write-to-file
608 * gnus-summary-write-body-to-file
610 Those commands and functions save just text displayed in the article
611 buffer to a file if the value of this variable is non-nil. Note that
612 buttonized MIME parts will be lost in a saved file in that case.
613 Otherwise, raw articles will be saved."
614 :group 'gnus-article-saving
616 :format "%{%t%}:\n %[Value Menu%] %v"
617 (const :tag "Save raw articles" nil)
620 (lambda (arg) (if (mm-coding-system-p (nth 3 arg)) arg))
621 '((const :tag "UTF-8" utf-8)
622 (const :tag "iso-2022-7bit" iso-2022-7bit)
623 (const :tag "Emacs internal" emacs-mule)
624 (const :tag "escape-quoted" escape-quoted))))
625 (symbol :tag "Coding system")))
627 (defcustom gnus-rmail-save-name 'gnus-plain-save-name
628 "A function generating a file name to save articles in Rmail format.
629 The function is called with NEWSGROUP, HEADERS, and optional LAST-FILE."
630 :group 'gnus-article-saving
633 (defcustom gnus-mail-save-name 'gnus-plain-save-name
634 "A function generating a file name to save articles in Unix mail format.
635 The function is called with NEWSGROUP, HEADERS, and optional LAST-FILE."
636 :group 'gnus-article-saving
639 (defcustom gnus-folder-save-name 'gnus-folder-save-name
640 "A function generating a file name to save articles in MH folder.
641 The function is called with NEWSGROUP, HEADERS, and optional LAST-FOLDER."
642 :group 'gnus-article-saving
645 (defcustom gnus-file-save-name 'gnus-numeric-save-name
646 "A function generating a file name to save articles in article format.
647 The function is called with NEWSGROUP, HEADERS, and optional
649 :group 'gnus-article-saving
652 (defcustom gnus-split-methods
653 '((gnus-article-archive-name)
654 (gnus-article-nndoc-name))
655 "*Variable used to suggest where articles are to be saved.
656 For instance, if you would like to save articles related to Gnus in
657 the file \"gnus-stuff\", and articles related to VM in \"vm-stuff\",
658 you could set this variable to something like:
660 '((\"^Subject:.*gnus\\|^Newsgroups:.*gnus\" \"gnus-stuff\")
661 (\"^Subject:.*vm\\|^Xref:.*vm\" \"vm-stuff\"))
663 This variable is an alist where the key is the match and the
664 value is a list of possible files to save in if the match is
667 If the match is a string, it is used as a regexp match on the
668 article. If the match is a symbol, that symbol will be funcalled
669 from the buffer of the article to be saved with the newsgroup as the
670 parameter. If it is a list, it will be evaled in the same buffer.
672 If this form or function returns a string, this string will be used as a
673 possible file name; and if it returns a non-nil list, that list will be
674 used as possible file names."
675 :group 'gnus-article-saving
676 :type '(repeat (choice (list :value (fun) function)
677 (cons :value ("" "") regexp (repeat string))
680 (defcustom gnus-page-delimiter "^\^L"
681 "*Regexp describing what to use as article page delimiters.
682 The default value is \"^\^L\", which is a form linefeed at the
683 beginning of a line."
685 :group 'gnus-article-various)
687 (defcustom gnus-article-mode-line-format "Gnus: %g [%w] %S%m"
688 "*The format specification for the article mode line.
689 See `gnus-summary-mode-line-format' for a closer description.
691 The following additional specs are available:
693 %w The article washing status.
694 %m The number of MIME parts in the article."
696 :group 'gnus-article-various)
698 (defcustom gnus-article-mode-hook nil
699 "*A hook for Gnus article mode."
701 :group 'gnus-article-various)
703 (when (featurep 'xemacs)
704 ;; Extracted from gnus-xmas-define in order to preserve user settings
705 (when (fboundp 'turn-off-scroll-in-place)
706 (add-hook 'gnus-article-mode-hook 'turn-off-scroll-in-place))
707 ;; Extracted from gnus-xmas-redefine in order to preserve user settings
708 (add-hook 'gnus-article-mode-hook 'gnus-xmas-article-menu-add))
710 (defcustom gnus-article-menu-hook nil
711 "*Hook run after the creation of the article mode menu."
713 :group 'gnus-article-various)
715 (defcustom gnus-article-prepare-hook nil
716 "*A hook called after an article has been prepared in the article buffer."
718 :group 'gnus-article-various)
720 (defcustom gnus-copy-article-ignored-headers nil
721 "List of headers to be removed when copying an article.
722 Each element is a regular expression."
723 :version "23.1" ;; No Gnus
724 :type '(repeat regexp)
725 :group 'gnus-article-various)
727 (make-obsolete-variable 'gnus-article-hide-pgp-hook nil
728 "Gnus 5.10 (Emacs 22.1)")
731 '((t (:weight bold)))
732 "Face used for highlighting a button in the article buffer."
733 :group 'gnus-article-buttons)
735 (defcustom gnus-article-button-face 'gnus-button
736 "Face used for highlighting buttons in the article buffer.
738 An article button is a piece of text that you can activate by pressing
739 `RET' or `mouse-2' above it."
741 :group 'gnus-article-buttons)
743 (defcustom gnus-article-mouse-face 'highlight
744 "Face used for mouse highlighting in the article buffer.
746 Article buttons will be displayed in this face when the cursor is
749 :group 'gnus-article-buttons)
751 (defcustom gnus-signature-face 'gnus-signature
752 "Face used for highlighting a signature in the article buffer.
753 Obsolete; use the face `gnus-signature' for customizations instead."
755 :group 'gnus-article-highlight
756 :group 'gnus-article-signature)
758 (defface gnus-signature
761 "Face used for highlighting a signature in the article buffer."
762 :group 'gnus-article-highlight
763 :group 'gnus-article-signature)
764 ;; backward-compatibility alias
765 (put 'gnus-signature-face 'face-alias 'gnus-signature)
766 (put 'gnus-signature-face 'obsolete-face "22.1")
768 (defface gnus-header-from
771 (:foreground "PaleGreen1"))
774 (:foreground "red3"))
777 "Face used for displaying from headers."
778 :group 'gnus-article-headers
779 :group 'gnus-article-highlight)
780 ;; backward-compatibility alias
781 (put 'gnus-header-from-face 'face-alias 'gnus-header-from)
782 (put 'gnus-header-from-face 'obsolete-face "22.1")
784 (defface gnus-header-subject
787 (:foreground "SeaGreen1"))
790 (:foreground "red4"))
792 (:bold t :italic t)))
793 "Face used for displaying subject headers."
794 :group 'gnus-article-headers
795 :group 'gnus-article-highlight)
796 ;; backward-compatibility alias
797 (put 'gnus-header-subject-face 'face-alias 'gnus-header-subject)
798 (put 'gnus-header-subject-face 'obsolete-face "22.1")
800 (defface gnus-header-newsgroups
803 (:foreground "yellow" :italic t))
806 (:foreground "MidnightBlue" :italic t))
809 "Face used for displaying newsgroups headers.
810 In the default setup this face is only used for crossposted
812 :group 'gnus-article-headers
813 :group 'gnus-article-highlight)
814 ;; backward-compatibility alias
815 (put 'gnus-header-newsgroups-face 'face-alias 'gnus-header-newsgroups)
816 (put 'gnus-header-newsgroups-face 'obsolete-face "22.1")
818 (defface gnus-header-name
821 (:foreground "SpringGreen2"))
824 (:foreground "maroon"))
827 "Face used for displaying header names."
828 :group 'gnus-article-headers
829 :group 'gnus-article-highlight)
830 ;; backward-compatibility alias
831 (put 'gnus-header-name-face 'face-alias 'gnus-header-name)
832 (put 'gnus-header-name-face 'obsolete-face "22.1")
834 (defface gnus-header-content
837 (:foreground "SpringGreen1" :italic t))
840 (:foreground "indianred4" :italic t))
842 (:italic t))) "Face used for displaying header content."
843 :group 'gnus-article-headers
844 :group 'gnus-article-highlight)
845 ;; backward-compatibility alias
846 (put 'gnus-header-content-face 'face-alias 'gnus-header-content)
847 (put 'gnus-header-content-face 'obsolete-face "22.1")
849 (defcustom gnus-header-face-alist
850 '(("From" nil gnus-header-from)
851 ("Subject" nil gnus-header-subject)
852 ("Newsgroups:.*," nil gnus-header-newsgroups)
853 ("" gnus-header-name gnus-header-content))
854 "*Controls highlighting of article headers.
856 An alist of the form (HEADER NAME CONTENT).
858 HEADER is a regular expression which should match the name of a
859 header and NAME and CONTENT are either face names or nil.
861 The name of each header field will be displayed using the face
862 specified by the first element in the list where HEADER matches
863 the header name and NAME is non-nil. Similarly, the content will
864 be displayed by the first non-nil matching CONTENT face."
865 :group 'gnus-article-headers
866 :group 'gnus-article-highlight
867 :type '(repeat (list (regexp :tag "Header")
869 (item :tag "skip" nil)
870 (face :value default))
871 (choice :tag "Content"
872 (item :tag "skip" nil)
873 (face :value default)))))
875 (defcustom gnus-face-properties-alist (if (featurep 'xemacs)
876 '((xface . (:face gnus-x-face)))
877 '((pbm . (:face gnus-x-face))
879 "Alist of image types and properties applied to Face and X-Face images.
882 ;; Specify the altitude of Face images in the From header.
883 \(setq gnus-face-properties-alist
884 '((pbm . (:face gnus-x-face :ascent 80))
885 (png . (:ascent 80))))
887 ;; Show Face images as pressed buttons.
888 \(setq gnus-face-properties-alist
889 '((pbm . (:face gnus-x-face :relief -2))
890 (png . (:relief -2))))
892 See the manual for the valid properties for various image types.
893 Currently, `pbm' is used for X-Face images and `png' is used for Face
894 images in Emacs. Only the `:face' property is effective on the `xface'
895 image type in XEmacs if it is built with the libcompface library."
896 :version "23.1" ;; No Gnus
897 :group 'gnus-article-headers
898 :type '(repeat (cons :format "%v" (symbol :tag "Image type") plist)))
900 (defcustom gnus-article-decode-hook
901 '(article-decode-charset article-decode-encoded-words
902 article-decode-group-name article-decode-idna-rhs)
903 "*Hook run to decode charsets in articles."
904 :group 'gnus-article-headers
907 (defcustom gnus-display-mime-function 'gnus-display-mime
908 "Function to display MIME articles."
909 :group 'gnus-article-mime
912 (defvar gnus-decode-header-function 'mail-decode-encoded-word-region
913 "Function used to decode headers.")
915 (defvar gnus-decode-address-function 'mail-decode-encoded-address-region
916 "Function used to decode addresses.")
918 (defvar gnus-article-dumbquotes-map
938 "Table for MS-to-Latin1 translation.")
940 (defcustom gnus-ignored-mime-types nil
941 "List of MIME types that should be ignored by Gnus."
943 :group 'gnus-article-mime
944 :type '(repeat regexp))
946 (defcustom gnus-unbuttonized-mime-types '(".*/.*")
947 "List of MIME types that should not be given buttons when rendered inline.
948 See also `gnus-buttonized-mime-types' which may override this variable.
949 This variable is only used when `gnus-inhibit-mime-unbuttonizing' is nil."
951 :group 'gnus-article-mime
952 :type '(repeat regexp))
954 (defcustom gnus-buttonized-mime-types nil
955 "List of MIME types that should be given buttons when rendered inline.
956 If set, this variable overrides `gnus-unbuttonized-mime-types'.
957 To see e.g. security buttons you could set this to
958 `(\"multipart/signed\")'. You could also add \"multipart/alternative\" to
959 this list to display radio buttons that allow you to choose one of two
960 media types those mails include. See also `mm-discouraged-alternatives'.
961 This variable is only used when `gnus-inhibit-mime-unbuttonizing' is nil."
963 :group 'gnus-article-mime
964 :type '(repeat regexp))
966 (defcustom gnus-inhibit-mime-unbuttonizing nil
967 "If non-nil, all MIME parts get buttons.
968 When nil (the default value), then some MIME parts do not get buttons,
969 as described by the variables `gnus-buttonized-mime-types' and
970 `gnus-unbuttonized-mime-types'."
972 :group 'gnus-article-mime
975 (defcustom gnus-body-boundary-delimiter "_"
976 "String used to delimit header and body.
977 This variable is used by `gnus-article-treat-body-boundary' which can
978 be controlled by `gnus-treat-body-boundary'."
980 :group 'gnus-article-various
981 :type '(choice (item :tag "None" :value nil)
984 (defcustom gnus-picon-databases '("/usr/lib/picon" "/usr/local/faces"
986 "Defines the location of the faces database.
987 For information on obtaining this database of pretty pictures, please
988 see http://www.cs.indiana.edu/picons/ftp/index.html"
990 :type '(repeat directory)
991 :link '(url-link :tag "download"
992 "http://www.cs.indiana.edu/picons/ftp/index.html")
993 :link '(custom-manual "(gnus)Picons")
996 (defun gnus-picons-installed-p ()
997 "Say whether picons are installed on your machine."
998 (let ((installed nil))
999 (dolist (database gnus-picon-databases)
1000 (when (file-exists-p database)
1001 (setq installed t)))
1004 (defcustom gnus-article-mime-part-function nil
1005 "Function called with a MIME handle as the argument.
1006 This is meant for people who want to do something automatic based
1007 on parts -- for instance, adding Vcard info to a database."
1008 :group 'gnus-article-mime
1009 :type '(choice (const nil)
1012 (defcustom gnus-mime-multipart-functions nil
1013 "An alist of MIME types to functions to display them."
1015 :group 'gnus-article-mime
1016 :type '(repeat (cons :format "%v" (string :tag "MIME type") function)))
1018 (defcustom gnus-article-date-lapsed-new-header nil
1019 "Whether the X-Sent and Date headers can coexist.
1020 When using `gnus-treat-date-lapsed', the \"X-Sent:\" header will
1021 either replace the old \"Date:\" header (if this variable is nil), or
1022 be added below it (otherwise)."
1024 :group 'gnus-article-headers
1027 (defcustom gnus-article-mime-match-handle-function 'undisplayed-alternative
1028 "Function called with a MIME handle as the argument.
1029 This is meant for people who want to view first matched part.
1030 For `undisplayed-alternative' (default), the first undisplayed
1031 part or alternative part is used. For `undisplayed', the first
1032 undisplayed part is used. For a function, the first part which
1033 the function return t is used. For nil, the first part is
1036 :group 'gnus-article-mime
1038 (item :tag "first" :value nil)
1039 (item :tag "undisplayed" :value undisplayed)
1040 (item :tag "undisplayed or alternative"
1041 :value undisplayed-alternative)
1044 (defcustom gnus-mime-action-alist
1045 '(("save to file" . gnus-mime-save-part)
1046 ("save and strip" . gnus-mime-save-part-and-strip)
1047 ("replace with file" . gnus-mime-replace-part)
1048 ("delete part" . gnus-mime-delete-part)
1049 ("display as text" . gnus-mime-inline-part)
1050 ("view the part" . gnus-mime-view-part)
1051 ("pipe to command" . gnus-mime-pipe-part)
1052 ("toggle display" . gnus-article-press-button)
1053 ("toggle display" . gnus-article-view-part-as-charset)
1054 ("view as type" . gnus-mime-view-part-as-type)
1055 ("view internally" . gnus-mime-view-part-internally)
1056 ("view externally" . gnus-mime-view-part-externally))
1057 "An alist of actions that run on the MIME attachment."
1058 :group 'gnus-article-mime
1059 :type '(repeat (cons (string :tag "name")
1062 (defcustom gnus-auto-select-part 1
1063 "Advance to next MIME part when deleting or stripping parts.
1065 When 0, point will be placed on the same part as before. When
1066 positive (negative), move point forward (backwards) this many
1067 parts. When nil, redisplay article."
1068 :version "23.1" ;; No Gnus
1069 :group 'gnus-article-mime
1070 :type '(choice (const nil :tag "Redisplay article.")
1071 (const 1 :tag "Next part.")
1072 (const 0 :tag "Current part.")
1076 ;;; The treatment variables
1079 (defvar gnus-part-display-hook nil
1080 "Hook called on parts that are to receive treatment.")
1082 (defvar gnus-article-treat-custom
1083 '(choice (const :tag "Off" nil)
1085 (const :tag "Header" head)
1086 (const :tag "First" first)
1087 (const :tag "Last" last)
1088 (integer :tag "Less")
1089 (repeat :tag "Groups" regexp)
1090 (sexp :tag "Predicate")))
1092 (defvar gnus-article-treat-head-custom
1093 '(choice (const :tag "Off" nil)
1094 (const :tag "Header" head)))
1096 (defvar gnus-article-treat-types '("text/plain" "text/x-verbatim"
1100 (defvar gnus-inhibit-treatment nil
1101 "Whether to inhibit treatment.")
1103 (defcustom gnus-treat-highlight-signature '(or t (typep "text/x-vcard"))
1104 "Highlight the signature.
1105 Valid values are nil, t, `head', `first', `last', an integer or a
1106 predicate. See Info node `(gnus)Customizing Articles'."
1107 :group 'gnus-article-treat
1108 :link '(custom-manual "(gnus)Customizing Articles")
1109 :type gnus-article-treat-custom)
1110 (put 'gnus-treat-highlight-signature 'highlight t)
1112 (defcustom gnus-treat-buttonize 100000
1114 Valid values are nil, t, `head', `first', `last', an integer or a
1115 predicate. See Info node `(gnus)Customizing Articles'."
1116 :group 'gnus-article-treat
1117 :link '(custom-manual "(gnus)Customizing Articles")
1118 :type gnus-article-treat-custom)
1119 (put 'gnus-treat-buttonize 'highlight t)
1121 (defcustom gnus-treat-buttonize-head 'head
1122 "Add buttons to the head.
1123 Valid values are nil, t, `head', `first', `last', an integer or a
1124 predicate. See Info node `(gnus)Customizing Articles'."
1125 :group 'gnus-article-treat
1126 :link '(custom-manual "(gnus)Customizing Articles")
1127 :type gnus-article-treat-head-custom)
1128 (put 'gnus-treat-buttonize-head 'highlight t)
1130 (defcustom gnus-treat-emphasize 50000
1132 Valid values are nil, t, `head', `first', `last', an integer or a
1133 predicate. See Info node `(gnus)Customizing Articles'."
1134 :group 'gnus-article-treat
1135 :link '(custom-manual "(gnus)Customizing Articles")
1136 :type gnus-article-treat-custom)
1137 (put 'gnus-treat-emphasize 'highlight t)
1139 (defcustom gnus-treat-strip-cr nil
1140 "Remove carriage returns.
1141 Valid values are nil, t, `head', `first', `last', an integer or a
1142 predicate. See Info node `(gnus)Customizing Articles'."
1144 :group 'gnus-article-treat
1145 :link '(custom-manual "(gnus)Customizing Articles")
1146 :type gnus-article-treat-custom)
1148 (defcustom gnus-treat-unsplit-urls nil
1149 "Remove newlines from within URLs.
1150 Valid values are nil, t, `head', `first', `last', an integer or a
1151 predicate. See Info node `(gnus)Customizing Articles'."
1153 :group 'gnus-article-treat
1154 :link '(custom-manual "(gnus)Customizing Articles")
1155 :type gnus-article-treat-custom)
1157 (defcustom gnus-treat-leading-whitespace nil
1158 "Remove leading whitespace in headers.
1159 Valid values are nil, t, `head', `first', `last', an integer or a
1160 predicate. See Info node `(gnus)Customizing Articles'."
1162 :group 'gnus-article-treat
1163 :link '(custom-manual "(gnus)Customizing Articles")
1164 :type gnus-article-treat-custom)
1166 (defcustom gnus-treat-hide-headers 'head
1168 Valid values are nil, t, `head', `first', `last', an integer or a
1169 predicate. See Info node `(gnus)Customizing Articles'."
1170 :group 'gnus-article-treat
1171 :link '(custom-manual "(gnus)Customizing Articles")
1172 :type gnus-article-treat-head-custom)
1174 (defcustom gnus-treat-hide-boring-headers nil
1175 "Hide boring headers.
1176 Valid values are nil, t, `head', `first', `last', an integer or a
1177 predicate. See Info node `(gnus)Customizing Articles'."
1178 :group 'gnus-article-treat
1179 :link '(custom-manual "(gnus)Customizing Articles")
1180 :type gnus-article-treat-head-custom)
1182 (defcustom gnus-treat-hide-signature nil
1183 "Hide the signature.
1184 Valid values are nil, t, `head', `first', `last', an integer or a
1185 predicate. See Info node `(gnus)Customizing Articles'."
1186 :group 'gnus-article-treat
1187 :link '(custom-manual "(gnus)Customizing Articles")
1188 :type gnus-article-treat-custom)
1190 (defcustom gnus-treat-fill-article nil
1192 Valid values are nil, t, `head', `first', `last', an integer or a
1193 predicate. See Info node `(gnus)Customizing Articles'."
1194 :group 'gnus-article-treat
1195 :link '(custom-manual "(gnus)Customizing Articles")
1196 :type gnus-article-treat-custom)
1198 (defcustom gnus-treat-hide-citation nil
1200 Valid values are nil, t, `head', `first', `last', an integer or a
1201 predicate. See Info node `(gnus)Customizing Articles'."
1202 :group 'gnus-article-treat
1203 :link '(custom-manual "(gnus)Customizing Articles")
1204 :type gnus-article-treat-custom)
1206 (defcustom gnus-treat-hide-citation-maybe 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-strip-list-identifiers 'head
1215 "Strip list identifiers from `gnus-list-identifiers`.
1216 Valid values are nil, t, `head', `first', `last', an integer or a
1217 predicate. See Info node `(gnus)Customizing Articles'."
1219 :group 'gnus-article-treat
1220 :link '(custom-manual "(gnus)Customizing Articles")
1221 :type gnus-article-treat-custom)
1223 (make-obsolete-variable 'gnus-treat-strip-pgp nil
1224 "Gnus 5.10 (Emacs 22.1)")
1226 (defcustom gnus-treat-strip-pem nil
1227 "Strip PEM signatures.
1228 Valid values are nil, t, `head', `first', `last', an integer or a
1229 predicate. See Info node `(gnus)Customizing Articles'."
1230 :group 'gnus-article-treat
1231 :link '(custom-manual "(gnus)Customizing Articles")
1232 :type gnus-article-treat-custom)
1234 (defcustom gnus-treat-strip-banner t
1235 "Strip banners from articles.
1236 The banner to be stripped is specified in the `banner' group parameter.
1237 Valid values are nil, t, `head', `first', `last', an integer or a
1238 predicate. See Info node `(gnus)Customizing Articles'."
1239 :group 'gnus-article-treat
1240 :link '(custom-manual "(gnus)Customizing Articles")
1241 :type gnus-article-treat-custom)
1243 (defcustom gnus-treat-highlight-headers 'head
1244 "Highlight the headers.
1245 Valid values are nil, t, `head', `first', `last', an integer or a
1246 predicate. See Info node `(gnus)Customizing Articles'."
1247 :group 'gnus-article-treat
1248 :link '(custom-manual "(gnus)Customizing Articles")
1249 :type gnus-article-treat-head-custom)
1250 (put 'gnus-treat-highlight-headers 'highlight t)
1252 (defcustom gnus-treat-highlight-citation t
1253 "Highlight cited text.
1254 Valid values are nil, t, `head', `first', `last', an integer or a
1255 predicate. See Info node `(gnus)Customizing Articles'."
1256 :group 'gnus-article-treat
1257 :link '(custom-manual "(gnus)Customizing Articles")
1258 :type gnus-article-treat-custom)
1259 (put 'gnus-treat-highlight-citation 'highlight t)
1261 (defcustom gnus-treat-date-ut nil
1262 "Display the Date in UT (GMT).
1263 Valid values are nil, t, `head', `first', `last', an integer or a
1264 predicate. See Info node `(gnus)Customizing Articles'."
1265 :group 'gnus-article-treat
1266 :link '(custom-manual "(gnus)Customizing Articles")
1267 :type gnus-article-treat-head-custom)
1269 (defcustom gnus-treat-date-local nil
1270 "Display the Date in the local timezone.
1271 Valid values are nil, t, `head', `first', `last', an integer or a
1272 predicate. See Info node `(gnus)Customizing Articles'."
1273 :group 'gnus-article-treat
1274 :link '(custom-manual "(gnus)Customizing Articles")
1275 :type gnus-article-treat-head-custom)
1277 (defcustom gnus-treat-date-english nil
1278 "Display the Date in a format that can be read aloud in English.
1279 Valid values are nil, t, `head', `first', `last', an integer or a
1280 predicate. See Info node `(gnus)Customizing Articles'."
1282 :group 'gnus-article-treat
1283 :link '(custom-manual "(gnus)Customizing Articles")
1284 :type gnus-article-treat-head-custom)
1286 (defcustom gnus-treat-date-lapsed nil
1287 "Display the Date header in a way that says how much time has elapsed.
1288 Valid values are nil, t, `head', `first', `last', an integer or a
1289 predicate. See Info node `(gnus)Customizing Articles'."
1290 :group 'gnus-article-treat
1291 :link '(custom-manual "(gnus)Customizing Articles")
1292 :type gnus-article-treat-head-custom)
1294 (defcustom gnus-treat-date-original nil
1295 "Display the date in the original timezone.
1296 Valid values are nil, t, `head', `first', `last', an integer or a
1297 predicate. See Info node `(gnus)Customizing Articles'."
1298 :group 'gnus-article-treat
1299 :link '(custom-manual "(gnus)Customizing Articles")
1300 :type gnus-article-treat-head-custom)
1302 (defcustom gnus-treat-date-iso8601 nil
1303 "Display the date in the ISO8601 format.
1304 Valid values are nil, t, `head', `first', `last', an integer or a
1305 predicate. See Info node `(gnus)Customizing Articles'."
1307 :group 'gnus-article-treat
1308 :link '(custom-manual "(gnus)Customizing Articles")
1309 :type gnus-article-treat-head-custom)
1311 (defcustom gnus-treat-date-user-defined nil
1312 "Display the date in a user-defined format.
1313 The format is defined by the `gnus-article-time-format' variable.
1314 Valid values are nil, t, `head', `first', `last', an integer or a
1315 predicate. See Info node `(gnus)Customizing Articles'."
1316 :group 'gnus-article-treat
1317 :link '(custom-manual "(gnus)Customizing Articles")
1318 :type gnus-article-treat-head-custom)
1320 (defcustom gnus-treat-strip-headers-in-body t
1321 "Strip the X-No-Archive header line from the beginning of the body.
1322 Valid values are nil, t, `head', `first', `last', an integer or a
1323 predicate. See Info node `(gnus)Customizing Articles'."
1325 :group 'gnus-article-treat
1326 :link '(custom-manual "(gnus)Customizing Articles")
1327 :type gnus-article-treat-custom)
1329 (defcustom gnus-treat-strip-trailing-blank-lines nil
1330 "Strip trailing blank lines.
1331 Valid values are nil, t, `head', `first', `last', an integer or a
1332 predicate. See Info node `(gnus)Customizing Articles'.
1334 When set to t, it also strips trailing blanks in all MIME parts.
1335 Consider to use `last' instead."
1336 :group 'gnus-article-treat
1337 :link '(custom-manual "(gnus)Customizing Articles")
1338 :type gnus-article-treat-custom)
1340 (defcustom gnus-treat-strip-leading-blank-lines nil
1341 "Strip leading blank lines.
1342 Valid values are nil, t, `head', `first', `last', an integer or a
1343 predicate. See Info node `(gnus)Customizing Articles'.
1345 When set to t, it also strips trailing blanks in all MIME parts."
1346 :group 'gnus-article-treat
1347 :link '(custom-manual "(gnus)Customizing Articles")
1348 :type gnus-article-treat-custom)
1350 (defcustom gnus-treat-strip-multiple-blank-lines nil
1351 "Strip multiple blank lines.
1352 Valid values are nil, t, `head', `first', `last', an integer or a
1353 predicate. See Info node `(gnus)Customizing Articles'."
1354 :group 'gnus-article-treat
1355 :link '(custom-manual "(gnus)Customizing Articles")
1356 :type gnus-article-treat-custom)
1358 (defcustom gnus-treat-unfold-headers 'head
1359 "Unfold folded header lines.
1360 Valid values are nil, t, `head', `first', `last', an integer or a
1361 predicate. See Info node `(gnus)Customizing Articles'."
1363 :group 'gnus-article-treat
1364 :link '(custom-manual "(gnus)Customizing Articles")
1365 :type gnus-article-treat-custom)
1367 (defcustom gnus-article-unfold-long-headers nil
1368 "If non-nil, allow unfolding headers even if the header is long.
1369 If it is a regexp, only long headers matching this regexp are unfolded.
1370 If it is t, all long headers are unfolded.
1372 This variable has no effect if `gnus-treat-unfold-headers' is nil."
1373 :version "23.1" ;; No Gnus
1374 :group 'gnus-article-treat
1375 :type '(choice (const nil)
1376 (const :tag "all" t)
1379 (defcustom gnus-treat-fold-headers nil
1381 Valid values are nil, t, `head', `first', `last', an integer or a
1382 predicate. See Info node `(gnus)Customizing Articles'."
1384 :group 'gnus-article-treat
1385 :link '(custom-manual "(gnus)Customizing Articles")
1386 :type gnus-article-treat-custom)
1388 (defcustom gnus-treat-fold-newsgroups 'head
1389 "Fold the Newsgroups and Followup-To headers.
1390 Valid values are nil, t, `head', `first', `last', an integer or a
1391 predicate. See Info node `(gnus)Customizing Articles'."
1393 :group 'gnus-article-treat
1394 :link '(custom-manual "(gnus)Customizing Articles")
1395 :type gnus-article-treat-custom)
1397 (defcustom gnus-treat-overstrike t
1398 "Treat overstrike highlighting.
1399 Valid values are nil, t, `head', `first', `last', an integer or a
1400 predicate. See Info node `(gnus)Customizing Articles'."
1401 :group 'gnus-article-treat
1402 :link '(custom-manual "(gnus)Customizing Articles")
1403 :type gnus-article-treat-custom)
1404 (put 'gnus-treat-overstrike 'highlight t)
1406 (defcustom gnus-treat-ansi-sequences (if (locate-library "ansi-color") t)
1407 "Treat ANSI SGR control sequences.
1408 Valid values are nil, t, `head', `first', `last', an integer or a
1409 predicate. See Info node `(gnus)Customizing Articles'."
1410 :group 'gnus-article-treat
1411 :link '(custom-manual "(gnus)Customizing Articles")
1412 :type gnus-article-treat-custom)
1414 (make-obsolete-variable 'gnus-treat-display-xface
1415 'gnus-treat-display-x-face "Emacs 22.1")
1417 (defcustom gnus-treat-display-x-face
1418 (and (not noninteractive)
1419 (gnus-image-type-available-p 'xbm)
1420 (if (featurep 'xemacs)
1423 (and (string-match "^0x" (shell-command-to-string "uncompface"))
1424 (executable-find "icontopbm"))
1425 ;; shell-command-to-string may signal an error, e.g. if
1426 ;; shell-file-name is not found.
1429 "Display X-Face headers.
1430 Valid values are nil and `head'.
1431 See Info node `(gnus)Customizing Articles' and Info node
1432 `(gnus)X-Face' for details."
1433 :group 'gnus-article-treat
1435 :link '(custom-manual "(gnus)Customizing Articles")
1436 :link '(custom-manual "(gnus)X-Face")
1437 :type gnus-article-treat-head-custom
1438 :set (lambda (symbol value)
1441 (cond ((or (boundp symbol) (get symbol 'saved-value))
1443 ((boundp 'gnus-treat-display-xface)
1445 ** gnus-treat-display-xface is an obsolete variable;\
1446 use gnus-treat-display-x-face instead")
1447 (default-value 'gnus-treat-display-xface))
1448 ((get 'gnus-treat-display-xface 'saved-value)
1450 ** gnus-treat-display-xface is an obsolete variable;\
1451 use gnus-treat-display-x-face instead")
1452 (eval (car (get 'gnus-treat-display-xface 'saved-value))))
1455 (put 'gnus-treat-display-x-face 'highlight t)
1457 (defcustom gnus-treat-display-face
1458 (and (not noninteractive)
1459 (gnus-image-type-available-p 'png)
1461 "Display Face headers.
1462 Valid values are nil, t, `head', `first', `last', an integer or a
1463 predicate. See Info node `(gnus)Customizing Articles' and Info
1464 node `(gnus)Face' for details."
1465 :group 'gnus-article-treat
1467 :link '(custom-manual "(gnus)Customizing Articles")
1468 :link '(custom-manual "(gnus)X-Face")
1469 :type gnus-article-treat-head-custom)
1470 (put 'gnus-treat-display-face 'highlight t)
1472 (defcustom gnus-treat-display-smileys (gnus-image-type-available-p 'xpm)
1474 Valid values are nil, t, `head', `first', `last', an integer or a
1475 predicate. See Info node `(gnus)Customizing Articles' and Info
1476 node `(gnus)Smileys' for details."
1477 :group 'gnus-article-treat
1479 :link '(custom-manual "(gnus)Customizing Articles")
1480 :link '(custom-manual "(gnus)Smileys")
1481 :type gnus-article-treat-custom)
1482 (put 'gnus-treat-display-smileys 'highlight t)
1484 (defcustom gnus-treat-from-picon
1485 (if (and (gnus-image-type-available-p 'xpm)
1486 (gnus-picons-installed-p))
1488 "Display picons in the From header.
1489 Valid values are nil, t, `head', `first', `last', an integer or a
1490 predicate. See Info node `(gnus)Customizing Articles' and Info
1491 node `(gnus)Picons' for details."
1493 :group 'gnus-article-treat
1495 :link '(custom-manual "(gnus)Customizing Articles")
1496 :link '(custom-manual "(gnus)Picons")
1497 :type gnus-article-treat-head-custom)
1498 (put 'gnus-treat-from-picon 'highlight t)
1500 (defcustom gnus-treat-mail-picon
1501 (if (and (gnus-image-type-available-p 'xpm)
1502 (gnus-picons-installed-p))
1504 "Display picons in To and Cc headers.
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-mail-picon 'highlight t)
1516 (defcustom gnus-treat-newsgroups-picon
1517 (if (and (gnus-image-type-available-p 'xpm)
1518 (gnus-picons-installed-p))
1520 "Display picons in the Newsgroups and Followup-To 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-newsgroups-picon 'highlight t)
1532 (defcustom gnus-treat-from-gravatar nil
1533 "Display gravatars in the From header.
1534 Valid values are nil, t, `head', `first', `last', an integer or a
1535 predicate. See Info node `(gnus)Customizing Articles' and Info
1536 node `(gnus)Gravatars' for details."
1538 :group 'gnus-article-treat
1539 :group 'gnus-gravatar
1540 :link '(custom-manual "(gnus)Customizing Articles")
1541 :link '(custom-manual "(gnus)Gravatars")
1542 :type gnus-article-treat-head-custom)
1543 (put 'gnus-treat-from-gravatar 'highlight t)
1545 (defcustom gnus-treat-mail-gravatar nil
1546 "Display gravatars in To and Cc headers.
1547 Valid values are nil, t, `head', `first', `last', an integer or a
1548 predicate. See Info node `(gnus)Customizing Articles' and Info
1549 node `(gnus)Gravatars' for details."
1551 :group 'gnus-article-treat
1552 :group 'gnus-gravatar
1553 :link '(custom-manual "(gnus)Customizing Articles")
1554 :link '(custom-manual "(gnus)Gravatars")
1555 :type gnus-article-treat-head-custom)
1556 (put 'gnus-treat-mail-gravatar 'highlight t)
1558 (defcustom gnus-treat-body-boundary
1559 (if (or gnus-treat-newsgroups-picon
1560 gnus-treat-mail-picon
1561 gnus-treat-from-picon
1562 gnus-treat-from-gravatar
1563 gnus-treat-mail-gravatar)
1564 ;; If there's much decoration, the user might prefer a boundery.
1567 "Draw a boundary at the end of the headers.
1568 Valid values are nil and `head'.
1569 See Info node `(gnus)Customizing Articles' for details."
1571 :group 'gnus-article-treat
1572 :link '(custom-manual "(gnus)Customizing Articles")
1573 :type gnus-article-treat-head-custom)
1575 (defcustom gnus-treat-capitalize-sentences nil
1576 "Capitalize sentence-starting words.
1577 Valid values are nil, t, `head', `first', `last', an integer or a
1578 predicate. See Info node `(gnus)Customizing Articles'."
1580 :group 'gnus-article-treat
1581 :link '(custom-manual "(gnus)Customizing Articles")
1582 :type gnus-article-treat-custom)
1584 (defcustom gnus-treat-wash-html nil
1586 Valid values are nil, t, `head', `first', `last', an integer or a
1587 predicate. See Info node `(gnus)Customizing Articles'."
1589 :group 'gnus-article-treat
1590 :link '(custom-manual "(gnus)Customizing Articles")
1591 :type gnus-article-treat-custom)
1593 (defcustom gnus-treat-fill-long-lines '(typep "text/plain")
1595 Valid values are nil, t, `head', `first', `last', an integer or a
1596 predicate. See Info node `(gnus)Customizing Articles'."
1597 :group 'gnus-article-treat
1598 :link '(custom-manual "(gnus)Customizing Articles")
1599 :type gnus-article-treat-custom)
1601 (defcustom gnus-treat-x-pgp-sig nil
1603 To automatically treat X-PGP-Sig, set it to head.
1604 Valid values are nil, t, `head', `first', `last', an integer or a
1605 predicate. See Info node `(gnus)Customizing Articles'."
1607 :group 'gnus-article-treat
1608 :group 'mime-security
1609 :link '(custom-manual "(gnus)Customizing Articles")
1610 :type gnus-article-treat-custom)
1612 (defvar gnus-article-encrypt-protocol-alist
1613 '(("PGP" . mml2015-self-encrypt)))
1615 ;; Set to nil if more than one protocol added to
1616 ;; gnus-article-encrypt-protocol-alist.
1617 (defcustom gnus-article-encrypt-protocol "PGP"
1618 "The protocol used for encrypt articles.
1619 It is a string, such as \"PGP\". If nil, ask user."
1622 :group 'mime-security)
1624 (defcustom gnus-use-idna (and (condition-case nil (require 'idna) (file-error))
1625 (mm-coding-system-p 'utf-8)
1626 (executable-find idna-program))
1627 "Whether IDNA decoding of headers is used when viewing messages.
1628 This requires GNU Libidn, and by default only enabled if it is found."
1630 :group 'gnus-article-headers
1633 (defcustom gnus-article-over-scroll nil
1634 "If non-nil, allow scrolling the article buffer even when there no more text."
1636 :group 'gnus-article
1639 (defcustom gnus-blocked-images 'gnus-block-private-groups
1640 "Images that have URLs matching this regexp will be blocked.
1641 This can also be a function to be evaluated. If so, it will be
1642 called with the group name as the parameter, and should return a
1648 ;;; Internal variables
1650 (defvar gnus-english-month-names
1651 '("January" "February" "March" "April" "May" "June" "July" "August"
1652 "September" "October" "November" "December"))
1654 (defvar article-goto-body-goes-to-point-min-p nil)
1655 (defvar gnus-article-wash-types nil)
1656 (defvar gnus-article-emphasis-alist nil)
1657 (defvar gnus-article-image-alist nil)
1659 (defvar gnus-article-mime-handle-alist-1 nil)
1660 (defvar gnus-treatment-function-alist
1661 '((gnus-treat-x-pgp-sig gnus-article-verify-x-pgp-sig)
1662 (gnus-treat-strip-banner gnus-article-strip-banner)
1663 (gnus-treat-strip-headers-in-body gnus-article-strip-headers-in-body)
1664 (gnus-treat-highlight-signature gnus-article-highlight-signature)
1665 (gnus-treat-buttonize gnus-article-add-buttons)
1666 (gnus-treat-fill-article gnus-article-fill-cited-article)
1667 (gnus-treat-fill-long-lines gnus-article-fill-cited-long-lines)
1668 (gnus-treat-strip-cr gnus-article-remove-cr)
1669 (gnus-treat-unsplit-urls gnus-article-unsplit-urls)
1670 (gnus-treat-date-ut gnus-article-date-ut)
1671 (gnus-treat-date-local gnus-article-date-local)
1672 (gnus-treat-date-english gnus-article-date-english)
1673 (gnus-treat-date-original gnus-article-date-original)
1674 (gnus-treat-date-user-defined gnus-article-date-user)
1675 (gnus-treat-date-iso8601 gnus-article-date-iso8601)
1676 (gnus-treat-date-lapsed gnus-article-date-lapsed)
1677 (gnus-treat-display-x-face gnus-article-display-x-face)
1678 (gnus-treat-display-face gnus-article-display-face)
1679 (gnus-treat-hide-headers gnus-article-maybe-hide-headers)
1680 (gnus-treat-hide-boring-headers gnus-article-hide-boring-headers)
1681 (gnus-treat-hide-signature gnus-article-hide-signature)
1682 (gnus-treat-strip-list-identifiers gnus-article-hide-list-identifiers)
1683 (gnus-treat-leading-whitespace gnus-article-remove-leading-whitespace)
1684 (gnus-treat-from-picon gnus-treat-from-picon)
1685 (gnus-treat-mail-picon gnus-treat-mail-picon)
1686 (gnus-treat-newsgroups-picon gnus-treat-newsgroups-picon)
1687 (gnus-treat-strip-pem gnus-article-hide-pem)
1688 (gnus-treat-from-gravatar gnus-treat-from-gravatar)
1689 (gnus-treat-mail-gravatar gnus-treat-mail-gravatar)
1690 (gnus-treat-highlight-headers gnus-article-highlight-headers)
1691 (gnus-treat-highlight-signature gnus-article-highlight-signature)
1692 (gnus-treat-strip-trailing-blank-lines
1693 gnus-article-remove-trailing-blank-lines)
1694 (gnus-treat-strip-leading-blank-lines
1695 gnus-article-strip-leading-blank-lines)
1696 (gnus-treat-strip-multiple-blank-lines
1697 gnus-article-strip-multiple-blank-lines)
1698 (gnus-treat-overstrike gnus-article-treat-overstrike)
1699 (gnus-treat-ansi-sequences gnus-article-treat-ansi-sequences)
1700 (gnus-treat-unfold-headers gnus-article-treat-unfold-headers)
1701 (gnus-treat-fold-newsgroups gnus-article-treat-fold-newsgroups)
1702 (gnus-treat-fold-headers gnus-article-treat-fold-headers)
1703 (gnus-treat-buttonize-head gnus-article-add-buttons-to-head)
1704 (gnus-treat-display-smileys gnus-treat-smiley)
1705 (gnus-treat-capitalize-sentences gnus-article-capitalize-sentences)
1706 (gnus-treat-wash-html gnus-article-wash-html)
1707 (gnus-treat-emphasize gnus-article-emphasize)
1708 (gnus-treat-hide-citation gnus-article-hide-citation)
1709 (gnus-treat-hide-citation-maybe gnus-article-hide-citation-maybe)
1710 (gnus-treat-highlight-citation gnus-article-highlight-citation)
1711 (gnus-treat-body-boundary gnus-article-treat-body-boundary)))
1713 (defvar gnus-article-mime-handle-alist nil)
1714 (defvar article-lapsed-timer nil)
1715 (defvar gnus-article-current-summary nil)
1717 (defvar gnus-article-mode-syntax-table
1718 (let ((table (copy-syntax-table text-mode-syntax-table)))
1719 ;; This causes the citation match run O(2^n).
1720 ;; (modify-syntax-entry ?- "w" table)
1721 (modify-syntax-entry ?> ")<" table)
1722 (modify-syntax-entry ?< "(>" table)
1723 ;; make M-. in article buffers work for `foo' strings
1724 (modify-syntax-entry ?' " " table)
1725 (modify-syntax-entry ?` " " table)
1727 "Syntax table used in article mode buffers.
1728 Initialized from `text-mode-syntax-table.")
1730 (defvar gnus-save-article-buffer nil)
1732 (defvar gnus-number-of-articles-to-be-saved nil)
1734 (defvar gnus-inhibit-hiding nil)
1736 (defvar gnus-article-edit-mode nil)
1738 ;;; Macros for dealing with the article buffer.
1740 (defmacro gnus-with-article-headers (&rest forms)
1741 `(with-current-buffer gnus-article-buffer
1743 (let ((inhibit-read-only t)
1744 (inhibit-point-motion-hooks t)
1745 (case-fold-search t))
1746 (article-narrow-to-head)
1749 (put 'gnus-with-article-headers 'lisp-indent-function 0)
1750 (put 'gnus-with-article-headers 'edebug-form-spec '(body))
1752 (defmacro gnus-with-article-buffer (&rest forms)
1753 `(with-current-buffer gnus-article-buffer
1754 (let ((inhibit-read-only t))
1757 (put 'gnus-with-article-buffer 'lisp-indent-function 0)
1758 (put 'gnus-with-article-buffer 'edebug-form-spec '(body))
1760 (defun gnus-article-goto-header (header)
1761 "Go to HEADER, which is a regular expression."
1762 (re-search-forward (concat "^\\(" header "\\):") nil t))
1764 (defsubst gnus-article-hide-text (b e props)
1765 "Set text PROPS on the B to E region, extending `intangible' 1 past B."
1766 (gnus-add-text-properties-when 'article-type nil b e props)
1767 (when (memq 'intangible props)
1769 (max (1- b) (point-min))
1770 b 'intangible (cddr (memq 'intangible props)))))
1772 (defsubst gnus-article-unhide-text (b e)
1773 "Remove hidden text properties from region between B and E."
1774 (remove-text-properties b e gnus-hidden-properties)
1775 (when (memq 'intangible gnus-hidden-properties)
1776 (put-text-property (max (1- b) (point-min))
1777 b 'intangible nil)))
1779 (defun gnus-article-hide-text-type (b e type)
1780 "Hide text of TYPE between B and E."
1781 (gnus-add-wash-type type)
1782 (gnus-article-hide-text
1783 b e (cons 'article-type (cons type gnus-hidden-properties))))
1785 (defun gnus-article-unhide-text-type (b e type)
1786 "Unhide text of TYPE between B and E."
1787 (gnus-delete-wash-type type)
1788 (remove-text-properties
1789 b e (cons 'article-type (cons type gnus-hidden-properties)))
1790 (when (memq 'intangible gnus-hidden-properties)
1791 (put-text-property (max (1- b) (point-min))
1792 b 'intangible nil)))
1794 (defun gnus-article-hide-text-of-type (type)
1795 "Hide text of TYPE in the current buffer."
1797 (let ((b (point-min))
1799 (while (setq b (text-property-any b e 'article-type type))
1800 (add-text-properties b (incf b) gnus-hidden-properties)))))
1802 (defun gnus-article-delete-text-of-type (type)
1803 "Delete text of TYPE in the current buffer."
1805 (let ((b (point-min)))
1806 (if (eq type 'multipart)
1807 ;; Remove MIME buttons associated with multipart/alternative parts.
1810 (while (if (get-text-property (point) 'gnus-part)
1812 (when (setq b (next-single-property-change (point)
1817 (skip-chars-forward "\n")
1818 (when (eq (get-text-property b 'article-type) 'multipart)
1819 (delete-region b (point)))))
1820 (while (setq b (text-property-any b (point-max) 'article-type type))
1822 b (or (text-property-not-all b (point-max) 'article-type type)
1825 (defun gnus-article-delete-invisible-text ()
1826 "Delete all invisible text in the current buffer."
1828 (let ((b (point-min)))
1829 (while (setq b (text-property-any b (point-max) 'invisible t))
1831 b (or (text-property-not-all b (point-max) 'invisible t)
1834 (defun gnus-article-text-type-exists-p (type)
1835 "Say whether any text of type TYPE exists in the buffer."
1836 (text-property-any (point-min) (point-max) 'article-type type))
1838 (defsubst gnus-article-header-rank ()
1839 "Give the rank of the string HEADER as given by `gnus-sorted-header-list'."
1840 (let ((list gnus-sorted-header-list)
1843 (if (looking-at (car list))
1845 (setq list (cdr list))
1849 (defun article-hide-headers (&optional arg delete)
1850 "Hide unwanted headers and possibly sort them as well."
1852 ;; This function might be inhibited.
1853 (unless gnus-inhibit-hiding
1854 (let ((inhibit-read-only t)
1855 (case-fold-search t)
1856 (max (1+ (length gnus-sorted-header-list)))
1857 (inhibit-point-motion-hooks t)
1858 (cur (current-buffer))
1859 ignored visible beg)
1861 ;; `gnus-ignored-headers' and `gnus-visible-headers' may be
1862 ;; group parameters, so we should go to the summary buffer.
1865 (progn (set-buffer gnus-summary-buffer) t)
1867 (setq ignored (when (not gnus-visible-headers)
1868 (cond ((stringp gnus-ignored-headers)
1869 gnus-ignored-headers)
1870 ((listp gnus-ignored-headers)
1871 (mapconcat 'identity
1872 gnus-ignored-headers
1874 visible (cond ((stringp gnus-visible-headers)
1875 gnus-visible-headers)
1876 ((and gnus-visible-headers
1877 (listp gnus-visible-headers))
1878 (mapconcat 'identity
1879 gnus-visible-headers
1883 ;; First we narrow to just the headers.
1884 (article-narrow-to-head)
1885 ;; Hide any "From " lines at the beginning of (mail) articles.
1886 (while (looking-at "From ")
1889 (delete-region (point-min) (point)))
1890 ;; Then treat the rest of the header lines.
1891 ;; Then we use the two regular expressions
1892 ;; `gnus-ignored-headers' and `gnus-visible-headers' to
1893 ;; select which header lines is to remain visible in the
1895 (while (re-search-forward "^[^ \t:]*:" nil t)
1897 ;; Mark the rank of the header.
1899 (point) (1+ (point)) 'message-rank
1900 (if (or (and visible (looking-at visible))
1902 (not (looking-at ignored))))
1903 (gnus-article-header-rank)
1906 (message-sort-headers-1)
1907 (when (setq beg (text-property-any
1908 (point-min) (point-max) 'message-rank (+ 2 max)))
1909 ;; We delete the unwanted headers.
1910 (gnus-add-wash-type 'headers)
1911 (add-text-properties (point-min) (+ 5 (point-min))
1912 '(article-type headers dummy-invisible t))
1913 (delete-region beg (point-max))))))))
1915 (defun article-hide-boring-headers (&optional arg)
1916 "Toggle hiding of headers that aren't very interesting.
1917 If given a negative prefix, always show; if given a positive prefix,
1919 (interactive (gnus-article-hidden-arg))
1920 (when (and (not (gnus-article-check-hidden-text 'boring-headers arg))
1921 (not gnus-show-all-headers))
1924 (let ((inhibit-read-only t)
1925 (inhibit-point-motion-hooks t))
1926 (article-narrow-to-head)
1927 (dolist (elem gnus-boring-article-headers)
1928 (goto-char (point-min))
1930 ;; Hide empty headers.
1932 (while (re-search-forward "^[^: \t]+:[ \t]*\n[^ \t]" nil t)
1934 (gnus-article-hide-text-type
1938 (if (re-search-forward "^[^ \t]" nil t)
1942 ;; Hide boring Newsgroups header.
1943 ((eq elem 'newsgroups)
1944 (when (gnus-string-equal
1945 (gnus-fetch-field "newsgroups")
1946 (gnus-group-real-name
1947 (if (boundp 'gnus-newsgroup-name)
1950 (gnus-article-hide-header "newsgroups")))
1951 ((eq elem 'to-address)
1952 (let ((to (message-fetch-field "to"))
1954 (gnus-parameter-to-address
1955 (if (boundp 'gnus-newsgroup-name)
1956 gnus-newsgroup-name ""))))
1957 (when (and to to-address
1960 ;; only one address in To
1961 (nth 1 (mail-extract-address-components to))
1963 (gnus-article-hide-header "to"))))
1965 (let ((to (message-fetch-field "to"))
1967 (gnus-parameter-to-list
1968 (if (boundp 'gnus-newsgroup-name)
1969 gnus-newsgroup-name ""))))
1970 (when (and to to-list
1973 ;; only one address in To
1974 (nth 1 (mail-extract-address-components to))
1976 (gnus-article-hide-header "to"))))
1978 (let ((cc (message-fetch-field "cc"))
1980 (gnus-parameter-to-list
1981 (if (boundp 'gnus-newsgroup-name)
1982 gnus-newsgroup-name ""))))
1983 (when (and cc to-list
1986 ;; only one address in CC
1987 (nth 1 (mail-extract-address-components cc))
1989 (gnus-article-hide-header "cc"))))
1990 ((eq elem 'followup-to)
1991 (when (gnus-string-equal
1992 (message-fetch-field "followup-to")
1993 (message-fetch-field "newsgroups"))
1994 (gnus-article-hide-header "followup-to")))
1995 ((eq elem 'reply-to)
1996 (if (gnus-group-find-parameter
1997 gnus-newsgroup-name 'broken-reply-to)
1998 (gnus-article-hide-header "reply-to")
1999 (let ((from (message-fetch-field "from"))
2000 (reply-to (message-fetch-field "reply-to")))
2007 (lambda (x) (downcase (cadr x)))
2008 (mail-extract-address-components from t))
2011 (lambda (x) (downcase (cadr x)))
2012 (mail-extract-address-components reply-to t))
2014 (gnus-article-hide-header "reply-to")))))
2016 (let ((date (with-current-buffer gnus-original-article-buffer
2017 ;; If date in `gnus-article-buffer' is localized
2018 ;; (`gnus-treat-date-user-defined'),
2019 ;; `days-between' might fail.
2020 (message-fetch-field "date"))))
2022 (< (days-between (current-time-string) date)
2024 (gnus-article-hide-header "date"))))
2026 (let ((to (message-fetch-field "to"))
2027 (cc (message-fetch-field "cc")))
2028 (when (> (length to) 1024)
2029 (gnus-article-hide-header "to"))
2030 (when (> (length cc) 1024)
2031 (gnus-article-hide-header "cc"))))
2035 (goto-char (point-min))
2036 (while (re-search-forward "^to:" nil t)
2037 (setq to-count (1+ to-count)))
2038 (when (> to-count 1)
2039 (while (> to-count 0)
2040 (goto-char (point-min))
2042 (re-search-forward "^to:" nil nil to-count)
2044 (narrow-to-region (point) (point-max))
2045 (gnus-article-hide-header "to"))
2046 (setq to-count (1- to-count))))
2047 (goto-char (point-min))
2048 (while (re-search-forward "^cc:" nil t)
2049 (setq cc-count (1+ cc-count)))
2050 (when (> cc-count 1)
2051 (while (> cc-count 0)
2052 (goto-char (point-min))
2054 (re-search-forward "^cc:" nil nil cc-count)
2056 (narrow-to-region (point) (point-max))
2057 (gnus-article-hide-header "cc"))
2058 (setq cc-count (1- cc-count)))))))))))))
2060 (defun gnus-article-hide-header (header)
2062 (goto-char (point-min))
2063 (when (re-search-forward (concat "^" header ":") nil t)
2064 (gnus-article-hide-text-type
2068 (if (re-search-forward "^[^ \t]" nil t)
2073 (defvar gnus-article-normalized-header-length 40
2074 "Length of normalized headers.")
2076 (defun article-normalize-headers ()
2077 "Make all header lines 40 characters long."
2079 (let ((inhibit-read-only t)
2083 (article-narrow-to-head)
2086 ((< (setq column (- (point-at-eol) (point)))
2087 gnus-article-normalized-header-length)
2089 (insert (make-string
2090 (- gnus-article-normalized-header-length column)
2092 ((> column gnus-article-normalized-header-length)
2093 (gnus-put-text-property
2095 (forward-char gnus-article-normalized-header-length)
2102 (forward-line 1))))))
2104 (defun article-treat-dumbquotes ()
2105 "Translate M****s*** sm*rtq**t*s and other symbols into proper text.
2106 Note that this function guesses whether a character is a sm*rtq**t* or
2107 not, so it should only be used interactively.
2109 Sm*rtq**t*s are M****s***'s unilateral extension to the
2110 iso-8859-1 character map in an attempt to provide more quoting
2111 characters. If you see something like \\222 or \\264 where
2112 you're expecting some kind of apostrophe or quotation mark, then
2115 (article-translate-strings gnus-article-dumbquotes-map))
2117 (defvar org-entities)
2119 (defun article-treat-non-ascii ()
2120 "Translate many Unicode characters into their ASCII equivalents."
2122 (require 'org-entities)
2123 (let ((table (make-char-table (if (featurep 'xemacs) 'generic))))
2124 (dolist (elem org-entities)
2125 (when (and (listp elem)
2126 (= (length (nth 6 elem)) 1))
2127 (if (featurep 'xemacs)
2128 (put-char-table (aref (nth 6 elem) 0) (nth 4 elem) table)
2129 (set-char-table-range table (aref (nth 6 elem) 0) (nth 4 elem)))))
2131 (when (article-goto-body)
2132 (let ((inhibit-read-only t)
2135 (if (not (setq replace (if (featurep 'xemacs)
2136 (get-char-table (following-char) table)
2137 (aref table (following-char)))))
2140 (setq props (text-properties-at (point)))
2142 (add-text-properties (point) (progn (insert replace) (point))
2144 (insert replace)))))))))
2146 (defun article-translate-characters (from to)
2147 "Translate all characters in the body of the article according to FROM and TO.
2148 FROM is a string of characters to translate from; to is a string of
2149 characters to translate to."
2151 (when (article-goto-body)
2152 (let ((inhibit-read-only t)
2153 (x (make-string 225 ?x))
2155 (while (< (incf i) (length x))
2158 (while (< i (length from))
2159 (aset x (aref from i) (aref to i))
2161 (translate-region (point) (point-max) x)))))
2163 (defun article-translate-strings (map)
2164 "Translate all string in the body of the article according to MAP.
2165 MAP is an alist where the elements are on the form (\"from\" \"to\")."
2167 (when (article-goto-body)
2168 (let ((inhibit-read-only t))
2170 (let ((from (car elem))
2174 (while (search-forward from nil t)
2177 (if (eq (following-char) from)
2181 (forward-char 1)))))))))))
2183 (defun article-treat-overstrike ()
2184 "Translate overstrikes into bold text."
2187 (when (article-goto-body)
2188 (let ((inhibit-read-only t))
2189 (while (search-forward "\b" nil t)
2190 (let ((next (char-after))
2191 (previous (char-after (- (point) 2))))
2192 ;; We do the boldification/underlining by hiding the
2193 ;; overstrikes and putting the proper text property
2197 (gnus-article-hide-text-type (- (point) 2) (point) 'overstrike)
2198 (put-text-property (point) (1+ (point)) 'face 'bold))
2200 (gnus-article-hide-text-type
2201 (1- (point)) (1+ (point)) 'overstrike)
2203 (- (point) 2) (1- (point)) 'face 'underline))
2205 (gnus-article-hide-text-type (- (point) 2) (point) 'overstrike)
2207 (point) (1+ (point)) 'face 'underline)))))))))
2209 (defun article-treat-ansi-sequences ()
2210 "Translate ANSI SGR control sequences into overlays or extents."
2213 (when (article-goto-body)
2214 (let ((inhibit-read-only t))
2215 (ansi-color-apply-on-region (point) (point-max))))))
2217 (defun gnus-article-treat-unfold-headers ()
2218 "Unfold folded message headers.
2219 Only the headers that fit into the current window width will be
2222 (gnus-with-article-headers
2226 (mail-header-narrow-to-field)
2227 (let* ((header (buffer-string))
2229 (or (equal gnus-article-unfold-long-headers t)
2230 (and (stringp gnus-article-unfold-long-headers)
2231 (string-match gnus-article-unfold-long-headers header)))))
2234 (goto-char (point-min))
2235 (while (re-search-forward "\n[\t ]" nil t)
2236 (replace-match " " t t)))
2237 (setq length (- (point-max) (point-min) 1))
2238 (when (or unfoldable
2239 (< length (window-width)))
2240 (while (re-search-forward "\n[\t ]" nil t)
2241 (replace-match " " t t))))
2242 (goto-char (point-max)))))))
2244 (defun gnus-article-treat-fold-headers ()
2245 "Fold message headers."
2247 (gnus-with-article-headers
2250 (mail-header-narrow-to-field)
2251 (mail-header-fold-field)
2252 (goto-char (point-max))))))
2254 (defun gnus-treat-smiley ()
2255 "Toggle display of textual emoticons (\"smileys\") as small graphical icons."
2257 (gnus-with-article-buffer
2258 (if (memq 'smiley gnus-article-wash-types)
2259 (gnus-delete-images 'smiley)
2261 (let ((images (smiley-region (point) (point-max))))
2263 (gnus-add-wash-type 'smiley)
2264 (dolist (image images)
2265 (gnus-add-image 'smiley image)))))))
2267 (defun gnus-article-remove-images ()
2268 "Remove all images from the article buffer."
2270 (gnus-with-article-buffer
2271 (dolist (elem gnus-article-image-alist)
2272 (gnus-delete-images (car elem)))))
2274 (defun gnus-article-treat-fold-newsgroups ()
2275 "Unfold folded message headers.
2276 Only the headers that fit into the current window width will be
2279 (gnus-with-article-headers
2280 (while (gnus-article-goto-header "newsgroups\\|followup-to")
2282 (mail-header-narrow-to-field)
2283 (while (re-search-forward ", *" nil t)
2284 (replace-match ", " t t))
2285 (mail-header-fold-field)
2286 (goto-char (point-max))))))
2288 (defcustom gnus-article-truncate-lines (default-value 'truncate-lines)
2289 "Value of `truncate-lines' in Gnus Article buffer.
2290 Valid values are nil, t, `head', `first', `last', an integer or a
2291 predicate. See Info node `(gnus)Customizing Articles'."
2292 :version "23.1" ;; No Gnus
2293 :group 'gnus-article
2294 ;; :link '(custom-manual "(gnus)Customizing Articles")
2297 (defun gnus-article-toggle-truncate-lines (&optional arg)
2298 "Toggle whether to fold or truncate long lines in article the buffer.
2299 If ARG is non-nil and not a number, toggle
2300 `gnus-article-truncate-lines' too. If ARG is a number, truncate
2301 long lines if and only if arg is positive."
2304 ((and (numberp arg) (> arg 0))
2305 (setq gnus-article-truncate-lines t))
2307 (setq gnus-article-truncate-lines nil))
2309 (setq gnus-article-truncate-lines
2310 (not gnus-article-truncate-lines))))
2311 (gnus-with-article-buffer
2313 ((and (numberp arg) (> arg 0))
2314 (setq truncate-lines nil))
2316 (setq truncate-lines t)))
2317 ;; In versions of Emacs 22 (CVS) before 2006-05-26,
2318 ;; `toggle-truncate-lines' needs an argument.
2319 (toggle-truncate-lines)))
2321 (defun gnus-article-treat-body-boundary ()
2322 "Place a boundary line at the end of the headers."
2324 (when (and gnus-body-boundary-delimiter
2325 (> (length gnus-body-boundary-delimiter) 0))
2326 (gnus-with-article-headers
2327 (goto-char (point-max))
2328 (let ((start (point)))
2329 (insert "X-Boundary: ")
2330 (gnus-add-text-properties start (point) '(invisible t intangible t))
2332 (while (>= (window-width) (length str))
2333 (setq str (concat str gnus-body-boundary-delimiter)))
2334 (substring str 0 (window-width)))
2336 (gnus-put-text-property start (point) 'gnus-decoration 'header)))))
2338 (defun article-fill-long-lines ()
2339 "Fill lines that are wider than the window width."
2342 (let ((inhibit-read-only t)
2343 (width (window-width (get-buffer-window (current-buffer)))))
2346 (let ((adaptive-fill-mode nil)) ;Why? -sm
2349 (when (>= (current-column) (min fill-column width))
2350 (narrow-to-region (min (1+ (point)) (point-max))
2352 (let ((goback (point-marker)))
2353 (fill-paragraph nil)
2354 (goto-char (marker-position goback)))
2356 (forward-line 1)))))))
2358 (defun article-capitalize-sentences ()
2359 "Capitalize the first word in each sentence."
2362 (let ((inhibit-read-only t)
2363 (paragraph-start "^[\n\^L]"))
2367 (forward-sentence)))))
2369 (defun article-remove-cr ()
2370 "Remove trailing CRs and then translate remaining CRs into LFs."
2373 (let ((inhibit-read-only t))
2374 (goto-char (point-min))
2375 (while (re-search-forward "\r+$" nil t)
2376 (replace-match "" t t))
2377 (goto-char (point-min))
2378 (while (search-forward "\r" nil t)
2379 (replace-match "\n" t t)))))
2381 (defun article-remove-trailing-blank-lines ()
2382 "Remove all trailing blank lines from the article."
2385 (let ((inhibit-read-only t))
2386 (goto-char (point-max))
2390 (while (and (not (bobp))
2391 (looking-at "^[ \t]*$")
2392 (not (gnus-annotation-in-region-p
2393 (point) (point-at-eol))))
2398 (defvar gnus-face-properties-alist)
2400 (defun article-display-face (&optional force)
2401 "Display any Face headers in the header."
2402 (interactive (list 'force))
2403 (let ((wash-face-p buffer-read-only))
2404 (gnus-with-article-headers
2405 ;; When displaying parts, this function can be called several times on
2406 ;; the same article, without any intended toggle semantic (as typing `W
2407 ;; D d' would have). So face deletion must occur only when we come from
2408 ;; an interactive command, that is when the *Article* buffer is
2410 (if (and wash-face-p (memq 'face gnus-article-wash-types))
2411 (gnus-delete-images 'face)
2412 (let ((from (message-fetch-field "from"))
2414 (save-current-buffer
2415 (when (and wash-face-p
2416 (gnus-buffer-live-p gnus-original-article-buffer)
2417 (not (re-search-forward "^Face:[\t ]*" nil t)))
2418 (set-buffer gnus-original-article-buffer))
2420 (mail-narrow-to-head)
2422 ;; Check whether this face is censored.
2423 (not (and gnus-article-x-face-too-ugly
2425 (setq from (message-fetch-field "from")))
2426 (string-match gnus-article-x-face-too-ugly
2428 (while (gnus-article-goto-header "Face")
2429 (push (mail-header-field-value) faces)))))
2431 (goto-char (point-min))
2433 (unless (setq from (gnus-article-goto-header "from"))
2436 (insert " [no `from' set]\n"))
2438 (when (setq png (gnus-convert-face-to-png (pop faces)))
2440 (apply 'gnus-create-image png 'png t
2441 (cdr (assq 'png gnus-face-properties-alist))))
2443 (gnus-add-wash-type 'face)
2444 (gnus-add-image 'face image)
2445 (gnus-put-image image nil 'face))))))))))
2447 (defun article-display-x-face (&optional force)
2448 "Look for an X-Face header and display it if present."
2449 (interactive (list 'force))
2450 (let ((wash-face-p buffer-read-only)) ;; When type `W f'
2451 (gnus-with-article-headers
2452 ;; Delete the old process, if any.
2453 (when (process-status "article-x-face")
2454 (delete-process "article-x-face"))
2455 ;; See the comment in `article-display-face'.
2456 (if (and wash-face-p (memq 'xface gnus-article-wash-types))
2457 ;; We have already displayed X-Faces, so we remove them
2459 (gnus-delete-images 'xface)
2461 (let ((from (message-fetch-field "from"))
2463 (save-current-buffer
2464 (when (and wash-face-p
2465 (gnus-buffer-live-p gnus-original-article-buffer)
2466 (not (re-search-forward "^X-Face:[\t ]*" nil t)))
2467 ;; If type `W f', use gnus-original-article-buffer,
2468 ;; otherwise use the current buffer because displaying
2469 ;; RFC822 parts calls this function too.
2470 (set-buffer gnus-original-article-buffer))
2472 (mail-narrow-to-head)
2473 (and gnus-article-x-face-command
2475 ;; Check whether this face is censored.
2476 (not (and gnus-article-x-face-too-ugly
2478 (setq from (message-fetch-field "from")))
2479 (string-match gnus-article-x-face-too-ugly
2481 (while (gnus-article-goto-header "X-Face")
2482 (push (mail-header-field-value) x-faces)))))
2484 ;; We display the face.
2485 (cond ((functionp gnus-article-x-face-command)
2486 ;; The command is a lisp function, so we call it.
2487 (mapc gnus-article-x-face-command x-faces))
2488 ((stringp gnus-article-x-face-command)
2489 ;; The command is a string, so we interpret the command
2490 ;; as a, well, command, and fork it off.
2491 (let ((process-connection-type nil))
2492 (gnus-set-process-query-on-exit-flag
2494 "article-x-face" nil shell-file-name
2495 shell-command-switch gnus-article-x-face-command)
2497 ;; Sending multiple EOFs to xv doesn't work,
2498 ;; so we only do a single external face.
2500 (insert (car x-faces))
2501 (process-send-region "article-x-face"
2502 (point-min) (point-max)))
2503 (process-send-eof "article-x-face")))
2505 (error "`%s' set to `%s' is not a function"
2506 gnus-article-x-face-command
2507 'gnus-article-x-face-command)))))))))
2509 (defun article-decode-mime-words ()
2510 "Decode all MIME-encoded words in the article."
2512 (gnus-with-article-buffer
2513 (let ((inhibit-point-motion-hooks t)
2514 (mail-parse-charset gnus-newsgroup-charset)
2515 (mail-parse-ignored-charsets
2516 (with-current-buffer gnus-summary-buffer
2517 gnus-newsgroup-ignored-charsets)))
2518 (mail-decode-encoded-word-region (point-min) (point-max)))))
2520 (defun article-decode-charset (&optional prompt)
2521 "Decode charset-encoded text in the article.
2522 If PROMPT (the prefix), prompt for a coding system to use."
2524 (let ((inhibit-point-motion-hooks t) (case-fold-search t)
2525 (inhibit-read-only t)
2526 (mail-parse-charset gnus-newsgroup-charset)
2527 (mail-parse-ignored-charsets
2528 (save-excursion (condition-case nil
2529 (set-buffer gnus-summary-buffer)
2531 gnus-newsgroup-ignored-charsets))
2532 ct cte ctl charset format)
2535 (article-narrow-to-head)
2536 (setq ct (message-fetch-field "Content-Type" t)
2537 cte (message-fetch-field "Content-Transfer-Encoding" t)
2538 ctl (and ct (mail-header-parse-content-type ct))
2541 (mm-read-coding-system "Charset to decode: "))
2543 (mail-content-type-get ctl 'charset)))
2544 format (and ctl (mail-content-type-get ctl 'format)))
2546 (setq cte (mail-header-strip cte)))
2547 (if (and ctl (not (string-match "/" (car ctl))))
2549 (goto-char (point-max)))
2552 (narrow-to-region (point) (point-max))
2553 (when (and (eq mail-parse-charset 'gnus-decoded)
2554 (eq (mm-body-7-or-8) '8bit))
2555 ;; The text code could have been decoded.
2556 (setq charset mail-parse-charset))
2557 (when (and (or (not ctl)
2558 (equal (car ctl) "text/plain"))
2559 (not format)) ;; article with format will decode later.
2561 charset (and cte (intern (downcase
2562 (gnus-strip-whitespace cte))))
2565 (defun article-decode-encoded-words ()
2566 "Remove encoded-word encoding from headers."
2567 (let ((inhibit-point-motion-hooks t)
2568 (mail-parse-charset gnus-newsgroup-charset)
2569 (mail-parse-ignored-charsets
2570 (save-excursion (condition-case nil
2571 (set-buffer gnus-summary-buffer)
2573 gnus-newsgroup-ignored-charsets))
2574 (inhibit-read-only t)
2576 (goto-char (point-min))
2577 (when (search-forward "\n\n" nil 'move)
2584 (memq (char-after) '(?\t ? )))))
2585 (setq start (point))
2587 \\(?:Resent-\\)?\\(?:From\\|Cc\\|To\\|Bcc\\|\\(?:In-\\)?Reply-To\\|Sender\
2588 \\|Mail-Followup-To\\|Mail-Copies-To\\|Approved\\):")
2589 (funcall gnus-decode-address-function start end)
2590 (funcall gnus-decode-header-function start end))
2591 (goto-char (setq end start)))))
2593 (defun article-decode-group-name ()
2594 "Decode group names in Newsgroups, Followup-To and Xref headers."
2595 (let ((inhibit-point-motion-hooks t)
2596 (inhibit-read-only t)
2597 (method (gnus-find-method-for-group gnus-newsgroup-name))
2599 (when (and (or gnus-group-name-charset-method-alist
2600 gnus-group-name-charset-group-alist)
2601 (gnus-buffer-live-p gnus-original-article-buffer))
2603 (article-narrow-to-head)
2604 (dolist (header '("Newsgroups" "Followup-To" "Xref"))
2605 (with-current-buffer gnus-original-article-buffer
2606 (goto-char (point-min)))
2607 (setq regexp (concat "^" header
2608 ":\\([^\n]*\\(?:\n[\t ]+[^\n]+\\)*\\)\n"))
2609 (while (re-search-forward regexp nil t)
2610 (replace-match (save-match-data
2611 (gnus-decode-newsgroups
2612 ;; XXX how to use data in article buffer?
2613 (with-current-buffer gnus-original-article-buffer
2614 (re-search-forward regexp nil t)
2616 gnus-newsgroup-name method))
2618 (goto-char (point-min)))))))
2620 (autoload 'idna-to-unicode "idna")
2622 (defun article-decode-idna-rhs ()
2623 "Decode IDNA strings in RHS in various headers in current buffer.
2624 The following headers are decoded: From:, To:, Cc:, Reply-To:,
2625 Mail-Reply-To: and Mail-Followup-To:."
2628 (let ((inhibit-point-motion-hooks t)
2629 (inhibit-read-only t))
2630 (article-narrow-to-head)
2631 (goto-char (point-min))
2632 (while (re-search-forward "@[^ \t\n\r,>]*\\(xn--[-A-Za-z0-9.]*\\)[ \t\n\r,>]" nil t)
2634 (when (save-match-data
2635 (and (setq ace (match-string 1))
2637 (and (re-search-backward "^[^ \t]" nil t)
2638 (looking-at "From\\|To\\|Cc\\|Reply-To\\|Mail-Reply-To\\|Mail-Followup-To")))
2639 (setq unicode (idna-to-unicode ace))))
2640 (unless (string= ace unicode)
2641 (replace-match unicode nil nil nil 1)))))))))
2643 (defun article-de-quoted-unreadable (&optional force read-charset)
2644 "Translate a quoted-printable-encoded article.
2645 If FORCE, decode the article whether it is marked as quoted-printable
2647 If READ-CHARSET, ask for a coding system."
2648 (interactive (list 'force current-prefix-arg))
2650 (let ((inhibit-read-only t) type charset)
2651 (if (gnus-buffer-live-p gnus-original-article-buffer)
2652 (with-current-buffer gnus-original-article-buffer
2654 (gnus-fetch-field "content-transfer-encoding"))
2655 (let* ((ct (gnus-fetch-field "content-type"))
2656 (ctl (and ct (mail-header-parse-content-type ct))))
2657 (setq charset (and ctl
2658 (mail-content-type-get ctl 'charset)))
2659 (if (stringp charset)
2660 (setq charset (intern (downcase charset)))))))
2662 (setq charset (mm-read-coding-system "Charset: " charset)))
2664 (setq charset gnus-newsgroup-charset))
2666 (and type (let ((case-fold-search t))
2667 (string-match "quoted-printable" type))))
2669 (quoted-printable-decode-region
2670 (point) (point-max) (mm-charset-to-coding-system charset))))))
2672 (defun article-de-base64-unreadable (&optional force read-charset)
2673 "Translate a base64 article.
2674 If FORCE, decode the article whether it is marked as base64 not.
2675 If READ-CHARSET, ask for a coding system."
2676 (interactive (list 'force current-prefix-arg))
2678 (let ((inhibit-read-only t) type charset)
2679 (if (gnus-buffer-live-p gnus-original-article-buffer)
2680 (with-current-buffer gnus-original-article-buffer
2682 (gnus-fetch-field "content-transfer-encoding"))
2683 (let* ((ct (gnus-fetch-field "content-type"))
2684 (ctl (and ct (mail-header-parse-content-type ct))))
2685 (setq charset (and ctl
2686 (mail-content-type-get ctl 'charset)))
2687 (if (stringp charset)
2688 (setq charset (intern (downcase charset)))))))
2690 (setq charset (mm-read-coding-system "Charset: " charset)))
2692 (setq charset gnus-newsgroup-charset))
2694 (and type (let ((case-fold-search t))
2695 (string-match "base64" type))))
2698 (narrow-to-region (point) (point-max))
2699 (base64-decode-region (point-min) (point-max))
2700 (mm-decode-coding-region
2701 (point-min) (point-max) (mm-charset-to-coding-system charset)))))))
2706 (defun article-decode-HZ ()
2707 "Translate a HZ-encoded article."
2711 (let ((inhibit-read-only t))
2712 (rfc1843-decode-region (point-min) (point-max)))))
2714 (defun article-unsplit-urls ()
2715 "Remove the newlines that some other mailers insert into URLs."
2718 (let ((inhibit-read-only t))
2719 (goto-char (point-min))
2720 (while (re-search-forward
2721 "\\(\\(https?\\|ftp\\)://\\S-+\\) *\n\\(\\S-+\\)" nil t)
2722 (replace-match "\\1\\3" t)))
2723 (when (interactive-p)
2724 (gnus-treat-article nil))))
2726 (defun article-wash-html ()
2727 "Format an HTML article."
2730 (buffer-read-only nil))
2731 (when (gnus-buffer-live-p gnus-original-article-buffer)
2732 (setq handles (mm-dissect-buffer t t)))
2734 (delete-region (point) (point-max))
2735 (mm-inline-text-html handles)))
2737 (defvar gnus-article-browse-html-temp-list nil
2738 "List of temporary files created by `gnus-article-browse-html-parts'.
2739 Internal variable.")
2741 (defcustom gnus-article-browse-delete-temp 'ask
2742 "What to do with temporary files from `gnus-article-browse-html-parts'.
2743 If nil, don't delete temporary files. If it is t, delete them on
2744 exit from the summary buffer. If it is the symbol `file', query
2745 on each file, if it is `ask' ask once when exiting from the
2747 :group 'gnus-article
2748 :version "23.1" ;; No Gnus
2749 :type '(choice (const :tag "Don't delete" nil)
2750 (const :tag "Don't ask" t)
2751 (const :tag "Ask" ask)
2752 (const :tag "Ask for each file" file)))
2754 ;; Cf. mm-postponed-undisplay-list / mm-destroy-postponed-undisplay-list.
2756 (defun gnus-article-browse-delete-temp-files (&optional how)
2757 "Delete temp-files created by `gnus-article-browse-html-parts'."
2758 (when (and gnus-article-browse-html-temp-list
2760 (or how (setq how gnus-article-browse-delete-temp))
2762 (let ((files (length gnus-article-browse-html-temp-list)))
2763 (gnus-y-or-n-p (format
2764 "Delete all %s temporary HTML file%s? "
2766 (if (> files 1) "s" ""))))
2768 (dolist (file gnus-article-browse-html-temp-list)
2769 (cond ((file-directory-p file)
2770 (when (or (not (eq how 'file))
2773 "Delete temporary HTML file(s) in directory `%s'? "
2774 (file-name-as-directory file))))
2775 (gnus-delete-directory file)))
2776 ((file-exists-p file)
2777 (when (or (not (eq how 'file))
2779 (format "Delete temporary HTML file `%s'? " file)))
2780 (delete-file file)))))
2781 ;; Also remove file from the list when not deleted or if file doesn't
2783 (setq gnus-article-browse-html-temp-list nil))
2784 gnus-article-browse-html-temp-list)
2786 (defun gnus-article-browse-html-save-cid-content (cid handles directory)
2787 "Find CID content in HANDLES and save it in a file in DIRECTORY.
2792 (dolist (handle handles)
2794 ((not (listp handle)))
2795 ((equal (mm-handle-media-supertype handle) "multipart")
2796 (when (setq file (gnus-article-browse-html-save-cid-content
2797 cid handle directory))
2798 (throw 'found file)))
2799 ((equal (concat "<" cid ">") (mm-handle-id handle))
2802 (or (mail-content-type-get
2803 (mm-handle-disposition handle) 'filename)
2804 (mail-content-type-get
2805 (setq type (mm-handle-type handle)) 'name)
2807 (make-temp-name "cid")
2808 (car (rassoc (car type) mailcap-mime-extensions))))
2810 (mm-save-part-to-file handle file)
2811 (throw 'found file))))))))
2813 (defun gnus-article-browse-html-parts (list &optional header)
2814 "View all \"text/html\" parts from LIST.
2815 Recurse into multiparts. The optional HEADER that should be a decoded
2816 message header will be added to the bodies of the \"text/html\" parts."
2817 ;; Internal function used by `gnus-article-browse-html-article'.
2818 (let (type file charset content cid-dir tmp-file showed)
2819 ;; Find and show the html-parts.
2820 (dolist (handle list)
2821 ;; If HTML, show it:
2822 (cond ((not (listp handle)))
2823 ((or (equal (car (setq type (mm-handle-type handle))) "text/html")
2824 (and (equal (car type) "message/external-body")
2826 (setq file (or (mail-content-type-get type 'name)
2827 (mail-content-type-get
2828 (mm-handle-disposition handle)
2830 (or (mm-handle-cache handle)
2831 (condition-case code
2832 (progn (mm-extern-cache-contents handle) t)
2834 (gnus-message 3 "%s" (error-message-string code))
2835 (when (>= gnus-verbose 3) (sit-for 2))
2838 (setq handle (mm-handle-cache handle)
2839 type (mm-handle-type handle))
2840 (equal (car type) "text/html"))))
2841 (setq charset (mail-content-type-get type 'charset)
2842 content (mm-get-part handle))
2844 (if (eq charset 'gnus-decoded)
2845 (mm-enable-multibyte)
2846 (mm-disable-multibyte))
2848 ;; resolve cid contents
2849 (let ((case-fold-search t)
2851 (goto-char (point-min))
2852 (while (re-search-forward "\
2853 <img[\t\n ]+\\(?:[^\t\n >]+[\t\n ]+\\)*src=\"\\(cid:\\([^\"]+\\)\\)\""
2856 (setq cid-dir (mm-make-temp-file "cid" t))
2857 (add-to-list 'gnus-article-browse-html-temp-list cid-dir))
2860 (when (setq cid-file
2861 (gnus-article-browse-html-save-cid-content
2863 (with-current-buffer gnus-article-buffer
2864 gnus-article-mime-handles)
2866 (replace-match (concat "file://" cid-file)
2868 (unless content (setq content (buffer-string))))
2869 (when (or charset header (not file))
2870 (setq tmp-file (mm-make-temp-file
2871 ;; Do we need to care for 8.3 filenames?
2872 "mm-" nil ".html")))
2873 ;; Add a meta html tag to specify charset and a header.
2876 (let (title eheader body hcharset coding force-charset)
2878 (mm-enable-multibyte)
2879 (setq case-fold-search t)
2880 (insert header "\n")
2881 (setq title (message-fetch-field "subject"))
2882 (goto-char (point-min))
2883 (while (re-search-forward "\\(<\\)\\|\\(>\\)\\|&" nil t)
2884 (replace-match (cond ((match-beginning 1) "<")
2885 ((match-beginning 2) ">")
2887 (goto-char (point-min))
2889 (goto-char (point-max))
2890 (insert "</pre>\n<hr>\n")
2891 ;; We have to examine charset one by one since
2892 ;; charset specified in parts might be different.
2893 (if (eq charset 'gnus-decoded)
2894 (setq charset 'utf-8
2895 eheader (mm-encode-coding-string (buffer-string)
2898 (mm-encode-coding-string title charset))
2899 body (mm-encode-coding-string content charset)
2901 (setq hcharset (mm-find-mime-charset-region (point-min)
2903 (cond ((= (length hcharset) 1)
2904 (setq hcharset (car hcharset)
2905 coding (mm-charset-to-coding-system
2907 ((> (length hcharset) 1)
2908 (setq hcharset 'utf-8
2914 (mm-charset-to-coding-system charset))
2915 (if (eq coding body)
2916 (setq eheader (mm-encode-coding-string
2917 (buffer-string) coding)
2919 (mm-encode-coding-string
2922 (setq charset 'utf-8
2923 eheader (mm-encode-coding-string
2924 (buffer-string) charset)
2926 (mm-encode-coding-string
2928 body (mm-encode-coding-string
2929 (mm-decode-coding-string
2933 (setq charset hcharset
2934 eheader (mm-encode-coding-string
2935 (buffer-string) coding)
2937 (mm-encode-coding-string
2940 (setq eheader (mm-string-as-unibyte (buffer-string))
2943 (mm-disable-multibyte)
2946 (mm-add-meta-html-tag handle charset force-charset))
2948 (goto-char (point-min))
2949 (unless (search-forward "<title>" nil t)
2950 (re-search-forward "<head>\\s-*" nil t)
2951 (insert "<title>" title "</title>\n")))
2952 (goto-char (point-min))
2953 (or (re-search-forward
2954 "<body\\(?:\\s-+[^>]+\\|\\s-*\\)>\\s-*" nil t)
2956 "</head\\(?:\\s-+[^>]+\\|\\s-*\\)>\\s-*" nil t))
2958 (mm-write-region (point-min) (point-max)
2959 tmp-file nil nil nil 'binary t))))
2961 (mm-with-unibyte-buffer
2962 (insert (if (eq charset 'gnus-decoded)
2963 (mm-encode-coding-string content
2964 (setq charset 'utf-8))
2966 (if (or (mm-add-meta-html-tag handle charset)
2968 (mm-write-region (point-min) (point-max)
2969 tmp-file nil nil nil 'binary t)
2970 (setq tmp-file nil))))
2972 (mm-save-part-to-file handle tmp-file)))
2974 (add-to-list 'gnus-article-browse-html-temp-list tmp-file))
2975 (add-hook 'gnus-summary-prepare-exit-hook
2976 'gnus-article-browse-delete-temp-files)
2977 (add-hook 'gnus-exit-gnus-hook
2979 (gnus-article-browse-delete-temp-files t)))
2980 ;; FIXME: Warn if there's an <img> tag?
2981 (browse-url-of-file (or tmp-file (expand-file-name file)))
2983 ;; If multipart, recurse
2984 ((equal (mm-handle-media-supertype handle) "multipart")
2985 (when (gnus-article-browse-html-parts handle header)
2987 ((equal (mm-handle-media-type handle) "message/rfc822")
2988 (mm-with-multibyte-buffer
2989 (mm-insert-part handle)
2990 (setq handle (mm-dissect-buffer t t))
2991 (when (and (bufferp (car handle))
2992 (stringp (car (mm-handle-type handle))))
2993 (setq handle (list handle)))
2995 (article-decode-encoded-words)
2996 (let ((gnus-visible-headers
2997 (or (get 'gnus-visible-headers 'standard-value)
2998 gnus-visible-headers)))
2999 (article-hide-headers))
3000 (goto-char (point-min))
3001 (search-forward "\n\n" nil 'move)
3002 (skip-chars-backward "\t\n ")
3003 (setq header (buffer-substring (point-min) (point)))))
3005 (gnus-article-browse-html-parts handle header)
3006 (mm-destroy-parts handle))
3010 (defun gnus-article-browse-html-article (&optional arg)
3011 "View \"text/html\" parts of the current article with a WWW browser.
3012 Inline images embedded in a message using the cid scheme, as they are
3013 generally considered to be safe, will be processed properly.
3014 The message header is added to the beginning of every html part unless
3015 the prefix argument ARG is given.
3017 Warning: Spammers use links to images (using the http scheme) in HTML
3018 articles to verify whether you have read the message. As
3019 `gnus-article-browse-html-article' passes the HTML content to the
3020 browser without eliminating these \"web bugs\" you should only
3021 use it for mails from trusted senders.
3023 If you always want to display HTML parts in the browser, set
3024 `mm-text-html-renderer' to nil.
3026 This command creates temporary files to pass HTML contents including
3027 images if any to the browser, and deletes them when exiting the group
3029 ;; Cf. `mm-w3m-safe-url-regexp'
3032 (gnus-summary-show-article)
3033 (let ((gnus-visible-headers (or (get 'gnus-visible-headers 'standard-value)
3034 gnus-visible-headers))
3035 ;; As we insert a <hr>, there's no need for the body boundary.
3036 (gnus-treat-body-boundary nil))
3037 (gnus-summary-show-article)))
3038 (with-current-buffer gnus-article-buffer
3039 (let ((header (unless arg
3042 (buffer-substring-no-properties
3043 (goto-char (point-min))
3044 (if (search-forward "\n\n" nil t)
3046 (goto-char (point-max))
3047 (skip-chars-backward "\t\n ")
3050 (set-buffer gnus-original-article-buffer)
3051 (setq parts (mm-dissect-buffer t t))
3052 ;; If singlepart, enforce a list.
3053 (when (and (bufferp (car parts))
3054 (stringp (car (mm-handle-type parts))))
3055 (setq parts (list parts)))
3057 (unless (gnus-article-browse-html-parts parts header)
3058 (gnus-error 3 "Mail doesn't contain a \"text/html\" part!"))
3059 (mm-destroy-parts parts)
3061 (gnus-summary-show-article)))))
3063 (defun article-hide-list-identifiers ()
3064 "Remove list identifies from the Subject header.
3065 The `gnus-list-identifiers' variable specifies what to do."
3067 (let ((inhibit-point-motion-hooks t)
3068 (regexp (if (consp gnus-list-identifiers)
3069 (mapconcat 'identity gnus-list-identifiers " *\\|")
3070 gnus-list-identifiers))
3071 (inhibit-read-only t))
3075 (article-narrow-to-head)
3076 (goto-char (point-min))
3077 (while (re-search-forward
3078 (concat "^Subject: +\\(R[Ee]: +\\)*\\(" regexp " *\\)")
3080 (delete-region (match-beginning 2) (match-end 0))
3081 (beginning-of-line))
3082 (when (re-search-forward
3083 "^Subject: +\\(\\(R[Ee]: +\\)+\\)R[Ee]: +" nil t)
3084 (delete-region (match-beginning 1) (match-end 1))))))))
3086 (defun article-hide-pem (&optional arg)
3087 "Toggle hiding of any PEM headers and signatures in the current article.
3088 If given a negative prefix, always show; if given a positive prefix,
3090 (interactive (gnus-article-hidden-arg))
3091 (unless (gnus-article-check-hidden-text 'pem arg)
3093 (let ((inhibit-read-only t) end)
3094 (goto-char (point-min))
3095 ;; Hide the horrendously ugly "header".
3096 (when (and (search-forward
3097 "\n-----BEGIN PRIVACY-ENHANCED MESSAGE-----\n"
3099 (setq end (1+ (match-beginning 0))))
3100 (gnus-add-wash-type 'pem)
3101 (gnus-article-hide-text-type
3103 (if (search-forward "\n\n" nil t)
3107 ;; Hide the trailer as well
3108 (when (search-forward "\n-----END PRIVACY-ENHANCED MESSAGE-----\n"
3110 (gnus-article-hide-text-type
3111 (match-beginning 0) (match-end 0) 'pem)))))))
3113 (defun article-strip-banner ()
3114 "Strip the banners specified by the `banner' group parameter and by
3115 `gnus-article-address-banner-alist'."
3119 (let ((inhibit-point-motion-hooks t))
3120 (when (gnus-parameter-banner gnus-newsgroup-name)
3121 (article-really-strip-banner
3122 (gnus-parameter-banner gnus-newsgroup-name)))
3123 (when gnus-article-address-banner-alist
3124 ;; Note that the From header is decoded here, so it is
3125 ;; required that the *-extract-address-components function
3126 ;; supports non-ASCII text.
3127 (let ((from (save-restriction
3129 (article-narrow-to-head)
3130 (mail-fetch-field "from"))))
3133 (cadr (funcall gnus-extract-address-components
3136 (dolist (pair gnus-article-address-banner-alist)
3137 (when (string-match (car pair) from)
3139 (article-really-strip-banner (cdr pair)))))))))))))
3141 (defun article-really-strip-banner (banner)
3142 "Strip the banner specified by the argument."
3145 (let ((inhibit-point-motion-hooks t)
3146 (gnus-signature-limit nil)
3147 (inhibit-read-only t))
3150 ((eq banner 'signature)
3151 (when (gnus-article-narrow-to-signature)
3154 (delete-region (point) (point-max))))
3156 (if (setq banner (cdr (assq banner gnus-article-banner-alist)))
3157 (while (re-search-forward banner nil t)
3158 (delete-region (match-beginning 0) (match-end 0)))))
3160 (while (re-search-forward banner nil t)
3161 (delete-region (match-beginning 0) (match-end 0)))))))))
3163 (defun article-babel ()
3164 "Translate article using an online translation service."
3167 (gnus-with-article-buffer
3168 (when (article-goto-body)
3169 (let* ((start (point))
3171 (orig (buffer-substring start end))
3172 (trans (babel-as-string orig)))
3174 (narrow-to-region start end)
3175 (delete-region start end)
3178 (defun article-hide-signature (&optional arg)
3179 "Hide the signature in the current article.
3180 If given a negative prefix, always show; if given a positive prefix,
3182 (interactive (gnus-article-hidden-arg))
3183 (unless (gnus-article-check-hidden-text 'signature arg)
3186 (let ((inhibit-read-only t))
3187 (when (gnus-article-narrow-to-signature)
3188 (gnus-article-hide-text-type
3189 (point-min) (point-max) 'signature))))))
3190 (gnus-set-mode-line 'article))
3192 (defun article-strip-headers-in-body ()
3193 "Strip offensive headers from bodies."
3197 (let ((case-fold-search t))
3198 (when (looking-at "x-no-archive:")
3199 (gnus-delete-line)))))
3201 (defun article-strip-leading-blank-lines ()
3202 "Remove all blank lines from the beginning of the article."
3205 (let ((inhibit-point-motion-hooks t)
3206 (inhibit-read-only t))
3207 (when (article-goto-body)
3208 (while (and (not (eobp))
3209 (looking-at "[ \t]*$"))
3210 (gnus-delete-line))))))
3212 (defun article-narrow-to-head ()
3213 "Narrow the buffer to the head of the message.
3214 Point is left at the beginning of the narrowed-to region."
3216 (goto-char (point-min))
3217 (if (search-forward "\n\n" nil 1)
3220 (goto-char (point-min)))
3222 (defun article-goto-body ()
3223 "Place point at the start of the body."
3224 (goto-char (point-min))
3226 ;; This variable is only bound when dealing with separate
3228 (article-goto-body-goes-to-point-min-p
3230 ((search-forward "\n\n" nil t)
3233 (goto-char (point-max))
3236 (defun article-strip-multiple-blank-lines ()
3237 "Replace consecutive blank lines with one empty line."
3240 (let ((inhibit-point-motion-hooks t)
3241 (inhibit-read-only t))
3242 ;; First make all blank lines empty.
3244 (while (re-search-forward "^[ \t]+$" nil t)
3245 (unless (gnus-annotation-in-region-p
3246 (match-beginning 0) (match-end 0))
3247 (replace-match "" nil t)))
3248 ;; Then replace multiple empty lines with a single empty line.
3250 (while (re-search-forward "\n\n\\(\n+\\)" nil t)
3251 (unless (gnus-annotation-in-region-p
3252 (match-beginning 0) (match-end 0))
3253 (delete-region (match-beginning 1) (match-end 1)))))))
3255 (defun article-strip-leading-space ()
3256 "Remove all white space from the beginning of the lines in the article."
3259 (let ((inhibit-point-motion-hooks t)
3260 (inhibit-read-only t))
3262 (while (re-search-forward "^[ \t]+" nil t)
3263 (replace-match "" t t)))))
3265 (defun article-strip-trailing-space ()
3266 "Remove all white space from the end of the lines in the article."
3269 (let ((inhibit-point-motion-hooks t)
3270 (inhibit-read-only t))
3272 (while (re-search-forward "[ \t]+$" nil t)
3273 (replace-match "" t t)))))
3275 (defun article-strip-blank-lines ()
3276 "Strip leading, trailing and multiple blank lines."
3278 (article-strip-leading-blank-lines)
3279 (article-remove-trailing-blank-lines)
3280 (article-strip-multiple-blank-lines))
3282 (defun article-strip-all-blank-lines ()
3283 "Strip all blank lines."
3286 (let ((inhibit-point-motion-hooks t)
3287 (inhibit-read-only t))
3289 (while (re-search-forward "^[ \t]*\n" nil t)
3290 (replace-match "" t t)))))
3292 (defun gnus-article-narrow-to-signature ()
3293 "Narrow to the signature; return t if a signature is found, else nil."
3294 (let ((inhibit-point-motion-hooks t))
3295 (when (gnus-article-search-signature)
3297 ;; Check whether we have some limits to what we consider
3298 ;; to be a signature.
3299 (let ((limits (if (listp gnus-signature-limit) gnus-signature-limit
3300 (list gnus-signature-limit)))
3302 (while (setq limit (pop limits))
3303 (if (or (and (integerp limit)
3304 (< (- (point-max) (point)) limit))
3306 (< (count-lines (point) (point-max)) limit))
3307 (and (functionp limit)
3309 (and (stringp limit)
3310 (not (re-search-forward limit nil t))))
3311 () ; This limit did not succeed.
3315 (narrow-to-region (point) (point-max))
3318 (defun gnus-article-search-signature ()
3319 "Search the current buffer for the signature separator.
3320 Put point at the beginning of the signature separator."
3321 (let ((cur (point)))
3322 (goto-char (point-max))
3323 (if (if (stringp gnus-signature-separator)
3324 (re-search-backward gnus-signature-separator nil t)
3325 (let ((seps gnus-signature-separator))
3327 (not (re-search-backward (car seps) nil t)))
3334 (defun gnus-article-hidden-arg ()
3335 "Return the current prefix arg as a number, or 0 if no prefix."
3336 (list (if current-prefix-arg
3337 (prefix-numeric-value current-prefix-arg)
3340 (defun gnus-article-check-hidden-text (type arg)
3341 "Return nil if hiding is necessary.
3342 Arg can be nil or a number. nil and positive means hide, negative
3343 means show, 0 means toggle."
3346 (let ((hide (gnus-article-hidden-text-p type)))
3352 (gnus-article-show-hidden-text type)
3355 (if (eq hide 'hidden)
3357 (gnus-article-show-hidden-text type)
3361 (defun gnus-article-hidden-text-p (type)
3362 "Say whether the current buffer contains hidden text of type TYPE."
3363 (let ((pos (text-property-any (point-min) (point-max) 'article-type type)))
3365 (not (get-text-property pos 'invisible))
3366 (not (get-text-property pos 'dummy-invisible)))
3368 (text-property-any (1+ pos) (point-max) 'article-type type)))
3373 (defun gnus-article-show-hidden-text (type &optional dummy)
3374 "Show all hidden text of type TYPE.
3375 Originally it is hide instead of DUMMY."
3376 (let ((inhibit-read-only t)
3377 (inhibit-point-motion-hooks t))
3378 (gnus-remove-text-properties-when
3380 (point-min) (point-max)
3381 (cons 'article-type (cons type
3382 gnus-hidden-properties)))
3383 (gnus-delete-wash-type type)))
3385 (defconst article-time-units
3386 `((year . ,(* 365.25 24 60 60))
3387 (week . ,(* 7 24 60 60))
3388 (day . ,(* 24 60 60))
3392 "Mapping from time units to seconds.")
3394 (defun gnus-article-forward-header ()
3395 "Move point to the start of the next header.
3396 If the current header is a continuation header, this can be several
3401 (if (looking-at "[ \t]+[^ \t]")
3405 (defun article-date-ut (&optional type highlight)
3406 "Convert DATE date to universal time in the current article.
3407 If TYPE is `local', convert to local time; if it is `lapsed', output
3408 how much time has lapsed since DATE. For `lapsed', the value of
3409 `gnus-article-date-lapsed-new-header' says whether the \"X-Sent:\" header
3410 should replace the \"Date:\" one, or should be added below it."
3411 (interactive (list 'ut t))
3412 (let* ((tdate-regexp "^Date:[ \t]\\|^X-Sent:[ \t]")
3413 (date-regexp (cond ((not gnus-article-date-lapsed-new-header)
3417 (article-lapsed-timer
3421 (case-fold-search t)
3422 (inhibit-read-only t)
3423 (inhibit-point-motion-hooks t)
3424 pos date bface eface)
3428 (goto-char (point-min))
3429 (while (or (setq date (get-text-property (setq pos (point))
3431 (when (setq pos (next-single-property-change
3432 (point) 'original-date))
3433 (setq date (get-text-property pos 'original-date))
3436 pos (if (setq pos (text-property-any pos (point-max)
3437 'original-date nil))
3440 (if (or (bolp) (eobp))
3444 (goto-char (point-min))
3445 (when (re-search-forward tdate-regexp nil t)
3446 (setq bface (get-text-property (point-at-bol) 'face)
3447 eface (get-text-property (1- (point-at-eol)) 'face)))
3448 (goto-char (point-min))
3450 ;; Delete any old Date headers.
3451 (while (re-search-forward date-regexp nil t)
3453 (delete-region (point-at-bol) (progn
3454 (gnus-article-forward-header)
3456 (delete-region (point-at-bol) (progn
3457 (gnus-article-forward-header)
3460 (setq pos (point))))
3461 (when (and (not pos)
3462 (re-search-forward tdate-regexp nil t))
3464 (gnus-goto-char pos)
3465 (insert (article-make-date-line date (or type 'ut)))
3471 (when (looking-at "\\([^:]+\\): *\\(.*\\)$")
3472 (put-text-property (match-beginning 1) (1+ (match-end 1))
3474 (put-text-property (match-beginning 2) (match-end 2)
3476 (put-text-property (point-min) (1- (point-max)) 'original-date date)
3477 (goto-char (point-max))
3480 (defun article-make-date-line (date type)
3481 "Return a DATE line of TYPE."
3482 (unless (memq type '(local ut original user iso8601 lapsed english))
3483 (error "Unknown conversion type: %s" type))
3485 (let ((time (date-to-time date)))
3487 ;; Convert to the local timezone.
3489 (concat "Date: " (message-make-date time)))
3490 ;; Convert to Universal Time.
3495 (let* ((e (parse-time-string date))
3496 (tm (apply 'encode-time e))
3498 (ls (- (cadr tm) (car (current-time-zone time)))))
3499 (cond ((< ls 0) (list (1- ms) (+ ls 65536)))
3500 ((> ls 65535) (list (1+ ms) (- ls 65536)))
3504 ;; Get the original date from the article.
3505 ((eq type 'original)
3506 (concat "Date: " (if (string-match "\n+$" date)
3507 (substring date 0 (match-beginning 0))
3509 ;; Let the user define the format.
3511 (let ((format (or (condition-case nil
3512 (with-current-buffer gnus-summary-buffer
3513 gnus-article-time-format)
3515 gnus-article-time-format)))
3516 (if (functionp format)
3517 (funcall format time)
3518 (concat "Date: " (format-time-string format time)))))
3521 (let ((tz (car (current-time-zone time))))
3524 (format-time-string "%Y%m%dT%H%M%S" time)
3525 (format "%s%02d%02d"
3526 (if (> tz 0) "+" "-") (/ (abs tz) 3600)
3527 (/ (% (abs tz) 3600) 60)))))
3528 ;; Do an X-Sent lapsed format.
3530 ;; If the date is seriously mangled, the timezone functions are
3531 ;; liable to bug out, so we ignore all errors.
3532 (let* ((now (current-time))
3533 (real-time (subtract-time now time))
3534 (real-sec (and real-time
3535 (+ (* (float (car real-time)) 65536)
3537 (sec (and real-time (abs real-sec)))
3547 ;; This is a bit convoluted, but basically we go
3548 ;; through the time units for years, weeks, etc,
3549 ;; and divide things to see whether that results
3550 ;; in positive answers.
3553 (if (zerop (setq num (ffloor (/ sec (cdr unit)))))
3554 ;; The (remaining) seconds are too few to
3555 ;; be divided into this time unit.
3557 ;; It's big enough, so we output it.
3558 (setq sec (- sec (* num (cdr unit))))
3560 (concat (if prev ", " "") (int-to-string
3562 " " (symbol-name (car unit))
3563 (if (> num 1) "s" ""))
3565 article-time-units "")
3566 ;; If dates are odd, then it might appear like the
3567 ;; article was sent in the future.
3570 " in the future"))))))
3571 ;; Display the date in proper English
3573 (let ((dtime (decode-time time)))
3576 (number-to-string (nth 3 dtime))
3577 (let ((digit (% (nth 3 dtime) 10)))
3579 ((memq (nth 3 dtime) '(11 12 13)) "th")
3585 (nth (1- (nth 4 dtime)) gnus-english-month-names)
3587 (number-to-string (nth 5 dtime))
3589 (format "%02d" (nth 2 dtime))
3591 (format "%02d" (nth 1 dtime)))))))
3593 (format "Date: %s (from Gnus)" date))))
3595 (defun article-date-local (&optional highlight)
3596 "Convert the current article date to the local timezone."
3597 (interactive (list t))
3598 (article-date-ut 'local highlight))
3600 (defun article-date-english (&optional highlight)
3601 "Convert the current article date to something that is proper English."
3602 (interactive (list t))
3603 (article-date-ut 'english highlight))
3605 (defun article-date-original (&optional highlight)
3606 "Convert the current article date to what it was originally.
3607 This is only useful if you have used some other date conversion
3608 function and want to see what the date was before converting."
3609 (interactive (list t))
3610 (article-date-ut 'original highlight))
3612 (defun article-date-lapsed (&optional highlight)
3613 "Convert the current article date to time lapsed since it was sent."
3614 (interactive (list t))
3615 (article-date-ut 'lapsed highlight))
3617 (defun article-update-date-lapsed ()
3618 "Function to be run from a timer to update the lapsed time line."
3620 (let (deactivate-mark)
3625 (set-buffer (window-buffer w))
3626 (when (eq major-mode 'gnus-article-mode)
3627 (let ((mark (point-marker)))
3628 (goto-char (point-min))
3629 (when (re-search-forward "^X-Sent:" nil t)
3630 (article-date-lapsed t))
3631 (goto-char (marker-position mark))
3632 (move-marker mark nil))))
3635 (defun gnus-start-date-timer (&optional n)
3636 "Start a timer to update the X-Sent header in the article buffers.
3637 The numerical prefix says how frequently (in seconds) the function
3642 (gnus-stop-date-timer)
3643 (setq article-lapsed-timer
3644 (run-at-time 1 n 'article-update-date-lapsed)))
3646 (defun gnus-stop-date-timer ()
3647 "Stop the X-Sent timer."
3649 (when article-lapsed-timer
3650 (nnheader-cancel-timer article-lapsed-timer)
3651 (setq article-lapsed-timer nil)))
3653 (defun article-date-user (&optional highlight)
3654 "Convert the current article date to the user-defined format.
3655 This format is defined by the `gnus-article-time-format' variable."
3656 (interactive (list t))
3657 (article-date-ut 'user highlight))
3659 (defun article-date-iso8601 (&optional highlight)
3660 "Convert the current article date to ISO8601."
3661 (interactive (list t))
3662 (article-date-ut 'iso8601 highlight))
3664 (defmacro gnus-article-save-original-date (&rest forms)
3665 "Save the original date as a text property and evaluate FORMS."
3666 `(let* ((case-fold-search t)
3668 (goto-char (point-min))
3669 (when (and (re-search-forward "^date:[\t\n ]+" nil t)
3672 (date (when (and start
3673 (re-search-forward "[\t ]*\n\\(?:[^\t ]\\|\\'\\)"
3675 (buffer-substring-no-properties start
3676 (match-beginning 0)))))
3677 (goto-char (point-max))
3678 (skip-chars-backward "\n")
3679 (put-text-property (point-min) (point) 'original-date date)
3681 (goto-char (point-max))
3682 (skip-chars-backward "\n")
3683 (put-text-property (point-min) (point) 'original-date date)))
3685 ;; (defun article-show-all ()
3686 ;; "Show all hidden text in the article buffer."
3689 ;; (let ((inhibit-read-only t))
3690 ;; (gnus-article-unhide-text (point-min) (point-max)))))
3692 (defun article-remove-leading-whitespace ()
3693 "Remove excessive whitespace from all headers."
3697 (let ((inhibit-read-only t))
3698 (article-narrow-to-head)
3699 (goto-char (point-min))
3700 (while (re-search-forward "^[^ :]+: \\([ \t]+\\)" nil t)
3701 (delete-region (match-beginning 1) (match-end 1)))))))
3703 (defun article-emphasize (&optional arg)
3704 "Emphasize text according to `gnus-emphasis-alist'."
3705 (interactive (gnus-article-hidden-arg))
3706 (unless (gnus-article-check-hidden-text 'emphasis arg)
3710 (with-current-buffer gnus-summary-buffer
3711 gnus-article-emphasis-alist)
3713 gnus-emphasis-alist))
3714 (inhibit-read-only t)
3715 (props (append '(article-type emphasis)
3716 gnus-hidden-properties))
3717 regexp elem beg invisible visible face)
3720 (while (setq elem (pop alist))
3722 (setq regexp (car elem)
3723 invisible (nth 1 elem)
3724 visible (nth 2 elem)
3726 (while (re-search-forward regexp nil t)
3727 (when (and (match-beginning visible) (match-beginning invisible))
3728 (gnus-article-hide-text
3729 (match-beginning invisible) (match-end invisible) props)
3730 (gnus-article-unhide-text-type
3731 (match-beginning visible) (match-end visible) 'emphasis)
3732 (gnus-put-overlay-excluding-newlines
3733 (match-beginning visible) (match-end visible) 'face face)
3734 (gnus-add-wash-type 'emphasis)
3735 (goto-char (match-end invisible)))))))))
3737 (defun gnus-article-setup-highlight-words (&optional highlight-words)
3738 "Setup newsgroup emphasis alist."
3739 (unless gnus-article-emphasis-alist
3740 (let ((name (and gnus-newsgroup-name
3741 (gnus-group-real-name gnus-newsgroup-name))))
3742 (make-local-variable 'gnus-article-emphasis-alist)
3743 (setq gnus-article-emphasis-alist
3745 (let ((alist gnus-group-highlight-words-alist) elem highlight)
3746 (while (setq elem (pop alist))
3747 (when (and name (string-match (car elem) name))
3749 highlight (copy-sequence (cdr elem)))))
3751 (copy-sequence highlight-words)
3752 (if gnus-newsgroup-name
3753 (copy-sequence (gnus-group-find-parameter
3754 gnus-newsgroup-name 'highlight-words t)))
3755 gnus-emphasis-alist)))))
3757 (defvar gnus-summary-article-menu)
3758 (defvar gnus-summary-post-menu)
3760 ;;; Saving functions.
3762 (defun gnus-article-save (save-buffer file &optional num)
3763 "Save the currently selected article."
3764 (when (or (get gnus-default-article-saver :headers)
3765 (not gnus-save-all-headers))
3766 ;; Remove headers according to `gnus-saved-headers' or the value
3767 ;; of the `:headers' property that the saver function might have.
3768 (let ((gnus-visible-headers
3769 (or (symbol-value (get gnus-default-article-saver :headers))
3770 gnus-saved-headers gnus-visible-headers))
3771 ;; Ignore group parameter. See `article-hide-headers'.
3772 (gnus-summary-buffer nil))
3773 (with-current-buffer save-buffer
3774 (article-hide-headers 1 t))))
3775 (save-window-excursion
3776 (if (not gnus-default-article-saver)
3777 (error "No default saver is defined")
3778 ;; !!! Magic! The saving functions all save
3779 ;; `gnus-save-article-buffer' (or so they think), but we
3780 ;; bind that variable to our save-buffer.
3781 (set-buffer gnus-article-buffer)
3782 (let* ((gnus-save-article-buffer save-buffer)
3785 ((not gnus-prompt-before-saving) 'default)
3786 ((eq gnus-prompt-before-saving 'always) nil)
3788 (gnus-number-of-articles-to-be-saved
3789 (when (eq gnus-prompt-before-saving t)
3791 (set-buffer gnus-article-current-summary)
3792 (funcall gnus-default-article-saver filename)))))
3794 (defun gnus-read-save-file-name (prompt &optional filename
3795 function group headers variable
3798 (funcall function group headers (symbol-value variable)))
3803 ((eq filename 'default)
3809 (when (symbol-value dir-var)
3810 (setq default-name (expand-file-name
3811 (file-name-nondirectory default-name)
3812 (symbol-value dir-var))))
3813 (let* ((split-name (gnus-get-split-value gnus-split-methods))
3816 (if (and gnus-number-of-articles-to-be-saved
3817 (> gnus-number-of-articles-to-be-saved 1))
3818 (format "these %d articles"
3819 gnus-number-of-articles-to-be-saved)
3822 ;; Let the split methods have their say.
3824 ;; No split name was found.
3827 (concat prompt " (default "
3828 (file-name-nondirectory default-name) "): ")
3829 (file-name-directory default-name)
3831 ;; A single group name is returned.
3832 ((stringp split-name)
3834 (funcall function split-name headers
3835 (symbol-value variable)))
3837 (concat prompt " (default "
3838 (file-name-nondirectory default-name) "): ")
3839 (file-name-directory default-name)
3841 ;; A single split name was found
3842 ((= 1 (length split-name))
3843 (let* ((name (expand-file-name
3845 gnus-article-save-directory))
3846 (dir (cond ((file-directory-p name)
3847 (file-name-as-directory name))
3848 ((file-exists-p name) name)
3849 (t gnus-article-save-directory))))
3851 (concat prompt " (default " name "): ")
3853 ;; A list of splits was found.
3855 (setq split-name (nreverse split-name))
3857 (let ((file-name-history
3858 (nconc split-name file-name-history)))
3862 (concat prompt " (`M-p' for defaults): ")
3863 gnus-article-save-directory
3865 gnus-article-save-directory)))
3866 (car (push result file-name-history)))))))
3867 ;; Create the directory.
3868 (gnus-make-directory (file-name-directory file))
3869 ;; If we have read a directory, we append the default file name.
3870 (when (file-directory-p file)
3871 (setq file (expand-file-name (file-name-nondirectory
3873 (file-name-as-directory file))))
3874 ;; Possibly translate some characters.
3875 (nnheader-translate-file-chars file))))))
3876 (gnus-make-directory (file-name-directory result))
3878 (set variable result))
3880 (set dir-var (file-name-directory result)))
3883 (defun gnus-article-archive-name (group)
3884 "Return the first instance of an \"Archive-name\" in the current buffer."
3885 (let ((case-fold-search t))
3886 (when (re-search-forward "archive-name: *\\([^ \n\t]+\\)[ \t]*$" nil t)
3887 (nnheader-concat gnus-article-save-directory
3888 (match-string 1)))))
3890 (defun gnus-article-nndoc-name (group)
3891 "If GROUP is an nndoc group, return the name of the parent group."
3892 (when (eq (car (gnus-find-method-for-group group)) 'nndoc)
3893 (gnus-group-get-parameter group 'save-article-group)))
3895 (defun gnus-summary-save-in-rmail (&optional filename)
3896 "Append this article to Rmail file.
3897 Optional argument FILENAME specifies file name.
3898 Directory to save to is default to `gnus-article-save-directory'."
3899 (setq filename (gnus-read-save-file-name
3900 "Save %s in rmail file" filename
3901 gnus-rmail-save-name gnus-newsgroup-name
3902 gnus-current-headers 'gnus-newsgroup-last-rmail))
3903 (with-current-buffer gnus-save-article-buffer
3907 ;; Note that unlike gnus-summary-save-in-mail, there is no
3908 ;; check to see if filename is Babyl. Rmail in Emacs 23 does
3910 (gnus-output-to-rmail filename))))
3913 (defun gnus-summary-save-in-mail (&optional filename)
3914 "Append this article to Unix mail file.
3915 Optional argument FILENAME specifies file name.
3916 Directory to save to is default to `gnus-article-save-directory'."
3917 (setq filename (gnus-read-save-file-name
3918 "Save %s in Unix mail file" filename
3919 gnus-mail-save-name gnus-newsgroup-name
3920 gnus-current-headers 'gnus-newsgroup-last-mail))
3921 (with-current-buffer gnus-save-article-buffer
3925 (if (and (file-readable-p filename)
3926 (file-regular-p filename)
3927 (mail-file-babyl-p filename))
3928 (gnus-output-to-rmail filename)
3929 (gnus-output-to-mail filename)))))
3932 (put 'gnus-summary-save-in-file :decode t)
3933 (put 'gnus-summary-save-in-file :headers 'gnus-saved-headers)
3934 (defun gnus-summary-save-in-file (&optional filename overwrite)
3935 "Append this article to file.
3936 Optional argument FILENAME specifies file name.
3937 Directory to save to is default to `gnus-article-save-directory'."
3938 (setq filename (gnus-read-save-file-name
3939 "Save %s in file" filename
3940 gnus-file-save-name gnus-newsgroup-name
3941 gnus-current-headers 'gnus-newsgroup-last-file))
3942 (with-current-buffer gnus-save-article-buffer
3946 (when (and overwrite
3947 (file-exists-p filename))
3948 (delete-file filename))
3949 (gnus-output-to-file filename))))
3952 (put 'gnus-summary-write-to-file :decode t)
3953 (put 'gnus-summary-write-to-file :function 'gnus-summary-save-in-file)
3954 (put 'gnus-summary-write-to-file :headers 'gnus-saved-headers)
3955 (defun gnus-summary-write-to-file (&optional filename)
3956 "Write this article to a file, overwriting it if the file exists.
3957 Optional argument FILENAME specifies file name.
3958 The directory to save in defaults to `gnus-article-save-directory'."
3959 (setq filename (gnus-read-save-file-name
3960 "Save %s in file" filename
3961 gnus-file-save-name gnus-newsgroup-name
3962 gnus-current-headers nil 'gnus-newsgroup-last-directory))
3963 (gnus-summary-save-in-file filename t))
3965 (put 'gnus-summary-save-body-in-file :decode t)
3966 (defun gnus-summary-save-body-in-file (&optional filename overwrite)
3967 "Append this article body to a file.
3968 Optional argument FILENAME specifies file name.
3969 The directory to save in defaults to `gnus-article-save-directory'."
3970 (setq filename (gnus-read-save-file-name
3971 "Save %s body in file" filename
3972 gnus-file-save-name gnus-newsgroup-name
3973 gnus-current-headers 'gnus-newsgroup-last-file))
3974 (with-current-buffer gnus-save-article-buffer
3978 (when (article-goto-body)
3979 (narrow-to-region (point) (point-max)))
3980 (when (and overwrite
3981 (file-exists-p filename))
3982 (delete-file filename))
3983 (gnus-output-to-file filename))))
3986 (put 'gnus-summary-write-body-to-file :decode t)
3987 (put 'gnus-summary-write-body-to-file
3988 :function 'gnus-summary-save-body-in-file)
3989 (defun gnus-summary-write-body-to-file (&optional filename)
3990 "Write this article body to a file, overwriting it if the file exists.
3991 Optional argument FILENAME specifies file name.
3992 The directory to save in defaults to `gnus-article-save-directory'."
3993 (setq filename (gnus-read-save-file-name
3994 "Save %s body in file" filename
3995 gnus-file-save-name gnus-newsgroup-name
3996 gnus-current-headers nil 'gnus-newsgroup-last-directory))
3997 (gnus-summary-save-body-in-file filename t))
3999 (put 'gnus-summary-save-in-pipe :decode t)
4000 (put 'gnus-summary-save-in-pipe :headers 'gnus-saved-headers)
4001 (defun gnus-summary-save-in-pipe (&optional command raw)
4002 "Pipe this article to subprocess COMMAND.
4003 Valid values for COMMAND include:
4005 The executable command name and possibly arguments.
4007 You will be prompted for the command in the minibuffer.
4008 the symbol `default'
4009 It will be replaced with the command which the variable
4010 `gnus-summary-pipe-output-default-command' holds or the command
4011 last used for saving.
4012 Non-nil value for RAW overrides `:decode' and `:headers' properties
4013 and the raw article including all headers will be piped."
4014 (let ((article (gnus-summary-article-number))
4016 (get 'gnus-summary-save-in-pipe :decode)))
4017 save-buffer default)
4019 (if (vectorp (gnus-summary-article-header article))
4020 (save-current-buffer
4021 (gnus-summary-select-article decode decode nil article)
4022 (insert-buffer-substring
4026 gnus-original-article-buffer)
4028 (nnheader-set-temp-buffer " *Gnus Save*"))))
4029 ;; Remove unwanted headers.
4030 (when (and (not raw)
4031 (or (get 'gnus-summary-save-in-pipe :headers)
4032 (not gnus-save-all-headers)))
4033 (let ((gnus-visible-headers
4034 (or (symbol-value (get 'gnus-summary-save-in-pipe
4036 gnus-saved-headers gnus-visible-headers))
4037 (gnus-summary-buffer nil))
4038 (article-hide-headers 1 t))))
4039 (error "%d is not a real article" article))
4040 (error "No article to pipe"))
4041 (setq default (or gnus-summary-pipe-output-default-command
4042 gnus-last-shell-command))
4043 (unless (stringp command)
4045 (if (and (eq command 'default) default)
4047 (gnus-read-shell-command "Shell command on this article: "
4049 (when (string-equal command "")
4051 (setq command default)
4052 (error "A command is required")))
4053 (with-current-buffer save-buffer
4056 (shell-command-on-region (point-min) (point-max) command nil)))
4057 (gnus-kill-buffer save-buffer))
4058 (setq gnus-summary-pipe-output-default-command command))
4060 (defun gnus-summary-pipe-to-muttprint (&optional command)
4061 "Pipe this article to muttprint."
4062 (unless (stringp command)
4063 (setq command (read-string
4064 "Print using command: " gnus-summary-muttprint-program
4065 nil gnus-summary-muttprint-program)))
4066 (let ((gnus-summary-pipe-output-default-command
4067 gnus-summary-pipe-output-default-command))
4068 (gnus-summary-save-in-pipe command))
4069 (setq gnus-summary-muttprint-program command))
4071 ;;; Article file names when saving.
4073 (defun gnus-capitalize-newsgroup (newsgroup)
4074 "Capitalize NEWSGROUP name."
4075 (when (not (zerop (length newsgroup)))
4076 (concat (char-to-string (upcase (aref newsgroup 0)))
4077 (substring newsgroup 1))))
4079 (defun gnus-Numeric-save-name (newsgroup headers &optional last-file)
4080 "Generate file name from NEWSGROUP, HEADERS, and optional LAST-FILE.
4081 If variable `gnus-use-long-file-name' is non-nil, it is ~/News/News.group/num.
4082 Otherwise, it is like ~/News/news/group/num."
4085 (concat (if (gnus-use-long-file-name 'not-save)
4086 (gnus-capitalize-newsgroup newsgroup)
4087 (gnus-newsgroup-directory-form newsgroup))
4088 "/" (int-to-string (mail-header-number headers)))
4089 gnus-article-save-directory)))
4091 (string-equal (file-name-directory default)
4092 (file-name-directory last-file))
4093 (string-match "^[0-9]+$" (file-name-nondirectory last-file)))
4095 (or last-file default))))
4097 (defun gnus-numeric-save-name (newsgroup headers &optional last-file)
4098 "Generate file name from NEWSGROUP, HEADERS, and optional LAST-FILE.
4099 If variable `gnus-use-long-file-name' is non-nil, it is
4100 ~/News/news.group/num. Otherwise, it is like ~/News/news/group/num."
4103 (concat (if (gnus-use-long-file-name 'not-save)
4105 (gnus-newsgroup-directory-form newsgroup))
4106 "/" (int-to-string (mail-header-number headers)))
4107 gnus-article-save-directory)))
4109 (string-equal (file-name-directory default)
4110 (file-name-directory last-file))
4111 (string-match "^[0-9]+$" (file-name-nondirectory last-file)))
4113 (or last-file default))))
4115 (defun gnus-plain-save-name (newsgroup headers &optional last-file)
4116 "Generate file name from NEWSGROUP, HEADERS, and optional LAST-FILE.
4117 If variable `gnus-use-long-file-name' is non-nil, it is
4118 ~/News/news.group. Otherwise, it is like ~/News/news/group/news."
4121 (if (gnus-use-long-file-name 'not-save)
4124 (expand-file-name "news" (gnus-newsgroup-directory-form newsgroup))
4126 gnus-article-save-directory)))
4128 (defun gnus-sender-save-name (newsgroup headers &optional last-file)
4129 "Generate file name from sender."
4130 (let ((from (mail-header-from headers)))
4132 (if (and from (string-match "\\([^ <]+\\)@" from))
4133 (match-string 1 from)
4135 gnus-article-save-directory)))
4137 (defun article-verify-x-pgp-sig ()
4139 ;; <ftp://ftp.isc.org/pub/pgpcontrol/FORMAT>
4141 (if (gnus-buffer-live-p gnus-original-article-buffer)
4142 (let ((sig (with-current-buffer gnus-original-article-buffer
4143 (gnus-fetch-field "X-PGP-Sig")))
4147 (mml2015-clear-verify-function))
4149 (insert-buffer-substring gnus-original-article-buffer)
4150 (setq items (split-string sig))
4151 (message-narrow-to-head)
4152 (let ((inhibit-point-motion-hooks t)
4153 (case-fold-search t))
4154 ;; Don't verify multiple headers.
4155 (setq headers (mapconcat (lambda (header)
4157 (mail-fetch-field header)
4159 (split-string (nth 1 items) ",") "")))
4160 (delete-region (point-min) (point-max))
4161 (insert "-----BEGIN PGP SIGNED MESSAGE-----\n\n")
4162 (insert "X-Signed-Headers: " (nth 1 items) "\n")
4167 (if (looking-at "^-")
4170 (insert "\n-----BEGIN PGP SIGNATURE-----\n")
4171 (insert "Version: " (car items) "\n\n")
4172 (insert (mapconcat 'identity (cddr items) "\n"))
4173 (insert "\n-----END PGP SIGNATURE-----\n")
4174 (let ((mm-security-handle (list (format "multipart/signed"))))
4175 (mml2015-clean-buffer)
4176 (let ((coding-system-for-write (or gnus-newsgroup-charset
4178 (funcall (mml2015-clear-verify-function)))
4180 (or (mm-handle-multipart-ctl-parameter
4181 mm-security-handle 'gnus-details)
4182 (mm-handle-multipart-ctl-parameter
4183 mm-security-handle 'gnus-info)))))
4185 (let ((inhibit-read-only t) bface eface)
4187 (message-narrow-to-head)
4188 (goto-char (point-max))
4190 (setq bface (get-text-property (point-at-bol) 'face)
4191 eface (get-text-property (1- (point-at-eol)) 'face))
4192 (message-remove-header "X-Gnus-PGP-Verify")
4193 (if (re-search-forward "^X-PGP-Sig:" nil t)
4195 (goto-char (point-max)))
4196 (narrow-to-region (point) (point))
4197 (insert "X-Gnus-PGP-Verify: " info "\n")
4198 (goto-char (point-min))
4201 (if (not (looking-at "^[ \t]"))
4205 (goto-char (point-min))
4206 (when (looking-at "\\([^:]+\\): *")
4207 (put-text-property (match-beginning 1) (1+ (match-end 1))
4209 (put-text-property (match-end 0) (point-max)
4210 'face eface)))))))))
4212 (autoload 'canlock-verify "canlock" nil t) ;; for XEmacs.
4214 (defun article-verify-cancel-lock ()
4215 "Verify Cancel-Lock header."
4217 (if (gnus-buffer-live-p gnus-original-article-buffer)
4218 (canlock-verify gnus-original-article-buffer)))
4225 (setq afunc (car func)
4228 gfunc (intern (format "gnus-%s" func))))
4230 (when (fboundp afunc)
4231 `(lambda (&optional interactive &rest args)
4232 ,(documentation afunc t)
4233 (interactive (list t))
4234 (with-current-buffer gnus-article-buffer
4236 (call-interactively ',afunc)
4237 (apply ',afunc args))))))))
4238 '(article-hide-headers
4239 article-verify-x-pgp-sig
4240 article-verify-cancel-lock
4241 article-hide-boring-headers
4242 article-treat-overstrike
4243 article-treat-ansi-sequences
4244 article-fill-long-lines
4245 article-capitalize-sentences
4247 article-remove-leading-whitespace
4248 article-display-x-face
4249 article-display-face
4250 article-de-quoted-unreadable
4251 article-de-base64-unreadable
4254 article-unsplit-urls
4255 article-hide-list-identifiers
4256 article-strip-banner
4259 article-hide-signature
4260 article-strip-headers-in-body
4261 article-remove-trailing-blank-lines
4262 article-strip-leading-blank-lines
4263 article-strip-multiple-blank-lines
4264 article-strip-leading-space
4265 article-strip-trailing-space
4266 article-strip-blank-lines
4267 article-strip-all-blank-lines
4269 article-date-english
4270 article-date-iso8601
4271 article-date-original
4273 article-decode-mime-words
4274 article-decode-charset
4275 article-decode-encoded-words
4279 article-treat-dumbquotes
4280 article-treat-non-ascii
4281 article-normalize-headers
4282 ;;(article-show-all . gnus-article-show-all-headers)
4286 ;;; Gnus article mode
4289 (put 'gnus-article-mode 'mode-class 'special)
4291 (set-keymap-parent gnus-article-mode-map widget-keymap)
4293 (gnus-define-keys gnus-article-mode-map
4294 " " gnus-article-goto-next-page
4295 "\177" gnus-article-goto-prev-page
4296 [delete] gnus-article-goto-prev-page
4297 [backspace] gnus-article-goto-prev-page
4298 "\C-c^" gnus-article-refer-article
4299 "h" gnus-article-show-summary
4300 "s" gnus-article-show-summary
4301 "\C-c\C-m" gnus-article-mail
4302 "?" gnus-article-describe-briefly
4303 "<" beginning-of-buffer
4305 "\C-c\C-i" gnus-info-find-node
4307 "R" gnus-article-reply-with-original
4308 "F" gnus-article-followup-with-original
4309 "\C-hk" gnus-article-describe-key
4310 "\C-hc" gnus-article-describe-key-briefly
4311 "\C-hb" gnus-article-describe-bindings
4313 "e" gnus-article-read-summary-keys
4314 "\C-d" gnus-article-read-summary-keys
4315 "\M-*" gnus-article-read-summary-keys
4316 "\M-#" gnus-article-read-summary-keys
4317 "\M-^" gnus-article-read-summary-keys
4318 "\M-g" gnus-article-read-summary-keys)
4320 (substitute-key-definition
4321 'undefined 'gnus-article-read-summary-keys gnus-article-mode-map)
4323 (gnus-define-keys (gnus-article-send-map "S" gnus-article-mode-map)
4324 "W" gnus-article-wide-reply-with-original)
4325 (if (featurep 'xemacs)
4326 (set-keymap-default-binding gnus-article-send-map
4327 'gnus-article-read-summary-send-keys)
4328 (define-key gnus-article-send-map [t] 'gnus-article-read-summary-send-keys))
4330 (defun gnus-article-make-menu-bar ()
4331 (unless (boundp 'gnus-article-commands-menu)
4332 (gnus-summary-make-menu-bar))
4333 (unless (boundp 'gnus-article-article-menu)
4335 gnus-article-article-menu gnus-article-mode-map ""
4337 ["Scroll forwards" gnus-article-goto-next-page t]
4338 ["Scroll backwards" gnus-article-goto-prev-page t]
4339 ["Show summary" gnus-article-show-summary t]
4340 ["Fetch Message-ID at point" gnus-article-refer-article t]
4341 ["Mail to address at point" gnus-article-mail t]
4342 ["Send a bug report" gnus-bug t]))
4345 gnus-article-treatment-menu gnus-article-mode-map ""
4346 ;; Fixme: this should use :active (and maybe :visible).
4348 ["Hide headers" gnus-article-hide-headers t]
4349 ["Hide signature" gnus-article-hide-signature t]
4350 ["Hide citation" gnus-article-hide-citation t]
4351 ["Treat overstrike" gnus-article-treat-overstrike t]
4352 ["Treat ANSI sequences" gnus-article-treat-ansi-sequences t]
4353 ["Remove carriage return" gnus-article-remove-cr t]
4354 ["Remove leading whitespace" gnus-article-remove-leading-whitespace t]
4355 ["Remove quoted-unreadable" gnus-article-de-quoted-unreadable t]
4356 ["Remove base64" gnus-article-de-base64-unreadable t]
4357 ["Treat html" gnus-article-wash-html t]
4358 ["Remove newlines from within URLs" gnus-article-unsplit-urls t]
4359 ["Decode HZ" gnus-article-decode-HZ t]))
4361 ;; Note "Commands" menu is defined in gnus-sum.el for consistency
4363 ;; Note "Post" menu is defined in gnus-sum.el for consistency
4365 (gnus-run-hooks 'gnus-article-menu-hook)))
4367 (defvar bookmark-make-record-function)
4369 (defun gnus-article-mode ()
4370 "Major mode for displaying an article.
4372 All normal editing commands are switched off.
4374 The following commands are available in addition to all summary mode
4376 \\<gnus-article-mode-map>
4377 \\[gnus-article-next-page]\t Scroll the article one page forwards
4378 \\[gnus-article-prev-page]\t Scroll the article one page backwards
4379 \\[gnus-article-refer-article]\t Go to the article referred to by an article id near point
4380 \\[gnus-article-show-summary]\t Display the summary buffer
4381 \\[gnus-article-mail]\t Send a reply to the address near point
4382 \\[gnus-article-describe-briefly]\t Describe the current mode briefly
4383 \\[gnus-info-find-node]\t Go to the Gnus info node"
4385 (kill-all-local-variables)
4386 (gnus-simplify-mode-line)
4387 (setq mode-name "Article")
4388 (setq major-mode 'gnus-article-mode)
4389 (make-local-variable 'minor-mode-alist)
4390 (use-local-map gnus-article-mode-map)
4391 (when (gnus-visual-p 'article-menu 'menu)
4392 (gnus-article-make-menu-bar)
4393 (when gnus-summary-tool-bar-map
4394 (set (make-local-variable 'tool-bar-map) gnus-summary-tool-bar-map)))
4395 (gnus-update-format-specifications nil 'article-mode)
4396 (set (make-local-variable 'page-delimiter) gnus-page-delimiter)
4397 (set (make-local-variable 'gnus-page-broken) nil)
4398 (make-local-variable 'gnus-button-marker-list)
4399 (make-local-variable 'gnus-article-current-summary)
4400 (make-local-variable 'gnus-article-mime-handles)
4401 (make-local-variable 'gnus-article-decoded-p)
4402 (make-local-variable 'gnus-article-mime-handle-alist)
4403 (make-local-variable 'gnus-article-wash-types)
4404 (make-local-variable 'gnus-article-image-alist)
4405 (make-local-variable 'gnus-article-charset)
4406 (make-local-variable 'gnus-article-ignored-charsets)
4407 (set (make-local-variable 'bookmark-make-record-function)
4408 'gnus-summary-bookmark-make-record)
4409 ;; Prevent Emacs 22 from displaying non-break space with `nobreak-space'
4411 (set (make-local-variable 'nobreak-char-display) nil)
4412 (setq cursor-in-non-selected-windows nil)
4413 (gnus-set-default-directory)
4414 (buffer-disable-undo)
4415 (setq buffer-read-only t
4416 show-trailing-whitespace nil)
4417 (set-syntax-table gnus-article-mode-syntax-table)
4418 (mm-enable-multibyte)
4419 (gnus-run-mode-hooks 'gnus-article-mode-hook))
4421 (defvar gnus-button-marker-list nil
4422 "Regexp matching any of the regexps from `gnus-button-alist'.
4423 Internal variable.")
4425 (defun gnus-article-setup-buffer ()
4426 "Initialize the article buffer."
4427 (let* ((name (if gnus-single-article-buffer "*Article*"
4428 (concat "*Article " gnus-newsgroup-name "*")))
4430 (progn (string-match "\\*Article" name)
4431 (concat " *Original Article"
4432 (substring name (match-end 0))))))
4433 (setq gnus-article-buffer name)
4434 (setq gnus-original-article-buffer original)
4435 (setq gnus-article-mime-handle-alist nil)
4436 (with-current-buffer gnus-summary-buffer
4437 ;; This might be a variable local to the summary buffer.
4438 (unless gnus-single-article-buffer
4439 (setq gnus-article-buffer name)
4440 (setq gnus-original-article-buffer original)
4441 (gnus-set-global-variables)))
4442 (gnus-article-setup-highlight-words)
4443 ;; Init original article buffer.
4444 (with-current-buffer (gnus-get-buffer-create gnus-original-article-buffer)
4445 (mm-enable-multibyte)
4446 (setq major-mode 'gnus-original-article-mode)
4447 (make-local-variable 'gnus-original-article))
4448 (if (and (get-buffer name)
4449 (with-current-buffer name
4450 (if gnus-article-edit-mode
4451 (if (y-or-n-p "Article mode edit in progress; discard? ")
4453 (set-buffer-modified-p nil)
4454 (gnus-kill-buffer name)
4457 (error "Action aborted"))
4459 (with-current-buffer name
4460 (set (make-local-variable 'gnus-article-edit-mode) nil)
4461 (when gnus-article-mime-handles
4462 (mm-destroy-parts gnus-article-mime-handles)
4463 (setq gnus-article-mime-handles nil))
4464 ;; Set it to nil in article-buffer!
4465 (setq gnus-article-mime-handle-alist nil)
4466 (buffer-disable-undo)
4467 (setq buffer-read-only t)
4468 ;; This list just keeps growing if we don't reset it.
4469 (setq gnus-button-marker-list nil)
4470 (unless (eq major-mode 'gnus-article-mode)
4471 (gnus-article-mode))
4472 (setq truncate-lines gnus-article-truncate-lines)
4474 (with-current-buffer (gnus-get-buffer-create name)
4476 (setq truncate-lines gnus-article-truncate-lines)
4477 (make-local-variable 'gnus-summary-buffer)
4478 (setq gnus-summary-buffer
4479 (gnus-summary-buffer-name gnus-newsgroup-name))
4480 (gnus-summary-set-local-parameters gnus-newsgroup-name)
4481 (current-buffer)))))
4483 ;; Set article window start at LINE, where LINE is the number of lines
4484 ;; from the head of the article.
4485 (defun gnus-article-set-window-start (&optional line)
4486 (let ((article-window (gnus-get-buffer-window gnus-article-buffer t)))
4487 (when article-window
4490 (with-current-buffer gnus-article-buffer
4491 (goto-char (point-min))
4494 (gnus-message 6 "Moved to bookmark")
4495 (search-forward "\n\n" nil t)
4499 (defun gnus-article-prepare (article &optional all-headers header)
4500 "Prepare ARTICLE in article mode buffer.
4501 ARTICLE should either be an article number or a Message-ID.
4502 If ARTICLE is an id, HEADER should be the article headers.
4503 If ALL-HEADERS is non-nil, no headers are hidden."
4505 ;; Make sure we start in a summary buffer.
4506 (unless (eq major-mode 'gnus-summary-mode)
4507 (set-buffer gnus-summary-buffer))
4508 (setq gnus-summary-buffer (current-buffer))
4509 (let* ((gnus-article (if header (mail-header-number header) article))
4510 (summary-buffer (current-buffer))
4511 (gnus-tmp-internal-hook gnus-article-internal-prepare-hook)
4512 (group gnus-newsgroup-name)
4515 (gnus-article-setup-buffer)
4516 (set-buffer gnus-article-buffer)
4517 ;; Deactivate active regions.
4518 (when (and (boundp 'transient-mark-mode)
4519 transient-mark-mode)
4520 (setq mark-active nil))
4521 (if (not (setq result (let ((inhibit-read-only t))
4522 (gnus-request-article-this-buffer
4524 ;; There is no such article.
4526 (when (and (numberp article)
4527 (not (memq article gnus-newsgroup-sparse)))
4528 (setq gnus-article-current
4529 (cons gnus-newsgroup-name article))
4530 (set-buffer gnus-summary-buffer)
4531 (setq gnus-current-article article)
4532 (if (and (memq article gnus-newsgroup-undownloaded)
4533 (not (gnus-online (gnus-find-method-for-group
4534 gnus-newsgroup-name))))
4536 (gnus-summary-set-agent-mark article)
4537 (message "Message marked for downloading"))
4538 (gnus-summary-mark-article article gnus-canceled-mark)
4539 (unless (memq article gnus-newsgroup-sparse)
4540 (gnus-error 1 "No such article (may have expired or been canceled)")))))
4541 (if (or (eq result 'pseudo)
4542 (eq result 'nneething))
4544 (with-current-buffer summary-buffer
4545 (push article gnus-newsgroup-history)
4546 (setq gnus-last-article gnus-current-article
4547 gnus-current-article 0
4548 gnus-current-headers nil
4549 gnus-article-current nil)
4550 (if (eq result 'nneething)
4551 (gnus-configure-windows 'summary)
4552 (gnus-configure-windows 'article))
4553 (gnus-set-global-variables))
4554 (let ((gnus-article-mime-handle-alist-1
4555 gnus-article-mime-handle-alist))
4556 (gnus-set-mode-line 'article)))
4557 ;; The result from the `request' was an actual article -
4558 ;; or at least some text that is now displayed in the
4560 (when (and (numberp article)
4561 (not (eq article gnus-current-article)))
4562 ;; Seems like a new article has been selected.
4563 ;; `gnus-current-article' must be an article number.
4564 (with-current-buffer summary-buffer
4565 (push article gnus-newsgroup-history)
4566 (setq gnus-last-article gnus-current-article
4567 gnus-current-article article
4568 gnus-current-headers
4569 (gnus-summary-article-header gnus-current-article)
4570 gnus-article-current
4571 (cons gnus-newsgroup-name gnus-current-article))
4572 (unless (vectorp gnus-current-headers)
4573 (setq gnus-current-headers nil))
4574 (gnus-summary-goto-subject gnus-current-article)
4575 (when (gnus-summary-show-thread)
4576 ;; If the summary buffer really was folded, the
4577 ;; previous goto may not actually have gone to
4578 ;; the right article, but the thread root instead.
4580 (gnus-summary-goto-subject gnus-current-article))
4581 (gnus-run-hooks 'gnus-mark-article-hook)
4582 (gnus-set-mode-line 'summary)
4583 (when (gnus-visual-p 'article-highlight 'highlight)
4584 (gnus-run-hooks 'gnus-visual-mark-article-hook))
4585 ;; Set the global newsgroup variables here.
4586 (gnus-set-global-variables)
4587 (setq gnus-have-all-headers
4588 (or all-headers gnus-show-all-headers))))
4590 (gnus-configure-windows 'article))
4591 (when (or (numberp article)
4593 (gnus-article-prepare-display)
4595 (goto-char (point-min))
4596 (when gnus-break-pages
4597 (gnus-narrow-to-page)))
4598 (let ((gnus-article-mime-handle-alist-1
4599 gnus-article-mime-handle-alist))
4600 (gnus-set-mode-line 'article))
4604 (set-window-point (get-buffer-window (current-buffer)) (point))
4605 (gnus-configure-windows 'article)
4609 (defun gnus-article-prepare-display ()
4610 "Make the current buffer look like a nice article."
4611 ;; Hooks for getting information from the article.
4612 ;; This hook must be called before being narrowed.
4613 (let ((gnus-article-buffer (current-buffer))
4615 (inhibit-read-only t))
4616 (unless (eq major-mode 'gnus-article-mode)
4617 (gnus-article-mode))
4618 (setq buffer-read-only nil
4619 gnus-article-wash-types nil
4620 gnus-article-image-alist nil)
4621 (gnus-run-hooks 'gnus-tmp-internal-hook)
4622 (when gnus-display-mime-function
4623 (funcall gnus-display-mime-function))
4624 (gnus-run-hooks 'gnus-article-prepare-hook)))
4627 ;;; Gnus Sticky Article Mode
4630 (define-derived-mode gnus-sticky-article-mode gnus-article-mode "StickyArticle"
4631 "Mode for sticky articles."
4632 ;; Release bindings that won't work.
4633 (substitute-key-definition 'gnus-article-read-summary-keys 'undefined
4634 gnus-sticky-article-mode-map)
4635 (substitute-key-definition 'gnus-article-refer-article 'undefined
4636 gnus-sticky-article-mode-map)
4637 (dolist (k '("e" "h" "s" "F" "R"))
4638 (define-key gnus-sticky-article-mode-map k nil))
4639 (define-key gnus-sticky-article-mode-map "k" 'gnus-kill-sticky-article-buffer)
4640 (define-key gnus-sticky-article-mode-map "q" 'bury-buffer)
4641 (define-key gnus-sticky-article-mode-map "\C-hc" 'describe-key-briefly)
4642 (define-key gnus-sticky-article-mode-map "\C-hk" 'describe-key))
4644 (defun gnus-sticky-article (arg)
4645 "Make the current article sticky.
4646 If a prefix ARG is given, ask for a name for this sticky article buffer."
4648 (gnus-summary-show-thread)
4649 (gnus-summary-select-article nil nil 'pseudo)
4650 (let (new-art-buf-name)
4651 (gnus-eval-in-buffer-window gnus-article-buffer
4652 (setq new-art-buf-name
4656 (read-from-minibuffer "Sticky article buffer name: ")
4657 (gnus-with-article-headers
4658 (gnus-article-goto-header "subject")
4659 (setq new-art-buf-name
4660 (buffer-substring-no-properties
4661 (line-beginning-position) (line-end-position)))
4662 (goto-char (point-min))
4663 (gnus-article-goto-header "from")
4664 (setq new-art-buf-name
4666 new-art-buf-name ", "
4667 (buffer-substring-no-properties
4668 (line-beginning-position) (line-end-position))))
4669 (goto-char (point-min))
4670 (gnus-article-goto-header "date")
4671 (setq new-art-buf-name
4673 new-art-buf-name ", "
4674 (buffer-substring-no-properties
4675 (line-beginning-position) (line-end-position))))))
4677 (if (and (gnus-buffer-live-p new-art-buf-name)
4678 (with-current-buffer new-art-buf-name
4679 (eq major-mode 'gnus-sticky-article-mode)))
4680 (switch-to-buffer new-art-buf-name)
4681 (setq new-art-buf-name (rename-buffer new-art-buf-name t)))
4682 (gnus-sticky-article-mode))
4683 (setq gnus-article-buffer new-art-buf-name))
4684 (gnus-summary-recenter)
4685 (gnus-summary-position-point))
4687 (defun gnus-kill-sticky-article-buffer (&optional buffer)
4688 "Kill the given sticky article BUFFER.
4689 If none is given, assume the current buffer and kill it if it has
4690 `gnus-sticky-article-mode'."
4693 (setq buffer (current-buffer)))
4694 (with-current-buffer buffer
4695 (when (eq major-mode 'gnus-sticky-article-mode)
4696 (gnus-kill-buffer buffer))))
4698 (defun gnus-kill-sticky-article-buffers (arg)
4699 "Kill all sticky article buffers.
4700 If a prefix ARG is given, ask for confirmation."
4702 (dolist (buf (gnus-buffers))
4703 (with-current-buffer buf
4704 (when (eq major-mode 'gnus-sticky-article-mode)
4706 (gnus-kill-buffer buf)
4707 (when (yes-or-no-p (concat "Kill buffer " (buffer-name buf) "? "))
4708 (gnus-kill-buffer buf)))))))
4711 ;;; Gnus MIME viewing functions
4714 (defvar gnus-mime-button-line-format "%{%([%p. %d%T]%)%}%e\n"
4715 "Format of the MIME buttons.
4717 Valid specifiers include:
4719 %T MIME type, along with additional info
4720 %n The `name' parameter
4721 %d The description, if any
4722 %l The length of the encoded part
4723 %p The part identifier number
4724 %e Dots if the part isn't displayed
4726 General format specifiers can also be used. See Info node
4727 `(gnus)Formatting Variables'.")
4729 (defvar gnus-mime-button-line-format-alist
4730 '((?t gnus-tmp-type ?s)
4731 (?T gnus-tmp-type-long ?s)
4732 (?n gnus-tmp-name ?s)
4733 (?d gnus-tmp-description ?s)
4735 (?l gnus-tmp-length ?d)
4736 (?e gnus-tmp-dots ?s)))
4738 (defvar gnus-mime-button-commands
4739 '((gnus-article-press-button "\r" "Toggle Display")
4740 (gnus-mime-view-part "v" "View Interactively...")
4741 (gnus-mime-view-part-as-type "t" "View As Type...")
4742 (gnus-mime-view-part-as-charset "C" "View As charset...")
4743 (gnus-mime-save-part "o" "Save...")
4744 (gnus-mime-save-part-and-strip "\C-o" "Save and Strip")
4745 (gnus-mime-replace-part "r" "Replace part")
4746 (gnus-mime-delete-part "d" "Delete part")
4747 (gnus-mime-copy-part "c" "View As Text, In Other Buffer")
4748 (gnus-mime-inline-part "i" "View As Text, In This Buffer")
4749 (gnus-mime-view-part-internally "E" "View Internally") ;; Why `E'?
4750 (gnus-mime-view-part-externally "e" "View Externally")
4751 (gnus-mime-print-part "p" "Print")
4752 (gnus-mime-pipe-part "|" "Pipe To Command...")
4753 (gnus-mime-action-on-part "." "Take action on the part...")))
4755 (defun gnus-article-mime-part-status ()
4756 (if gnus-article-mime-handle-alist-1
4757 (if (eq 1 (length gnus-article-mime-handle-alist-1))
4759 (format " (%d parts)" (length gnus-article-mime-handle-alist-1)))
4762 (defvar gnus-mime-button-map
4763 (let ((map (make-sparse-keymap)))
4764 (define-key map gnus-mouse-2 'gnus-article-push-button)
4765 (define-key map gnus-down-mouse-3 'gnus-mime-button-menu)
4766 (dolist (c gnus-mime-button-commands)
4767 (define-key map (cadr c) (car c)))
4771 gnus-mime-button-menu gnus-mime-button-map "MIME button menu."
4773 ,@(mapcar (lambda (c)
4774 (vector (caddr c) (car c) :active t))
4775 gnus-mime-button-commands)))
4777 (defvar gnus-url-button-commands
4778 '((gnus-article-copy-string "u" "Copy URL to kill ring")))
4780 (defvar gnus-url-button-map
4781 (let ((map (make-sparse-keymap)))
4782 (dolist (c gnus-url-button-commands)
4783 (define-key map (cadr c) (car c)))
4787 gnus-url-button-menu gnus-url-button-map "URL button menu."
4789 ,@(mapcar (lambda (c)
4790 (vector (caddr c) (car c) :active t))
4791 gnus-url-button-commands)))
4793 (defmacro gnus-bind-safe-url-regexp (&rest body)
4794 "Bind `mm-w3m-safe-url-regexp' according to `gnus-safe-html-newsgroups'."
4795 `(let ((mm-w3m-safe-url-regexp
4796 (let ((group (if (and (eq major-mode 'gnus-article-mode)
4798 gnus-article-current-summary))
4799 (with-current-buffer gnus-article-current-summary
4800 gnus-newsgroup-name)
4801 gnus-newsgroup-name)))
4802 (if (cond ((not group)
4803 ;; Maybe we're in a mml-preview buffer
4804 ;; and no group is selected.
4806 ((stringp gnus-safe-html-newsgroups)
4807 (string-match gnus-safe-html-newsgroups group))
4808 ((consp gnus-safe-html-newsgroups)
4809 (member group gnus-safe-html-newsgroups)))
4811 mm-w3m-safe-url-regexp))))
4814 (defun gnus-mime-button-menu (event prefix)
4815 "Construct a context-sensitive menu of MIME commands."
4816 (interactive "e\nP")
4817 (save-window-excursion
4818 (let ((pos (event-start event)))
4819 (select-window (posn-window pos))
4820 (goto-char (posn-point pos))
4821 (gnus-article-check-buffer)
4822 (popup-menu gnus-mime-button-menu nil prefix))))
4824 (defun gnus-mime-view-all-parts (&optional handles)
4825 "View all the MIME parts."
4827 (with-current-buffer gnus-article-buffer
4828 (let ((handles (or handles gnus-article-mime-handles))
4829 (mail-parse-charset gnus-newsgroup-charset)
4830 (mail-parse-ignored-charsets
4831 (with-current-buffer gnus-summary-buffer
4832 gnus-newsgroup-ignored-charsets)))
4834 (mm-remove-parts handles)
4835 (goto-char (point-min))
4836 (or (search-forward "\n\n") (goto-char (point-max)))
4837 (let ((inhibit-read-only t))
4838 (delete-region (point) (point-max))
4839 (gnus-bind-safe-url-regexp (mm-display-parts handles)))))))
4841 (defun gnus-article-jump-to-part (n)
4842 "Jump to MIME part N."
4844 (let ((parts (with-current-buffer gnus-article-buffer
4845 (length gnus-article-mime-handle-alist))))
4847 (error "No such part"))
4848 (pop-to-buffer gnus-article-buffer)
4849 ;; FIXME: why is it necessary?
4852 (setq n (if (= parts 1)
4854 (read-number (format "Jump to part (1..%s): " parts)))))
4855 (unless (and (integerp n) (<= n parts) (>= n 1))
4858 (gnus-message 7 "Invalid part `%s', using %s instead."
4861 (gnus-message 9 "Jumping to part %s." n)
4862 (cond ((>= gnus-auto-select-part 1)
4863 (while (and (<= n parts)
4864 (not (gnus-article-goto-part n)))
4866 ((< gnus-auto-select-part 0)
4867 (while (and (>= n 1)
4868 (not (gnus-article-goto-part n)))
4871 (gnus-article-goto-part n)))))
4873 (defvar gnus-mime-buttonized-part-id nil
4874 "ID of a mime part that should be buttonized.
4875 `gnus-mime-save-part-and-strip' and `gnus-mime-delete-part' bind it.")
4878 (defsubst gnus-article-edit-part (handles &optional current-id)
4879 "Edit an article in order to delete a mime part.
4880 This function is exclusively used by `gnus-mime-save-part-and-strip'
4881 and `gnus-mime-delete-part', and not provided at run-time normally."
4882 (gnus-article-edit-article
4884 (buffer-disable-undo)
4886 (let ((mail-parse-charset (or gnus-article-charset
4887 ',gnus-newsgroup-charset))
4888 (mail-parse-ignored-charsets
4889 (or gnus-article-ignored-charsets
4890 ',gnus-newsgroup-ignored-charsets))
4891 (mbl mml-buffer-list))
4892 (setq mml-buffer-list nil)
4893 (insert-buffer-substring gnus-original-article-buffer)
4894 (mime-to-mml ',handles)
4895 (setq gnus-article-mime-handles nil)
4896 (let ((mbl1 mml-buffer-list))
4897 (setq mml-buffer-list mbl)
4898 (set (make-local-variable 'mml-buffer-list) mbl1))
4899 (gnus-make-local-hook 'kill-buffer-hook)
4900 (add-hook 'kill-buffer-hook 'mml-destroy-buffers t t)))
4901 `(lambda (no-highlight)
4902 (let ((mail-parse-charset (or gnus-article-charset
4903 ',gnus-newsgroup-charset))
4904 (message-options message-options)
4905 (message-options-set-recipient)
4906 (mail-parse-ignored-charsets
4907 (or gnus-article-ignored-charsets
4908 ',gnus-newsgroup-ignored-charsets)))
4910 (mml-destroy-buffers)
4911 (remove-hook 'kill-buffer-hook
4912 'mml-destroy-buffers t)
4913 (kill-local-variable 'mml-buffer-list))
4914 (gnus-summary-edit-article-done
4915 ,(or (mail-header-references gnus-current-headers) "")
4916 ,(gnus-group-read-only-p)
4917 ,gnus-summary-buffer no-highlight))
4919 ;; Force buttonizing this part.
4920 (let ((gnus-mime-buttonized-part-id current-id))
4921 (gnus-article-edit-done))
4922 (gnus-configure-windows 'article)
4923 (when (and current-id (integerp gnus-auto-select-part))
4924 (gnus-article-jump-to-part
4925 (min (max (+ current-id gnus-auto-select-part) 1)
4926 (with-current-buffer gnus-article-buffer
4927 (length gnus-article-mime-handle-alist)))))))
4929 (defun gnus-mime-replace-part (file)
4930 "Replace MIME part under point with an external body."
4931 ;; Useful if file has already been saved to disk
4934 (read-file-name "Replace MIME part with file: "
4935 (or mm-default-directory default-directory)
4937 (gnus-mime-save-part-and-strip file))
4939 (defun gnus-mime-save-part-and-strip (&optional file)
4940 "Save the MIME part under point then replace it with an external body.
4941 If FILE is given, use it for the external part."
4943 (gnus-article-check-buffer)
4944 (when (gnus-group-read-only-p)
4945 (error "The current group does not support deleting of parts"))
4946 (when (mm-complicated-handles gnus-article-mime-handles)
4948 The current article has a complicated MIME structure, giving up..."))
4949 (let* ((data (get-text-property (point) 'gnus-data))
4950 (id (get-text-property (point) 'gnus-part))
4952 (handles gnus-article-mime-handles))
4955 (and data (mm-save-part data "Delete MIME part and save to: "))))
4957 (with-current-buffer (mm-handle-buffer data)
4959 (insert "Content-Type: " (mm-handle-media-type data))
4960 (mml-insert-parameter-string (cdr (mm-handle-type data))
4962 ;; Add a filename for the sake of saving the part again.
4963 (mml-insert-parameter
4964 (mail-header-encode-parameter "name" (file-name-nondirectory file)))
4966 (insert "Content-ID: " (message-make-message-id) "\n")
4967 (insert "Content-Transfer-Encoding: binary\n")
4970 (cdr (mm-make-handle nil
4971 `("message/external-body"
4972 (access-type . "LOCAL-FILE")
4974 ;; (set-buffer gnus-summary-buffer)
4975 (gnus-article-edit-part handles id))))
4977 ;; A function like `gnus-summary-save-parts' (`X m', `<MIME> <Extract all
4978 ;; parts...>') but with stripping would be nice.
4980 (defun gnus-mime-delete-part ()
4981 "Delete the MIME part under point.
4982 Replace it with some information about the removed part."
4984 (gnus-article-check-buffer)
4985 (when (gnus-group-read-only-p)
4986 (error "The current group does not support deleting of parts"))
4987 (when (mm-complicated-handles gnus-article-mime-handles)
4989 The current article has a complicated MIME structure, giving up..."))
4990 (when (or gnus-expert-user
4991 (gnus-yes-or-no-p "\
4992 Deleting parts may malfunction or destroy the article; continue? "))
4993 (let* ((data (get-text-property (point) 'gnus-data))
4994 (id (get-text-property (point) 'gnus-part))
4995 (handles gnus-article-mime-handles)
4998 (let ((desc (mm-handle-description data)))
5000 (mail-decode-encoded-word-string desc))))
5002 (or (mail-content-type-get (mm-handle-disposition data) 'filename)
5004 (type (mm-handle-media-type data)))
5006 (error "No MIME part under point"))
5007 (with-current-buffer (mm-handle-buffer data)
5008 (let ((bsize (buffer-size)))
5013 "| The following attachment has been deleted:\n"
5015 "| Type: " type "\n"
5016 "| Filename: " filename "\n"
5017 "| Size (encoded): " (format "%s byte%s\n"
5018 bsize (if (= bsize 1)
5022 (concat "| Description: " description "\n"))
5025 (cdr (mm-make-handle
5026 nil `("text/plain" (charset . gnus-decoded)) nil nil
5028 (format "Deleted attachment (%s bytes)" bsize))))))
5029 ;; (set-buffer gnus-summary-buffer)
5030 (gnus-article-edit-part handles id))))
5032 (defun gnus-mime-save-part ()
5033 "Save the MIME part under point."
5035 (gnus-article-check-buffer)
5036 (let ((data (get-text-property (point) 'gnus-data)))
5038 (mm-save-part data))))
5040 (defun gnus-mime-pipe-part (&optional cmd)
5041 "Pipe the MIME part under point to a process.
5042 Use CMD as the process."
5044 (gnus-article-check-buffer)
5045 (let ((data (get-text-property (point) 'gnus-data)))
5047 (mm-pipe-part data cmd))))
5049 (defun gnus-mime-view-part ()
5050 "Interactively choose a viewing method for the MIME part under point."
5052 (gnus-article-check-buffer)
5053 (let ((data (get-text-property (point) 'gnus-data)))
5055 (setq gnus-article-mime-handles
5057 gnus-article-mime-handles (setq data (copy-sequence data))))
5058 (mm-interactively-view-part data))))
5060 (defun gnus-mime-view-part-as-type-internal ()
5061 (gnus-article-check-buffer)
5062 (let* ((handle (get-text-property (point) 'gnus-data))
5064 ;; Content-Type: foo/bar; name=...
5065 (mail-content-type-get (mm-handle-type handle) 'name)
5066 ;; Content-Disposition: attachment; filename=...
5067 (cdr (assq 'filename (cdr (mm-handle-disposition handle))))))
5068 (def-type (and name (mm-default-file-encoding name))))
5069 (or (and def-type (cons def-type 0))
5071 (equal (mm-handle-media-supertype handle) "text")
5072 '("text/plain" . 0))
5073 '("application/octet-stream" . 0))))
5075 (defun gnus-mime-view-part-as-type (&optional mime-type pred)
5076 "Choose a MIME media type, and view the part as such.
5077 If non-nil, PRED is a predicate to use during completion to limit the
5078 available media-types."
5082 (let ((default (gnus-mime-view-part-as-type-internal)))
5083 (gnus-completing-read
5086 (gnus-remove-if-not pred (mailcap-mime-types))
5087 (mailcap-mime-types))
5090 (gnus-article-check-buffer)
5091 (let ((handle (get-text-property (point) 'gnus-data)))
5093 (when (equal (mm-handle-media-type handle) "message/external-body")
5094 (unless (mm-handle-cache handle)
5095 (mm-extern-cache-contents handle))
5096 (setq handle (mm-handle-cache handle)))
5098 (mm-make-handle (mm-handle-buffer handle)
5099 (cons mime-type (cdr (mm-handle-type handle)))
5100 (mm-handle-encoding handle)
5101 (mm-handle-undisplayer handle)
5102 (mm-handle-disposition handle)
5103 (mm-handle-description handle)
5105 (mm-handle-id handle)))
5106 (setq gnus-article-mime-handles
5107 (mm-merge-handles gnus-article-mime-handles handle))
5108 (when (mm-handle-displayed-p handle)
5109 (mm-remove-part handle))
5110 (gnus-mm-display-part handle))))
5112 (defun gnus-mime-copy-part (&optional handle arg)
5113 "Put the MIME part under point into a new buffer.
5114 If `auto-compression-mode' is enabled, compressed files like .gz and .bz2
5116 (interactive (list nil current-prefix-arg))
5117 (gnus-article-check-buffer)
5119 (setq handle (get-text-property (point) 'gnus-data)))
5121 (let ((filename (or (mail-content-type-get (mm-handle-type handle)
5123 (mail-content-type-get (mm-handle-disposition handle)
5125 contents dont-decode charset coding-system)
5126 (mm-with-unibyte-buffer
5127 (mm-insert-part handle)
5128 (setq contents (or (condition-case nil
5129 (mm-decompress-buffer filename nil 'sig)
5131 (setq dont-decode t)
5134 (setq filename (cond (filename (file-name-nondirectory filename))
5135 (dont-decode "*raw data*")
5140 (unless (setq charset (mail-content-type-get
5141 (mm-handle-type handle) 'charset))
5142 (unless (setq coding-system (mm-with-unibyte-buffer
5144 (mm-find-buffer-file-coding-system)))
5145 (setq charset gnus-newsgroup-charset))))
5147 (setq charset (or (cdr (assq arg
5148 gnus-summary-show-article-charset-alist))
5149 (mm-read-coding-system "Charset: ")))))
5150 (switch-to-buffer (generate-new-buffer filename))
5151 (if (or coding-system
5153 (setq coding-system (mm-charset-to-coding-system charset))
5154 (not (eq coding-system 'ascii))))
5156 (mm-enable-multibyte)
5157 (insert (mm-decode-coding-string contents coding-system))
5158 (setq buffer-file-coding-system
5159 (if (boundp 'last-coding-system-used)
5160 (symbol-value 'last-coding-system-used)
5162 (mm-disable-multibyte)
5164 (setq buffer-file-coding-system mm-binary-coding-system))
5165 ;; We do it this way to make `normal-mode' set the appropriate mode.
5168 (setq buffer-file-name (expand-file-name filename))
5170 (setq buffer-file-name nil))
5171 (goto-char (point-min)))))
5173 (defun gnus-mime-print-part (&optional handle filename)
5174 "Print the MIME part under point."
5175 (interactive (list nil (ps-print-preprint current-prefix-arg)))
5176 (gnus-article-check-buffer)
5177 (let* ((handle (or handle (get-text-property (point) 'gnus-data)))
5178 (contents (and handle (mm-get-part handle)))
5179 (file (mm-make-temp-file (expand-file-name "mm." mm-tmp-directory)))
5180 (printer (mailcap-mime-info (mm-handle-media-type handle) "print")))
5185 (mm-save-part-to-file handle file)
5186 (call-process shell-file-name nil
5187 (generate-new-buffer " *mm*")
5189 shell-command-switch
5191 printer file (mm-handle-type handle))))
5195 (gnus-print-buffer))
5196 (ps-despool filename)))))
5198 (defun gnus-mime-inline-part (&optional handle arg)
5199 "Insert the MIME part under point into the current buffer.
5200 Compressed files like .gz and .bz2 are decompressed."
5201 (interactive (list nil current-prefix-arg))
5202 (gnus-article-check-buffer)
5204 (setq handle (get-text-property (point) 'gnus-data)))
5207 (inhibit-read-only t)
5208 contents charset coding-system)
5209 (if (and (not arg) (mm-handle-undisplayer handle))
5210 (mm-remove-part handle)
5211 (mm-with-unibyte-buffer
5212 (mm-insert-part handle)
5214 (or (mm-decompress-buffer
5215 (or (mail-content-type-get (mm-handle-type handle)
5217 (mail-content-type-get (mm-handle-disposition handle)
5223 (unless (setq charset (mail-content-type-get
5224 (mm-handle-type handle) 'charset))
5225 (unless (setq coding-system
5226 (mm-with-unibyte-buffer
5228 (mm-find-buffer-file-coding-system)))
5229 (setq charset gnus-newsgroup-charset))))
5231 (if (mm-handle-undisplayer handle)
5232 (mm-remove-part handle))
5235 gnus-summary-show-article-charset-alist))
5236 (mm-read-coding-system "Charset: "))))
5238 (if (mm-handle-undisplayer handle)
5239 (mm-remove-part handle))))
5243 (if (or coding-system
5246 (mm-charset-to-coding-system charset))
5247 (not (eq coding-system 'ascii))))
5248 (mm-decode-coding-string contents coding-system)
5249 (mm-string-to-multibyte contents)))
5252 (defun gnus-mime-set-charset-parameters (handle charset)
5253 "Set CHARSET to parameters in HANDLE.
5254 CHARSET may either be a string or a symbol."
5255 (unless (stringp charset)
5256 (setq charset (symbol-name charset)))
5257 (if (stringp (car handle))
5258 (dolist (h (cdr handle))
5259 (gnus-mime-set-charset-parameters h charset))
5260 (let* ((type (mm-handle-type (if (equal (mm-handle-media-type handle)
5261 "message/external-body")
5263 (unless (mm-handle-cache handle)
5264 (mm-extern-cache-contents handle))
5265 (mm-handle-cache handle))
5267 (param (assq 'charset (cdr type))))
5269 (setcdr param charset)
5270 (setcdr type (cons (cons 'charset charset) (cdr type)))))))
5272 (defun gnus-mime-view-part-as-charset (&optional handle arg)
5273 "Insert the MIME part under point into the current buffer using the
5275 (interactive (list nil current-prefix-arg))
5276 (gnus-article-check-buffer)
5277 (let ((handle (or handle (get-text-property (point) 'gnus-data)))
5278 (fun (get-text-property (point) 'gnus-callback))
5279 (gnus-newsgroup-ignored-charsets 'gnus-all)
5280 charset form preferred parts)
5287 gnus-summary-show-article-charset-alist))
5288 (mm-read-coding-system "Charset: "))))
5289 (if (mm-handle-undisplayer handle)
5290 (mm-remove-part handle)))
5291 (gnus-mime-set-charset-parameters handle charset)
5292 (when (and (consp (setq form (cdr-safe fun)))
5293 (setq form (ignore-errors
5294 (assq 'gnus-mime-display-alternative form)))
5295 (setq preferred (caddr form))
5297 (when (eq (car preferred) 'quote)
5298 (setq preferred (cadr preferred)))
5299 (not (equal preferred
5300 (get-text-property (point) 'gnus-data))))
5301 (setq parts (get-text-property (point) 'gnus-part))
5302 (setq parts (cdr (assq parts
5303 gnus-article-mime-handle-alist)))
5304 (equal (mm-handle-media-type parts) "multipart/alternative")
5305 (setq parts (reverse (cdr parts))))
5307 (list 'quote (or (cadr (member preferred parts))
5309 (funcall fun handle)))))
5311 (defun gnus-mime-view-part-externally (&optional handle)
5312 "View the MIME part under point with an external viewer."
5314 (gnus-article-check-buffer)
5315 (let* ((handle (or handle (get-text-property (point) 'gnus-data)))
5316 (mm-user-display-methods nil)
5317 (mm-inlined-types nil)
5318 (mail-parse-charset gnus-newsgroup-charset)
5319 (mail-parse-ignored-charsets
5320 (with-current-buffer gnus-summary-buffer
5321 gnus-newsgroup-ignored-charsets))
5322 (type (mm-handle-media-type handle))
5323 (method (mailcap-mime-info type))
5324 (mm-enable-external t))
5325 (if (not (stringp method))
5326 (gnus-mime-view-part-as-type
5327 nil (lambda (type) (stringp (mailcap-mime-info type))))
5329 (mm-display-part handle nil t)))))
5331 (defun gnus-mime-view-part-internally (&optional handle)
5332 "View the MIME part under point with an internal viewer.
5333 If no internal viewer is available, use an external viewer."
5335 (gnus-article-check-buffer)
5336 (let* ((handle (or handle (get-text-property (point) 'gnus-data)))
5337 (mm-inlined-types '(".*"))
5338 (mm-inline-large-images t)
5339 (mail-parse-charset gnus-newsgroup-charset)
5340 (mail-parse-ignored-charsets
5341 (with-current-buffer gnus-summary-buffer
5342 gnus-newsgroup-ignored-charsets))
5343 (inhibit-read-only t))
5344 (if (not (mm-inlinable-p handle))
5345 (gnus-mime-view-part-as-type
5346 nil (lambda (type) (mm-inlinable-p handle type)))
5348 (gnus-bind-safe-url-regexp (mm-display-part handle))))))
5350 (defun gnus-mime-action-on-part (&optional action)
5351 "Do something with the MIME attachment at \(point\)."
5353 (list (gnus-completing-read "Action" (mapcar 'car gnus-mime-action-alist) t)))
5354 (gnus-article-check-buffer)
5355 (let ((action-pair (assoc action gnus-mime-action-alist)))
5357 (funcall (cdr action-pair)))))
5359 (defun gnus-article-part-wrapper (n function &optional no-handle interactive)
5360 "Call FUNCTION on MIME part N.
5361 Unless NO-HANDLE, call FUNCTION with N-th MIME handle as it's only argument.
5362 If INTERACTIVE, call FUNCTION interactivly."
5364 ;; Check whether the article is displayed.
5365 (unless (and (gnus-buffer-live-p gnus-article-buffer)
5366 (setq window (get-buffer-window gnus-article-buffer t))
5367 (frame-visible-p (setq frame (window-frame window))))
5368 (error "No article is displayed"))
5369 (with-current-buffer gnus-article-buffer
5370 ;; Check whether the article displays the right contents.
5371 (unless (with-current-buffer gnus-summary-buffer
5372 (eq gnus-current-article (gnus-summary-article-number)))
5373 (error "You should select the right article first"))
5375 (setq n (prefix-numeric-value n))
5377 (setq n (or (get-text-property pt 'gnus-part)
5379 (get-text-property (1- pt) 'gnus-part))
5380 (get-text-property (prog2
5386 (or (and (setq pt (previous-single-property-change
5389 (next-single-property-change (point) 'gnus-part)
5393 ;; Check whether the specified part exists.
5394 (when (> n (length gnus-article-mime-handle-alist))
5395 (error "No such part")))
5398 ;; To select the window is needed so that the cursor
5399 ;; might be visible on the MIME button.
5400 (select-window (prog1
5402 (setq window (selected-window))
5403 ;; Article may be displayed in the other frame.
5404 (gnus-select-frame-set-input-focus
5407 (setq frame (selected-frame))))))
5408 (when (gnus-article-goto-part n)
5409 ;; We point the cursor and the arrow at the MIME button
5410 ;; when the `function' prompt the user for something.
5411 (unless (and (pos-visible-in-window-p)
5412 (> (count-lines (point) (window-end))
5413 (/ (1- (window-height)) 3)))
5414 (recenter (/ (1- (window-height)) 3)))
5415 (let ((cursor-in-non-selected-windows t)
5416 (overlay-arrow-string "=>")
5417 (overlay-arrow-position (point-marker)))
5420 ((and no-handle interactive)
5421 (call-interactively function))
5426 function (get-text-property (point) 'gnus-data)))
5429 (get-text-property (point) 'gnus-data))))
5430 (set-marker overlay-arrow-position nil)
5431 (unless gnus-auto-select-part
5432 (gnus-select-frame-set-input-focus frame)
5433 (select-window window))))
5435 (if gnus-inhibit-mime-unbuttonizing
5436 ;; This is the default though the program shouldn't reach here.
5437 (error "No such part")
5438 ;; The part which doesn't have the MIME button is selected.
5439 ;; So, we display all the buttons and redo it.
5440 (let ((gnus-inhibit-mime-unbuttonizing t))
5441 (gnus-summary-show-article)
5442 (gnus-article-part-wrapper n function no-handle))))))
5444 (defun gnus-article-pipe-part (n)
5445 "Pipe MIME part N, which is the numerical prefix."
5447 (gnus-article-part-wrapper n 'mm-pipe-part))
5449 (defun gnus-article-save-part (n)
5450 "Save MIME part N, which is the numerical prefix."
5452 (gnus-article-part-wrapper n 'mm-save-part))
5454 (defun gnus-article-interactively-view-part (n)
5455 "View MIME part N interactively, which is the numerical prefix."
5457 (gnus-article-part-wrapper n 'mm-interactively-view-part))
5459 (defun gnus-article-copy-part (n)
5460 "Copy MIME part N, which is the numerical prefix."
5462 (gnus-article-part-wrapper n 'gnus-mime-copy-part))
5464 (defun gnus-article-view-part-as-charset (n)
5465 "View MIME part N using a specified charset.
5466 N is the numerical prefix."
5468 (gnus-article-part-wrapper n 'gnus-mime-view-part-as-charset))
5470 (defun gnus-article-view-part-externally (n)
5471 "View MIME part N externally, which is the numerical prefix."
5473 (gnus-article-part-wrapper n 'gnus-mime-view-part-externally))
5475 (defun gnus-article-inline-part (n)
5476 "Inline MIME part N, which is the numerical prefix."
5478 (gnus-article-part-wrapper n 'gnus-mime-inline-part))
5480 (defun gnus-article-save-part-and-strip (n)
5481 "Save MIME part N and replace it with an external body.
5482 N is the numerical prefix."
5484 (gnus-article-part-wrapper n 'gnus-mime-save-part-and-strip t))
5486 (defun gnus-article-replace-part (n)
5487 "Replace MIME part N with an external body.
5488 N is the numerical prefix."
5490 (gnus-article-part-wrapper n 'gnus-mime-replace-part t t))
5492 (defun gnus-article-delete-part (n)
5493 "Delete MIME part N and add some information about the removed part.
5494 N is the numerical prefix."
5496 (gnus-article-part-wrapper n 'gnus-mime-delete-part t))
5498 (defun gnus-article-view-part-as-type (n)
5499 "Choose a MIME media type, and view part N as such.
5500 N is the numerical prefix."
5502 (gnus-article-part-wrapper n 'gnus-mime-view-part-as-type t))
5504 (defun gnus-article-mime-match-handle-first (condition)
5507 (dolist (ihandle gnus-article-mime-handle-alist)
5509 ((functionp condition)
5510 (funcall condition (cdr ihandle)))
5511 ((eq condition 'undisplayed)
5512 (not (or (mm-handle-undisplayer (cdr ihandle))
5513 (equal (mm-handle-media-type (cdr ihandle))
5514 "multipart/alternative"))))
5515 ((eq condition 'undisplayed-alternative)
5516 (not (mm-handle-undisplayer (cdr ihandle))))
5518 (gnus-article-goto-part (car ihandle))
5519 (or (not n) (< (car ihandle) n)))
5520 (setq n (car ihandle))))
5524 (defun gnus-article-view-part (&optional n)
5525 "View MIME part N, which is the numerical prefix.
5526 If the part is already shown, hide the part. If N is nil, view
5529 (with-current-buffer gnus-article-buffer
5530 (or (numberp n) (setq n (gnus-article-mime-match-handle-first
5531 gnus-article-mime-match-handle-function)))
5532 (when (> n (length gnus-article-mime-handle-alist))
5533 (error "No such part"))
5534 (let ((handle (cdr (assq n gnus-article-mime-handle-alist))))
5535 (when (gnus-article-goto-part n)
5536 (if (equal (car handle) "multipart/alternative")
5537 (gnus-article-press-button)
5538 (when (eq (gnus-mm-display-part handle) 'internal)
5539 (gnus-set-window-start)))))))
5541 (defsubst gnus-article-mime-total-parts ()
5542 (if (bufferp (car gnus-article-mime-handles))
5544 (1- (length gnus-article-mime-handles))))
5546 (defun gnus-mm-display-part (handle)
5547 "Display HANDLE and fix MIME button."
5548 (let ((id (get-text-property (point) 'gnus-part))
5550 (inhibit-read-only t))
5553 (let ((window (selected-window))
5554 (mail-parse-charset gnus-newsgroup-charset)
5555 (mail-parse-ignored-charsets
5556 (if (gnus-buffer-live-p gnus-summary-buffer)
5557 (with-current-buffer gnus-summary-buffer
5558 gnus-newsgroup-ignored-charsets)
5562 (let ((win (gnus-get-buffer-window (current-buffer) t))
5565 (select-window win))
5568 (if (mm-handle-displayed-p handle)
5569 ;; This will remove the part.
5570 (mm-display-part handle)
5572 (narrow-to-region (point)
5573 (if (eobp) (point) (1+ (point))))
5574 (gnus-bind-safe-url-regexp (mm-display-part handle))
5575 ;; We narrow to the part itself and
5576 ;; then call the treatment functions.
5577 (goto-char (point-min))
5579 (narrow-to-region (point) (point-max))
5582 (gnus-article-mime-total-parts)
5583 (mm-handle-media-type handle)))))
5584 (if (window-live-p window)
5585 (select-window window)))))
5588 (gnus-insert-mime-button
5589 handle id (list (mm-handle-displayed-p handle)))
5590 (goto-char point))))
5592 (defun gnus-article-goto-part (n)
5593 "Go to MIME part N."
5594 (when gnus-break-pages
5597 (let ((start (text-property-any (point-min) (point-max) 'gnus-part n))
5598 part handle end next handles)
5601 (if (setq handle (get-text-property start 'gnus-data))
5603 ;; Go to the displayed subpart, assuming this is
5604 ;; multipart/alternative.
5607 (while (and (not handle)
5610 (setq next (text-property-not-all part end
5613 handle (get-text-property part 'gnus-data))
5614 (push (cons handle part) handles)
5615 (unless (mm-handle-displayed-p handle)
5617 part (text-property-any part end 'gnus-data nil))))
5619 ;; No subpart is displayed, so we find preferred one.
5621 (cdr (assq (mm-preferred-alternative
5622 (nreverse (mapcar 'car handles)))
5625 (goto-char (1+ part))
5627 (when gnus-break-pages
5628 (gnus-narrow-to-page))))
5630 (defun gnus-insert-mime-button (handle gnus-tmp-id &optional displayed)
5631 (let ((gnus-tmp-name
5632 (or (mail-content-type-get (mm-handle-type handle) 'name)
5633 (mail-content-type-get (mm-handle-disposition handle) 'filename)
5634 (mail-content-type-get (mm-handle-type handle) 'url)
5636 (gnus-tmp-type (mm-handle-media-type handle))
5637 (gnus-tmp-description (or (mm-handle-description handle) ""))
5639 (if (if displayed (car displayed)
5640 (mm-handle-displayed-p handle))
5642 (gnus-tmp-length (with-current-buffer (mm-handle-buffer handle)
5644 gnus-tmp-type-long b e)
5645 (when (string-match ".*/" gnus-tmp-name)
5646 (setq gnus-tmp-name (replace-match "" t t gnus-tmp-name)))
5647 (setq gnus-tmp-type-long (concat gnus-tmp-type
5648 (and (not (equal gnus-tmp-name ""))
5649 (concat "; " gnus-tmp-name))))
5650 (unless (equal gnus-tmp-description "")
5651 (setq gnus-tmp-type-long (concat " --- " gnus-tmp-type-long)))
5656 gnus-mime-button-line-format gnus-mime-button-line-format-alist
5657 `(keymap ,gnus-mime-button-map
5658 gnus-callback gnus-mm-display-part
5659 gnus-part ,gnus-tmp-id
5660 article-type annotation
5663 ;; Exclude a newline.
5666 (when gnus-article-button-face
5667 (gnus-overlay-put (gnus-make-overlay b e nil t)
5668 'face gnus-article-button-face))
5669 (widget-convert-button
5672 :action 'gnus-widget-press-button
5673 :button-keymap gnus-mime-button-map
5676 ;; Needed to properly clear the message due to a bug in
5677 ;; wid-edit (XEmacs only).
5678 (if (boundp 'help-echo-owns-message)
5679 (setq help-echo-owns-message t))
5681 "%S: %s the MIME part; %S: more options"
5682 (aref gnus-mouse-2 0)
5683 (if (mm-handle-displayed-p (widget-get widget :mime-handle))
5685 (aref gnus-down-mouse-3 0))))))
5687 (defun gnus-widget-press-button (elems el)
5688 (goto-char (widget-get elems :from))
5689 (gnus-article-press-button))
5691 (defvar gnus-displaying-mime nil)
5693 (defun gnus-display-mime (&optional ihandles)
5694 "Display the MIME parts."
5696 (save-selected-window
5697 (let ((window (get-buffer-window gnus-article-buffer))
5700 (select-window window)
5701 ;; We have to do this since selecting the window
5702 ;; may change the point. So we set the window point.
5703 (set-window-point window point)))
5704 (let ((handles ihandles)
5705 (inhibit-read-only t)
5708 ((setq handles (mm-dissect-buffer nil gnus-article-loose-mime))
5709 (when gnus-article-emulate-mime
5710 (mm-uu-dissect-text-parts handles)))
5711 (gnus-article-emulate-mime
5712 (setq handles (mm-uu-dissect))))
5713 (when (and (not ihandles)
5714 (not gnus-displaying-mime))
5715 ;; Top-level call; we clean up.
5716 (when gnus-article-mime-handles
5717 (mm-destroy-parts gnus-article-mime-handles)
5718 (setq gnus-article-mime-handle-alist nil));; A trick.
5719 (setq gnus-article-mime-handles handles)
5720 ;; We allow users to glean info from the handles.
5721 (when gnus-article-mime-part-function
5722 (gnus-mime-part-function handles)))
5724 (or (not (stringp (car handles)))
5727 (when (and (not ihandles)
5728 (not gnus-displaying-mime))
5729 ;; Clean up for mime parts.
5731 (delete-region (point) (point-max)))
5732 (let ((gnus-displaying-mime t))
5733 (gnus-mime-display-part handles)))
5736 (narrow-to-region (point) (point-max))
5737 (gnus-treat-article nil 1 1 "text/plain")
5740 ;; Highlight the headers.
5744 (narrow-to-region (point-min) (point))
5745 (gnus-article-save-original-date
5746 (gnus-treat-article 'head)))))))
5747 ;; Cope with broken MIME messages.
5748 (goto-char (point-max))
5752 (defcustom gnus-mime-display-multipart-as-mixed nil
5753 "Display \"multipart\" parts as \"multipart/mixed\".
5755 If t, it overrides nil values of
5756 `gnus-mime-display-multipart-alternative-as-mixed' and
5757 `gnus-mime-display-multipart-related-as-mixed'."
5758 :group 'gnus-article-mime
5761 (defcustom gnus-mime-display-multipart-alternative-as-mixed nil
5762 "Display \"multipart/alternative\" parts as \"multipart/mixed\"."
5764 :group 'gnus-article-mime
5767 (defcustom gnus-mime-display-multipart-related-as-mixed nil
5768 "Display \"multipart/related\" parts as \"multipart/mixed\".
5770 If displaying \"text/html\" is discouraged \(see
5771 `mm-discouraged-alternatives'\) images or other material inside a
5772 \"multipart/related\" part might be overlooked when this variable is nil."
5774 :group 'gnus-article-mime
5777 (defun gnus-mime-display-part (handle)
5779 ;; Maybe a broken MIME message.
5782 ((not (stringp (car handle)))
5783 (gnus-mime-display-single handle))
5784 ;; User-defined multipart
5785 ((cdr (assoc (car handle) gnus-mime-multipart-functions))
5786 (funcall (cdr (assoc (car handle) gnus-mime-multipart-functions))
5788 ;; multipart/alternative
5789 ((and (equal (car handle) "multipart/alternative")
5790 (not (or gnus-mime-display-multipart-as-mixed
5791 gnus-mime-display-multipart-alternative-as-mixed)))
5792 (let ((id (1+ (length gnus-article-mime-handle-alist))))
5793 (push (cons id handle) gnus-article-mime-handle-alist)
5794 (gnus-mime-display-alternative (cdr handle) nil nil id)))
5795 ;; multipart/related
5796 ((and (equal (car handle) "multipart/related")
5797 (not (or gnus-mime-display-multipart-as-mixed
5798 gnus-mime-display-multipart-related-as-mixed)))
5799 ;;;!!!We should find the start part, but we just default
5800 ;;;!!!to the first part.
5801 ;;(gnus-mime-display-part (cadr handle))
5802 ;;;!!! Most multipart/related is an HTML message plus images.
5803 ;;;!!! Unfortunately we are unable to let W3 display those
5804 ;;;!!! included images, so we just display it as a mixed multipart.
5805 ;;(gnus-mime-display-mixed (cdr handle))
5806 ;;;!!! No, w3 can display everything just fine.
5807 (gnus-mime-display-part (cadr handle)))
5808 ((equal (car handle) "multipart/signed")
5809 (gnus-add-wash-type 'signed)
5810 (gnus-mime-display-security handle))
5811 ((equal (car handle) "multipart/encrypted")
5812 (gnus-add-wash-type 'encrypted)
5813 (gnus-mime-display-security handle))
5814 ;; Other multiparts are handled like multipart/mixed.
5816 (gnus-mime-display-mixed (cdr handle)))))
5818 (defun gnus-mime-part-function (handles)
5819 (if (stringp (car handles))
5820 (mapcar 'gnus-mime-part-function (cdr handles))
5821 (funcall gnus-article-mime-part-function handles)))
5823 (defun gnus-mime-display-mixed (handles)
5824 (mapcar 'gnus-mime-display-part handles))
5826 (defun gnus-mime-display-single (handle)
5827 (let ((type (mm-handle-media-type handle))
5828 (ignored gnus-ignored-mime-types)
5835 (when (string-match (pop ignored) type)
5836 (throw 'ignored nil)))
5837 (if (and (setq not-attachment
5838 (and (not (mm-inline-override-p handle))
5839 (or (not (mm-handle-disposition handle))
5840 (equal (car (mm-handle-disposition handle))
5842 (mm-attachment-override-p handle))))
5843 (mm-automatic-display-p handle)
5845 (mm-inlinable-p handle)
5846 (mm-inlined-p handle))
5847 (mm-automatic-external-display-p type)))
5849 (when (equal (mm-handle-media-supertype handle) "text")
5851 (let ((id (1+ (length gnus-article-mime-handle-alist)))
5853 (push (cons id handle) gnus-article-mime-handle-alist)
5855 (equal (mm-handle-media-supertype handle) "message"))
5858 (cond ((not (bolp)) 2)
5859 ((or (bobp) (eq (char-before (1- (point))) ?\n)) 0)
5861 (when (or (not display)
5862 (not (gnus-unbuttonized-mime-type-p type))
5863 (eq id gnus-mime-buttonized-part-id))
5864 (gnus-insert-mime-button
5865 handle id (list (or display (and not-attachment text))))
5866 (gnus-article-insert-newline)
5867 ;; Remember modify the number of forward lines.
5875 (let ((mail-parse-charset gnus-newsgroup-charset)
5876 (mail-parse-ignored-charsets
5877 (save-excursion (condition-case ()
5878 (set-buffer gnus-summary-buffer)
5880 gnus-newsgroup-ignored-charsets)))
5881 (gnus-bind-safe-url-regexp (mm-display-part handle t)))
5882 (goto-char (point-max)))
5883 ((and text not-attachment)
5887 (gnus-article-insert-newline)
5890 (let ((charset (or (mail-content-type-get (mm-handle-type handle)
5892 (and (equal type "text/calendar") 'utf-8))))
5893 (cond ((not charset)
5894 (mm-string-as-multibyte (mm-get-part handle)))
5895 ((eq charset 'gnus-decoded)
5896 (with-current-buffer (mm-handle-buffer handle)
5899 (mm-decode-string (mm-get-part handle) charset)))))
5900 (goto-char (point-max))))
5904 (narrow-to-region beg (point))
5905 (if (eq handle gnus-article-mime-handles)
5906 ;; The format=flowed case.
5907 (gnus-treat-article nil 1 1 (mm-handle-media-type handle))
5908 ;; Don't count signature parts that are never displayed.
5909 ;; The part number should be re-calculated supposing this
5910 ;; might be a message/rfc822 part.
5912 (dolist (part gnus-article-mime-handles)
5913 (unless (or (stringp part)
5914 (equal (car (mm-handle-type part))
5915 "application/pgp-signature"))
5916 (push part handles)))
5918 nil (length (memq handle handles)) (length handles)
5919 (mm-handle-media-type handle)))))))))))
5921 (defun gnus-unbuttonized-mime-type-p (type)
5922 "Say whether TYPE is to be unbuttonized."
5923 (unless gnus-inhibit-mime-unbuttonizing
5925 (let ((types gnus-unbuttonized-mime-types))
5927 (when (string-match (pop types) type)
5928 (throw 'found t)))))
5930 (let ((types gnus-buttonized-mime-types))
5932 (when (string-match (pop types) type)
5933 (throw 'found t)))))))))
5935 (defun gnus-article-insert-newline ()
5936 "Insert a newline, but mark it as undeletable."
5937 (gnus-put-text-property
5938 (point) (progn (insert "\n") (point)) 'gnus-undeletable t))
5940 (defun gnus-mime-display-alternative (handles &optional preferred ibegend id)
5941 (let* ((preferred (or preferred (mm-preferred-alternative handles)))
5944 handle (inhibit-read-only t) from props begend not-pref)
5945 (save-window-excursion
5948 (narrow-to-region (car ibegend)
5951 (goto-char (car ibegend))
5954 (delete-region (point-min) (point-max))
5955 (mm-remove-parts handles))
5956 (setq begend (list (point-marker)))
5958 (unless (setq not-pref (cadr (member preferred ihandles)))
5959 (setq not-pref (car ihandles)))
5962 (not (gnus-unbuttonized-mime-type-p
5963 "multipart/alternative")))
5964 (gnus-add-text-properties
5967 (insert (format "%d. " id))
5971 (unless ,(not ibegend)
5972 (setq gnus-article-mime-handle-alist
5973 ',gnus-article-mime-handle-alist))
5974 (gnus-mime-display-alternative
5975 ',ihandles ',not-pref ',begend ,id))
5976 keymap ,gnus-mime-button-map
5977 ,gnus-mouse-face-prop ,gnus-article-mouse-face
5978 face ,gnus-article-button-face
5980 article-type multipart))
5981 (widget-convert-button 'link from (point)
5982 :action 'gnus-widget-press-button
5983 :button-keymap gnus-widget-button-keymap)
5985 (while (setq handle (pop handles))
5986 (gnus-add-text-properties
5989 (insert (format "(%c) %-18s"
5990 (if (equal handle preferred) ?* ? )
5991 (mm-handle-media-type handle)))
5995 (unless ,(not ibegend)
5996 (setq gnus-article-mime-handle-alist
5997 ',gnus-article-mime-handle-alist))
5998 (gnus-mime-display-alternative
5999 ',ihandles ',handle ',begend ,id))
6000 keymap ,gnus-mime-button-map
6001 ,gnus-mouse-face-prop ,gnus-article-mouse-face
6002 face ,gnus-article-button-face
6005 (widget-convert-button 'link from (point)
6006 :action 'gnus-widget-press-button
6007 :button-keymap gnus-widget-button-keymap)
6011 (if (stringp (car preferred))
6012 (gnus-display-mime preferred)
6013 (let ((mail-parse-charset gnus-newsgroup-charset)
6014 (mail-parse-ignored-charsets
6015 (with-current-buffer gnus-summary-buffer
6016 gnus-newsgroup-ignored-charsets)))
6017 (gnus-bind-safe-url-regexp (mm-display-part preferred))
6021 (narrow-to-region (car begend) (point-max))
6023 nil (length gnus-article-mime-handle-alist)
6024 (gnus-article-mime-total-parts)
6025 (mm-handle-media-type preferred))))))
6026 (goto-char (point-max))
6027 (setcdr begend (point-marker)))))
6029 (goto-char point))))
6031 (defconst gnus-article-wash-status-strings
6032 (let ((alist '((cite "c" "Possible hidden citation text"
6033 " " "All citation text visible")
6034 (headers "h" "Hidden headers"
6035 " " "All headers visible.")
6036 (pgp "p" "Encrypted or signed message status hidden"
6037 " " "No hidden encryption nor digital signature status")
6038 (signature "s" "Signature has been hidden"
6039 " " "Signature is visible")
6040 (overstrike "o" "Overstrike (^H) characters applied"
6041 " " "No overstrike characters applied")
6042 (emphasis "e" "/*_Emphasis_*/ characters applied"
6043 " " "No /*_emphasis_*/ characters applied")))
6045 (dolist (entry alist result)
6046 (let ((key (nth 0 entry))
6047 (on (copy-sequence (nth 1 entry)))
6048 (on-help (nth 2 entry))
6049 (off (copy-sequence (nth 3 entry)))
6050 (off-help (nth 4 entry)))
6051 (put-text-property 0 1 'help-echo on-help on)
6052 (put-text-property 0 1 'help-echo off-help off)
6053 (push (list key on off) result))))
6054 "Alist of strings describing wash status in the mode line.
6055 Each entry has the form (KEY ON OF), where the KEY is a symbol
6056 representing the particular washing function, ON is the string to use
6057 in the article mode line when the washing function is active, and OFF
6058 is the string to use when it is inactive.")
6060 (defun gnus-article-wash-status-entry (key value)
6061 (let ((entry (assoc key gnus-article-wash-status-strings)))
6062 (if value (nth 1 entry) (nth 2 entry))))
6064 (defun gnus-article-wash-status ()
6065 "Return a string which display status of article washing."
6066 (with-current-buffer gnus-article-buffer
6067 (let ((cite (memq 'cite gnus-article-wash-types))
6068 (headers (memq 'headers gnus-article-wash-types))
6069 (boring (memq 'boring-headers gnus-article-wash-types))
6070 (pgp (memq 'pgp gnus-article-wash-types))
6071 (pem (memq 'pem gnus-article-wash-types))
6072 (signed (memq 'signed gnus-article-wash-types))
6073 (encrypted (memq 'encrypted gnus-article-wash-types))
6074 (signature (memq 'signature gnus-article-wash-types))
6075 (overstrike (memq 'overstrike gnus-article-wash-types))
6076 (emphasis (memq 'emphasis gnus-article-wash-types)))
6078 (gnus-article-wash-status-entry 'cite cite)
6079 (gnus-article-wash-status-entry 'headers (or headers boring))
6080 (gnus-article-wash-status-entry 'pgp (or pgp pem signed encrypted))
6081 (gnus-article-wash-status-entry 'signature signature)
6082 (gnus-article-wash-status-entry 'overstrike overstrike)
6083 (gnus-article-wash-status-entry 'emphasis emphasis)))))
6085 (defun gnus-add-wash-type (type)
6086 "Add a washing of TYPE to the current status."
6087 (add-to-list 'gnus-article-wash-types type))
6089 (defun gnus-delete-wash-type (type)
6090 "Add a washing of TYPE to the current status."
6091 (setq gnus-article-wash-types (delq type gnus-article-wash-types)))
6093 (defun gnus-add-image (category image)
6094 "Add IMAGE of CATEGORY to the list of displayed images."
6095 (let ((entry (assq category gnus-article-image-alist)))
6097 (setq entry (list category))
6098 (push entry gnus-article-image-alist))
6099 (nconc entry (list image))))
6101 (defun gnus-delete-images (category)
6102 "Delete all images in CATEGORY."
6103 (let ((entry (assq category gnus-article-image-alist)))
6104 (dolist (image (cdr entry))
6105 (gnus-remove-image image category))
6106 (setq gnus-article-image-alist (delq entry gnus-article-image-alist))
6107 (gnus-delete-wash-type category)))
6109 (defalias 'gnus-article-hide-headers-if-wanted 'gnus-article-maybe-hide-headers)
6111 (defun gnus-article-maybe-hide-headers ()
6112 "Hide unwanted headers if `gnus-have-all-headers' is nil.
6113 Provided for backwards compatibility."
6114 (when (and (or (not (gnus-buffer-live-p gnus-summary-buffer))
6115 (not (with-current-buffer gnus-summary-buffer
6116 gnus-have-all-headers)))
6117 (not gnus-inhibit-hiding))
6118 (gnus-article-hide-headers)))
6122 (defun gnus-output-to-file (file-name)
6123 "Append the current article to a file named FILE-NAME.
6124 If `gnus-article-save-coding-system' is non-nil, it is used to encode
6125 text and used as the value of the coding cookie which is added to the
6126 top of a file. Otherwise, this function saves a raw article without
6128 (let* ((artbuf (current-buffer))
6129 (file-name-coding-system nnmail-pathname-coding-system)
6130 (coding gnus-article-save-coding-system)
6131 (coding-system-for-read (if coding
6132 nil ;; Rely on the coding cookie.
6133 mm-text-coding-system))
6134 (coding-system-for-write (or coding
6135 mm-text-coding-system-for-write
6136 mm-text-coding-system))
6137 (exists (file-exists-p file-name)))
6140 (insert-file-contents file-name)
6141 (goto-char (point-min))
6142 ;; Remove the existing coding cookie.
6143 (when (looking-at "X-Gnus-Coding-System: .+\n\n")
6144 (delete-region (match-beginning 0) (match-end 0))))
6145 (goto-char (point-max))
6146 (insert-buffer-substring artbuf)
6147 ;; Append newline at end of the buffer as separator, and then
6149 (goto-char (point-max))
6152 ;; If the coding system is not suitable to encode the text,
6153 ;; ask a user for a proper one.
6154 (when (fboundp 'select-safe-coding-system)
6155 (setq coding (coding-system-base
6156 (save-window-excursion
6157 (select-safe-coding-system (point-min) (point-max)
6159 (setq coding-system-for-write
6160 (or (cdr (assq coding '((mule-utf-8 . utf-8))))
6162 (goto-char (point-min))
6163 ;; Add the coding cookie.
6164 (insert (format "X-Gnus-Coding-System: -*- coding: %s; -*-\n\n"
6165 coding-system-for-write)))
6168 (write-region (point-min) (point-max) file-name nil 'no-message)
6169 (message "Appended to %s" file-name))
6170 (write-region (point-min) (point-max) file-name))))
6173 (defun gnus-narrow-to-page (&optional arg)
6174 "Narrow the article buffer to a page.
6175 If given a numerical ARG, move forward ARG pages."
6177 (setq arg (if arg (prefix-numeric-value arg) 0))
6178 (with-current-buffer gnus-article-buffer
6180 ;; Remove any old next/prev buttons.
6181 (when (gnus-visual-p 'page-marker)
6182 (let ((inhibit-read-only t))
6183 (gnus-remove-text-with-property 'gnus-prev)
6184 (gnus-remove-text-with-property 'gnus-next)))
6186 (when (save-excursion
6188 (if (re-search-backward page-delimiter nil 'move (abs arg))
6190 (setq nd (match-beginning 0)
6192 (when (re-search-backward page-delimiter nil t)
6193 (setq st (match-end 0))))
6194 (when (re-search-forward page-delimiter nil t)
6195 (setq nd (match-beginning 0)
6198 (if (re-search-forward page-delimiter nil 'move arg)
6200 (setq st (match-end 0)
6202 (when (re-search-forward page-delimiter nil t)
6203 (setq nd (match-beginning 0))))
6204 (when (re-search-backward page-delimiter nil t)
6205 (setq st (match-end 0)
6208 (when (re-search-backward page-delimiter nil t)
6209 (goto-char (setq st (match-end 0))))
6210 (when (re-search-forward page-delimiter nil t)
6211 (setq nd (match-beginning 0)))
6213 (setq gnus-page-broken t)
6214 (when pt (goto-char pt))
6215 (narrow-to-region (or st (point-min)) (or nd (point-max)))
6216 (when (gnus-visual-p 'page-marker)
6220 (gnus-insert-next-page-button))
6223 (gnus-insert-prev-page-button))))))))
6225 ;; Article mode commands
6227 (defun gnus-article-goto-next-page ()
6228 "Show the next page of the article."
6230 (when (gnus-article-next-page)
6231 (goto-char (point-min))
6232 (gnus-article-read-summary-keys nil (gnus-character-to-event ?n))))
6235 (defun gnus-article-goto-prev-page ()
6236 "Show the previous page of the article."
6238 (if (save-restriction (widen) (bobp)) ;; Real beginning-of-buffer?
6239 (gnus-article-read-summary-keys nil (gnus-character-to-event ?p))
6240 (gnus-article-prev-page nil)))
6242 ;; This is cleaner but currently breaks `gnus-pick-mode':
6244 ;; (defun gnus-article-goto-next-page ()
6245 ;; "Show the next page of the article."
6247 ;; (gnus-eval-in-buffer-window gnus-summary-buffer
6248 ;; (gnus-summary-next-page)))
6250 ;; (defun gnus-article-goto-prev-page ()
6251 ;; "Show the next page of the article."
6253 ;; (gnus-eval-in-buffer-window gnus-summary-buffer
6254 ;; (gnus-summary-prev-page)))
6256 (defun gnus-article-next-page (&optional lines)
6257 "Show the next page of the current article.
6258 If end of article, return non-nil. Otherwise return nil.
6259 Argument LINES specifies lines to be scrolled up."
6261 (move-to-window-line (if (featurep 'xemacs) -1 (- -1 scroll-margin)))
6262 (if (and (not (and gnus-article-over-scroll
6263 (> (count-lines (window-start) (point-max))
6264 (if (featurep 'xemacs)
6265 (or lines (1- (window-height)))
6266 (+ (or lines (1- (window-height))) scroll-margin)))))
6269 (and (pos-visible-in-window-p) ;Not continuation line.
6270 (>= (1+ (point)) (point-max))))) ;Allow for trailing newline.
6271 ;; Nothing in this page.
6272 (if (or (not gnus-page-broken)
6277 (eobp)))) ;Real end-of-buffer?
6279 (when gnus-article-over-scroll
6280 (gnus-article-next-page-1 lines))
6282 (gnus-narrow-to-page 1) ;Go to next page.
6284 ;; More in this page.
6285 (gnus-article-next-page-1 lines)
6288 (defun gnus-article-beginning-of-window ()
6289 "Move point to the beginning of the window.
6290 In Emacs, the point is placed at the line number which `scroll-margin'
6292 (if (featurep 'xemacs)
6293 (move-to-window-line 0)
6294 ;; There is an obscure bug in Emacs that makes it impossible to
6295 ;; scroll past big pictures in the article buffer. Try to fix
6296 ;; this by adding a sanity check by counting the lines visible.
6297 (when (> (count-lines (window-start) (window-end)) 30)
6298 (move-to-window-line
6299 (min (max 0 scroll-margin)
6300 (max 1 (- (window-height)
6301 (if mode-line-format 1 0)
6302 (if header-line-format 1 0)
6305 (defun gnus-article-next-page-1 (lines)
6307 (let ((scroll-in-place nil))
6310 ;; Long lines may cause an end-of-buffer error.
6311 (goto-char (point-max))))
6312 (gnus-article-beginning-of-window))
6314 (defun gnus-article-prev-page (&optional lines)
6315 "Show previous page of current article.
6316 Argument LINES specifies lines to be scrolled down."
6318 (move-to-window-line 0)
6319 (if (and gnus-page-broken
6321 (not (save-restriction (widen) (bobp)))) ;Real beginning-of-buffer?
6323 (gnus-narrow-to-page -1) ;Go to previous page.
6324 (goto-char (point-max))
6325 (recenter (if gnus-article-over-scroll
6327 (max (if (featurep 'xemacs)
6329 (+ lines scroll-margin))
6331 (- (window-height) 2))
6335 (let ((scroll-in-place nil))
6336 (scroll-down lines))
6337 (beginning-of-buffer
6338 (goto-char (point-min))))
6339 (gnus-article-beginning-of-window))))
6341 (defun gnus-article-only-boring-p ()
6342 "Decide whether there is only boring text remaining in the article.
6343 Something \"interesting\" is a word of at least two letters that does
6344 not have a face in `gnus-article-boring-faces'."
6345 (when (and gnus-article-skip-boring
6346 (boundp 'gnus-article-boring-faces)
6347 (symbol-value 'gnus-article-boring-faces))
6349 (let ((inhibit-point-motion-hooks t))
6351 (while (re-search-forward "\\b\\w\\w" nil t)
6353 (when (not (gnus-intersection
6354 (gnus-faces-at (point))
6355 (symbol-value 'gnus-article-boring-faces)))
6356 (throw 'only-boring nil)))
6357 (throw 'only-boring t))))))
6359 (defun gnus-article-refer-article ()
6360 "Read article specified by message-id around point."
6363 (re-search-backward "[ \t]\\|^" (point-at-bol) t)
6364 (re-search-forward "<?news:<?\\|<" (point-at-eol) t)
6365 (if (re-search-forward "[^@ ]+@[^ \t>]+" (point-at-eol) t)
6366 (let ((msg-id (concat "<" (match-string 0) ">")))
6367 (set-buffer gnus-summary-buffer)
6368 (gnus-summary-refer-article msg-id))
6369 (error "No references around point"))))
6371 (defun gnus-article-show-summary ()
6372 "Reconfigure windows to show summary buffer."
6374 (if (not (gnus-buffer-live-p gnus-summary-buffer))
6375 (error "There is no summary buffer for this article buffer")
6376 (gnus-article-set-globals)
6377 (gnus-configure-windows 'article)
6378 (gnus-summary-goto-subject gnus-current-article)
6379 (gnus-summary-position-point)))
6381 (defun gnus-article-describe-briefly ()
6382 "Describe article mode commands briefly."
6384 (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")))
6386 (defun gnus-article-check-buffer ()
6387 "Beep if not in an article buffer."
6388 (unless (equal major-mode 'gnus-article-mode)
6389 (error "Command invoked outside of a Gnus article buffer")))
6391 (defun gnus-article-read-summary-keys (&optional arg key not-restore-window)
6392 "Read a summary buffer key sequence and execute it from the article buffer."
6394 (gnus-article-check-buffer)
6396 '("q" "Q" "c" "r" "\C-c\C-f" "m" "a" "f"
6397 "Zc" "ZC" "ZE" "ZQ" "ZZ" "Zn" "ZR" "ZG" "ZN" "ZP"
6398 "=" "^" "\M-^" "|"))
6400 '("A " "A<" "A>" "AM" "AP" "AR" "AT" "A\C-?" "A\M-\r" "A\r" "Ab" "Ae"
6401 "An" "Ap" [?A (meta return)] [?A delete]))
6405 '("n" "Gn" "p" "Gp"))
6407 (with-current-buffer gnus-article-current-summary
6408 (let (gnus-pick-mode)
6409 (setq unread-command-events (nconc unread-command-events
6410 (list (or key last-command-event)))
6411 keys (if (featurep 'xemacs)
6412 (events-to-keys (read-key-sequence nil t))
6413 (read-key-sequence nil t)))))
6418 ((eq (aref keys (1- (length keys))) ?\C-h)
6419 (gnus-article-describe-bindings (substring keys 0 -1)))
6420 ((or (member keys nosaves)
6421 (member keys nosave-but-article)
6422 (member keys nosave-in-article))
6424 (save-window-excursion
6425 (pop-to-buffer gnus-article-current-summary)
6426 ;; We disable the pick minor mode commands.
6427 (let (gnus-pick-mode)
6428 (setq func (key-binding keys t))))
6432 (unless (member keys nosave-in-article)
6433 (set-buffer gnus-article-current-summary))
6434 (call-interactively func)
6435 (setq new-sum-point (point)))
6436 (when (member keys nosave-but-article)
6437 (pop-to-buffer gnus-article-buffer))))
6439 ;; These commands should restore window configuration.
6440 (let ((obuf (current-buffer))
6441 (owin (current-window-configuration))
6442 win func in-buffer selected new-sum-start new-sum-hscroll err)
6443 (cond (not-restore-window
6444 (pop-to-buffer gnus-article-current-summary)
6445 (setq win (selected-window)))
6446 ((setq win (get-buffer-window gnus-article-current-summary))
6447 (select-window win))
6449 (let ((summary-buffer gnus-article-current-summary))
6450 (gnus-configure-windows 'article)
6451 (unless (setq win (get-buffer-window summary-buffer 'visible))
6452 (let ((gnus-buffer-configuration
6453 '((article ((vertical 1.0
6454 (summary 0.25 point)
6456 (gnus-configure-windows 'article))
6457 (setq win (get-buffer-window summary-buffer 'visible)))
6458 (gnus-select-frame-set-input-focus (window-frame win))
6459 (select-window win))))
6460 (setq in-buffer (current-buffer))
6461 ;; We disable the pick minor mode commands.
6462 (if (and (setq func (let (gnus-pick-mode)
6463 (key-binding keys t)))
6465 (condition-case code
6467 (call-interactively func)
6473 (when (eq win (selected-window))
6474 (setq new-sum-point (point)
6475 new-sum-start (window-start win)
6476 new-sum-hscroll (window-hscroll win)))
6477 (when (or (eq in-buffer (current-buffer))
6478 (when (eq obuf (current-buffer))
6479 (set-buffer in-buffer)
6481 (setq selected (gnus-summary-select-article))
6483 (unless not-restore-window
6484 (set-window-configuration owin))
6485 (when (and (eq selected 'old)
6487 (set-window-start (get-buffer-window (current-buffer))
6489 (set-window-point (get-buffer-window (current-buffer))
6490 (if (article-goto-body)
6493 (when (and (not not-restore-window)
6496 (with-current-buffer (window-buffer win)
6497 (eq major-mode 'gnus-summary-mode)))
6498 (set-window-point win new-sum-point)
6499 (set-window-start win new-sum-start)
6500 (set-window-hscroll win new-sum-hscroll))))
6501 (set-window-configuration owin)
6503 (signal (car err) (cdr err))
6506 (defun gnus-article-read-summary-send-keys ()
6508 (let ((unread-command-events (list (gnus-character-to-event ?S))))
6509 (gnus-article-read-summary-keys)))
6511 (defun gnus-article-describe-key (key)
6512 "Display documentation of the function invoked by KEY.
6513 KEY is a string or a vector."
6514 (interactive (list (let ((cursor-in-echo-area t)) ;; better for XEmacs.
6515 (read-key-sequence "Describe key: "))))
6516 (gnus-article-check-buffer)
6517 (if (memq (key-binding key t) '(gnus-article-read-summary-keys
6518 gnus-article-read-summary-send-keys))
6519 (with-current-buffer gnus-article-current-summary
6520 (setq unread-command-events
6521 (if (featurep 'xemacs)
6523 (mapcar (lambda (x) (if (and (integerp x) (>= x 128))
6524 (list 'meta (- x 128))
6527 (let ((cursor-in-echo-area t)
6529 (describe-key (read-key-sequence nil t))))
6530 (describe-key key)))
6532 (defun gnus-article-describe-key-briefly (key &optional insert)
6533 "Display documentation of the function invoked by KEY.
6534 KEY is a string or a vector."
6535 (interactive (list (let ((cursor-in-echo-area t)) ;; better for XEmacs.
6536 (read-key-sequence "Describe key: "))
6537 current-prefix-arg))
6538 (gnus-article-check-buffer)
6539 (if (memq (key-binding key t) '(gnus-article-read-summary-keys
6540 gnus-article-read-summary-send-keys))
6541 (with-current-buffer gnus-article-current-summary
6542 (setq unread-command-events
6543 (if (featurep 'xemacs)
6545 (mapcar (lambda (x) (if (and (integerp x) (>= x 128))
6546 (list 'meta (- x 128))
6549 (let ((cursor-in-echo-area t)
6551 (describe-key-briefly (read-key-sequence nil t) insert)))
6552 (describe-key-briefly key insert)))
6554 ;;`gnus-agent-mode' in gnus-agent.el will define it.
6555 (defvar gnus-agent-summary-mode)
6556 (defvar gnus-draft-mode)
6557 ;; Calling help-buffer will autoload help-mode.
6558 (defvar help-xref-stack-item)
6559 ;; Emacs 22 doesn't load it in the batch mode.
6561 (autoload 'help-buffer "help-mode"))
6563 (defun gnus-article-describe-bindings (&optional prefix)
6564 "Show a list of all defined keys, and their definitions.
6565 The optional argument PREFIX, if non-nil, should be a key sequence;
6566 then we display only bindings that start with that prefix."
6568 (gnus-article-check-buffer)
6569 (let ((keymap (copy-keymap gnus-article-mode-map))
6570 (map (copy-keymap gnus-article-send-map))
6571 (sumkeys (where-is-internal 'gnus-article-read-summary-keys))
6573 (define-key keymap "S" map)
6574 (define-key map [t] nil)
6575 (with-current-buffer gnus-article-current-summary
6578 (if (setq parent (keymap-parent gnus-article-mode-map))
6580 (setq parent (copy-keymap parent))
6581 (set-keymap-parent parent (current-local-map)))
6582 (current-local-map)))
6583 (set-keymap-parent map (key-binding "S"))
6584 (let (key def gnus-pick-mode)
6586 (setq key (pop sumkeys))
6587 (cond ((and (vectorp key) (= (length key) 1)
6588 (consp (setq def (aref key 0)))
6589 (numberp (car def)) (numberp (cdr def)))
6590 (when (< (max (car def) (cdr def)) 128)
6594 (nreverse (gnus-uncompress-range def)))
6596 ((setq def (key-binding key))
6597 (unless (eq def 'undefined)
6598 (define-key keymap key def))))))
6599 (when (boundp 'gnus-agent-summary-mode)
6600 (setq agent gnus-agent-summary-mode))
6601 (when (boundp 'gnus-draft-mode)
6602 (setq draft gnus-draft-mode)))
6604 (use-local-map keymap)
6605 (set (make-local-variable 'gnus-agent-summary-mode) agent)
6606 (set (make-local-variable 'gnus-draft-mode) draft)
6607 (describe-bindings prefix))
6608 (let ((item `((lambda (prefix)
6609 (with-current-buffer ,(current-buffer)
6610 (gnus-article-describe-bindings prefix)))
6612 (with-current-buffer (let (help-xref-following) (help-buffer))
6613 (setq help-xref-stack-item item)))))
6615 (defun gnus-article-reply-with-original (&optional wide)
6616 "Start composing a reply mail to the current message.
6617 The text in the region will be yanked. If the region isn't active,
6618 the entire article will be yanked."
6620 (let ((article (cdr gnus-article-current))
6622 (if (not (gnus-region-active-p))
6623 (with-current-buffer gnus-summary-buffer
6624 (gnus-summary-reply (list (list article)) wide))
6625 (setq contents (buffer-substring (point) (mark t)))
6626 ;; Deactivate active regions.
6627 (when (and (boundp 'transient-mark-mode)
6628 transient-mark-mode)
6629 (setq mark-active nil))
6630 (with-current-buffer gnus-summary-buffer
6632 (list (list article contents)) wide)))))
6634 (defun gnus-article-wide-reply-with-original ()
6635 "Start composing a wide reply mail to the current message.
6636 The text in the region will be yanked. If the region isn't active,
6637 the entire article will be yanked."
6639 (gnus-article-reply-with-original t))
6641 (defun gnus-article-followup-with-original ()
6642 "Compose a followup to the current article.
6643 The text in the region will be yanked. If the region isn't active,
6644 the entire article will be yanked."
6646 (let ((article (cdr gnus-article-current))
6648 (if (not (gnus-region-active-p))
6649 (with-current-buffer gnus-summary-buffer
6650 (gnus-summary-followup (list (list article))))
6651 (setq contents (buffer-substring (point) (mark t)))
6652 ;; Deactivate active regions.
6653 (when (and (boundp 'transient-mark-mode)
6654 transient-mark-mode)
6655 (setq mark-active nil))
6656 (with-current-buffer gnus-summary-buffer
6657 (gnus-summary-followup
6658 (list (list article contents)))))))
6660 (defun gnus-article-hide (&optional arg force)
6661 "Hide all the gruft in the current article.
6662 This means that signatures, cited text and (some) headers will be
6664 If given a prefix, show the hidden text instead."
6665 (interactive (append (gnus-article-hidden-arg) (list 'force)))
6666 (gnus-article-hide-headers arg)
6667 (gnus-article-hide-list-identifiers arg)
6668 (gnus-article-hide-citation-maybe arg force)
6669 (gnus-article-hide-signature arg))
6671 (defun gnus-article-maybe-highlight ()
6672 "Do some article highlighting if article highlighting is requested."
6673 (when (gnus-visual-p 'article-highlight 'highlight)
6674 (gnus-article-highlight-some)))
6676 (defun gnus-check-group-server ()
6677 ;; Make sure the connection to the server is alive.
6678 (unless (gnus-server-opened
6679 (gnus-find-method-for-group gnus-newsgroup-name))
6680 (gnus-check-server (gnus-find-method-for-group gnus-newsgroup-name))
6681 (gnus-request-group gnus-newsgroup-name t)))
6684 (autoload 'nneething-get-file-name "nneething"))
6686 (defun gnus-request-article-this-buffer (article group)
6687 "Get an article and insert it into this buffer."
6688 (let (do-update-line sparse-header)
6692 (gnus-kill-all-overlays)
6693 (setq group (or group gnus-newsgroup-name))
6695 ;; Using `gnus-request-article' directly will insert the article into
6696 ;; `nntp-server-buffer' - so we'll save some time by not having to
6697 ;; copy it from the server buffer into the article buffer.
6699 ;; We only request an article by message-id when we do not have the
6700 ;; headers for it, so we'll have to get those.
6701 (when (stringp article)
6702 (gnus-read-header article))
6704 ;; If the article number is negative, that means that this article
6705 ;; doesn't belong in this newsgroup (possibly), so we find its
6706 ;; message-id and request it by id instead of number.
6707 (when (and (numberp article)
6709 (get-buffer gnus-summary-buffer)
6710 (gnus-buffer-exists-p gnus-summary-buffer))
6711 (with-current-buffer gnus-summary-buffer
6712 (let ((header (gnus-summary-article-header article)))
6715 ((memq article gnus-newsgroup-sparse)
6716 ;; This is a sparse gap article.
6717 (setq do-update-line article)
6718 (setq article (mail-header-id header))
6719 (setq sparse-header (gnus-read-header article))
6720 (setq gnus-newsgroup-sparse
6721 (delq article gnus-newsgroup-sparse)))
6723 ;; It's a real article.
6724 (setq article (mail-header-id header)))
6726 ;; It is an extracted pseudo-article.
6727 (setq article 'pseudo)
6728 (gnus-request-pseudo-article header))))
6730 (let ((method (gnus-find-method-for-group
6731 gnus-newsgroup-name)))
6732 (when (and (eq (car method) 'nneething)
6734 (let ((dir (nneething-get-file-name
6735 (mail-header-id header))))
6736 (when (and (stringp dir)
6737 (file-directory-p dir))
6738 (setq article 'nneething)
6739 (gnus-group-enter-directory dir))))))))
6742 ;; Refuse to select canceled articles.
6743 ((and (numberp article)
6745 (get-buffer gnus-summary-buffer)
6746 (gnus-buffer-exists-p gnus-summary-buffer)
6747 (eq (cdr (with-current-buffer gnus-summary-buffer
6748 (assq article gnus-newsgroup-reads)))
6749 gnus-canceled-mark))
6751 ;; We first check `gnus-original-article-buffer'.
6752 ((and (get-buffer gnus-original-article-buffer)
6754 (with-current-buffer gnus-original-article-buffer
6755 (and (equal (car gnus-original-article) group)
6756 (eq (cdr gnus-original-article) article))))
6757 ;; `insert-buffer-substring' would incorrectly use the
6758 ;; equivalent of string-make-multibyte which amount to decoding
6759 ;; with locale-coding-system, causing failure of
6760 ;; subsequent decoding.
6761 (insert (mm-string-to-multibyte
6762 (with-current-buffer gnus-original-article-buffer
6763 (buffer-substring (point-min) (point-max)))))
6765 ;; Check the backlog.
6766 ((and gnus-keep-backlog
6767 (gnus-backlog-request-article group article (current-buffer)))
6769 ;; Check asynchronous pre-fetch.
6770 ((gnus-async-request-fetched-article group article (current-buffer))
6771 (gnus-async-prefetch-next group article gnus-summary-buffer)
6772 (when (and (numberp article) gnus-keep-backlog)
6773 (gnus-backlog-enter-article group article (current-buffer)))
6776 ((and gnus-use-cache
6778 (gnus-cache-request-article article group))
6780 ;; Check the agent cache.
6781 ((gnus-agent-request-article article group)
6783 ;; Get the article and put into the article buffer.
6784 ((or (stringp article)
6786 (let ((gnus-override-method gnus-override-method)
6787 (methods (and (stringp article)
6788 gnus-refer-article-method))
6789 (backend (car (gnus-find-method-for-group
6790 gnus-newsgroup-name)))
6792 (inhibit-read-only t))
6793 (if (or (not (listp methods))
6794 (and (symbolp (car methods))
6795 (assq (car methods) nnoo-definition-alist)))
6796 (setq methods (list methods)))
6797 (when (and (null gnus-override-method)
6799 (setq gnus-override-method (pop methods)))
6801 (when (eq gnus-override-method 'current)
6802 (setq gnus-override-method
6803 (with-current-buffer gnus-summary-buffer
6804 gnus-current-select-method)))
6806 (gnus-kill-all-overlays)
6807 (let ((gnus-newsgroup-name group))
6808 (gnus-check-group-server))
6810 ((gnus-request-article article group (current-buffer))
6811 (when (numberp article)
6812 (gnus-async-prefetch-next group article
6813 gnus-summary-buffer)
6814 (when gnus-keep-backlog
6815 (gnus-backlog-enter-article
6816 group article (current-buffer))))
6817 (setq result 'article))
6819 (setq gnus-override-method (pop methods)))
6820 ((not (string-match "^400 "
6821 (nnheader-get-report backend)))
6822 ;; If we get 400 server disconnect, reconnect and
6823 ;; retry; otherwise, assume the article has expired.
6824 (setq result 'done))))
6825 (and (eq result 'article) 'article)))
6829 ;; Associate this article with the current summary buffer.
6830 (setq gnus-article-current-summary gnus-summary-buffer)
6832 ;; Take the article from the original article buffer
6833 ;; and place it in the buffer it's supposed to be in.
6834 (when (and (get-buffer gnus-article-buffer)
6835 (equal (buffer-name (current-buffer))
6836 (buffer-name (get-buffer gnus-article-buffer))))
6838 (if (get-buffer gnus-original-article-buffer)
6839 (set-buffer gnus-original-article-buffer)
6840 (set-buffer (gnus-get-buffer-create gnus-original-article-buffer))
6841 (buffer-disable-undo)
6842 (setq major-mode 'gnus-original-article-mode)
6843 (setq buffer-read-only t))
6844 (let ((inhibit-read-only t))
6846 (insert-buffer-substring gnus-article-buffer))
6847 (setq gnus-original-article (cons group article)))
6850 (run-hooks 'gnus-article-decode-hook)
6851 ;; Mark article as decoded or not.
6852 (setq gnus-article-decoded-p gnus-article-decode-hook))
6854 ;; Update sparse articles.
6855 (when (and do-update-line
6856 (or (numberp article)
6858 (let ((buf (current-buffer)))
6859 (set-buffer gnus-summary-buffer)
6860 (gnus-summary-update-article do-update-line sparse-header)
6861 (gnus-summary-goto-subject do-update-line nil t)
6862 (set-window-point (gnus-get-buffer-window (current-buffer) t)
6864 (set-buffer buf))))))
6866 (defun gnus-block-private-groups (group)
6867 (if (gnus-news-group-p group)
6868 ;; Block nothing in news groups.
6870 ;; Block everything anywhere else.
6873 (defun gnus-blocked-images ()
6874 (if (functionp gnus-blocked-images)
6875 (funcall gnus-blocked-images gnus-newsgroup-name)
6876 gnus-blocked-images))
6882 (defcustom gnus-article-edit-mode-hook nil
6883 "Hook run in article edit mode buffers."
6884 :group 'gnus-article-various
6887 (defvar gnus-article-edit-done-function nil)
6889 (defvar gnus-article-edit-mode-map nil)
6891 ;; Should we be using derived.el for this?
6892 (unless gnus-article-edit-mode-map
6893 (setq gnus-article-edit-mode-map (make-keymap))
6894 (set-keymap-parent gnus-article-edit-mode-map text-mode-map)
6896 (gnus-define-keys gnus-article-edit-mode-map
6897 "\C-c?" describe-mode
6898 "\C-c\C-c" gnus-article-edit-done
6899 "\C-c\C-k" gnus-article-edit-exit
6900 "\C-c\C-f\C-t" message-goto-to
6901 "\C-c\C-f\C-o" message-goto-from
6902 "\C-c\C-f\C-b" message-goto-bcc
6903 ;;"\C-c\C-f\C-w" message-goto-fcc
6904 "\C-c\C-f\C-c" message-goto-cc
6905 "\C-c\C-f\C-s" message-goto-subject
6906 "\C-c\C-f\C-r" message-goto-reply-to
6907 "\C-c\C-f\C-n" message-goto-newsgroups
6908 "\C-c\C-f\C-d" message-goto-distribution
6909 "\C-c\C-f\C-f" message-goto-followup-to
6910 "\C-c\C-f\C-m" message-goto-mail-followup-to
6911 "\C-c\C-f\C-k" message-goto-keywords
6912 "\C-c\C-f\C-u" message-goto-summary
6913 "\C-c\C-f\C-i" message-insert-or-toggle-importance
6914 "\C-c\C-f\C-a" message-generate-unsubscribed-mail-followup-to
6915 "\C-c\C-b" message-goto-body
6916 "\C-c\C-i" message-goto-signature
6918 "\C-c\C-t" message-insert-to
6919 "\C-c\C-n" message-insert-newsgroups
6920 "\C-c\C-o" message-sort-headers
6921 "\C-c\C-e" message-elide-region
6922 "\C-c\C-v" message-delete-not-region
6923 "\C-c\C-z" message-kill-to-signature
6924 "\M-\r" message-newline-and-reformat
6925 "\C-c\C-a" mml-attach-file
6926 "\C-a" message-beginning-of-line
6928 "\M-;" comment-region)
6930 (gnus-define-keys (gnus-article-edit-wash-map
6931 "\C-c\C-w" gnus-article-edit-mode-map)
6932 "f" gnus-article-edit-full-stops))
6935 gnus-article-edit-mode-field-menu gnus-article-edit-mode-map ""
6937 ["Fetch To" message-insert-to t]
6938 ["Fetch Newsgroups" message-insert-newsgroups t]
6940 ["To" message-goto-to t]
6941 ["From" message-goto-from t]
6942 ["Subject" message-goto-subject t]
6943 ["Cc" message-goto-cc t]
6944 ["Reply-To" message-goto-reply-to t]
6945 ["Summary" message-goto-summary t]
6946 ["Keywords" message-goto-keywords t]
6947 ["Newsgroups" message-goto-newsgroups t]
6948 ["Followup-To" message-goto-followup-to t]
6949 ["Mail-Followup-To" message-goto-mail-followup-to t]
6950 ["Distribution" message-goto-distribution t]
6951 ["Body" message-goto-body t]
6952 ["Signature" message-goto-signature t]))
6954 (define-derived-mode gnus-article-edit-mode message-mode "Article Edit"
6955 "Major mode for editing articles.
6956 This is an extended text-mode.
6958 \\{gnus-article-edit-mode-map}"
6959 (make-local-variable 'gnus-article-edit-done-function)
6960 (make-local-variable 'gnus-prev-winconf)
6961 (set (make-local-variable 'font-lock-defaults)
6962 '(message-font-lock-keywords t))
6963 (set (make-local-variable 'mail-header-separator) "")
6964 (set (make-local-variable 'gnus-article-edit-mode) t)
6965 (easy-menu-add message-mode-field-menu message-mode-map)
6967 (setq buffer-read-only nil)
6968 (buffer-enable-undo)
6971 (defun gnus-article-edit (&optional force)
6972 "Edit the current article.
6973 This will have permanent effect only in mail groups.
6974 If FORCE is non-nil, allow editing of articles even in read-only
6977 (when (and (not force)
6978 (gnus-group-read-only-p))
6979 (error "The current newsgroup does not support article editing"))
6980 (gnus-article-date-original)
6981 (gnus-article-edit-article
6983 `(lambda (no-highlight)
6985 (gnus-summary-edit-article-done
6986 ,(or (mail-header-references gnus-current-headers) "")
6987 ,(gnus-group-read-only-p) ,gnus-summary-buffer no-highlight))))
6989 (defun gnus-article-edit-article (start-func exit-func &optional quiet)
6990 "Start editing the contents of the current article buffer."
6991 (let ((winconf (current-window-configuration)))
6992 (set-buffer gnus-article-buffer)
6993 (let ((message-auto-save-directory
6994 ;; Don't associate the article buffer with a draft file.
6996 (gnus-article-edit-mode))
6997 (funcall start-func)
6998 (set-buffer-modified-p nil)
6999 (gnus-configure-windows 'edit-article)
7000 (setq gnus-article-edit-done-function exit-func)
7001 (setq gnus-prev-winconf winconf)
7003 (gnus-message 6 "C-c C-c to end edits"))))
7005 (defun gnus-article-edit-done (&optional arg)
7006 "Update the article edits and exit."
7008 (let ((func gnus-article-edit-done-function)
7009 (buf (current-buffer))
7010 (start (window-start))
7012 (winconf gnus-prev-winconf))
7013 (widen) ;; Widen it in case that users narrowed the buffer.
7016 ;; The cache and backlog have to be flushed somewhat.
7017 (when gnus-keep-backlog
7018 (gnus-backlog-remove-article
7019 (car gnus-article-current) (cdr gnus-article-current)))
7020 ;; Flush original article as well.
7021 (gnus-flush-original-article-buffer)
7022 (when gnus-use-cache
7023 (gnus-cache-update-article
7024 (car gnus-article-current) (cdr gnus-article-current)))
7025 ;; We remove all text props from the article buffer.
7026 (kill-all-local-variables)
7027 (set-text-properties (point-min) (point-max) nil)
7029 (set-window-configuration winconf)
7031 (set-window-start (get-buffer-window buf) start)
7032 (set-window-point (get-buffer-window buf) (point)))
7033 (gnus-summary-show-article))
7035 (defun gnus-flush-original-article-buffer ()
7036 (when (get-buffer gnus-original-article-buffer)
7037 (with-current-buffer gnus-original-article-buffer
7038 (setq gnus-original-article nil))))
7040 (defun gnus-article-edit-exit ()
7041 "Exit the article editing without updating."
7043 (when (or (not (buffer-modified-p))
7044 (yes-or-no-p "Article modified; kill anyway? "))
7045 (let ((curbuf (current-buffer))
7047 (window-start (window-start)))
7049 (if (gnus-buffer-live-p gnus-original-article-buffer)
7050 (insert-buffer-substring gnus-original-article-buffer))
7051 (let ((winconf gnus-prev-winconf))
7052 (kill-all-local-variables)
7054 (set-window-configuration winconf)
7055 ;; Tippy-toe some to make sure that point remains where it was.
7056 (save-current-buffer
7058 (set-window-start (get-buffer-window (current-buffer)) window-start)
7060 (gnus-summary-show-article)))
7062 (defun gnus-article-edit-full-stops ()
7063 "Interactively repair spacing at end of sentences."
7066 (goto-char (point-min))
7067 (search-forward-regexp "^$" nil t)
7068 (let ((case-fold-search nil))
7069 (query-replace-regexp "\\([.!?][])}]* \\)\\([[({A-Z]\\)" "\\1 \\2"))))
7072 ;;; Article highlights
7075 ;; Written by Per Abrahamsen <abraham@iesd.auc.dk>.
7077 ;;; Internal Variables:
7079 (defcustom gnus-button-url-regexp
7081 "\\b\\(\\(www\\.\\|\\(s?https?\\|ftp\\|file\\|gopher\\|"
7082 "nntp\\|news\\|telnet\\|wais\\|mailto\\|info\\):\\)"
7083 "\\(//[-a-z0-9_.]+:[0-9]*\\)?"
7084 (if (string-match "[[:digit:]]" "1") ;; Support POSIX?
7085 (let ((chars "-a-z0-9_=#$@~%&*+\\/[:word:]")
7089 ;; Match paired parentheses, e.g. in Wikipedia URLs:
7090 ;; http://thread.gmane.org/47B4E3B2.3050402@gmail.com
7091 "[" chars punct "]+" "(" "[" chars punct "]+" "[" chars "]*)" "[" chars "]*"
7093 "[" chars punct "]+" "[" chars "]"
7095 (concat ;; XEmacs 21.4 doesn't support POSIX.
7096 "\\([-a-z0-9_=!?#$@~%&*+\\/:;.,]\\|\\w\\)+"
7097 "\\([-a-z0-9_=#$@~%&*+\\/]\\|\\w\\)"))
7099 "Regular expression that matches URLs."
7100 :group 'gnus-article-buttons
7103 (defcustom gnus-button-valid-fqdn-regexp
7104 message-valid-fqdn-regexp
7105 "Regular expression that matches a valid FQDN."
7107 :group 'gnus-article-buttons
7110 ;; Regexp suggested by Felix Wiemann in <87oeuomcz9.fsf@news2.ososo.de>
7111 (defcustom gnus-button-valid-localpart-regexp
7112 "[a-z0-9$%(*-=?[_][^<>\")!;:,{}\n\t @]*"
7113 "Regular expression that matches a localpart of mail addresses or MIDs."
7115 :group 'gnus-article-buttons
7118 (defcustom gnus-button-man-handler 'manual-entry
7119 "Function to use for displaying man pages.
7120 The function must take at least one argument with a string naming the
7123 :type '(choice (function-item :tag "Man" manual-entry)
7124 (function-item :tag "Woman" woman)
7125 (function :tag "Other"))
7126 :group 'gnus-article-buttons)
7128 (defcustom gnus-button-mid-or-mail-regexp
7129 (concat "\\b\\(<?" gnus-button-valid-localpart-regexp "@"
7130 gnus-button-valid-fqdn-regexp
7132 "Regular expression that matches a message ID or a mail address."
7134 :group 'gnus-article-buttons
7137 (defcustom gnus-button-prefer-mid-or-mail 'gnus-button-mid-or-mail-heuristic
7138 "What to do when the button on a string as \"foo123@bar.invalid\" is pushed.
7139 Strings like this can be either a message ID or a mail address. If it is one
7140 of the symbols `mid' or `mail', Gnus will always assume that the string is a
7141 message ID or a mail address, respectively. If this variable is set to the
7142 symbol `ask', always query the user what do do. If it is a function, this
7143 function will be called with the string as its only argument. The function
7144 must return `mid', `mail', `invalid' or `ask'."
7146 :group 'gnus-article-buttons
7147 :type '(choice (function-item :tag "Heuristic function"
7148 gnus-button-mid-or-mail-heuristic)
7153 (defcustom gnus-button-mid-or-mail-heuristic-alist
7154 '((-10.0 . ".+\\$.+@")
7157 (-5.0 . "\\+[^+]*\\+.*@") ;; # two plus signs
7158 (-5.0 . "@[Nn][Ee][Ww][Ss]") ;; /\@news/i
7159 (-5.0 . "@.*[Dd][Ii][Aa][Ll][Uu][Pp]") ;; /\@.*dialup/i;
7160 (-1.0 . "^[^a-z]+@")
7162 (-5.0 . "\\.[0-9][0-9]+.*@") ;; "\.[0-9]{2,}.*\@"
7163 (-5.0 . "[a-z].*[A-Z].*[a-z].*[A-Z].*@") ;; "([a-z].*[A-Z].*){2,}\@"
7164 (-3.0 . "[A-Z][A-Z][a-z][a-z].*@")
7165 (-5.0 . "\\...?.?@") ;; (-5.0 . "\..{1,3}\@")
7168 (-1.0 . "^[0-9][0-9]")
7170 ;; -3.0 /^[0-9][0-9a-fA-F]{2,2}/;
7171 (-3.0 . "^[0-9][0-9a-fA-F][0-9a-fA-F][^0-9a-fA-F]")
7172 ;; -5.0 /^[0-9][0-9a-fA-F]{3,3}/;
7173 (-5.0 . "^[0-9][0-9a-fA-F][0-9a-fA-F][0-9a-fA-F][^0-9a-fA-F]")
7175 (-3.0 . "[0-9][0-9][0-9][0-9][0-9][^0-9].*@") ;; "[0-9]{5,}.*\@"
7176 (-3.0 . "[0-9][0-9][0-9][0-9][0-9][0-9][0-9][0-9][^0-9].*@")
7179 . "[0-9][0-9][0-9][0-9][0-9][0-9][0-9][0-9][0-9][0-9][0-9][0-9].*@")
7181 ;; compensation for TDMA dated mail addresses:
7182 (25.0 . "-dated-[0-9][0-9][0-9][0-9][0-9][0-9][0-9][0-9]+.*@")
7184 (-20.0 . "\\.fsf@") ;; Gnus
7187 (-20.0 . "^alpine\\.")
7188 (-20.0 . "_-_") ;; Subject change in thread
7190 (-20.0 . "\\.ln@") ;; leafnode
7191 (-30.0 . "@ID-[0-9]+\\.[a-zA-Z]+\\.dfncis\\.de")
7192 (-30.0 . "@4[Aa][Xx]\\.com") ;; Forte Agent
7194 ;; (5.0 . "") ;; $local_part_len <= 7
7195 (10.0 . "^[^0-9]+@")
7196 (3.0 . "^[^0-9]+[0-9][0-9]?[0-9]?@")
7197 ;; ^[^0-9]+[0-9]{1,3}\@ digits only at end of local part
7200 (2.0 . "[a-z][a-z][._-][A-Z][a-z].*@")
7202 (0.5 . "^[A-Z][a-z]")
7203 (0.5 . "^[A-Z][a-z][a-z]")
7204 (1.5 . "^[A-Z][a-z][A-Z][a-z][^a-z]") ;; ^[A-Z][a-z]{3,3}
7205 (2.0 . "^[A-Z][a-z][A-Z][a-z][a-z][^a-z]")) ;; ^[A-Z][a-z]{4,4}
7206 "An alist of \(RATE . REGEXP\) pairs for `gnus-button-mid-or-mail-heuristic'.
7208 A negative RATE indicates a message IDs, whereas a positive indicates a mail
7209 address. The REGEXP is processed with `case-fold-search' set to nil."
7211 :group 'gnus-article-buttons
7212 :type '(repeat (cons (number :tag "Rate")
7213 (regexp :tag "Regexp"))))
7215 (defun gnus-button-mid-or-mail-heuristic (mid-or-mail)
7216 "Guess whether MID-OR-MAIL is a message ID or a mail address.
7217 Returns `mid' if MID-OR-MAIL is a message IDs, `mail' if it's a mail
7218 address, `ask' if unsure and `invalid' if the string is invalid."
7219 (let ((case-fold-search nil)
7220 (list gnus-button-mid-or-mail-heuristic-alist)
7221 (result 0) rate regexp lpartlen elem)
7223 (length (gnus-replace-in-string mid-or-mail "^\\(.*\\)@.*$" "\\1")))
7224 (gnus-message 8 "`%s', length of local part=`%s'." mid-or-mail lpartlen)
7225 ;; Certain special cases...
7228 "^0[0-9]+-[0-9][0-9][0-9][0-9]@t-online\\.de$\\|"
7229 "^[0-9]+\\.[0-9]+@compuserve\\|"
7230 "@public\\.gmane\\.org")
7232 (gnus-message 8 "`%s' is a known mail address." mid-or-mail)
7233 (setq result 'mail))
7234 (when (string-match "@.*@\\| " mid-or-mail)
7235 (gnus-message 8 "`%s' is invalid." mid-or-mail)
7236 (setq result 'invalid))
7237 ;; Nothing more to do, if result is not a number here...
7238 (when (numberp result)
7240 (setq elem (car list)
7244 (when (string-match regexp mid-or-mail)
7245 (setq result (+ result rate))
7247 9 "`%s' matched `%s', rate `%s', result `%s'."
7248 mid-or-mail regexp rate result)))
7249 (when (<= lpartlen 7)
7250 (setq result (+ result 5.0))
7251 (gnus-message 9 "`%s' matched (<= lpartlen 7), result `%s'."
7252 mid-or-mail result))
7253 (when (>= lpartlen 12)
7254 (gnus-message 9 "`%s' matched (>= lpartlen 12)" mid-or-mail)
7256 ((string-match "[0-9][^0-9]+[0-9].*@" mid-or-mail)
7257 ;; Long local part should contain realname if e-mail address,
7258 ;; too many digits: message-id.
7259 ;; $score -= 5.0 + 0.1 * $local_part_len;
7260 (setq rate (* -1.0 (+ 5.0 (* 0.1 lpartlen))))
7261 (setq result (+ result rate))
7263 9 "Many digits in `%s', rate `%s', result `%s'."
7264 mid-or-mail rate result))
7265 ((string-match "[^aeiouy][^aeiouy][^aeiouy][^aeiouy]+.*\@"
7267 ;; Too few vowels [^aeiouy]{4,}.*\@
7268 (setq result (+ result -5.0))
7270 9 "Few vowels in `%s', rate `%s', result `%s'."
7271 mid-or-mail -5.0 result))
7273 (setq result (+ result 5.0))
7275 9 "`%s', rate `%s', result `%s'." mid-or-mail 5.0 result)))))
7276 (gnus-message 8 "`%s': Final rate is `%s'." mid-or-mail result)
7277 ;; Maybe we should make this a customizable alist: (condition . 'result)
7279 ((symbolp result) result)
7280 ;; Now convert number into proper results:
7281 ((< result -10.0) 'mid)
7282 ((> result 10.0) 'mail)
7285 (defun gnus-button-handle-mid-or-mail (mid-or-mail)
7286 (let* ((pref gnus-button-prefer-mid-or-mail) guessed
7287 (url-mid (concat "news" ":" mid-or-mail))
7288 (url-mailto (concat "mailto" ":" mid-or-mail)))
7289 (gnus-message 9 "mid-or-mail=%s" mid-or-mail)
7290 (when (fboundp pref)
7292 ;; get rid of surrounding angles...
7294 (gnus-replace-in-string mid-or-mail "^<\\|>$" "")))
7295 (if (or (eq 'mid guessed) (eq 'mail guessed))
7299 (save-window-excursion
7300 (if (y-or-n-p (concat "Is <" mid-or-mail "> a mail address? "))
7303 (cond ((eq pref 'mid)
7304 (gnus-message 8 "calling `gnus-button-handle-news' %s" url-mid)
7305 (gnus-button-handle-news url-mid))
7307 (gnus-message 8 "calling `gnus-url-mailto' %s" url-mailto)
7308 (gnus-url-mailto url-mailto))
7309 (t (gnus-message 3 "Invalid string.")))))
7311 (defun gnus-button-handle-custom (fun arg)
7312 "Call function FUN on argument ARG.
7313 Both FUN and ARG are supposed to be strings. ARG will be passed
7314 as a symbol to FUN."
7315 (funcall (intern fun)
7316 (if (string-match "^customize-apropos" fun)
7320 (defvar gnus-button-handle-describe-prefix "^\\(C-h\\|<?[Ff]1>?\\)")
7322 ;; FIXME: Maybe we should merge some of the functions that do quite similar
7325 (defun gnus-button-handle-describe-function (url)
7326 "Call `describe-function' when pushing the corresponding URL button."
7329 (gnus-replace-in-string url gnus-button-handle-describe-prefix ""))))
7331 (defun gnus-button-handle-describe-variable (url)
7332 "Call `describe-variable' when pushing the corresponding URL button."
7335 (gnus-replace-in-string url gnus-button-handle-describe-prefix ""))))
7337 (defun gnus-button-handle-symbol (url)
7338 "Display help on variable or function.
7339 Calls `describe-variable' or `describe-function'."
7340 (let ((sym (intern url)))
7342 ((fboundp sym) (describe-function sym))
7343 ((boundp sym) (describe-variable sym))
7344 (t (gnus-message 3 "`%s' is not a known function of variable." url)))))
7346 (defun gnus-button-handle-describe-key (url)
7347 "Call `describe-key' when pushing the corresponding URL button."
7349 (gnus-replace-in-string url gnus-button-handle-describe-prefix ""))
7350 (keys (ignore-errors (eval `(kbd ,key-string)))))
7353 (gnus-message 3 "Invalid key sequence in button: %s" key-string))))
7355 (defun gnus-button-handle-apropos (url)
7356 "Call `apropos' when pushing the corresponding URL button."
7357 (apropos (gnus-replace-in-string url gnus-button-handle-describe-prefix "")))
7359 (defun gnus-button-handle-apropos-command (url)
7360 "Call `apropos' when pushing the corresponding URL button."
7362 (gnus-replace-in-string url gnus-button-handle-describe-prefix "")))
7364 (defun gnus-button-handle-apropos-variable (url)
7365 "Call `apropos' when pushing the corresponding URL button."
7367 (if (fboundp 'apropos-variable) 'apropos-variable 'apropos)
7368 (gnus-replace-in-string url gnus-button-handle-describe-prefix "")))
7370 (defun gnus-button-handle-apropos-documentation (url)
7371 "Call `apropos' when pushing the corresponding URL button."
7373 (if (fboundp 'apropos-documentation) 'apropos-documentation 'apropos)
7374 (gnus-replace-in-string url gnus-button-handle-describe-prefix "")))
7376 (defun gnus-button-handle-library (url)
7377 "Call `locate-library' when pushing the corresponding URL button."
7378 (gnus-message 9 "url=`%s'" url)
7379 (let* ((lib (locate-library url))
7380 (file (gnus-replace-in-string (or lib "") "\.elc" ".el")))
7382 (gnus-message 1 "Cannot locale library `%s'." url)
7383 (find-file-read-only file))))
7385 (defcustom gnus-button-man-level 5
7386 "*Integer that says how many man-related buttons Gnus will show.
7387 The higher the number, the more buttons will appear and the more false
7388 positives are possible. Note that you can set this variable local to
7389 specific groups. Setting it higher in Unix groups is probably a good idea.
7390 See Info node `(gnus)Group Parameters' and the variable `gnus-parameters' on
7391 how to set variables in specific groups."
7393 :group 'gnus-article-buttons
7394 :link '(custom-manual "(gnus)Group Parameters")
7397 (defcustom gnus-button-emacs-level 5
7398 "*Integer that says how many emacs-related buttons Gnus will show.
7399 The higher the number, the more buttons will appear and the more false
7400 positives are possible. Note that you can set this variable local to
7401 specific groups. Setting it higher in Emacs or Gnus related groups is
7402 probably a good idea. See Info node `(gnus)Group Parameters' and the variable
7403 `gnus-parameters' on how to set variables in specific groups."
7405 :group 'gnus-article-buttons
7406 :link '(custom-manual "(gnus)Group Parameters")
7409 (defcustom gnus-button-message-level 5
7410 "*Integer that says how many buttons for news or mail messages will appear.
7411 The higher the number, the more buttons will appear and the more false
7412 positives are possible."
7413 ;; mail addresses, MIDs, URLs for news, ...
7415 :group 'gnus-article-buttons
7418 (defcustom gnus-button-browse-level 5
7419 "*Integer that says how many buttons for browsing will appear.
7420 The higher the number, the more buttons will appear and the more false
7421 positives are possible."
7422 ;; stuff handled by `browse-url' or `gnus-button-embedded-url'
7424 :group 'gnus-article-buttons
7427 (defcustom gnus-button-alist
7428 '(("<\\(url:[>\n\t ]*?\\)?\\(nntp\\|news\\):[>\n\t ]*\\([^>\n\t ]*@[^>\n\t ]*\\)>"
7429 0 (>= gnus-button-message-level 0) gnus-button-handle-news 3)
7430 ((concat "\\b\\(nntp\\|news\\):\\("
7431 gnus-button-valid-localpart-regexp "@[a-z0-9.-]+[a-z]\\)")
7432 0 t gnus-button-handle-news 2)
7433 ("\\(\\b<\\(url:[>\n\t ]*\\)?\\(nntp\\|news\\):[>\n\t ]*\\(//\\)?\\([^>\n\t ]*\\)>\\)"
7434 1 (>= gnus-button-message-level 0) gnus-button-fetch-group 5)
7435 ("\\b\\(nntp\\|news\\):\\(//\\)?\\([^'\">\n\t ]+\\)"
7436 0 (>= gnus-button-message-level 0) gnus-button-fetch-group 3)
7437 ;; RFC 2392 (Don't allow `/' in domain part --> CID)
7438 ("\\bmid:\\(//\\)?\\([^'\">\n\t ]+@[^'\">\n\t /]+\\)"
7439 0 (>= gnus-button-message-level 0) gnus-button-message-id 2)
7440 ("\\bin\\( +article\\| +message\\)? +\\(<\\([^\n @<>]+@[^\n @<>]+\\)>\\)"
7441 2 (>= gnus-button-message-level 0) gnus-button-message-id 3)
7442 ("\\b\\(mid\\|message-id\\):? +\\(<\\([^\n @<>]+@[^\n @<>]+\\)>\\)"
7443 2 (>= gnus-button-message-level 0) gnus-button-message-id 3)
7444 ("\\(<URL: *\\)mailto: *\\([^> \n\t]+\\)>"
7445 0 (>= gnus-button-message-level 0) gnus-url-mailto 2)
7446 ;; RFC 2368 (The mailto URL scheme)
7447 ("\\bmailto:\\([-a-z.@_+0-9%=?&/]+\\)"
7448 0 (>= gnus-button-message-level 0) gnus-url-mailto 1)
7449 ("\\bmailto:\\([^ \n\t]+\\)"
7450 0 (>= gnus-button-message-level 0) gnus-url-mailto 1)
7451 ;; Info Konqueror style <info:/foo/bar baz>.
7452 ;; Must come before " Gnus home-grown style".
7453 ("\\binfo://?\\([^'\">\n\t]+\\)"
7454 0 (>= gnus-button-emacs-level 1) gnus-button-handle-info-url 1)
7455 ;; Info, Gnus home-grown style (deprecated) <info://foo/bar+baz>
7456 ("\\binfo://\\([^'\">\n\t ]+\\)"
7457 0 (>= gnus-button-emacs-level 1) gnus-button-handle-info-url 1)
7458 ;; Info GNOME style <info:foo#bar_baz>
7459 ("\\binfo:\\([^('\n\t\r \"><][^'\n\t\r \"><]*\\)"
7460 0 (>= gnus-button-emacs-level 1) gnus-button-handle-info-url-gnome 1)
7461 ;; Info KDE style <info:(foo)bar baz>
7462 ("<\\(info:\\(([^)]+)[^>\n\r]*\\)\\)>"
7463 1 (>= gnus-button-emacs-level 1) gnus-button-handle-info-url-kde 2)
7464 ("\\((Info-goto-node\\|(info\\)[ \t\n]*\\(\"[^\"]*\"\\))" 0
7465 (>= gnus-button-emacs-level 1) gnus-button-handle-info-url 2)
7466 ("\\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,]*\\)\\)?"
7467 ;; Info links like `C-h i d m Gnus RET' or `C-h i d m Gnus RET i partial RET'
7468 0 (>= gnus-button-emacs-level 1) gnus-button-handle-info-keystrokes 0)
7470 ("M-x[ \t\n]\\(customize-[^ ]+\\)[ \t\n]RET[ \t\n]\\([^ ]+\\)[ \t\n]RET" 0
7471 (>= gnus-button-emacs-level 1) gnus-button-handle-custom 1 2)
7472 ;; Emacs help commands
7473 ("M-x[ \t\n]+apropos[ \t\n]+RET[ \t\n]+\\([^ \t\n]+\\)[ \t\n]+RET"
7474 ;; regexp doesn't match arguments containing ` '.
7475 0 (>= gnus-button-emacs-level 1) gnus-button-handle-apropos 1)
7476 ("M-x[ \t\n]+apropos-command[ \t\n]+RET[ \t\n]+\\([^ \t\n]+\\)[ \t\n]+RET"
7477 0 (>= gnus-button-emacs-level 1) gnus-button-handle-apropos-command 1)
7478 ("M-x[ \t\n]+apropos-variable[ \t\n]+RET[ \t\n]+\\([^ \t\n]+\\)[ \t\n]+RET"
7479 0 (>= gnus-button-emacs-level 1) gnus-button-handle-apropos-variable 1)
7480 ("M-x[ \t\n]+apropos-documentation[ \t\n]+RET[ \t\n]+\\([^ \t\n]+\\)[ \t\n]+RET"
7481 0 (>= gnus-button-emacs-level 1) gnus-button-handle-apropos-documentation 1)
7482 ;; The following entries may lead to many false positives so don't enable
7483 ;; them by default (use a high button level).
7484 ("/\\([a-z][-a-z0-9]+\\.el\\)\\>[^.?]"
7485 ;; Exclude [.?] for URLs in gmane.emacs.cvs
7486 1 (>= gnus-button-emacs-level 8) gnus-button-handle-library 1)
7487 ("`\\([a-z][-a-z0-9]+\\.el\\)'"
7488 1 (>= gnus-button-emacs-level 8) gnus-button-handle-library 1)
7489 ("`\\([a-z][a-z0-9]+-[a-z0-9]+-[-a-z0-9]*[a-z]\\|\\(gnus\\|message\\)-[-a-z]+\\)'"
7490 0 (>= gnus-button-emacs-level 8) gnus-button-handle-symbol 1)
7491 ("`\\([a-z][a-z0-9]+-[a-z]+\\)'"
7492 0 (>= gnus-button-emacs-level 9) gnus-button-handle-symbol 1)
7493 ("(setq[ \t\n]+\\([a-z][a-z0-9]+-[-a-z0-9]+\\)[ \t\n]+.+)"
7494 1 (>= gnus-button-emacs-level 7) gnus-button-handle-describe-variable 1)
7495 ("\\bM-x[ \t\n]+\\([^ \t\n]+\\)[ \t\n]+RET"
7496 1 (>= gnus-button-emacs-level 7) gnus-button-handle-describe-function 1)
7497 ("\\b\\(C-h\\|<?[Ff]1>?\\)[ \t\n]+f[ \t\n]+\\([^ \t\n]+\\)[ \t\n]+RET"
7498 0 (>= gnus-button-emacs-level 1) gnus-button-handle-describe-function 2)
7499 ("\\b\\(C-h\\|<?[Ff]1>?\\)[ \t\n]+v[ \t\n]+\\([^ \t\n]+\\)[ \t\n]+RET"
7500 0 (>= gnus-button-emacs-level 1) gnus-button-handle-describe-variable 2)
7501 ("`\\(\\(C-h\\|<?[Ff]1>?\\)[ \t\n]+k[ \t\n]+\\([^']+\\)\\)'"
7502 ;; Unlike the other regexps we really have to require quoting
7503 ;; here to determine where it ends.
7504 1 (>= gnus-button-emacs-level 1) gnus-button-handle-describe-key 3)
7505 ;; This is how URLs _should_ be embedded in text (RFC 1738, RFC 2396)...
7506 ("<URL: *\\([^\n<>]*\\)>"
7507 1 (>= gnus-button-browse-level 0) gnus-button-embedded-url 1)
7508 ;; RFC 2396 (2.4.3., delims) ...
7509 ("\"URL: *\\([^\n\"]*\\)\""
7510 1 (>= gnus-button-browse-level 0) gnus-button-embedded-url 1)
7512 (gnus-button-url-regexp
7513 0 (>= gnus-button-browse-level 0) browse-url 0)
7515 ("\\b\\([a-z][a-z]+([1-9])\\)\\W"
7516 0 (and (>= gnus-button-man-level 1) (< gnus-button-man-level 3))
7517 gnus-button-handle-man 1)
7518 ;; more man pages: resolv.conf(5), iso_8859-1(7), xterm(1x)
7519 ("\\b\\([a-z][-_.a-z0-9]+([1-9])\\)\\W"
7520 0 (and (>= gnus-button-man-level 3) (< gnus-button-man-level 5))
7521 gnus-button-handle-man 1)
7522 ;; even more: Apache::PerlRun(3pm), PDL::IO::FastRaw(3pm),
7523 ;; SoWWWAnchor(3iv), XSelectInput(3X11), X(1), X(7)
7524 ("\\b\\(\\(?:[a-z][-+_.:a-z0-9]+([1-9][X1a-z]*)\\)\\|\\b\\(?:X([1-9])\\)\\)\\W"
7525 0 (>= gnus-button-man-level 5) gnus-button-handle-man 1)
7526 ;; Recognizing patches to .el files. This is somewhat obscure,
7527 ;; but considering the percentage of Gnus users who hack Emacs
7529 ("^--- \\([^ .]+\\.el\\).*\n.*\n@@ -?\\([0-9]+\\)" 1
7530 (>= gnus-button-message-level 4) gnus-button-patch 1 2)
7531 ("^\\*\\*\\* \\([^ .]+\\.el\\).*\n.*\n\\*+\n\\*\\*\\* \\([0-9]+\\)" 1
7532 (>= gnus-button-message-level 4) gnus-button-patch 1 2)
7533 ;; MID or mail: To avoid too many false positives we don't try to catch
7534 ;; all kind of allowed MIDs or mail addresses. Domain part must contain
7535 ;; at least one dot. TLD must contain two or three chars or be a know TLD
7536 ;; (info|name|...). Put this entry near the _end_ of `gnus-button-alist'
7537 ;; so that non-ambiguous entries (see above) match first.
7538 (gnus-button-mid-or-mail-regexp
7539 0 (>= gnus-button-message-level 5) gnus-button-handle-mid-or-mail 1))
7540 "*Alist of regexps matching buttons in article bodies.
7542 Each entry has the form (REGEXP BUTTON FORM CALLBACK PAR...), where
7543 REGEXP: is the string (case insensitive) matching text around the button (can
7544 also be Lisp expression evaluating to a string),
7545 BUTTON: is the number of the regexp grouping actually matching the button,
7546 FORM: is a Lisp expression which must eval to true for the button to
7548 CALLBACK: is the function to call when the user push this button, and each
7549 PAR: is a number of a regexp grouping whose text will be passed to CALLBACK.
7551 CALLBACK can also be a variable, in that case the value of that
7552 variable it the real callback function."
7553 :group 'gnus-article-buttons
7554 :type '(repeat (list (choice regexp variable sexp)
7555 (integer :tag "Button")
7557 (function :tag "Callback")
7560 (integer :tag "Regexp group")))))
7561 (put 'gnus-button-alist 'risky-local-variable t)
7563 (defcustom gnus-header-button-alist
7564 '(("^\\(References\\|Message-I[Dd]\\|^In-Reply-To\\):" "<[^<>]+>"
7565 0 (>= gnus-button-message-level 0) gnus-button-message-id 0)
7566 ("^\\(From\\|Reply-To\\):" ": *\\(.+\\)$"
7567 1 (>= gnus-button-message-level 0) gnus-button-reply 1)
7568 ("^\\(Cc\\|To\\):" "[^ \t\n<>,()\"]+@[^ \t\n<>,()\"]+"
7569 0 (>= gnus-button-message-level 0) gnus-msg-mail 0)
7570 ("^X-[Uu][Rr][Ll]:" gnus-button-url-regexp
7571 0 (>= gnus-button-browse-level 0) browse-url 0)
7572 ("^Subject:" gnus-button-url-regexp
7573 0 (>= gnus-button-browse-level 0) browse-url 0)
7574 ("^[^:]+:" gnus-button-url-regexp
7575 0 (>= gnus-button-browse-level 0) browse-url 0)
7576 ("^OpenPGP:.*url=" gnus-button-url-regexp
7577 0 (>= gnus-button-browse-level 0) gnus-button-openpgp 0)
7578 ("^[^:]+:" "\\bmailto:\\([-a-z.@_+0-9%=?&/]+\\)"
7579 0 (>= gnus-button-message-level 0) gnus-url-mailto 1)
7580 ("^[^:]+:" "\\(<\\(url: \\)?\\(nntp\\|news\\):\\([^>\n ]*\\)>\\)"
7581 1 (>= gnus-button-message-level 0) gnus-button-message-id 4))
7582 "*Alist of headers and regexps to match buttons in article heads.
7584 This alist is very similar to `gnus-button-alist', except that each
7585 alist has an additional HEADER element first in each entry:
7587 \(HEADER REGEXP BUTTON FORM CALLBACK PAR)
7589 HEADER is a regexp to match a header. For a fuller explanation, see
7590 `gnus-button-alist'."
7591 :group 'gnus-article-buttons
7592 :group 'gnus-article-headers
7593 :type '(repeat (list (regexp :tag "Header")
7594 (choice regexp variable)
7595 (integer :tag "Button")
7597 (function :tag "Callback")
7600 (integer :tag "Regexp group")))))
7601 (put 'gnus-header-button-alist 'risky-local-variable t)
7605 (defun gnus-article-push-button (event)
7606 "Check text under the mouse pointer for a callback function.
7607 If the text under the mouse pointer has a `gnus-callback' property,
7608 call it with the value of the `gnus-data' text property."
7610 (set-buffer (window-buffer (posn-window (event-start event))))
7611 (let* ((pos (posn-point (event-start event)))
7612 (data (get-text-property pos 'gnus-data))
7613 (fun (get-text-property pos 'gnus-callback)))
7616 (funcall fun data))))
7618 (defun gnus-article-press-button ()
7619 "Check text at point for a callback function.
7620 If the text at point has a `gnus-callback' property,
7621 call it with the value of the `gnus-data' text property."
7623 (let ((data (get-text-property (point) 'gnus-data))
7624 (fun (get-text-property (point) 'gnus-callback)))
7626 (funcall fun data))))
7628 (defun gnus-article-highlight (&optional force)
7629 "Highlight current article.
7630 This function calls `gnus-article-highlight-headers',
7631 `gnus-article-highlight-citation',
7632 `gnus-article-highlight-signature', and `gnus-article-add-buttons' to
7633 do the highlighting. See the documentation for those functions."
7634 (interactive (list 'force))
7635 (gnus-article-highlight-headers)
7636 (gnus-article-highlight-citation force)
7637 (gnus-article-highlight-signature)
7638 (gnus-article-add-buttons force)
7639 (gnus-article-add-buttons-to-head))
7641 (defun gnus-article-highlight-some (&optional force)
7642 "Highlight current article.
7643 This function calls `gnus-article-highlight-headers',
7644 `gnus-article-highlight-signature', and `gnus-article-add-buttons' to
7645 do the highlighting. See the documentation for those functions."
7646 (interactive (list 'force))
7647 (gnus-article-highlight-headers)
7648 (gnus-article-highlight-signature)
7649 (gnus-article-add-buttons))
7651 (defun gnus-article-highlight-headers ()
7652 "Highlight article headers as specified by `gnus-header-face-alist'."
7654 (gnus-with-article-headers
7655 (let (regexp header-face field-face from hpoints fpoints)
7656 (dolist (entry gnus-header-face-alist)
7657 (goto-char (point-min))
7658 (setq regexp (concat "^\\("
7659 (if (string-equal "" (nth 0 entry))
7663 header-face (nth 1 entry)
7664 field-face (nth 2 entry))
7665 (while (and (re-search-forward regexp nil t)
7669 (unless (search-forward ":" nil t)
7671 (when (and header-face
7672 (not (memq (point) hpoints)))
7673 (push (point) hpoints)
7674 (gnus-put-text-property from (point) 'face header-face))
7675 (when (and field-face
7676 (not (memq (setq from (point)) fpoints)))
7678 (if (re-search-forward "^[^ \t]" nil t)
7680 (goto-char (point-max)))
7681 (gnus-put-text-property from (point) 'face field-face)))))))
7683 (defun gnus-article-highlight-signature ()
7684 "Highlight the signature in an article.
7685 It does this by highlighting everything after
7686 `gnus-signature-separator' using the face `gnus-signature'."
7688 (gnus-with-article-buffer
7689 (let ((inhibit-point-motion-hooks t))
7691 (when (and gnus-signature-face
7692 (gnus-article-narrow-to-signature))
7693 (gnus-overlay-put (gnus-make-overlay (point-min) (point-max) nil t)
7694 'face gnus-signature-face)
7696 (gnus-article-search-signature)
7697 (let ((start (match-beginning 0))
7698 (end (set-marker (make-marker) (1+ (match-end 0)))))
7699 (gnus-article-add-button start (1- end) 'gnus-signature-toggle
7702 (defun gnus-button-in-region-p (b e prop)
7703 "Say whether PROP exists in the region."
7704 (text-property-not-all b e prop nil))
7706 (defun gnus-article-add-buttons (&optional force)
7707 "Find external references in the article and make buttons of them.
7708 \"External references\" are things like Message-IDs and URLs, as
7709 specified by `gnus-button-alist'."
7710 (interactive (list 'force))
7711 (gnus-with-article-buffer
7712 (let ((inhibit-point-motion-hooks t)
7713 (case-fold-search t)
7714 (alist gnus-button-alist)
7716 ;; Remove all old markers.
7717 (let (marker entry new-list)
7718 (while (setq marker (pop gnus-button-marker-list))
7719 (if (or (< marker (point-min)) (>= marker (point-max)))
7720 (push marker new-list)
7722 (when (setq entry (gnus-button-entry))
7723 (put-text-property (match-beginning (nth 1 entry))
7724 (match-end (nth 1 entry))
7725 'gnus-callback nil))
7726 (set-marker marker nil)))
7727 (setq gnus-button-marker-list new-list))
7728 ;; We skip the headers.
7731 (while (setq entry (pop alist))
7732 (setq regexp (eval (car entry)))
7734 (while (re-search-forward regexp nil t)
7735 (let ((start (match-beginning (nth 1 entry)))
7736 (end (match-end (nth 1 entry)))
7737 (from (match-beginning 0)))
7738 (when (and (or (eq t (nth 2 entry))
7739 (eval (nth 2 entry)))
7740 (not (gnus-button-in-region-p
7741 start end 'gnus-callback)))
7742 ;; That optional form returned non-nil, so we add the
7744 (setq from (set-marker (make-marker) from))
7745 (push from gnus-button-marker-list)
7746 (unless (and (eq (car entry) 'gnus-button-url-regexp)
7747 (gnus-article-extend-url-button from start end))
7748 (gnus-article-add-button start end
7749 'gnus-button-push from)
7750 (gnus-put-text-property
7752 'gnus-string (buffer-substring-no-properties
7755 (defun gnus-article-extend-url-button (beg start end)
7756 "Extend url button if url is folded into two or more lines.
7757 Return non-nil if button is extended. BEG is a marker that points to
7758 the beginning position of a text containing url. START and END are
7759 the endpoints of a url button before it is extended. The concatenated
7760 url is put as the `gnus-button-url' overlay property on the button."
7761 (let ((opoint (point))
7762 (points (list start end))
7767 (not (looking-at "[\t ]*[\">]")))
7771 "\\(?:\"\\|\\(<\\)\\)[\t ]*\\(?:url[\t ]*:[\t ]*\\)?\\'"
7772 (buffer-substring (point-at-bol) start)))
7774 (setq url (list (buffer-substring start end))
7775 delim (if (match-beginning 1) ">" "\""))
7777 (setq regexp (concat
7778 (when (and (looking-at
7779 message-cite-prefix-regexp)
7780 (< (match-end 0) start))
7781 (regexp-quote (match-string 0)))
7783 \[\t ]*\\(?:\\([^\t\n \">]+\\)[\t ]*$\\|\\([^\t\n \">]*\\)[\t ]*"
7787 (and (looking-at regexp)
7790 (push (or (match-string 2)
7793 (push (setq end (or (match-end 2)
7796 (push (or (match-beginning 2)
7797 (match-beginning 1))
7799 (match-beginning 2)))
7800 (let (gnus-article-mouse-face widget-mouse-face)
7802 (gnus-article-add-button (pop points) (pop points)
7803 'gnus-button-push beg)))
7804 (let ((overlay (gnus-make-overlay start end)))
7805 (gnus-overlay-put overlay 'evaporate t)
7806 (gnus-overlay-put overlay 'gnus-button-url
7807 (list (mapconcat 'identity (nreverse url) "")))
7808 (when gnus-article-mouse-face
7809 (gnus-overlay-put overlay 'mouse-face gnus-article-mouse-face)))
7811 (goto-char opoint))))
7813 ;; Add buttons to the head of an article.
7814 (defun gnus-article-add-buttons-to-head ()
7815 "Add buttons to the head of the article."
7817 (gnus-with-article-headers
7819 (dolist (entry gnus-header-button-alist)
7820 ;; Each alist entry.
7821 (goto-char (point-min))
7822 (while (re-search-forward (car entry) nil t)
7823 ;; Each header matching the entry.
7824 (setq beg (match-beginning 0))
7825 (setq end (or (and (re-search-forward "^[^ \t]" nil t)
7826 (match-beginning 0))
7829 (while (re-search-forward (eval (nth 1 entry)) end t)
7830 ;; Each match within a header.
7831 (let* ((entry (cdr entry))
7832 (start (match-beginning (nth 1 entry)))
7833 (end (match-end (nth 1 entry)))
7834 (form (nth 2 entry)))
7835 (goto-char (match-end 0))
7837 (gnus-article-add-button
7838 start end (nth 3 entry)
7839 (buffer-substring (match-beginning (nth 4 entry))
7840 (match-end (nth 4 entry)))))))
7841 (goto-char end))))))
7843 ;;; External functions:
7845 (defun gnus-article-add-button (from to fun &optional data text)
7846 "Create a button between FROM and TO with callback FUN and data DATA."
7847 (when gnus-article-button-face
7848 (gnus-overlay-put (gnus-make-overlay from to nil t)
7849 'face gnus-article-button-face))
7850 (gnus-add-text-properties
7852 (nconc (and gnus-article-mouse-face
7853 (list gnus-mouse-face-prop gnus-article-mouse-face))
7854 (list 'gnus-callback fun)
7855 (and data (list 'gnus-data data))))
7856 (widget-convert-button 'link from to :action 'gnus-widget-press-button
7857 :help-echo (or text "Follow the link")
7858 :keymap gnus-url-button-map
7859 :button-keymap gnus-widget-button-keymap))
7861 (defun gnus-article-copy-string ()
7862 "Copy the string in the button to the kill ring."
7864 (gnus-article-check-buffer)
7865 (let ((data (get-text-property (point) 'gnus-string)))
7869 (copy-region-as-kill (point-min) (point-max))
7870 (message "Copied %s" data)))))
7872 ;;; Internal functions:
7874 (defun gnus-article-set-globals ()
7875 (with-current-buffer gnus-summary-buffer
7876 (gnus-set-global-variables)))
7878 (defun gnus-signature-toggle (end)
7879 (gnus-with-article-buffer
7880 (let ((inhibit-point-motion-hooks t))
7881 (if (text-property-any end (point-max) 'article-type 'signature)
7883 (gnus-delete-wash-type 'signature)
7884 (gnus-remove-text-properties-when
7885 'article-type 'signature end (point-max)
7886 (cons 'article-type (cons 'signature
7887 gnus-hidden-properties))))
7888 (gnus-add-wash-type 'signature)
7889 (gnus-add-text-properties-when
7890 'article-type nil end (point-max)
7891 (cons 'article-type (cons 'signature
7892 gnus-hidden-properties)))))
7893 (let ((gnus-article-mime-handle-alist-1 gnus-article-mime-handle-alist))
7894 (gnus-set-mode-line 'article))))
7896 (defun gnus-button-entry ()
7897 ;; Return the first entry in `gnus-button-alist' matching this place.
7898 (let ((alist gnus-button-alist)
7901 (setq entry (pop alist))
7902 (if (looking-at (eval (car entry)))
7907 (defun gnus-button-push (marker)
7908 ;; Push button starting at MARKER.
7911 (let* ((entry (gnus-button-entry))
7912 (inhibit-point-motion-hooks t)
7914 (args (or (and (eq (car entry) 'gnus-button-url-regexp)
7915 (get-char-property marker 'gnus-button-url))
7916 (mapcar (lambda (group)
7917 (let ((string (match-string group)))
7918 (set-text-properties
7919 0 (length string) nil string)
7921 (nthcdr 4 entry)))))
7926 (fboundp (symbol-value fun)))
7927 (apply (symbol-value fun) args))
7929 (gnus-message 1 "You must define `%S' to use this button"
7930 (cons fun args)))))))
7932 (defun gnus-parse-news-url (url)
7933 (let (scheme server port group message-id articles)
7936 (goto-char (point-min))
7937 (when (looking-at "\\([A-Za-z]+\\):")
7938 (setq scheme (match-string 1))
7939 (goto-char (match-end 0)))
7940 (when (looking-at "//\\([^:/]+\\)\\(:?\\)\\([0-9]+\\)?/")
7941 (setq server (match-string 1))
7942 (setq port (if (stringp (match-string 3))
7943 (string-to-number (match-string 3))
7945 (goto-char (match-end 0)))
7948 ((looking-at "\\(.*@.*\\)")
7949 (setq message-id (match-string 1)))
7950 ((looking-at "\\([^/]+\\)/\\([-0-9]+\\)")
7951 (setq group (match-string 1)
7952 articles (split-string (match-string 2) "-")))
7953 ((looking-at "\\([^/]+\\)/?")
7954 (setq group (match-string 1)))
7956 (error "Unknown news URL syntax"))))
7957 (list scheme server port group message-id articles)))
7959 (defun gnus-button-handle-news (url)
7961 (destructuring-bind (scheme server port group message-id articles)
7962 (gnus-parse-news-url url)
7965 (with-current-buffer gnus-summary-buffer
7967 (let ((gnus-refer-article-method
7968 (nconc (list (list 'nntp server))
7969 gnus-refer-article-method))
7970 (nntp-port-number (or port "nntp")))
7971 (gnus-message 7 "Fetching %s with %s"
7972 message-id gnus-refer-article-method)
7973 (gnus-summary-refer-article message-id))
7974 (gnus-summary-refer-article message-id))))
7976 (gnus-button-fetch-group url)))))
7978 (defun gnus-button-patch (library line)
7979 "Visit an Emacs Lisp library LIBRARY on line LINE."
7981 (let ((file (locate-library (file-name-nondirectory library))))
7983 (error "Couldn't find library %s" library))
7985 (goto-char (point-min))
7986 (forward-line (1- (string-to-number line)))))
7988 (defun gnus-button-handle-man (url)
7990 (gnus-message 9 "`%s' `%s'" gnus-button-man-handler url)
7991 (when (eq gnus-button-man-handler 'woman)
7992 (setq url (gnus-replace-in-string url "([1-9][X1a-z]*).*\\'" "")))
7993 (gnus-message 9 "`%s' `%s'" gnus-button-man-handler url)
7994 (funcall gnus-button-man-handler url))
7996 (defun gnus-button-handle-info-url (url)
7997 "Fetch an info URL."
7998 (setq url (mm-subst-char-in-string ?+ ?\ url))
8000 ((string-match "^\\([^:/]+\\)?/\\(.*\\)" url)
8001 (gnus-info-find-node
8002 (concat "(" (or (gnus-url-unhex-string (match-string 1 url))
8004 ")" (gnus-url-unhex-string (match-string 2 url)))))
8005 ((string-match "([^)\"]+)[^\"]+" url)
8007 (gnus-replace-in-string
8008 (gnus-replace-in-string url "[\n\t ]+" " ") "\"" ""))
8009 (gnus-info-find-node url))
8010 (t (error "Can't parse %s" url))))
8012 (defun gnus-button-handle-info-url-gnome (url)
8013 "Fetch GNOME style info URL."
8014 (setq url (mm-subst-char-in-string ?_ ?\ url))
8015 (if (string-match "\\([^#]+\\)#?\\(.*\\)" url)
8016 (gnus-info-find-node
8018 (gnus-url-unhex-string
8019 (match-string 1 url))
8021 (or (gnus-url-unhex-string
8022 (match-string 2 url))
8024 (error "Can't parse %s" url)))
8026 (defun gnus-button-handle-info-url-kde (url)
8027 "Fetch KDE style info URL."
8028 (gnus-info-find-node (gnus-url-unhex-string url)))
8030 ;; (info) will autoload info.el
8031 (declare-function Info-menu "info" (menu-item &optional fork))
8032 (declare-function Info-index-next "info" (num))
8034 (defun gnus-button-handle-info-keystrokes (url)
8035 "Call `info' when pushing the corresponding URL button."
8036 ;; For links like `C-h i d m gnus RET part RET , ,', `C-h i d m CC Mode RET'.
8037 (let (node indx comma)
8039 (concat "\\b\\(C-h\\|<?[Ff]1>?\\)[ \t\n]+i[ \t\n]+d?[ \t\n]?m[ \t\n]+"
8040 "\\([^ ]+ ?[^ ]+\\)[ \t\n]+RET"
8041 "\\([ \t\n]+i[ \t\n]+[^ ]+ ?[^ ]+[ \t\n]+RET"
8042 "\\(?:[ \t\n,]*\\)\\)?")
8044 (setq node (match-string 2 url)
8045 indx (match-string 3 url))
8046 (error "Can't parse %s" url))
8050 (when (> (length indx) 0)
8051 (string-match (concat "[ \t\n]+i[ \t\n]+\\([^ ]+ ?[^ ]+\\)[ \t\n]+RET"
8054 (setq comma (match-string 2 indx))
8055 (setq indx (match-string 1 indx))
8058 (dotimes (i (with-temp-buffer
8060 ;; Note: the XEmacs version of `how-many' takes
8061 ;; no optional argument.
8062 (goto-char (point-min))
8064 (Info-index-next 1)))
8067 ;; Called after pgg-snarf-keys-region, which autoloads pgg.el.
8068 (declare-function pgg-display-output-buffer "pgg" (start end status))
8070 (defun gnus-button-openpgp (url)
8071 "Retrieve and add an OpenPGP key given URL from an OpenPGP header."
8073 (mm-url-insert-file-contents-external url)
8074 (pgg-snarf-keys-region (point-min) (point-max))
8075 (pgg-display-output-buffer nil nil nil)))
8077 (defun gnus-button-message-id (message-id)
8079 (with-current-buffer gnus-summary-buffer
8080 (gnus-summary-refer-article message-id)))
8082 (defun gnus-button-fetch-group (address &rest ignore)
8083 "Fetch GROUP specified by ADDRESS."
8084 (when (string-match "\\`\\(nntp\\|news\\):\\(//\\)?\\(.*\\)\\'"
8086 ;; Allow to use `gnus-button-fetch-group' in `browse-url-browser-function'
8087 ;; for nntp:// and news://
8088 (setq address (match-string 3 address)))
8089 (if (not (string-match "[:/]" address))
8090 ;; This is just a simple group url.
8091 (gnus-group-read-ephemeral-group address gnus-select-method)
8094 "^\\([^:/]+\\)\\(:\\([^/]+\\)\\)?/\\([^/]+\\)\\(/\\([0-9]+\\)\\)?"
8096 (error "Can't parse %s" address)
8097 (gnus-group-read-ephemeral-group
8098 (match-string 4 address)
8099 `(nntp ,(match-string 1 address)
8100 (nntp-address ,(match-string 1 address))
8101 (nntp-port-number ,(if (match-end 3)
8102 (match-string 3 address)
8105 (and (match-end 6) (list (string-to-number (match-string 6 address))))))))
8107 (defun gnus-url-parse-query-string (query &optional downcase)
8108 (let (retval pairs cur key val)
8109 (setq pairs (split-string query "&"))
8111 (setq cur (car pairs)
8113 (if (not (string-match "=" cur))
8115 (setq key (gnus-url-unhex-string (substring cur 0 (match-beginning 0)))
8116 val (gnus-url-unhex-string (substring cur (match-end 0) nil) t))
8118 (setq key (downcase key)))
8119 (setq cur (assoc key retval))
8121 (setcdr cur (cons val (cdr cur)))
8122 (setq retval (cons (list key val) retval)))))
8125 (defun gnus-url-mailto (url)
8126 ;; Send mail to someone
8127 (when (string-match "mailto:/*\\(.*\\)" url)
8128 (setq url (substring url (match-beginning 1) nil)))
8129 (let (to args subject func)
8130 (setq args (gnus-url-parse-query-string
8131 (if (string-match "^\\?" url)
8133 (if (string-match "^\\([^?]+\\)\\?\\(.*\\)" url)
8134 (concat "to=" (match-string 1 url) "&"
8135 (match-string 2 url))
8136 (concat "to=" url)))
8138 subject (cdr-safe (assoc "subject" args)))
8141 (setq func (intern-soft (concat "message-goto-" (downcase (caar args)))))
8144 (message-position-on-field (caar args)))
8145 (insert (gnus-replace-in-string
8146 (mapconcat 'identity (reverse (cdar args)) ", ")
8148 (setq args (cdr args)))
8151 (message-goto-subject))))
8153 (defun gnus-button-embedded-url (address)
8154 "Activate ADDRESS with `browse-url'."
8155 (browse-url (gnus-strip-whitespace address)))
8157 ;;; Next/prev buttons in the article buffer.
8159 (defvar gnus-next-page-line-format "%{%(Next page...%)%}\n")
8160 (defvar gnus-prev-page-line-format "%{%(Previous page...%)%}\n")
8162 (defvar gnus-prev-page-map
8163 (let ((map (make-sparse-keymap)))
8164 (define-key map gnus-mouse-2 'gnus-button-prev-page)
8165 (define-key map "\r" 'gnus-button-prev-page)
8168 (defvar gnus-next-page-map
8169 (let ((map (make-sparse-keymap)))
8170 (define-key map gnus-mouse-2 'gnus-button-next-page)
8171 (define-key map "\r" 'gnus-button-next-page)
8174 (defun gnus-insert-prev-page-button ()
8176 (inhibit-read-only t))
8178 gnus-prev-page-line-format nil
8179 `(keymap ,gnus-prev-page-map
8181 gnus-callback gnus-article-button-prev-page
8182 article-type annotation))
8184 ;; Exclude a newline.
8187 (when gnus-article-button-face
8188 (gnus-overlay-put (gnus-make-overlay b e nil t)
8189 'face gnus-article-button-face))
8190 (widget-convert-button
8192 :action 'gnus-button-prev-page
8193 :button-keymap gnus-prev-page-map)))
8195 (defun gnus-button-next-page (&optional args more-args)
8196 "Go to the next page."
8198 (let ((win (selected-window)))
8199 (select-window (gnus-get-buffer-window gnus-article-buffer t))
8200 (gnus-article-next-page)
8201 (select-window win)))
8203 (defun gnus-button-prev-page (&optional args more-args)
8204 "Go to the prev page."
8206 (let ((win (selected-window)))
8207 (select-window (gnus-get-buffer-window gnus-article-buffer t))
8208 (gnus-article-prev-page)
8209 (select-window win)))
8211 (defun gnus-insert-next-page-button ()
8213 (inhibit-read-only t))
8214 (gnus-eval-format gnus-next-page-line-format nil
8215 `(keymap ,gnus-next-page-map
8217 gnus-callback gnus-article-button-next-page
8218 article-type annotation))
8220 ;; Exclude a newline.
8223 (when gnus-article-button-face
8224 (gnus-overlay-put (gnus-make-overlay b e nil t)
8225 'face gnus-article-button-face))
8226 (widget-convert-button
8228 :action 'gnus-button-next-page
8229 :button-keymap gnus-next-page-map)))
8231 (defun gnus-article-button-next-page (arg)
8232 "Go to the next page."
8234 (let ((win (selected-window)))
8235 (select-window (gnus-get-buffer-window gnus-article-buffer t))
8236 (gnus-article-next-page)
8237 (select-window win)))
8239 (defun gnus-article-button-prev-page (arg)
8240 "Go to the prev page."
8242 (let ((win (selected-window)))
8243 (select-window (gnus-get-buffer-window gnus-article-buffer t))
8244 (gnus-article-prev-page)
8245 (select-window win)))
8247 (defvar gnus-decode-header-methods
8248 '(mail-decode-encoded-word-region)
8249 "List of methods used to decode headers.
8251 This variable is a list of FUNCTION or (REGEXP . FUNCTION). If item
8252 is FUNCTION, FUNCTION will be applied to all newsgroups. If item is a
8253 \(REGEXP . FUNCTION), FUNCTION will be only apply to the newsgroups
8254 whose names match REGEXP.
8257 \((\"chinese\" . gnus-decode-encoded-word-region-by-guess)
8258 mail-decode-encoded-word-region
8259 (\"chinese\" . rfc1843-decode-region))
8262 (defvar gnus-decode-header-methods-cache nil)
8264 (defun gnus-multi-decode-header (start end)
8265 "Apply the functions from `gnus-encoded-word-methods' that match."
8266 (unless (and gnus-decode-header-methods-cache
8267 (eq gnus-newsgroup-name
8268 (car gnus-decode-header-methods-cache)))
8269 (setq gnus-decode-header-methods-cache (list gnus-newsgroup-name))
8270 (dolist (x gnus-decode-header-methods)
8272 (nconc gnus-decode-header-methods-cache (list x))
8273 (if (and gnus-newsgroup-name
8274 (string-match (car x) gnus-newsgroup-name))
8275 (nconc gnus-decode-header-methods-cache
8277 (let ((xlist gnus-decode-header-methods-cache))
8280 (narrow-to-region start end)
8282 (funcall (pop xlist) (point-min) (point-max))))))
8285 ;;; Treatment top-level handling.
8288 (defvar gnus-inhibit-article-treatments nil)
8290 (defun gnus-treat-article (gnus-treat-condition
8291 &optional part-number total-parts gnus-treat-type)
8292 (let ((gnus-treat-length (- (point-max) (point-min)))
8293 (alist gnus-treatment-function-alist)
8294 (article-goto-body-goes-to-point-min-p t)
8296 (or (not gnus-treat-type)
8298 (let ((list gnus-article-treat-types))
8300 (when (string-match (pop list) gnus-treat-type)
8301 (throw 'found t)))))))
8302 (highlightp (gnus-visual-p 'article-highlight 'highlight))
8304 (gnus-run-hooks 'gnus-part-display-hook)
8305 (dolist (elem alist)
8308 (when (gnus-buffer-live-p gnus-summary-buffer)
8309 (set-buffer gnus-summary-buffer))
8310 (symbol-value (car elem))))
8311 (when (and (or (consp val)
8313 (or (not gnus-inhibit-article-treatments)
8314 (eq gnus-treat-condition 'head))
8315 (gnus-treat-predicate val)
8316 (or (not (get (car elem) 'highlight))
8319 (funcall (cadr elem)))))))
8321 ;; Dynamic variables.
8322 (defvar part-number)
8323 (defvar total-parts)
8324 (defvar gnus-treat-type)
8325 (defvar gnus-treat-condition)
8326 (defvar gnus-treat-length)
8328 (defun gnus-treat-predicate (val)
8332 (gnus-treat-condition
8333 (eq gnus-treat-condition val))
8335 (stringp (car val)))
8336 (apply 'gnus-or (mapcar `(lambda (s)
8337 (string-match s ,(or gnus-newsgroup-name "")))
8340 (let ((pred (pop val)))
8343 (apply 'gnus-or (mapcar 'gnus-treat-predicate val)))
8345 (apply 'gnus-and (mapcar 'gnus-treat-predicate val)))
8347 (not (gnus-treat-predicate (car val))))
8349 (equal (car val) gnus-treat-type))
8351 (error "%S is not a valid predicate" pred)))))
8359 (eq part-number total-parts))
8361 (< gnus-treat-length val))
8363 (error "%S is not a valid value" val))))
8365 (defun gnus-article-encrypt-body (protocol &optional n)
8366 "Encrypt the article body."
8369 (or gnus-article-encrypt-protocol
8370 (gnus-completing-read "Encrypt protocol"
8371 (mapcar 'car gnus-article-encrypt-protocol-alist)
8373 current-prefix-arg))
8374 ;; User might hit `K E' instead of `K e', so prompt once.
8375 (when (and gnus-article-encrypt-protocol
8377 (unless (gnus-y-or-n-p "Really encrypt article(s)? ")
8378 (error "Encrypt aborted")))
8379 (let ((func (cdr (assoc protocol gnus-article-encrypt-protocol-alist))))
8381 (error "Can't find the encrypt protocol %s" protocol))
8382 (if (member gnus-newsgroup-name '("nndraft:delayed"
8385 (error "Can't encrypt the article in group %s"
8386 gnus-newsgroup-name))
8387 (gnus-summary-iterate n
8388 (with-current-buffer gnus-summary-buffer
8389 (let ((mail-parse-charset gnus-newsgroup-charset)
8390 (mail-parse-ignored-charsets gnus-newsgroup-ignored-charsets)
8391 (summary-buffer gnus-summary-buffer)
8393 (gnus-set-global-variables)
8394 (when (gnus-group-read-only-p)
8395 (error "The current newsgroup does not support article encrypt"))
8396 (gnus-summary-show-article t)
8398 (or (mail-header-references gnus-current-headers) ""))
8399 (set-buffer gnus-article-buffer)
8400 (let* ((inhibit-read-only t)
8402 (mapcar (lambda (field)
8403 (and (save-restriction
8404 (message-narrow-to-head)
8405 (goto-char (point-min))
8406 (search-forward field nil t))
8408 (message-narrow-to-field)
8410 (delete-region (point-min) (point-max))
8412 '("Content-Type:" "Content-Transfer-Encoding:"
8413 "Content-Disposition:"))))
8414 (message-narrow-to-head)
8415 (message-remove-header "MIME-Version")
8416 (goto-char (point-max))
8417 (setq point (point))
8418 (insert (apply 'concat headers))
8420 (narrow-to-region point (point-max))
8421 (let ((message-options message-options))
8422 (message-options-set 'message-sender user-mail-address)
8423 (message-options-set 'message-recipients user-mail-address)
8424 (message-options-set 'message-sign-encrypt 'not)
8426 (goto-char (point-min))
8427 (insert "MIME-Version: 1.0\n")
8429 (gnus-summary-edit-article-done
8430 references nil summary-buffer t))
8431 (when gnus-keep-backlog
8432 (gnus-backlog-remove-article
8433 (car gnus-article-current) (cdr gnus-article-current)))
8434 (gnus-flush-original-article-buffer)
8435 (when gnus-use-cache
8436 (gnus-cache-update-article
8437 (car gnus-article-current) (cdr gnus-article-current))))))))
8439 (defvar gnus-mime-security-button-line-format "%{%([[%t:%i]%D]%)%}\n"
8440 "The following specs can be used:
8441 %t The security MIME type
8444 %D Details if button is pressed")
8446 (defvar gnus-mime-security-button-end-line-format "%{%([[End of %t]%D]%)%}\n"
8447 "The following specs can be used:
8448 %t The security MIME type
8451 %D Details if button is pressed")
8453 (defvar gnus-mime-security-button-line-format-alist
8454 '((?t gnus-tmp-type ?s)
8455 (?i gnus-tmp-info ?s)
8456 (?d gnus-tmp-details ?s)
8457 (?D gnus-tmp-pressed-details ?s)))
8459 (defvar gnus-mime-security-button-commands
8460 '((gnus-article-press-button "\r" "Show Detail")
8464 (gnus-mime-security-save-part "o" "Save...")
8473 (gnus-mime-security-pipe-part "|" "Pipe To Command...")
8476 (defvar gnus-mime-security-button-map
8477 (let ((map (make-sparse-keymap)))
8478 (define-key map gnus-mouse-2 'gnus-article-push-button)
8479 (define-key map gnus-down-mouse-3 'gnus-mime-security-button-menu)
8480 (dolist (c gnus-mime-security-button-commands)
8481 (define-key map (cadr c) (car c)))
8485 gnus-mime-security-button-menu gnus-mime-security-button-map
8486 "Security button menu."
8490 (unless (eq (car c) 'undefined)
8491 (vector (caddr c) (car c) :active t)))
8492 gnus-mime-security-button-commands))))
8494 (defun gnus-mime-security-button-menu (event prefix)
8495 "Construct a context-sensitive menu of security commands."
8496 (interactive "e\nP")
8497 (save-window-excursion
8498 (let ((pos (event-start event)))
8499 (select-window (posn-window pos))
8500 (goto-char (posn-point pos))
8501 (gnus-article-check-buffer)
8502 (popup-menu gnus-mime-security-button-menu nil prefix))))
8504 (defvar gnus-mime-security-details-buffer nil)
8506 (defvar gnus-mime-security-button-pressed nil)
8508 (defvar gnus-mime-security-show-details-inline t
8509 "If non-nil, show details in the article buffer.")
8511 (defun gnus-mime-security-verify-or-decrypt (handle)
8512 (mm-remove-parts (cdr handle))
8513 (let ((region (mm-handle-multipart-ctl-parameter handle 'gnus-region))
8514 point (inhibit-read-only t))
8516 (goto-char (car region)))
8517 (setq point (point))
8518 (with-current-buffer (mm-handle-multipart-original-buffer handle)
8519 (let* ((mm-verify-option 'known)
8520 (mm-decrypt-option 'known)
8521 (nparts (mm-possibly-verify-or-decrypt (cdr handle) handle)))
8522 (unless (eq nparts (cdr handle))
8523 (mm-destroy-parts (cdr handle))
8524 (setcdr handle nparts))))
8525 (gnus-mime-display-security handle)
8527 (delete-region (point) (cdr region))
8528 (set-marker (car region) nil)
8529 (set-marker (cdr region) nil))
8532 (defun gnus-mime-security-show-details (handle)
8533 (let ((details (mm-handle-multipart-ctl-parameter handle 'gnus-details)))
8535 (gnus-message 5 "No details.")
8536 (if gnus-mime-security-show-details-inline
8537 (let ((gnus-mime-security-button-pressed
8538 (not (get-text-property (point) 'gnus-mime-details)))
8539 (gnus-mime-security-button-line-format
8540 (get-text-property (point) 'gnus-line-format))
8541 (inhibit-read-only t))
8543 (while (eq (get-text-property (point) 'gnus-line-format)
8544 gnus-mime-security-button-line-format)
8548 (narrow-to-region (point) (point))
8549 (gnus-insert-mime-security-button handle))
8550 (delete-region (point)
8551 (or (text-property-not-all
8554 gnus-mime-security-button-line-format)
8557 (if (gnus-buffer-live-p gnus-mime-security-details-buffer)
8558 (with-current-buffer gnus-mime-security-details-buffer
8561 (setq gnus-mime-security-details-buffer
8562 (gnus-get-buffer-create "*MIME Security Details*")))
8563 (with-current-buffer gnus-mime-security-details-buffer
8565 (goto-char (point-min)))
8566 (pop-to-buffer gnus-mime-security-details-buffer)))))
8568 (defun gnus-mime-security-press-button (handle)
8570 (if (mm-handle-multipart-ctl-parameter handle 'gnus-info)
8571 (gnus-mime-security-show-details handle)
8572 (gnus-mime-security-verify-or-decrypt handle))))
8574 (defun gnus-insert-mime-security-button (handle &optional displayed)
8575 (let* ((protocol (mm-handle-multipart-ctl-parameter handle 'protocol))
8578 (or (nth 2 (assoc protocol mm-verify-function-alist))
8579 (nth 2 (assoc protocol mm-decrypt-function-alist))
8581 (if (equal (car handle) "multipart/signed")
8582 " Signed" " Encrypted")
8585 (or (mm-handle-multipart-ctl-parameter handle 'gnus-info)
8588 (mm-handle-multipart-ctl-parameter handle 'gnus-details))
8589 gnus-tmp-pressed-details
8591 (setq gnus-tmp-details
8592 (if gnus-tmp-details
8593 (concat "\n" gnus-tmp-details)
8595 (setq gnus-tmp-pressed-details
8596 (if gnus-mime-security-button-pressed gnus-tmp-details ""))
8601 gnus-mime-security-button-line-format
8602 gnus-mime-security-button-line-format-alist
8603 `(keymap ,gnus-mime-security-button-map
8604 gnus-callback gnus-mime-security-press-button
8605 gnus-line-format ,gnus-mime-security-button-line-format
8606 gnus-mime-details ,gnus-mime-security-button-pressed
8607 article-type annotation
8610 ;; Exclude a newline.
8613 (when gnus-article-button-face
8614 (gnus-overlay-put (gnus-make-overlay b e nil t)
8615 'face gnus-article-button-face))
8616 (widget-convert-button
8619 :action 'gnus-widget-press-button
8620 :button-keymap gnus-mime-security-button-map
8623 ;; Needed to properly clear the message due to a bug in
8624 ;; wid-edit (XEmacs only).
8625 (when (boundp 'help-echo-owns-message)
8626 (setq help-echo-owns-message t))
8628 "%S: show detail; %S: more options"
8629 (aref gnus-mouse-2 0)
8630 (aref gnus-down-mouse-3 0))))))
8632 (defun gnus-mime-display-security (handle)
8634 (narrow-to-region (point) (point))
8635 (unless (gnus-unbuttonized-mime-type-p (car handle))
8636 (gnus-insert-mime-security-button handle))
8637 (gnus-mime-display-part (cadr handle))
8640 (unless (gnus-unbuttonized-mime-type-p (car handle))
8641 (let ((gnus-mime-security-button-line-format
8642 gnus-mime-security-button-end-line-format))
8643 (gnus-insert-mime-security-button handle)))
8644 (mm-set-handle-multipart-parameter
8646 (cons (set-marker (make-marker) (point-min))
8647 (set-marker (make-marker) (point-max))))
8648 (goto-char (point-max))))
8650 (defun gnus-mime-security-run-function (function)
8651 "Run FUNCTION with the security part under point."
8652 (gnus-article-check-buffer)
8653 (let ((data (get-text-property (point) 'gnus-data))
8655 (when (and (stringp (car-safe data))
8656 (setq buffer (mm-handle-multipart-original-buffer data))
8657 (setq handle (cadr data)))
8658 (if (bufferp (mm-handle-buffer handle))
8660 (setq handle (cons buffer (copy-sequence (cdr handle))))
8661 (mm-handle-set-undisplayer handle nil))
8662 (setq handle (mm-make-handle
8664 (mm-handle-multipart-ctl-parameter handle 'protocol)
8665 nil nil nil nil nil nil)))
8666 (funcall function handle))))
8668 (defun gnus-mime-security-save-part ()
8669 "Save the security part under point."
8671 (gnus-mime-security-run-function 'mm-save-part))
8673 (defun gnus-mime-security-pipe-part ()
8674 "Pipe the security part under point to a process."
8676 (gnus-mime-security-run-function 'mm-pipe-part))
8682 (run-hooks 'gnus-art-load-hook)
8684 ;;; gnus-art.el ends here