1 ;;; gnus-art.el --- article mode commands for Gnus
3 ;; Copyright (C) 1996-2015 Free Software Foundation, Inc.
5 ;; Author: Lars Magne Ingebrigtsen <larsi@gnus.org>
8 ;; This file is part of GNU Emacs.
10 ;; GNU Emacs is free software: you can redistribute it and/or modify
11 ;; it under the terms of the GNU General Public License as published by
12 ;; the Free Software Foundation, either version 3 of the License, or
13 ;; (at your option) any later version.
15 ;; GNU Emacs is distributed in the hope that it will be useful,
16 ;; but WITHOUT ANY WARRANTY; without even the implied warranty of
17 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 ;; GNU General Public License for more details.
20 ;; You should have received a copy of the GNU General Public License
21 ;; along with GNU Emacs. If not, see <http://www.gnu.org/licenses/>.
30 (defvar w3m-minor-mode-map)
47 (autoload 'gnus-msg-mail "gnus-msg" nil t)
48 (autoload 'gnus-button-mailto "gnus-msg")
49 (autoload 'gnus-button-reply "gnus-msg" nil t)
50 (autoload 'parse-time-string "parse-time" nil nil)
51 (autoload 'ansi-color-apply-on-region "ansi-color")
52 (autoload 'mm-url-insert-file-contents-external "mm-url")
53 (autoload 'mm-extern-cache-contents "mm-extern")
55 (defgroup gnus-article nil
57 :link '(custom-manual "(gnus)Article Buffer")
60 (defgroup gnus-article-treat nil
61 "Treating article parts."
62 :link '(custom-manual "(gnus)Article Hiding")
65 (defgroup gnus-article-hiding nil
66 "Hiding article parts."
67 :link '(custom-manual "(gnus)Article Hiding")
70 (defgroup gnus-article-highlight nil
71 "Article highlighting."
72 :link '(custom-manual "(gnus)Article Highlighting")
76 (defgroup gnus-article-signature nil
78 :link '(custom-manual "(gnus)Article Signature")
81 (defgroup gnus-article-headers nil
83 :link '(custom-manual "(gnus)Hiding Headers")
86 (defgroup gnus-article-washing nil
87 "Special commands on articles."
88 :link '(custom-manual "(gnus)Article Washing")
91 (defgroup gnus-article-emphasis nil
92 "Fontisizing articles."
93 :link '(custom-manual "(gnus)Article Fontisizing")
96 (defgroup gnus-article-saving nil
98 :link '(custom-manual "(gnus)Saving Articles")
101 (defgroup gnus-article-mime nil
102 "Worshiping the MIME wonder."
103 :link '(custom-manual "(gnus)Using MIME")
104 :group 'gnus-article)
106 (defgroup gnus-article-buttons nil
107 "Pushable buttons in the article buffer."
108 :link '(custom-manual "(gnus)Article Buttons")
109 :group 'gnus-article)
111 (defgroup gnus-article-various nil
112 "Other article options."
113 :link '(custom-manual "(gnus)Misc Article")
114 :group 'gnus-article)
116 (defcustom gnus-ignored-headers
119 (concat "^" header ":"))
120 '("Path" "Expires" "Date-Received" "References" "Xref" "Lines"
121 "Relay-Version" "Message-ID" "Approved" "Sender" "Received"
122 "X-UIDL" "MIME-Version" "Return-Path" "In-Reply-To"
123 "Content-Type" "Content-Transfer-Encoding" "X-WebTV-Signature"
124 "X-MimeOLE" "X-MSMail-Priority" "X-Priority" "X-Loop"
125 "X-Authentication-Warning" "X-MIME-Autoconverted" "X-Face"
126 "X-Attribution" "X-Originating-IP" "Delivered-To"
127 "NNTP-[-A-Za-z]+" "Distribution" "X-no-archive" "X-Trace"
128 "X-Complaints-To" "X-NNTP-Posting-Host" "X-Orig.*"
129 "Abuse-Reports-To" "Cache-Post-Path" "X-Article-Creation-Date"
130 "X-Poster" "X-Mail2News-Path" "X-Server-Date" "X-Cache"
131 "Originator" "X-Problems-To" "X-Auth-User" "X-Post-Time"
132 "X-Admin" "X-UID" "Resent-[-A-Za-z]+" "X-Mailing-List"
133 "Precedence" "Original-[-A-Za-z]+" "X-filename" "X-Orcpt"
134 "Old-Received" "X-Pgp" "X-Auth" "X-From-Line"
135 "X-Gnus-Article-Number" "X-Majordomo" "X-Url" "X-Sender"
136 "MBOX-Line" "Priority" "X400-[-A-Za-z]+"
137 "Status" "X-Gnus-Mail-Source" "Cancel-Lock"
138 "X-FTN" "X-EXP32-SerialNo" "Encoding" "Importance"
139 "Autoforwarded" "Original-Encoded-Information-Types" "X-Ya-Pop3"
140 "X-Face-Version" "X-Vms-To" "X-ML-NAME" "X-ML-COUNT"
141 "Mailing-List" "X-finfo" "X-md5sum" "X-md5sum-Origin"
142 "X-Sun-Charset" "X-Accept-Language" "X-Envelope-Sender"
143 "List-[A-Za-z]+" "X-Listprocessor-Version"
144 "X-Received" "X-Distribute" "X-Sequence" "X-Juno-Line-Breaks"
145 "X-Notes-Item" "X-MS-TNEF-Correlator" "x-uunet-gateway"
146 "X-Received" "Content-length" "X-precedence"
147 "X-Authenticated-User" "X-Comment" "X-Report" "X-Abuse-Info"
148 "X-HTTP-Proxy" "X-Mydeja-Info" "X-Copyright" "X-No-Markup"
149 "X-Abuse-Info" "X-From_" "X-Accept-Language" "Errors-To"
150 "X-BeenThere" "X-Mailman-Version" "List-Help" "List-Post"
151 "List-Subscribe" "List-Id" "List-Unsubscribe" "List-Archive"
152 "X-Content-length" "X-Posting-Agent" "Original-Received"
153 "X-Request-PGP" "X-Fingerprint" "X-WRIEnvto" "X-WRIEnvfrom"
154 "X-Virus-Scanned" "X-Delivery-Agent" "Posted-Date" "X-Gateway"
155 "X-Local-Origin" "X-Local-Destination" "X-UserInfo1"
156 "X-Received-Date" "X-Hashcash" "Face" "X-DMCA-Notifications"
157 "X-Abuse-and-DMCA-Info" "X-Postfilter" "X-Gpg-.*" "X-Disclaimer"
158 "Envelope-To" "X-Spam-Score" "System-Type" "X-Injected-Via-Gmane"
159 "X-Gmane-NNTP-Posting-Host" "Jabber-ID" "Archived-At"
160 "Envelope-Sender" "Envelope-Recipients"))
161 "*All headers that start with this regexp will be hidden.
162 This variable can also be a list of regexps of headers to be ignored.
163 If `gnus-visible-headers' is non-nil, this variable will be ignored."
164 :type '(choice regexp
166 :group 'gnus-article-hiding)
168 (defcustom gnus-visible-headers
169 "^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:"
170 "*All headers that do not match this regexp will be hidden.
171 This variable can also be a list of regexp of headers to remain visible.
172 If this variable is non-nil, `gnus-ignored-headers' will be ignored."
174 (repeat :value-to-internal (lambda (widget value)
175 (custom-split-regexp-maybe value))
176 :match (lambda (widget value)
178 (widget-editable-list-match widget value)))
180 (const :tag "Use gnus-ignored-headers" nil)
182 :group 'gnus-article-hiding)
184 (defcustom gnus-sorted-header-list
185 '("^From:" "^Subject:" "^Summary:" "^Keywords:" "^Newsgroups:"
186 "^Followup-To:" "^To:" "^Cc:" "^Date:" "^Organization:")
187 "*This variable is a list of regular expressions.
188 If it is non-nil, headers that match the regular expressions will
189 be placed first in the article buffer in the sequence specified by
191 :type '(repeat regexp)
192 :group 'gnus-article-hiding)
194 (defcustom gnus-boring-article-headers '(empty followup-to reply-to)
195 "Headers that are only to be displayed if they have interesting data.
196 Possible values in this list are:
198 'empty Headers with no content.
199 'newsgroups Newsgroup identical to Gnus group.
200 'to-address To identical to To-address.
201 'to-list To identical to To-list.
202 'cc-list CC identical to To-list.
203 'followup-to Followup-to identical to Newsgroups.
204 'reply-to Reply-to identical to From.
205 'date Date less than four days old.
206 'long-to To and/or Cc longer than 1024 characters.
207 'many-to Multiple To and/or Cc."
208 :type '(set (const :tag "Headers with no content." empty)
209 (const :tag "Newsgroups identical to Gnus group." newsgroups)
210 (const :tag "To identical to To-address." to-address)
211 (const :tag "To identical to To-list." to-list)
212 (const :tag "CC identical to To-list." cc-list)
213 (const :tag "Followup-to identical to Newsgroups." followup-to)
214 (const :tag "Reply-to identical to From." reply-to)
215 (const :tag "Date less than four days old." date)
216 (const :tag "To and/or Cc longer than 1024 characters." long-to)
217 (const :tag "Multiple To and/or Cc headers." many-to))
218 :group 'gnus-article-hiding)
220 (defcustom gnus-article-skip-boring nil
221 "Skip over text that is not worth reading.
222 By default, if you set this t, then Gnus will display citations and
223 signatures, but will never scroll down to show you a page consisting
224 only of boring text. Boring text is controlled by
225 `gnus-article-boring-faces'."
228 :group 'gnus-article-hiding)
230 (defcustom gnus-signature-separator '("^-- $" "^-- *$")
231 "Regexp matching signature separator.
232 This can also be a list of regexps. In that case, it will be checked
233 from head to tail looking for a separator. Searches will be done from
234 the end of the buffer."
235 :type '(choice :format "%{%t%}: %[Value Menu%]\n%v"
237 (repeat :tag "List of regexp" regexp))
238 :group 'gnus-article-signature)
240 (defcustom gnus-signature-limit nil
241 "Provide a limit to what is considered a signature.
242 If it is a number, no signature may not be longer (in characters) than
243 that number. If it is a floating point number, no signature may be
244 longer (in lines) than that number. If it is a function, the function
245 will be called without any parameters, and if it returns nil, there is
246 no signature in the buffer. If it is a string, it will be used as a
247 regexp. If it matches, the text in question is not a signature.
249 This can also be a list of the above values."
250 :type '(choice (const nil)
254 (regexp :value ".*"))
255 :group 'gnus-article-signature)
257 (defcustom gnus-hidden-properties
258 (if (featurep 'xemacs)
259 ;; `intangible' is evil, but I keep it here in case it's useful.
260 '(invisible t intangible t)
261 ;; Emacs's command loop moves point out of invisible text anyway, so
262 ;; `intangible' is clearly not needed there.
264 "Property list to use for hiding text."
266 :group 'gnus-article-hiding)
268 ;; Fixme: This isn't the right thing for mixed graphical and non-graphical
269 ;; frames in a session.
270 (defcustom gnus-article-x-face-command
271 (if (featurep 'xemacs)
272 (if (or (gnus-image-type-available-p 'xface)
273 (gnus-image-type-available-p 'pbm))
274 'gnus-display-x-face-in-from
276 '/* Format_version=1, Width=48, Height=48, Depth=1, Valid_bits_per_item=16 */'\
277 ; uncompface; } | icontopbm | ee -")
278 (if (gnus-image-type-available-p 'pbm)
279 'gnus-display-x-face-in-from
281 '/* Format_version=1, Width=48, Height=48, Depth=1, Valid_bits_per_item=16 */'\
282 ; uncompface; } | icontopbm | display -"))
283 "*String or function to be executed to display an X-Face header.
284 If it is a string, the command will be executed in a sub-shell
285 asynchronously. The compressed face will be piped to this command."
286 :type `(choice string
287 (function-item gnus-display-x-face-in-from)
291 :group 'gnus-article-washing)
293 (defcustom gnus-article-x-face-too-ugly nil
294 "Regexp matching posters whose face shouldn't be shown automatically."
295 :type '(choice regexp (const nil))
296 :group 'gnus-article-washing)
298 (defcustom gnus-article-banner-alist nil
299 "Banner alist for stripping.
301 ((egroups . \"^[ \\t\\n]*-------------------+\\\\( \\\\(e\\\\|Yahoo! \\\\)Groups Sponsor -+\\\\)?....\\n\\\\(.+\\n\\\\)+\"))"
303 :type '(repeat (cons symbol regexp))
304 :group 'gnus-article-washing)
306 (gnus-define-group-parameter
309 "Alist of regexps (to match group names) and banner."
310 :variable-group gnus-article-washing
312 '(choice :tag "Banner"
314 (const :tag "Remove signature" signature)
315 (symbol :tag "Item in `gnus-article-banner-alist'" none)
317 (const :tag "None" nil))
319 "If non-nil, specify how to remove `banners' from articles.
321 Symbol `signature' means to remove signatures delimited by
322 `gnus-signature-separator'. Any other symbol is used to look up a
323 regular expression to match the banner in `gnus-article-banner-alist'.
324 A string is used as a regular expression to match the banner
327 (defcustom gnus-article-address-banner-alist nil
328 "Alist of mail addresses and banners.
329 Each element has the form (ADDRESS . BANNER), where ADDRESS is a regexp
330 to match a mail address in the From: header, BANNER is one of a symbol
331 `signature', an item in `gnus-article-banner-alist', a regexp and nil.
332 If ADDRESS matches author's mail address, it will remove things like
333 advertisements. For example:
335 \((\"@yoo-hoo\\\\.co\\\\.jp\\\\'\" . \"\\n_+\\nDo You Yoo-hoo!\\\\?\\n.*\\n.*\\n\"))
339 (regexp :tag "Address")
340 (choice :tag "Banner" :value nil
341 (const :tag "Remove signature" signature)
342 (symbol :tag "Item in `gnus-article-banner-alist'" none)
344 (const :tag "None" nil))))
346 :group 'gnus-article-washing)
348 (defmacro gnus-emphasis-custom-with-format (&rest body)
350 \\(\\s-\\|^\\|\\=\\|[-\"]\\|\\s(\\)\\(%s\\(\\w+\\(\\s-+\\w+\\)*[.,]?\\)%s\\)\
351 \\(\\([-,.;:!?\"]\\|\\s)\\)+\\s-\\|[?!.]\\s-\\|\\s)\\|\\s-\\)"))
354 (defun gnus-emphasis-custom-value-to-external (value)
355 (gnus-emphasis-custom-with-format
356 (if (consp (car value))
357 (list (format format (car (car value)) (cdr (car value)))
359 (if (nth 1 value) 2 3)
363 (defun gnus-emphasis-custom-value-to-internal (value)
364 (gnus-emphasis-custom-with-format
365 (let ((regexp (concat "\\`"
366 (format (regexp-quote format)
367 "\\([^()]+\\)" "\\([^()]+\\)")
370 (if (string-match regexp (setq pattern (car value)))
371 (list (cons (match-string 1 pattern) (match-string 2 pattern))
376 (defcustom gnus-emphasis-alist
378 '(("\\*" "\\*" bold nil 2)
381 ("_/" "/_" underline-italic)
382 ("_\\*" "\\*_" underline-bold)
383 ("\\*/" "/\\*" bold-italic)
384 ("_\\*/" "/\\*_" underline-bold-italic))))
386 (gnus-emphasis-custom-with-format
387 (mapcar (lambda (spec)
388 (list (format format (car spec) (cadr spec))
391 (intern (format "gnus-emphasis-%s" (nth 2 spec)))))
393 '(;; I've never seen anyone use this strikethru convention whereas I've
394 ;; several times seen it triggered by normal text. --Stef
395 ;; Miles suggests that this form is sometimes used but for italics,
396 ;; so maybe we should map it to `italic'.
397 ;; ("\\(\\s-\\|^\\)\\(-\\(\\(\\w\\|-[^-]\\)+\\)-\\)\\(\\s-\\|[?!.,;]\\)"
398 ;; 2 3 gnus-emphasis-strikethru)
399 ("\\(\\s-\\|^\\)\\(_\\(\\(\\w\\|_[^_]\\)+\\)_\\)\\(\\s-\\|[?!.,;]\\)"
400 2 3 gnus-emphasis-underline))))
401 "*Alist that says how to fontify certain phrases.
402 Each item looks like this:
404 (\"_\\\\(\\\\w+\\\\)_\" 0 1 'underline)
406 The first element is a regular expression to be matched. The second
407 is a number that says what regular expression grouping used to find
408 the entire emphasized word. The third is a number that says what
409 regexp grouping should be displayed and highlighted. The fourth
410 is the face used for highlighting."
414 :format "%[Customizing Style%]\n%v"
416 (group :tag "Default"
417 :value ("" 0 0 default)
420 (let ((value (widget-get
421 (cadr (widget-get (widget-get widget :parent)
424 (if (not (eq (nth 2 value) 'default))
428 (gnus-emphasis-custom-value-to-external value))))
429 (widget-group-value-create widget))
431 (integer :format "Match group: %v")
432 (integer :format "Emphasize group: %v")
435 :value (("_" . "_") nil default)
437 (regexp :format "Start regexp: %v")
438 (regexp :format "End regexp: %v"))
439 (boolean :format "Show start and end patterns: %[%v%]\n"
440 :on " On " :off " Off ")
442 :get (lambda (symbol)
443 (mapcar 'gnus-emphasis-custom-value-to-internal
444 (default-value symbol)))
445 :set (lambda (symbol value)
446 (set-default symbol (mapcar 'gnus-emphasis-custom-value-to-external
448 :group 'gnus-article-emphasis)
450 (defcustom gnus-emphasize-whitespace-regexp "^[ \t]+\\|[ \t]*\n"
451 "A regexp to describe whitespace which should not be emphasized.
452 Typical values are \"^[ \\t]+\\\\|[ \\t]*\\n\" and \"[ \\t]+\\\\|[ \\t]*\\n\".
453 The former avoids underlining of leading and trailing whitespace,
454 and the latter avoids underlining any whitespace at all."
456 :group 'gnus-article-emphasis
459 (defface gnus-emphasis-bold '((t (:bold t)))
460 "Face used for displaying strong emphasized text (*word*)."
461 :group 'gnus-article-emphasis)
463 (defface gnus-emphasis-italic '((t (:italic t)))
464 "Face used for displaying italic emphasized text (/word/)."
465 :group 'gnus-article-emphasis)
467 (defface gnus-emphasis-underline '((t (:underline t)))
468 "Face used for displaying underlined emphasized text (_word_)."
469 :group 'gnus-article-emphasis)
471 (defface gnus-emphasis-underline-bold '((t (:bold t :underline t)))
472 "Face used for displaying underlined bold emphasized text (_*word*_)."
473 :group 'gnus-article-emphasis)
475 (defface gnus-emphasis-underline-italic '((t (:italic t :underline t)))
476 "Face used for displaying underlined italic emphasized text (_/word/_)."
477 :group 'gnus-article-emphasis)
479 (defface gnus-emphasis-bold-italic '((t (:bold t :italic t)))
480 "Face used for displaying bold italic emphasized text (/*word*/)."
481 :group 'gnus-article-emphasis)
483 (defface gnus-emphasis-underline-bold-italic
484 '((t (:bold t :italic t :underline t)))
485 "Face used for displaying underlined bold italic emphasized text.
486 Example: (_/*word*/_)."
487 :group 'gnus-article-emphasis)
489 (defface gnus-emphasis-strikethru (if (featurep 'xemacs)
490 '((t (:strikethru t)))
491 '((t (:strike-through t))))
492 "Face used for displaying strike-through text (-word-)."
493 :group 'gnus-article-emphasis)
495 (defface gnus-emphasis-highlight-words
496 '((t (:background "black" :foreground "yellow")))
497 "Face used for displaying highlighted words."
498 :group 'gnus-article-emphasis)
500 (defcustom gnus-article-time-format "%a, %d %b %Y %T %Z"
501 "Format for display of Date headers in article bodies.
502 See `format-time-string' for the possible values.
504 The variable can also be function, which should return a complete Date
505 header. The function is called with one argument, the time, which can
506 be fed to `format-time-string'."
507 :type '(choice string function)
508 :link '(custom-manual "(gnus)Article Date")
509 :group 'gnus-article-washing)
511 (defcustom gnus-save-all-headers t
512 "*If non-nil, don't remove any headers before saving.
513 This will be overridden by the `:headers' property that the symbol of
514 the saver function, which is specified by `gnus-default-article-saver',
516 :group 'gnus-article-saving
519 (defcustom gnus-prompt-before-saving 'always
520 "*This variable says how much prompting is to be done when saving articles.
521 If it is nil, no prompting will be done, and the articles will be
522 saved to the default files. If this variable is `always', each and
523 every article that is saved will be preceded by a prompt, even when
524 saving large batches of articles. If this variable is neither nil not
525 `always', there the user will be prompted once for a file name for
526 each invocation of the saving commands."
527 :group 'gnus-article-saving
528 :type '(choice (item always)
529 (item :tag "never" nil)
530 (sexp :tag "once" :format "%t\n" :value t)))
532 (defcustom gnus-saved-headers gnus-visible-headers
533 "Headers to keep if `gnus-save-all-headers' is nil.
534 If `gnus-save-all-headers' is non-nil, this variable will be ignored.
535 If that variable is nil, however, all headers that match this regexp
536 will be kept while the rest will be deleted before saving. This and
537 `gnus-save-all-headers' will be overridden by the `:headers' property
538 that the symbol of the saver function, which is specified by
539 `gnus-default-article-saver', might have."
540 :group 'gnus-article-saving
543 ;; Note that "Rmail format" is mbox since Emacs 23, but Babyl before.
544 (defcustom gnus-default-article-saver 'gnus-summary-save-in-rmail
545 "A function to save articles in your favorite format.
546 The function will be called by way of the `gnus-summary-save-article'
547 command, and friends such as `gnus-summary-save-article-rmail'.
549 Gnus provides the following functions:
551 * gnus-summary-save-in-rmail (Rmail format)
552 * gnus-summary-save-in-mail (Unix mail format)
553 * gnus-summary-save-in-folder (MH folder)
554 * gnus-summary-save-in-file (article format)
555 * gnus-summary-save-body-in-file (article body)
556 * gnus-summary-save-in-vm (use VM's folder format)
557 * gnus-summary-write-to-file (article format -- overwrite)
558 * gnus-summary-write-body-to-file (article body -- overwrite)
559 * gnus-summary-save-in-pipe (article format)
561 The symbol of each function may have the following properties:
564 The value non-nil means save decoded articles. This is meaningful
565 only with `gnus-summary-save-in-file', `gnus-summary-save-body-in-file',
566 `gnus-summary-write-to-file', `gnus-summary-write-body-to-file', and
567 `gnus-summary-save-in-pipe'.
570 The value specifies an alternative function which appends, not
571 overwrites, articles to a file. This implies that when saving many
572 articles at a time, `gnus-prompt-before-saving' is bound to t and all
573 articles are saved in a single file. This is meaningful only with
574 `gnus-summary-write-to-file' and `gnus-summary-write-body-to-file'.
577 The value specifies the symbol of a variable of which the value
578 specifies headers to be saved. If it is omitted,
579 `gnus-save-all-headers' and `gnus-saved-headers' control what
580 headers should be saved."
581 :group 'gnus-article-saving
582 :type '(radio (function-item gnus-summary-save-in-rmail)
583 (function-item gnus-summary-save-in-mail)
584 (function-item gnus-summary-save-in-folder)
585 (function-item gnus-summary-save-in-file)
586 (function-item gnus-summary-save-body-in-file)
587 (function-item gnus-summary-save-in-vm)
588 (function-item gnus-summary-write-to-file)
589 (function-item gnus-summary-write-body-to-file)
590 (function-item gnus-summary-save-in-pipe)
593 (defcustom gnus-article-save-coding-system
594 (or (and (mm-coding-system-p 'utf-8) 'utf-8)
595 (and (mm-coding-system-p 'iso-2022-7bit) 'iso-2022-7bit)
596 (and (mm-coding-system-p 'emacs-mule) 'emacs-mule)
597 (and (mm-coding-system-p 'escape-quoted) 'escape-quoted))
598 "Coding system used to save decoded articles to a file.
600 The recommended coding systems are `utf-8', `iso-2022-7bit' and so on,
601 which can safely encode any characters in text. This is used by the
604 * gnus-summary-save-article-file
605 * gnus-summary-save-article-body-file
606 * gnus-summary-write-article-file
607 * gnus-summary-write-article-body-file
609 and the functions to which you may set `gnus-default-article-saver':
611 * gnus-summary-save-in-file
612 * gnus-summary-save-body-in-file
613 * gnus-summary-write-to-file
614 * gnus-summary-write-body-to-file
616 Those commands and functions save just text displayed in the article
617 buffer to a file if the value of this variable is non-nil. Note that
618 buttonized MIME parts will be lost in a saved file in that case.
619 Otherwise, raw articles will be saved."
620 :group 'gnus-article-saving
622 :format "%{%t%}:\n %[Value Menu%] %v"
623 (const :tag "Save raw articles" nil)
626 (lambda (arg) (if (mm-coding-system-p (nth 3 arg)) arg))
627 '((const :tag "UTF-8" utf-8)
628 (const :tag "iso-2022-7bit" iso-2022-7bit)
629 (const :tag "Emacs internal" emacs-mule)
630 (const :tag "escape-quoted" escape-quoted))))
631 (symbol :tag "Coding system")))
633 (defcustom gnus-rmail-save-name 'gnus-plain-save-name
634 "A function generating a file name to save articles in Rmail format.
635 The function is called with NEWSGROUP, HEADERS, and optional LAST-FILE."
636 :group 'gnus-article-saving
639 (defcustom gnus-mail-save-name 'gnus-plain-save-name
640 "A function generating a file name to save articles in Unix mail format.
641 The function is called with NEWSGROUP, HEADERS, and optional LAST-FILE."
642 :group 'gnus-article-saving
645 (defcustom gnus-folder-save-name 'gnus-folder-save-name
646 "A function generating a file name to save articles in MH folder.
647 The function is called with NEWSGROUP, HEADERS, and optional LAST-FOLDER."
648 :group 'gnus-article-saving
651 (defcustom gnus-file-save-name 'gnus-numeric-save-name
652 "A function generating a file name to save articles in article format.
653 The function is called with NEWSGROUP, HEADERS, and optional
655 :group 'gnus-article-saving
658 (defcustom gnus-split-methods
659 '((gnus-article-archive-name)
660 (gnus-article-nndoc-name))
661 "*Variable used to suggest where articles are to be saved.
662 For instance, if you would like to save articles related to Gnus in
663 the file \"gnus-stuff\", and articles related to VM in \"vm-stuff\",
664 you could set this variable to something like:
666 '((\"^Subject:.*gnus\\|^Newsgroups:.*gnus\" \"gnus-stuff\")
667 (\"^Subject:.*vm\\|^Xref:.*vm\" \"vm-stuff\"))
669 This variable is an alist where the key is the match and the
670 value is a list of possible files to save in if the match is
673 If the match is a string, it is used as a regexp match on the
674 article. If the match is a symbol, that symbol will be funcalled
675 from the buffer of the article to be saved with the newsgroup as the
676 parameter. If it is a list, it will be evalled in the same buffer.
678 If this form or function returns a string, this string will be used as a
679 possible file name; and if it returns a non-nil list, that list will be
680 used as possible file names."
681 :group 'gnus-article-saving
682 :type '(repeat (choice (list :value (fun) function)
683 (cons :value ("" "") regexp (repeat string))
686 (defcustom gnus-page-delimiter "^\^L"
687 "*Regexp describing what to use as article page delimiters.
688 The default value is \"^\^L\", which is a form linefeed at the
689 beginning of a line."
691 :group 'gnus-article-various)
693 (defcustom gnus-article-mode-line-format "Gnus: %g %S%m"
694 "*The format specification for the article mode line.
695 See `gnus-summary-mode-line-format' for a closer description.
697 The following additional specs are available:
699 %w The article washing status.
700 %m The number of MIME parts in the article."
703 :group 'gnus-article-various)
705 (defcustom gnus-article-mode-hook nil
706 "*A hook for Gnus article mode."
708 :group 'gnus-article-various)
710 (when (featurep 'xemacs)
711 ;; Extracted from gnus-xmas-define in order to preserve user settings
712 (when (fboundp 'turn-off-scroll-in-place)
713 (add-hook 'gnus-article-mode-hook 'turn-off-scroll-in-place))
714 ;; Extracted from gnus-xmas-redefine in order to preserve user settings
715 (add-hook 'gnus-article-mode-hook 'gnus-xmas-article-menu-add))
717 (defcustom gnus-article-menu-hook nil
718 "*Hook run after the creation of the article mode menu."
720 :group 'gnus-article-various)
722 (defcustom gnus-article-prepare-hook nil
723 "*A hook called after an article has been prepared in the article buffer."
725 :group 'gnus-article-various)
727 (defcustom gnus-copy-article-ignored-headers nil
728 "List of headers to be removed when copying an article.
729 Each element is a regular expression."
730 :version "23.1" ;; No Gnus
731 :type '(repeat regexp)
732 :group 'gnus-article-various)
734 (make-obsolete-variable 'gnus-article-hide-pgp-hook nil
735 "Gnus 5.10 (Emacs 22.1)")
738 '((t (:weight bold)))
739 "Face used for highlighting a button in the article buffer."
740 :group 'gnus-article-buttons)
742 (defcustom gnus-article-button-face 'gnus-button
743 "Face used for highlighting buttons in the article buffer.
745 An article button is a piece of text that you can activate by pressing
746 `RET' or `mouse-2' above it."
748 :group 'gnus-article-buttons)
750 (defcustom gnus-article-mouse-face 'highlight
751 "Face used for mouse highlighting in the article buffer.
753 Article buttons will be displayed in this face when the cursor is
756 :group 'gnus-article-buttons)
758 (defcustom gnus-signature-face 'gnus-signature
759 "Face used for highlighting a signature in the article buffer.
760 Obsolete; use the face `gnus-signature' for customizations instead."
762 :group 'gnus-article-highlight
763 :group 'gnus-article-signature)
765 (defface gnus-signature
768 "Face used for highlighting a signature in the article buffer."
769 :group 'gnus-article-highlight
770 :group 'gnus-article-signature)
771 ;; backward-compatibility alias
772 (put 'gnus-signature-face 'face-alias 'gnus-signature)
773 (put 'gnus-signature-face 'obsolete-face "22.1")
775 (defface gnus-header-from
778 (:foreground "PaleGreen1"))
781 (:foreground "red3"))
784 "Face used for displaying from headers."
785 :group 'gnus-article-headers
786 :group 'gnus-article-highlight)
787 ;; backward-compatibility alias
788 (put 'gnus-header-from-face 'face-alias 'gnus-header-from)
789 (put 'gnus-header-from-face 'obsolete-face "22.1")
791 (defface gnus-header-subject
794 (:foreground "SeaGreen1"))
797 (:foreground "red4"))
799 (:bold t :italic t)))
800 "Face used for displaying subject headers."
801 :group 'gnus-article-headers
802 :group 'gnus-article-highlight)
803 ;; backward-compatibility alias
804 (put 'gnus-header-subject-face 'face-alias 'gnus-header-subject)
805 (put 'gnus-header-subject-face 'obsolete-face "22.1")
807 (defface gnus-header-newsgroups
810 (:foreground "yellow" :italic t))
813 (:foreground "MidnightBlue" :italic t))
816 "Face used for displaying newsgroups headers.
817 In the default setup this face is only used for crossposted
819 :group 'gnus-article-headers
820 :group 'gnus-article-highlight)
821 ;; backward-compatibility alias
822 (put 'gnus-header-newsgroups-face 'face-alias 'gnus-header-newsgroups)
823 (put 'gnus-header-newsgroups-face 'obsolete-face "22.1")
825 (defface gnus-header-name
828 (:foreground "SpringGreen2"))
831 (:foreground "maroon"))
834 "Face used for displaying header names."
835 :group 'gnus-article-headers
836 :group 'gnus-article-highlight)
837 ;; backward-compatibility alias
838 (put 'gnus-header-name-face 'face-alias 'gnus-header-name)
839 (put 'gnus-header-name-face 'obsolete-face "22.1")
841 (defface gnus-header-content
844 (:foreground "SpringGreen1" :italic t))
847 (:foreground "indianred4" :italic t))
849 (:italic t))) "Face used for displaying header content."
850 :group 'gnus-article-headers
851 :group 'gnus-article-highlight)
852 ;; backward-compatibility alias
853 (put 'gnus-header-content-face 'face-alias 'gnus-header-content)
854 (put 'gnus-header-content-face 'obsolete-face "22.1")
856 (defcustom gnus-header-face-alist
857 '(("From" nil gnus-header-from)
858 ("Subject" nil gnus-header-subject)
859 ("Newsgroups:.*," nil gnus-header-newsgroups)
860 ("" gnus-header-name gnus-header-content))
861 "*Controls highlighting of article headers.
863 An alist of the form (HEADER NAME CONTENT).
865 HEADER is a regular expression which should match the name of a
866 header and NAME and CONTENT are either face names or nil.
868 The name of each header field will be displayed using the face
869 specified by the first element in the list where HEADER matches
870 the header name and NAME is non-nil. Similarly, the content will
871 be displayed by the first non-nil matching CONTENT face."
872 :group 'gnus-article-headers
873 :group 'gnus-article-highlight
874 :type '(repeat (list (regexp :tag "Header")
876 (item :tag "skip" nil)
877 (face :value default))
878 (choice :tag "Content"
879 (item :tag "skip" nil)
880 (face :value default)))))
882 (defcustom gnus-face-properties-alist (if (featurep 'xemacs)
883 '((xface . (:face gnus-x-face)))
884 '((pbm . (:face gnus-x-face))
886 "Alist of image types and properties applied to Face and X-Face images.
889 ;; Specify the altitude of Face images in the From header.
890 \(setq gnus-face-properties-alist
891 '((pbm . (:face gnus-x-face :ascent 80))
892 (png . (:ascent 80))))
894 ;; Show Face images as pressed buttons.
895 \(setq gnus-face-properties-alist
896 '((pbm . (:face gnus-x-face :relief -2))
897 (png . (:relief -2))))
899 See the manual for the valid properties for various image types.
900 Currently, `pbm' is used for X-Face images and `png' is used for Face
901 images in Emacs. Only the `:face' property is effective on the `xface'
902 image type in XEmacs if it is built with the libcompface library."
903 :version "23.1" ;; No Gnus
904 :group 'gnus-article-headers
905 :type '(repeat (cons :format "%v" (symbol :tag "Image type") plist)))
907 (defcustom gnus-article-decode-hook
908 '(article-decode-charset article-decode-encoded-words
909 article-decode-group-name article-decode-idna-rhs)
910 "*Hook run to decode charsets in articles."
911 :group 'gnus-article-headers
914 (defcustom gnus-display-mime-function 'gnus-display-mime
915 "Function to display MIME articles."
916 :group 'gnus-article-mime
919 (defvar gnus-decode-header-function 'mail-decode-encoded-word-region
920 "Function used to decode headers.")
922 (defvar gnus-decode-address-function 'mail-decode-encoded-address-region
923 "Function used to decode addresses.")
925 (defvar gnus-article-dumbquotes-map
945 "Table for MS-to-Latin1 translation.")
947 (defcustom gnus-ignored-mime-types nil
948 "List of MIME types that should be ignored by Gnus."
950 :group 'gnus-article-mime
951 :type '(repeat regexp))
953 (defcustom gnus-unbuttonized-mime-types '(".*/.*")
954 "List of MIME types that should not be given buttons when rendered inline.
955 See also `gnus-buttonized-mime-types' which may override this variable.
956 This variable is only used when `gnus-inhibit-mime-unbuttonizing' is nil."
958 :group 'gnus-article-mime
959 :type '(repeat regexp))
961 (defcustom gnus-buttonized-mime-types nil
962 "List of MIME types that should be given buttons when rendered inline.
963 If set, this variable overrides `gnus-unbuttonized-mime-types'.
964 To see e.g. security buttons you could set this to
965 `(\"multipart/signed\")'. You could also add \"multipart/alternative\" to
966 this list to display radio buttons that allow you to choose one of two
967 media types those mails include. See also `mm-discouraged-alternatives'.
968 This variable is only used when `gnus-inhibit-mime-unbuttonizing' is nil."
970 :group 'gnus-article-mime
971 :type '(repeat regexp))
973 (defcustom gnus-inhibit-mime-unbuttonizing nil
974 "If non-nil, all MIME parts get buttons.
975 When nil (the default value), then some MIME parts do not get buttons,
976 as described by the variables `gnus-buttonized-mime-types' and
977 `gnus-unbuttonized-mime-types'."
979 :group 'gnus-article-mime
982 (defcustom gnus-body-boundary-delimiter "_"
983 "String used to delimit header and body.
984 This variable is used by `gnus-article-treat-body-boundary' which can
985 be controlled by `gnus-treat-body-boundary'."
987 :group 'gnus-article-various
988 :type '(choice (item :tag "None" :value nil)
991 (defcustom gnus-picon-databases '("/usr/lib/picon" "/usr/local/faces"
993 "Defines the location of the faces database.
994 For information on obtaining this database of pretty pictures, please
995 see http://www.cs.indiana.edu/picons/ftp/index.html"
997 :type '(repeat directory)
998 :link '(url-link :tag "download"
999 "http://www.cs.indiana.edu/picons/ftp/index.html")
1000 :link '(custom-manual "(gnus)Picons")
1003 (defun gnus-picons-installed-p ()
1004 "Say whether picons are installed on your machine."
1005 (let ((installed nil))
1006 (dolist (database gnus-picon-databases)
1007 (when (file-exists-p database)
1008 (setq installed t)))
1011 (defcustom gnus-article-mime-part-function nil
1012 "Function called with a MIME handle as the argument.
1013 This is meant for people who want to do something automatic based
1014 on parts -- for instance, adding Vcard info to a database."
1015 :group 'gnus-article-mime
1016 :type '(choice (const nil)
1019 (defcustom gnus-mime-multipart-functions nil
1020 "An alist of MIME types to functions to display them."
1022 :group 'gnus-article-mime
1023 :type '(repeat (cons :format "%v" (string :tag "MIME type") function)))
1025 (defcustom gnus-article-date-headers '(combined-lapsed)
1026 "A list of Date header formats to display.
1027 Valid formats are `ut' (universal time), `local' (local time
1028 zone), `english' (readable English), `lapsed' (elapsed time),
1029 `combined-lapsed' (both the original date and the elapsed time),
1030 `original' (the original date header), `iso8601' (ISO8601
1031 format), and `user-defined' (a user-defined format defined by the
1032 `gnus-article-time-format' variable).
1034 You have as many date headers as you want in the article buffer.
1035 Some of these headers are updated automatically. See
1036 `gnus-article-update-date-headers' for details."
1038 :group 'gnus-article-headers
1040 (const :tag "Universal time (UT)" ut)
1041 (const :tag "Local time zone" local)
1042 (const :tag "Readable English" english)
1043 (const :tag "Elapsed time" lapsed)
1044 (const :tag "Original and elapsed time" combined-lapsed)
1045 (const :tag "Original date header" original)
1046 (const :tag "ISO8601 format" iso8601)
1047 (const :tag "User-defined" user-defined)))
1049 (defcustom gnus-article-update-date-headers nil
1050 "A number that says how often to update the date header (in seconds).
1051 If nil, don't update it at all."
1053 :group 'gnus-article-headers
1055 (item :tag "Don't update" :value nil)
1058 (defcustom gnus-article-mime-match-handle-function 'undisplayed-alternative
1059 "Function called with a MIME handle as the argument.
1060 This is meant for people who want to view first matched part.
1061 For `undisplayed-alternative' (default), the first undisplayed
1062 part or alternative part is used. For `undisplayed', the first
1063 undisplayed part is used. For a function, the first part which
1064 the function return t is used. For nil, the first part is
1067 :group 'gnus-article-mime
1069 (item :tag "first" :value nil)
1070 (item :tag "undisplayed" :value undisplayed)
1071 (item :tag "undisplayed or alternative"
1072 :value undisplayed-alternative)
1075 (defcustom gnus-mime-action-alist
1076 '(("save to file" . gnus-mime-save-part)
1077 ("save and strip" . gnus-mime-save-part-and-strip)
1078 ("replace with file" . gnus-mime-replace-part)
1079 ("delete part" . gnus-mime-delete-part)
1080 ("display as text" . gnus-mime-inline-part)
1081 ("view the part" . gnus-mime-view-part)
1082 ("pipe to command" . gnus-mime-pipe-part)
1083 ("toggle display" . gnus-article-press-button)
1084 ("toggle display" . gnus-article-view-part-as-charset)
1085 ("view as type" . gnus-mime-view-part-as-type)
1086 ("view internally" . gnus-mime-view-part-internally)
1087 ("view externally" . gnus-mime-view-part-externally))
1088 "An alist of actions that run on the MIME attachment."
1089 :group 'gnus-article-mime
1090 :type '(repeat (cons (string :tag "name")
1093 (defcustom gnus-auto-select-part 1
1094 "Advance to next MIME part when deleting or stripping parts.
1096 When 0, point will be placed on the same part as before. When
1097 positive (negative), move point forward (backwards) this many
1098 parts. When nil, redisplay article."
1099 :version "23.1" ;; No Gnus
1100 :group 'gnus-article-mime
1101 :type '(choice (const nil :tag "Redisplay article.")
1102 (const 1 :tag "Next part.")
1103 (const 0 :tag "Current part.")
1107 ;;; The treatment variables
1110 (defvar gnus-part-display-hook nil
1111 "Hook called on parts that are to receive treatment.")
1113 (defvar gnus-article-treat-custom
1114 '(choice (const :tag "Off" nil)
1116 (const :tag "Header" head)
1117 (const :tag "First" first)
1118 (const :tag "Last" last)
1119 (integer :tag "Less")
1120 (repeat :tag "Groups" regexp)
1121 (sexp :tag "Predicate")))
1123 (defvar gnus-article-treat-head-custom
1124 '(choice (const :tag "Off" nil)
1125 (const :tag "Header" head)))
1127 (defvar gnus-article-treat-types '("text/plain" "text/x-verbatim"
1128 "text/x-patch" "text/html")
1129 "Part types eligible for treatment.")
1131 (defvar gnus-inhibit-treatment nil
1132 "Whether to inhibit treatment.")
1134 (defcustom gnus-treat-highlight-signature '(or t (typep "text/x-vcard"))
1135 "Highlight the signature.
1136 Valid values are nil, t, `head', `first', `last', an integer or a
1137 predicate. See Info node `(gnus)Customizing Articles'."
1138 :group 'gnus-article-treat
1139 :link '(custom-manual "(gnus)Customizing Articles")
1140 :type gnus-article-treat-custom)
1141 (put 'gnus-treat-highlight-signature 'highlight t)
1143 (defcustom gnus-treat-buttonize '(and 100000 (typep "text/plain"))
1145 Valid values are nil, t, `head', `first', `last', an integer or a
1146 predicate. See Info node `(gnus)Customizing Articles'."
1147 :group 'gnus-article-treat
1148 :link '(custom-manual "(gnus)Customizing Articles")
1149 :type gnus-article-treat-custom)
1150 (put 'gnus-treat-buttonize 'highlight t)
1152 (defcustom gnus-treat-buttonize-head 'head
1153 "Add buttons to the head.
1154 Valid values are nil, t, `head', `first', `last', an integer or a
1155 predicate. See Info node `(gnus)Customizing Articles'."
1156 :group 'gnus-article-treat
1157 :link '(custom-manual "(gnus)Customizing Articles")
1158 :type gnus-article-treat-head-custom)
1159 (put 'gnus-treat-buttonize-head 'highlight t)
1161 (defcustom gnus-treat-date 'head
1162 "Display dates according to the `gnus-article-date-headers' variable.
1163 Valid values are nil, t, `head', `first', `last', an integer or a
1164 predicate. See Info node `(gnus)Customizing Articles'."
1166 :group 'gnus-article-treat
1167 :link '(custom-manual "(gnus)Customizing Articles")
1168 :type gnus-article-treat-head-custom)
1170 (defcustom gnus-treat-emphasize 50000
1172 Valid values are nil, t, `head', `first', `last', an integer or a
1173 predicate. See Info node `(gnus)Customizing Articles'."
1174 :group 'gnus-article-treat
1175 :link '(custom-manual "(gnus)Customizing Articles")
1176 :type gnus-article-treat-custom)
1177 (put 'gnus-treat-emphasize 'highlight t)
1179 (defcustom gnus-treat-strip-cr nil
1180 "Remove carriage returns.
1181 Valid values are nil, t, `head', `first', `last', an integer or a
1182 predicate. See Info node `(gnus)Customizing Articles'."
1184 :group 'gnus-article-treat
1185 :link '(custom-manual "(gnus)Customizing Articles")
1186 :type gnus-article-treat-custom)
1188 (defcustom gnus-treat-unsplit-urls nil
1189 "Remove newlines from within URLs.
1190 Valid values are nil, t, `head', `first', `last', an integer or a
1191 predicate. See Info node `(gnus)Customizing Articles'."
1193 :group 'gnus-article-treat
1194 :link '(custom-manual "(gnus)Customizing Articles")
1195 :type gnus-article-treat-custom)
1197 (defcustom gnus-treat-leading-whitespace nil
1198 "Remove leading whitespace in headers.
1199 Valid values are nil, t, `head', `first', `last', an integer or a
1200 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-headers 'head
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-head-custom)
1214 (defcustom gnus-treat-hide-boring-headers nil
1215 "Hide boring headers.
1216 Valid values are nil, t, `head', `first', `last', an integer or a
1217 predicate. See Info node `(gnus)Customizing Articles'."
1218 :group 'gnus-article-treat
1219 :link '(custom-manual "(gnus)Customizing Articles")
1220 :type gnus-article-treat-head-custom)
1222 (defcustom gnus-treat-hide-signature nil
1223 "Hide the signature.
1224 Valid values are nil, t, `head', `first', `last', an integer or a
1225 predicate. See Info node `(gnus)Customizing Articles'."
1226 :group 'gnus-article-treat
1227 :link '(custom-manual "(gnus)Customizing Articles")
1228 :type gnus-article-treat-custom)
1230 (defcustom gnus-treat-fill-article nil
1232 Valid values are nil, t, `head', `first', `last', an integer or a
1233 predicate. See Info node `(gnus)Customizing Articles'."
1234 :group 'gnus-article-treat
1235 :link '(custom-manual "(gnus)Customizing Articles")
1236 :type gnus-article-treat-custom)
1238 (defcustom gnus-treat-hide-citation nil
1240 Valid values are nil, t, `head', `first', `last', an integer or a
1241 predicate. See Info node `(gnus)Customizing Articles'.
1243 See `gnus-article-highlight-citation' for variables used to
1244 control what it hides."
1245 :group 'gnus-article-treat
1246 :link '(custom-manual "(gnus)Customizing Articles")
1247 :type gnus-article-treat-custom)
1249 (defcustom gnus-treat-hide-citation-maybe nil
1250 "Hide cited text according to certain conditions.
1251 Valid values are nil, t, `head', `first', `last', an integer or a
1252 predicate. See Info node `(gnus)Customizing Articles'.
1254 See `gnus-cite-hide-percentage' and `gnus-cite-hide-absolute' for
1255 how to control what it hides."
1256 :group 'gnus-article-treat
1257 :link '(custom-manual "(gnus)Customizing Articles")
1258 :type gnus-article-treat-custom)
1260 (defcustom gnus-treat-strip-list-identifiers 'head
1261 "Strip list identifiers from `gnus-list-identifiers`.
1262 Valid values are nil, t, `head', `first', `last', an integer or a
1263 predicate. See Info node `(gnus)Customizing Articles'."
1265 :group 'gnus-article-treat
1266 :link '(custom-manual "(gnus)Customizing Articles")
1267 :type gnus-article-treat-custom)
1269 (gnus-define-group-parameter
1272 "Alist of regexps and correspondent identifiers."
1273 :variable-group gnus-article-washing
1275 '(choice :tag "Identifier"
1277 (symbol :tag "Item in `gnus-list-identifiers'" none)
1279 (const :tag "None" nil))
1281 "If non-nil, specify how to remove `identifiers' from articles' subject.
1283 Any symbol is used to look up a regular expression to match the
1284 banner in `gnus-list-identifiers'. A string is used as a regular
1285 expression to match the identifier directly.")
1287 (make-obsolete-variable 'gnus-treat-strip-pgp nil
1288 "Gnus 5.10 (Emacs 22.1)")
1290 (defcustom gnus-treat-strip-pem nil
1291 "Strip PEM signatures.
1292 Valid values are nil, t, `head', `first', `last', an integer or a
1293 predicate. See Info node `(gnus)Customizing Articles'."
1294 :group 'gnus-article-treat
1295 :link '(custom-manual "(gnus)Customizing Articles")
1296 :type gnus-article-treat-custom)
1298 (defcustom gnus-treat-strip-banner t
1299 "Strip banners from articles.
1300 The banner to be stripped is specified in the `banner' group parameter.
1301 Valid values are nil, t, `head', `first', `last', an integer or a
1302 predicate. See Info node `(gnus)Customizing Articles'."
1303 :group 'gnus-article-treat
1304 :link '(custom-manual "(gnus)Customizing Articles")
1305 :type gnus-article-treat-custom)
1307 (defcustom gnus-treat-highlight-headers 'head
1308 "Highlight the headers.
1309 Valid values are nil, t, `head', `first', `last', an integer or a
1310 predicate. See Info node `(gnus)Customizing Articles'."
1311 :group 'gnus-article-treat
1312 :link '(custom-manual "(gnus)Customizing Articles")
1313 :type gnus-article-treat-head-custom)
1314 (put 'gnus-treat-highlight-headers 'highlight t)
1316 (defcustom gnus-treat-highlight-citation t
1317 "Highlight cited text.
1318 Valid values are nil, t, `head', `first', `last', an integer or a
1319 predicate. See Info node `(gnus)Customizing Articles'."
1320 :group 'gnus-article-treat
1321 :link '(custom-manual "(gnus)Customizing Articles")
1322 :type gnus-article-treat-custom)
1323 (put 'gnus-treat-highlight-citation 'highlight t)
1325 (defcustom gnus-treat-strip-headers-in-body t
1326 "Strip the X-No-Archive header line from the beginning of the body.
1327 Valid values are nil, t, `head', `first', `last', an integer or a
1328 predicate. See Info node `(gnus)Customizing Articles'."
1330 :group 'gnus-article-treat
1331 :link '(custom-manual "(gnus)Customizing Articles")
1332 :type gnus-article-treat-custom)
1334 (defcustom gnus-treat-strip-trailing-blank-lines nil
1335 "Strip trailing blank lines.
1336 Valid values are nil, t, `head', `first', `last', an integer or a
1337 predicate. See Info node `(gnus)Customizing Articles'.
1339 When set to t, it also strips trailing blanks in all MIME parts.
1340 Consider to use `last' instead."
1341 :group 'gnus-article-treat
1342 :link '(custom-manual "(gnus)Customizing Articles")
1343 :type gnus-article-treat-custom)
1345 (defcustom gnus-treat-strip-leading-blank-lines nil
1346 "Strip leading blank lines.
1347 Valid values are nil, t, `head', `first', `last', an integer or a
1348 predicate. See Info node `(gnus)Customizing Articles'.
1350 When set to t, it also strips trailing blanks in all MIME parts."
1351 :group 'gnus-article-treat
1352 :link '(custom-manual "(gnus)Customizing Articles")
1353 :type gnus-article-treat-custom)
1355 (defcustom gnus-treat-strip-multiple-blank-lines nil
1356 "Strip multiple blank lines.
1357 Valid values are nil, t, `head', `first', `last', an integer or a
1358 predicate. See Info node `(gnus)Customizing Articles'."
1359 :group 'gnus-article-treat
1360 :link '(custom-manual "(gnus)Customizing Articles")
1361 :type gnus-article-treat-custom)
1363 (defcustom gnus-treat-unfold-headers 'head
1364 "Unfold folded header lines.
1365 Valid values are nil, t, `head', `first', `last', an integer or a
1366 predicate. See Info node `(gnus)Customizing Articles'."
1368 :group 'gnus-article-treat
1369 :link '(custom-manual "(gnus)Customizing Articles")
1370 :type gnus-article-treat-custom)
1372 (defcustom gnus-article-unfold-long-headers nil
1373 "If non-nil, allow unfolding headers even if the header is long.
1374 If it is a regexp, only long headers matching this regexp are unfolded.
1375 If it is t, all long headers are unfolded.
1377 This variable has no effect if `gnus-treat-unfold-headers' is nil."
1378 :version "23.1" ;; No Gnus
1379 :group 'gnus-article-treat
1380 :type '(choice (const nil)
1381 (const :tag "all" t)
1384 (defcustom gnus-treat-fold-headers nil
1386 Valid values are nil, t, `head', `first', `last', an integer or a
1387 predicate. See Info node `(gnus)Customizing Articles'."
1389 :group 'gnus-article-treat
1390 :link '(custom-manual "(gnus)Customizing Articles")
1391 :type gnus-article-treat-custom)
1393 (defcustom gnus-treat-fold-newsgroups 'head
1394 "Fold the Newsgroups and Followup-To headers.
1395 Valid values are nil, t, `head', `first', `last', an integer or a
1396 predicate. See Info node `(gnus)Customizing Articles'."
1398 :group 'gnus-article-treat
1399 :link '(custom-manual "(gnus)Customizing Articles")
1400 :type gnus-article-treat-custom)
1402 (defcustom gnus-treat-overstrike t
1403 "Treat overstrike highlighting.
1404 Valid values are nil, t, `head', `first', `last', an integer or a
1405 predicate. See Info node `(gnus)Customizing Articles'."
1406 :group 'gnus-article-treat
1407 :link '(custom-manual "(gnus)Customizing Articles")
1408 :type gnus-article-treat-custom)
1409 (put 'gnus-treat-overstrike 'highlight t)
1411 (defcustom gnus-treat-ansi-sequences (if (locate-library "ansi-color") t)
1412 "Treat ANSI SGR control sequences.
1413 Valid values are nil, t, `head', `first', `last', an integer or a
1414 predicate. See Info node `(gnus)Customizing Articles'."
1415 :group 'gnus-article-treat
1416 :link '(custom-manual "(gnus)Customizing Articles")
1417 :type gnus-article-treat-custom)
1419 (make-obsolete-variable 'gnus-treat-display-xface
1420 'gnus-treat-display-x-face "Emacs 22.1")
1422 (defcustom gnus-treat-display-x-face
1423 (and (not noninteractive)
1424 (gnus-image-type-available-p 'xbm)
1425 (if (featurep 'xemacs)
1428 (and (string-match "^0x" (shell-command-to-string "uncompface"))
1429 (executable-find "icontopbm"))
1430 ;; shell-command-to-string may signal an error, e.g. if
1431 ;; shell-file-name is not found.
1434 "Display X-Face headers.
1435 Valid values are nil and `head'.
1436 See Info node `(gnus)Customizing Articles' and Info node
1437 `(gnus)X-Face' for details."
1438 :group 'gnus-article-treat
1440 :link '(custom-manual "(gnus)Customizing Articles")
1441 :link '(custom-manual "(gnus)X-Face")
1442 :type gnus-article-treat-head-custom
1443 :set (lambda (symbol value)
1446 (cond ((or (boundp symbol) (get symbol 'saved-value))
1448 ((boundp 'gnus-treat-display-xface)
1450 ** gnus-treat-display-xface is an obsolete variable;\
1451 use gnus-treat-display-x-face instead")
1452 (default-value 'gnus-treat-display-xface))
1453 ((get 'gnus-treat-display-xface 'saved-value)
1455 ** gnus-treat-display-xface is an obsolete variable;\
1456 use gnus-treat-display-x-face instead")
1457 (eval (car (get 'gnus-treat-display-xface 'saved-value))))
1460 (put 'gnus-treat-display-x-face 'highlight t)
1462 (defcustom gnus-treat-display-face
1463 (and (not noninteractive)
1464 (gnus-image-type-available-p 'png)
1466 "Display Face headers.
1467 Valid values are nil, t, `head', `first', `last', an integer or a
1468 predicate. See Info node `(gnus)Customizing Articles' and Info
1469 node `(gnus)Face' for details."
1470 :group 'gnus-article-treat
1472 :link '(custom-manual "(gnus)Customizing Articles")
1473 :link '(custom-manual "(gnus)X-Face")
1474 :type gnus-article-treat-head-custom)
1475 (put 'gnus-treat-display-face 'highlight t)
1477 (defcustom gnus-treat-display-smileys (gnus-image-type-available-p 'xpm)
1479 Valid values are nil, t, `head', `first', `last', an integer or a
1480 predicate. See Info node `(gnus)Customizing Articles' and Info
1481 node `(gnus)Smileys' for details."
1482 :group 'gnus-article-treat
1484 :link '(custom-manual "(gnus)Customizing Articles")
1485 :link '(custom-manual "(gnus)Smileys")
1486 :type gnus-article-treat-custom)
1487 (put 'gnus-treat-display-smileys 'highlight t)
1489 (defcustom gnus-treat-from-picon
1490 (if (and (gnus-image-type-available-p 'xpm)
1491 (gnus-picons-installed-p))
1493 "Display picons in the From header.
1494 Valid values are nil, t, `head', `first', `last', an integer or a
1495 predicate. See Info node `(gnus)Customizing Articles' and Info
1496 node `(gnus)Picons' for details."
1498 :group 'gnus-article-treat
1500 :link '(custom-manual "(gnus)Customizing Articles")
1501 :link '(custom-manual "(gnus)Picons")
1502 :type gnus-article-treat-head-custom)
1503 (put 'gnus-treat-from-picon 'highlight t)
1505 (defcustom gnus-treat-mail-picon
1506 (if (and (gnus-image-type-available-p 'xpm)
1507 (gnus-picons-installed-p))
1509 "Display picons in To and Cc headers.
1510 Valid values are nil, t, `head', `first', `last', an integer or a
1511 predicate. See Info node `(gnus)Customizing Articles' and Info
1512 node `(gnus)Picons' for details."
1514 :group 'gnus-article-treat
1516 :link '(custom-manual "(gnus)Customizing Articles")
1517 :link '(custom-manual "(gnus)Picons")
1518 :type gnus-article-treat-head-custom)
1519 (put 'gnus-treat-mail-picon 'highlight t)
1521 (defcustom gnus-treat-newsgroups-picon
1522 (if (and (gnus-image-type-available-p 'xpm)
1523 (gnus-picons-installed-p))
1525 "Display picons in the Newsgroups and Followup-To headers.
1526 Valid values are nil, t, `head', `first', `last', an integer or a
1527 predicate. See Info node `(gnus)Customizing Articles' and Info
1528 node `(gnus)Picons' for details."
1530 :group 'gnus-article-treat
1532 :link '(custom-manual "(gnus)Customizing Articles")
1533 :link '(custom-manual "(gnus)Picons")
1534 :type gnus-article-treat-head-custom)
1535 (put 'gnus-treat-newsgroups-picon 'highlight t)
1537 (defcustom gnus-treat-from-gravatar nil
1538 "Display gravatars in the From header.
1539 Valid values are nil, t, `head', `first', `last', an integer or a
1540 predicate. See Info node `(gnus)Customizing Articles' and Info
1541 node `(gnus)Gravatars' for details."
1543 :group 'gnus-article-treat
1544 :group 'gnus-gravatar
1545 :link '(custom-manual "(gnus)Customizing Articles")
1546 :link '(custom-manual "(gnus)Gravatars")
1547 :type gnus-article-treat-head-custom)
1548 (put 'gnus-treat-from-gravatar 'highlight t)
1550 (defcustom gnus-treat-mail-gravatar nil
1551 "Display gravatars in To and Cc headers.
1552 Valid values are nil, t, `head', `first', `last', an integer or a
1553 predicate. See Info node `(gnus)Customizing Articles' and Info
1554 node `(gnus)Gravatars' for details."
1556 :group 'gnus-article-treat
1557 :group 'gnus-gravatar
1558 :link '(custom-manual "(gnus)Customizing Articles")
1559 :link '(custom-manual "(gnus)Gravatars")
1560 :type gnus-article-treat-head-custom)
1561 (put 'gnus-treat-mail-gravatar 'highlight t)
1563 (defcustom gnus-treat-body-boundary
1564 (if (or gnus-treat-newsgroups-picon
1565 gnus-treat-mail-picon
1566 gnus-treat-from-picon
1567 gnus-treat-from-gravatar
1568 gnus-treat-mail-gravatar)
1569 ;; If there's much decoration, the user might prefer a boundary.
1572 "Draw a boundary at the end of the headers.
1573 Valid values are nil and `head'.
1574 See Info node `(gnus)Customizing Articles' for details."
1576 :group 'gnus-article-treat
1577 :link '(custom-manual "(gnus)Customizing Articles")
1578 :type gnus-article-treat-head-custom)
1580 (defcustom gnus-treat-capitalize-sentences nil
1581 "Capitalize sentence-starting words.
1582 Valid values are nil, t, `head', `first', `last', an integer or a
1583 predicate. See Info node `(gnus)Customizing Articles'."
1585 :group 'gnus-article-treat
1586 :link '(custom-manual "(gnus)Customizing Articles")
1587 :type gnus-article-treat-custom)
1589 (defcustom gnus-treat-wash-html nil
1591 Valid values are nil, t, `head', `first', `last', an integer or a
1592 predicate. See Info node `(gnus)Customizing Articles'."
1594 :group 'gnus-article-treat
1595 :link '(custom-manual "(gnus)Customizing Articles")
1596 :type gnus-article-treat-custom)
1598 (defcustom gnus-treat-fill-long-lines '(typep "text/plain")
1600 Valid values are nil, t, `head', `first', `last', an integer or a
1601 predicate. See Info node `(gnus)Customizing Articles'."
1603 :group 'gnus-article-treat
1604 :link '(custom-manual "(gnus)Customizing Articles")
1605 :type gnus-article-treat-custom)
1607 (defcustom gnus-treat-x-pgp-sig nil
1609 To automatically treat X-PGP-Sig, set it to head.
1610 Valid values are nil, t, `head', `first', `last', an integer or a
1611 predicate. See Info node `(gnus)Customizing Articles'."
1613 :group 'gnus-article-treat
1614 :group 'mime-security
1615 :link '(custom-manual "(gnus)Customizing Articles")
1616 :type gnus-article-treat-custom)
1618 (defvar gnus-article-encrypt-protocol-alist
1619 '(("PGP" . mml2015-self-encrypt)))
1621 ;; Set to nil if more than one protocol added to
1622 ;; gnus-article-encrypt-protocol-alist.
1623 (defcustom gnus-article-encrypt-protocol "PGP"
1624 "The protocol used for encrypt articles.
1625 It is a string, such as \"PGP\". If nil, ask user."
1628 :group 'mime-security)
1630 (defvar idna-program)
1632 (defcustom gnus-use-idna (and (condition-case nil (require 'idna) (file-error))
1633 (mm-coding-system-p 'utf-8)
1635 (executable-find idna-program))
1636 "Whether IDNA decoding of headers is used when viewing messages.
1637 This requires GNU Libidn, and by default only enabled if it is found."
1639 :group 'gnus-article-headers
1642 (defcustom gnus-article-over-scroll nil
1643 "If non-nil, allow scrolling the article buffer even when there no more text."
1645 :group 'gnus-article
1648 (defcustom gnus-inhibit-images nil
1649 "Non-nil means inhibit displaying of images inline in the article body."
1651 :group 'gnus-article
1654 (defcustom gnus-blocked-images 'gnus-block-private-groups
1655 "Images that have URLs matching this regexp will be blocked.
1656 This can also be a function to be evaluated. If so, it will be
1657 called with the group name as the parameter, and should return a
1661 :type '(choice regexp function))
1663 ;;; Internal variables
1665 (defvar gnus-english-month-names
1666 '("January" "February" "March" "April" "May" "June" "July" "August"
1667 "September" "October" "November" "December"))
1669 (defvar article-goto-body-goes-to-point-min-p nil)
1670 (defvar gnus-article-wash-types nil)
1671 (defvar gnus-article-emphasis-alist nil)
1672 (defvar gnus-article-image-alist nil)
1674 (defvar gnus-article-mime-handle-alist-1 nil)
1675 (defvar gnus-treatment-function-alist
1676 '((gnus-treat-strip-cr gnus-article-remove-cr)
1677 (gnus-treat-x-pgp-sig gnus-article-verify-x-pgp-sig)
1678 (gnus-treat-strip-banner gnus-article-strip-banner)
1679 (gnus-treat-strip-headers-in-body gnus-article-strip-headers-in-body)
1680 (gnus-treat-highlight-signature gnus-article-highlight-signature)
1681 (gnus-treat-buttonize gnus-article-add-buttons)
1682 (gnus-treat-fill-article gnus-article-fill-cited-article)
1683 (gnus-treat-fill-long-lines gnus-article-fill-cited-long-lines)
1684 (gnus-treat-unsplit-urls gnus-article-unsplit-urls)
1685 (gnus-treat-display-x-face gnus-article-display-x-face)
1686 (gnus-treat-display-face gnus-article-display-face)
1687 (gnus-treat-hide-headers gnus-article-maybe-hide-headers)
1688 (gnus-treat-hide-boring-headers gnus-article-hide-boring-headers)
1689 (gnus-treat-hide-signature gnus-article-hide-signature)
1690 (gnus-treat-strip-list-identifiers gnus-article-hide-list-identifiers)
1691 (gnus-treat-leading-whitespace gnus-article-remove-leading-whitespace)
1692 (gnus-treat-from-picon gnus-treat-from-picon)
1693 (gnus-treat-mail-picon gnus-treat-mail-picon)
1694 (gnus-treat-newsgroups-picon gnus-treat-newsgroups-picon)
1695 (gnus-treat-strip-pem gnus-article-hide-pem)
1696 (gnus-treat-date gnus-article-treat-date)
1697 (gnus-treat-from-gravatar gnus-treat-from-gravatar)
1698 (gnus-treat-mail-gravatar gnus-treat-mail-gravatar)
1699 (gnus-treat-highlight-headers gnus-article-highlight-headers)
1700 (gnus-treat-highlight-signature gnus-article-highlight-signature)
1701 (gnus-treat-strip-trailing-blank-lines
1702 gnus-article-remove-trailing-blank-lines)
1703 (gnus-treat-strip-leading-blank-lines
1704 gnus-article-strip-leading-blank-lines)
1705 (gnus-treat-strip-multiple-blank-lines
1706 gnus-article-strip-multiple-blank-lines)
1707 (gnus-treat-overstrike gnus-article-treat-overstrike)
1708 (gnus-treat-ansi-sequences gnus-article-treat-ansi-sequences)
1709 (gnus-treat-unfold-headers gnus-article-treat-unfold-headers)
1710 (gnus-treat-fold-newsgroups gnus-article-treat-fold-newsgroups)
1711 (gnus-treat-fold-headers gnus-article-treat-fold-headers)
1712 (gnus-treat-buttonize-head gnus-article-add-buttons-to-head)
1713 (gnus-treat-display-smileys gnus-treat-smiley)
1714 (gnus-treat-capitalize-sentences gnus-article-capitalize-sentences)
1715 (gnus-treat-wash-html gnus-article-wash-html)
1716 (gnus-treat-emphasize gnus-article-emphasize)
1717 (gnus-treat-hide-citation gnus-article-hide-citation)
1718 (gnus-treat-hide-citation-maybe gnus-article-hide-citation-maybe)
1719 (gnus-treat-highlight-citation gnus-article-highlight-citation)
1720 (gnus-treat-body-boundary gnus-article-treat-body-boundary)))
1722 (defvar gnus-article-mime-handle-alist nil)
1723 (defvar article-lapsed-timer nil)
1724 (defvar gnus-article-current-summary nil)
1726 (defvar gnus-article-mode-syntax-table
1727 (let ((table (copy-syntax-table text-mode-syntax-table)))
1728 ;; This causes the citation match run O(2^n).
1729 ;; (modify-syntax-entry ?- "w" table)
1730 (modify-syntax-entry ?> ")<" table)
1731 (modify-syntax-entry ?< "(>" table)
1732 ;; make M-. in article buffers work for `foo' strings
1733 (modify-syntax-entry ?' " " table)
1734 (modify-syntax-entry ?` " " table)
1736 "Syntax table used in article mode buffers.
1737 Initialized from `text-mode-syntax-table.")
1739 (defvar gnus-save-article-buffer nil)
1741 (defvar gnus-number-of-articles-to-be-saved nil)
1743 (defvar gnus-inhibit-hiding nil)
1745 (defvar gnus-article-edit-mode nil)
1747 ;;; Macros for dealing with the article buffer.
1749 (defmacro gnus-with-article-headers (&rest forms)
1750 `(with-current-buffer gnus-article-buffer
1752 (let ((inhibit-read-only t)
1753 (inhibit-point-motion-hooks t)
1754 (case-fold-search t))
1755 (article-narrow-to-head)
1758 (put 'gnus-with-article-headers 'lisp-indent-function 0)
1759 (put 'gnus-with-article-headers 'edebug-form-spec '(body))
1761 (defmacro gnus-with-article-buffer (&rest forms)
1762 `(when (buffer-live-p (get-buffer gnus-article-buffer))
1763 (with-current-buffer gnus-article-buffer
1764 (let ((inhibit-read-only t))
1767 (put 'gnus-with-article-buffer 'lisp-indent-function 0)
1768 (put 'gnus-with-article-buffer 'edebug-form-spec '(body))
1770 (defun gnus-article-goto-header (header)
1771 "Go to HEADER, which is a regular expression."
1772 (re-search-forward (concat "^\\(" header "\\):") nil t))
1774 (defsubst gnus-article-hide-text (b e props)
1775 "Set text PROPS on the B to E region, extending `intangible' 1 past B."
1776 (gnus-add-text-properties-when 'article-type nil b e props)
1777 (when (memq 'intangible props)
1779 (max (1- b) (point-min))
1780 b 'intangible (cddr (memq 'intangible props)))))
1782 (defsubst gnus-article-unhide-text (b e)
1783 "Remove hidden text properties from region between B and E."
1784 (remove-text-properties b e gnus-hidden-properties)
1785 (when (memq 'intangible gnus-hidden-properties)
1786 (put-text-property (max (1- b) (point-min))
1787 b 'intangible nil)))
1789 (defun gnus-article-hide-text-type (b e type)
1790 "Hide text of TYPE between B and E."
1791 (gnus-add-wash-type type)
1792 (gnus-article-hide-text
1793 b e (cons 'article-type (cons type gnus-hidden-properties))))
1795 (defun gnus-article-unhide-text-type (b e type)
1796 "Unhide text of TYPE between B and E."
1797 (gnus-delete-wash-type type)
1798 (remove-text-properties
1799 b e (cons 'article-type (cons type gnus-hidden-properties)))
1800 (when (memq 'intangible gnus-hidden-properties)
1801 (put-text-property (max (1- b) (point-min))
1802 b 'intangible nil)))
1804 (defun gnus-article-delete-text-of-type (type)
1805 "Delete text of TYPE in the current buffer."
1807 (let ((b (point-min)))
1808 (if (eq type 'multipart)
1809 ;; Remove MIME buttons associated with multipart/alternative parts.
1812 (while (if (get-text-property (point) 'gnus-part)
1814 (when (setq b (next-single-property-change (point)
1819 (skip-chars-forward "\n")
1820 (when (eq (get-text-property b 'article-type) 'multipart)
1821 (delete-region b (point)))))
1822 (while (setq b (text-property-any b (point-max) 'article-type type))
1824 b (or (text-property-not-all b (point-max) 'article-type type)
1827 (defun gnus-article-delete-invisible-text ()
1828 "Delete all invisible text in the current buffer."
1830 (let ((b (point-min)))
1831 (while (setq b (text-property-any b (point-max) 'invisible t))
1833 b (or (text-property-not-all b (point-max) 'invisible t)
1836 (defsubst gnus-article-header-rank ()
1837 "Give the rank of the string HEADER as given by `gnus-sorted-header-list'."
1838 (let ((list gnus-sorted-header-list)
1841 (if (looking-at (car list))
1843 (setq list (cdr list))
1847 (defun article-hide-headers (&optional _arg _delete)
1848 "Hide unwanted headers and possibly sort them as well."
1850 ;; This function might be inhibited.
1851 (unless gnus-inhibit-hiding
1852 (let ((inhibit-read-only t)
1853 (case-fold-search t)
1854 (max (1+ (length gnus-sorted-header-list)))
1855 (inhibit-point-motion-hooks t)
1856 (cur (current-buffer))
1857 ignored visible beg)
1859 ;; `gnus-ignored-headers' and `gnus-visible-headers' may be
1860 ;; group parameters, so we should go to the summary buffer.
1863 (progn (set-buffer gnus-summary-buffer) t)
1865 (setq ignored (when (not gnus-visible-headers)
1866 (cond ((stringp gnus-ignored-headers)
1867 gnus-ignored-headers)
1868 ((listp gnus-ignored-headers)
1869 (mapconcat 'identity
1870 gnus-ignored-headers
1872 visible (cond ((stringp gnus-visible-headers)
1873 gnus-visible-headers)
1874 ((and gnus-visible-headers
1875 (listp gnus-visible-headers))
1876 (mapconcat 'identity
1877 gnus-visible-headers
1881 ;; First we narrow to just the headers.
1882 (article-narrow-to-head)
1883 ;; Hide any "From " lines at the beginning of (mail) articles.
1884 (while (looking-at "From ")
1887 (delete-region (point-min) (point)))
1888 ;; Then treat the rest of the header lines.
1889 ;; Then we use the two regular expressions
1890 ;; `gnus-ignored-headers' and `gnus-visible-headers' to
1891 ;; select which header lines is to remain visible in the
1893 (while (re-search-forward "^[^ \t:]*:" nil t)
1895 ;; Mark the rank of the header.
1897 (point) (1+ (point)) 'message-rank
1898 (if (or (and visible (looking-at visible))
1900 (not (looking-at ignored))))
1901 (gnus-article-header-rank)
1904 (message-sort-headers-1)
1905 (when (setq beg (text-property-any
1906 (point-min) (point-max) 'message-rank (+ 2 max)))
1907 ;; We delete the unwanted headers.
1908 (gnus-add-wash-type 'headers)
1909 (add-text-properties (point-min) (+ 5 (point-min))
1910 '(article-type headers dummy-invisible t))
1911 (delete-region beg (point-max))))))))
1913 (defun article-hide-boring-headers (&optional arg)
1914 "Toggle hiding of headers that aren't very interesting.
1915 If given a negative prefix, always show; if given a positive prefix,
1917 (interactive (gnus-article-hidden-arg))
1918 (when (and (not (gnus-article-check-hidden-text 'boring-headers arg))
1919 (not gnus-show-all-headers))
1922 (let ((inhibit-read-only t)
1923 (inhibit-point-motion-hooks t))
1924 (article-narrow-to-head)
1925 (dolist (elem gnus-boring-article-headers)
1926 (goto-char (point-min))
1928 ;; Hide empty headers.
1930 (while (re-search-forward "^[^: \t]+:[ \t]*\n[^ \t]" nil t)
1932 (gnus-article-hide-text-type
1936 (if (re-search-forward "^[^ \t]" nil t)
1940 ;; Hide boring Newsgroups header.
1941 ((eq elem 'newsgroups)
1942 (when (gnus-string-equal
1943 (gnus-fetch-field "newsgroups")
1944 (gnus-group-real-name
1945 (if (boundp 'gnus-newsgroup-name)
1948 (gnus-article-hide-header "newsgroups")))
1949 ((eq elem 'to-address)
1950 (let ((to (message-fetch-field "to"))
1952 (gnus-parameter-to-address
1953 (if (boundp 'gnus-newsgroup-name)
1954 gnus-newsgroup-name ""))))
1955 (when (and to to-address
1958 ;; only one address in To
1959 (nth 1 (mail-extract-address-components to))
1961 (gnus-article-hide-header "to"))))
1963 (let ((to (message-fetch-field "to"))
1965 (gnus-parameter-to-list
1966 (if (boundp 'gnus-newsgroup-name)
1967 gnus-newsgroup-name ""))))
1968 (when (and to to-list
1971 ;; only one address in To
1972 (nth 1 (mail-extract-address-components to))
1974 (gnus-article-hide-header "to"))))
1976 (let ((cc (message-fetch-field "cc"))
1978 (gnus-parameter-to-list
1979 (if (boundp 'gnus-newsgroup-name)
1980 gnus-newsgroup-name ""))))
1981 (when (and cc to-list
1984 ;; only one address in CC
1985 (nth 1 (mail-extract-address-components cc))
1987 (gnus-article-hide-header "cc"))))
1988 ((eq elem 'followup-to)
1989 (when (gnus-string-equal
1990 (message-fetch-field "followup-to")
1991 (message-fetch-field "newsgroups"))
1992 (gnus-article-hide-header "followup-to")))
1993 ((eq elem 'reply-to)
1994 (if (gnus-group-find-parameter
1995 gnus-newsgroup-name 'broken-reply-to)
1996 (gnus-article-hide-header "reply-to")
1997 (let ((from (message-fetch-field "from"))
1998 (reply-to (message-fetch-field "reply-to")))
2005 (lambda (x) (downcase (cadr x)))
2006 (mail-extract-address-components from t))
2009 (lambda (x) (downcase (cadr x)))
2010 (mail-extract-address-components reply-to t))
2012 (gnus-article-hide-header "reply-to")))))
2014 (let ((date (with-current-buffer gnus-original-article-buffer
2015 ;; If date in `gnus-article-buffer' is localized
2016 ;; (`gnus-treat-date-user-defined'),
2017 ;; `days-between' might fail.
2018 (message-fetch-field "date"))))
2020 (< (days-between (current-time-string) date)
2022 (gnus-article-hide-header "date"))))
2024 (let ((to (message-fetch-field "to"))
2025 (cc (message-fetch-field "cc")))
2026 (when (> (length to) 1024)
2027 (gnus-article-hide-header "to"))
2028 (when (> (length cc) 1024)
2029 (gnus-article-hide-header "cc"))))
2033 (goto-char (point-min))
2034 (while (re-search-forward "^to:" nil t)
2035 (setq to-count (1+ to-count)))
2036 (when (> to-count 1)
2037 (while (> to-count 0)
2038 (goto-char (point-min))
2040 (re-search-forward "^to:" nil nil to-count)
2042 (narrow-to-region (point) (point-max))
2043 (gnus-article-hide-header "to"))
2044 (setq to-count (1- to-count))))
2045 (goto-char (point-min))
2046 (while (re-search-forward "^cc:" nil t)
2047 (setq cc-count (1+ cc-count)))
2048 (when (> cc-count 1)
2049 (while (> cc-count 0)
2050 (goto-char (point-min))
2052 (re-search-forward "^cc:" nil nil cc-count)
2054 (narrow-to-region (point) (point-max))
2055 (gnus-article-hide-header "cc"))
2056 (setq cc-count (1- cc-count)))))))))))))
2058 (defun gnus-article-hide-header (header)
2060 (goto-char (point-min))
2061 (when (re-search-forward (concat "^" header ":") nil t)
2062 (gnus-article-hide-text-type
2066 (if (re-search-forward "^[^ \t]" nil t)
2071 (defvar gnus-article-normalized-header-length 40
2072 "Length of normalized headers.")
2074 (defun article-normalize-headers ()
2075 "Make all header lines 40 characters long."
2077 (let ((inhibit-read-only t)
2081 (article-narrow-to-head)
2084 ((< (setq column (- (point-at-eol) (point)))
2085 gnus-article-normalized-header-length)
2087 (insert (make-string
2088 (- gnus-article-normalized-header-length column)
2090 ((> column gnus-article-normalized-header-length)
2091 (gnus-put-text-property
2093 (forward-char gnus-article-normalized-header-length)
2100 (forward-line 1))))))
2102 (defun article-treat-dumbquotes ()
2103 "Translate M****s*** sm*rtq**t*s and other symbols into proper text.
2104 Note that this function guesses whether a character is a sm*rtq**t* or
2105 not, so it should only be used interactively.
2107 Sm*rtq**t*s are M****s***'s unilateral extension to the
2108 iso-8859-1 character map in an attempt to provide more quoting
2109 characters. If you see something like \\222 or \\264 where
2110 you're expecting some kind of apostrophe or quotation mark, then
2113 (article-translate-strings gnus-article-dumbquotes-map))
2115 (defvar org-entities)
2117 (defun article-treat-non-ascii ()
2118 "Translate many Unicode characters into their ASCII equivalents."
2120 (require 'org-entities)
2121 (let ((table (make-char-table (if (featurep 'xemacs) 'generic))))
2122 (dolist (elem org-entities)
2123 (when (and (listp elem)
2124 (= (length (nth 6 elem)) 1))
2125 (if (featurep 'xemacs)
2126 (put-char-table (aref (nth 6 elem) 0) (nth 4 elem) table)
2127 (set-char-table-range table (aref (nth 6 elem) 0) (nth 4 elem)))))
2129 (when (article-goto-body)
2130 (let ((inhibit-read-only t)
2133 (if (not (setq replace (if (featurep 'xemacs)
2134 (get-char-table (following-char) table)
2135 (aref table (following-char)))))
2138 (setq props (text-properties-at (point)))
2140 (add-text-properties (point) (progn (insert replace) (point))
2142 (insert replace)))))))))
2144 (defun article-translate-strings (map)
2145 "Translate all string in the body of the article according to MAP.
2146 MAP is an alist where the elements are on the form (\"from\" \"to\")."
2148 (when (article-goto-body)
2149 (let ((inhibit-read-only t))
2151 (let ((from (car elem))
2155 (while (search-forward from nil t)
2158 (if (eq (following-char) from)
2162 (forward-char 1)))))))))))
2164 (defun article-treat-overstrike ()
2165 "Translate overstrikes into bold text."
2168 (when (article-goto-body)
2169 (let ((inhibit-read-only t))
2170 (while (search-forward "\b" nil t)
2171 (let ((next (char-after))
2172 (previous (char-after (- (point) 2))))
2173 ;; We do the boldification/underlining by hiding the
2174 ;; overstrikes and putting the proper text property
2178 (gnus-article-hide-text-type (- (point) 2) (point) 'overstrike)
2179 (put-text-property (point) (1+ (point)) 'face 'bold))
2181 (gnus-article-hide-text-type
2182 (1- (point)) (1+ (point)) 'overstrike)
2184 (- (point) 2) (1- (point)) 'face 'underline))
2186 (gnus-article-hide-text-type (- (point) 2) (point) 'overstrike)
2188 (point) (1+ (point)) 'face 'underline)))))))))
2190 (defun article-treat-ansi-sequences ()
2191 "Translate ANSI SGR control sequences into overlays or extents."
2194 (when (article-goto-body)
2195 (let ((inhibit-read-only t))
2196 (ansi-color-apply-on-region (point) (point-max))))))
2198 (defun gnus-article-treat-unfold-headers ()
2199 "Unfold folded message headers.
2200 Only the headers that fit into the current window width will be
2203 (gnus-with-article-headers
2207 (mail-header-narrow-to-field)
2208 (let* ((header (buffer-string))
2210 (or (equal gnus-article-unfold-long-headers t)
2211 (and (stringp gnus-article-unfold-long-headers)
2212 (string-match gnus-article-unfold-long-headers
2216 (goto-char (point-min))
2217 (while (re-search-forward "\n[\t ]" nil t)
2218 (replace-match " " t t)))
2219 (setq length (- (point-max) (point-min) 1))
2220 (when (or unfoldable
2221 (< length (window-width)))
2222 (while (re-search-forward "\n[\t ]" nil t)
2223 (replace-match " " t t))))
2224 (goto-char (point-max)))))))
2226 (defun gnus-article-treat-fold-headers ()
2227 "Fold message headers."
2229 (gnus-with-article-headers
2232 (mail-header-narrow-to-field)
2233 (mail-header-fold-field)
2234 (goto-char (point-max))))))
2236 (defun gnus-treat-smiley ()
2237 "Toggle display of textual emoticons (\"smileys\") as small graphical icons."
2239 (gnus-with-article-buffer
2240 (if (memq 'smiley gnus-article-wash-types)
2241 (gnus-delete-images 'smiley)
2243 (let ((images (smiley-region (point) (point-max))))
2245 (gnus-add-wash-type 'smiley)
2246 (dolist (image images)
2247 (gnus-add-image 'smiley image)))))))
2249 (defun gnus-article-remove-images ()
2250 "Remove all images from the article buffer."
2252 (gnus-with-article-buffer
2255 (dolist (elem gnus-article-image-alist)
2256 (gnus-delete-images (car elem))))))
2258 (autoload 'w3m-toggle-inline-images "w3m")
2260 (defun gnus-article-show-images ()
2261 "Show any images that are in the HTML-rendered article buffer.
2262 This only works if the article in question is HTML."
2264 (gnus-with-article-buffer
2267 (if (eq mm-text-html-renderer 'w3m)
2268 (let ((mm-inline-text-html-with-images nil))
2269 (w3m-toggle-inline-images))
2270 (dolist (region (gnus-find-text-property-region (point-min) (point-max)
2272 (destructuring-bind (start end function) region
2273 (funcall function (get-text-property start 'image-url)
2276 (defun gnus-article-treat-fold-newsgroups ()
2277 "Unfold folded message headers.
2278 Only the headers that fit into the current window width will be
2281 (gnus-with-article-headers
2282 (while (gnus-article-goto-header "newsgroups\\|followup-to")
2284 (mail-header-narrow-to-field)
2285 (while (re-search-forward ", *" nil t)
2286 (replace-match ", " t t))
2287 (mail-header-fold-field)
2288 (goto-char (point-max))))))
2290 (defcustom gnus-article-truncate-lines (default-value 'truncate-lines)
2291 "Value of `truncate-lines' in Gnus Article buffer.
2292 Valid values are nil, t, `head', `first', `last', an integer or a
2293 predicate. See Info node `(gnus)Customizing Articles'."
2294 :version "23.1" ;; No Gnus
2295 :group 'gnus-article
2296 ;; :link '(custom-manual "(gnus)Customizing Articles")
2299 (defun gnus-article-toggle-truncate-lines (&optional arg)
2300 "Toggle whether to fold or truncate long lines in article the buffer.
2301 If ARG is non-nil and not a number, toggle
2302 `gnus-article-truncate-lines' too. If ARG is a number, truncate
2303 long lines if and only if arg is positive."
2306 ((and (numberp arg) (> arg 0))
2307 (setq gnus-article-truncate-lines t))
2309 (setq gnus-article-truncate-lines nil))
2311 (setq gnus-article-truncate-lines
2312 (not gnus-article-truncate-lines))))
2313 (gnus-with-article-buffer
2315 ((and (numberp arg) (> arg 0))
2316 (setq truncate-lines nil))
2318 (setq truncate-lines t)))
2319 ;; In versions of Emacs 22 (CVS) before 2006-05-26,
2320 ;; `toggle-truncate-lines' needs an argument.
2321 (toggle-truncate-lines)))
2323 (defun gnus-article-treat-body-boundary ()
2324 "Place a boundary line at the end of the headers."
2326 (when (and gnus-body-boundary-delimiter
2327 (> (length gnus-body-boundary-delimiter) 0))
2328 (gnus-with-article-headers
2329 (goto-char (point-max))
2330 (let ((start (point)))
2331 (insert "X-Boundary: ")
2332 (gnus-add-text-properties start (point) '(invisible t intangible t))
2333 (insert (let (str (max (window-width)))
2334 (if (featurep 'xemacs)
2335 (setq max (1- max)))
2336 (while (>= max (length str))
2337 (setq str (concat str gnus-body-boundary-delimiter)))
2338 (substring str 0 max))
2340 (gnus-put-text-property start (point) 'gnus-decoration 'header)))))
2342 (defun article-fill-long-lines ()
2343 "Fill lines that are wider than the window width."
2346 (let ((inhibit-read-only t)
2347 (width (window-width (get-buffer-window (current-buffer)))))
2350 (let ((adaptive-fill-mode nil)) ;Why? -sm
2353 (when (>= (current-column) (min fill-column width))
2354 (narrow-to-region (min (1+ (point)) (point-max))
2356 (let ((goback (point-marker)))
2357 (fill-paragraph nil)
2358 (goto-char (marker-position goback)))
2360 (forward-line 1)))))))
2362 (defun article-capitalize-sentences ()
2363 "Capitalize the first word in each sentence."
2366 (let ((inhibit-read-only t)
2367 (paragraph-start "^[\n\^L]"))
2371 (forward-sentence)))))
2373 (defun article-remove-cr ()
2374 "Remove trailing CRs and then translate remaining CRs into LFs."
2377 (let ((inhibit-read-only t))
2378 (goto-char (point-min))
2379 (while (re-search-forward "\r+$" nil t)
2380 (replace-match "" t t))
2381 (goto-char (point-min))
2382 (while (search-forward "\r" nil t)
2383 (replace-match "\n" t t)))))
2385 (defun article-remove-trailing-blank-lines ()
2386 "Remove all trailing blank lines from the article."
2389 (let ((inhibit-read-only t))
2390 (goto-char (point-max))
2394 (while (and (not (bobp))
2395 (looking-at "^[ \t]*$")
2396 (not (gnus-annotation-in-region-p
2397 (point) (point-at-eol))))
2402 (defvar gnus-face-properties-alist)
2404 (defun article-display-face (&optional force)
2405 "Display any Face headers in the header."
2406 (interactive (list 'force))
2407 (let ((wash-face-p buffer-read-only))
2408 (gnus-with-article-headers
2409 ;; When displaying parts, this function can be called several times on
2410 ;; the same article, without any intended toggle semantic (as typing `W
2411 ;; D d' would have). So face deletion must occur only when we come from
2412 ;; an interactive command, that is when the *Article* buffer is
2414 (if (and wash-face-p (memq 'face gnus-article-wash-types))
2415 (gnus-delete-images 'face)
2416 (let ((from (message-fetch-field "from"))
2418 (save-current-buffer
2419 (when (and wash-face-p
2420 (gnus-buffer-live-p gnus-original-article-buffer)
2421 (not (re-search-forward "^Face:[\t ]*" nil t)))
2422 (set-buffer gnus-original-article-buffer))
2424 (mail-narrow-to-head)
2426 ;; Check whether this face is censored.
2427 (not (and gnus-article-x-face-too-ugly
2429 (setq from (message-fetch-field "from")))
2430 (string-match gnus-article-x-face-too-ugly
2432 (while (gnus-article-goto-header "Face")
2433 (push (mail-header-field-value) faces)))))
2435 (goto-char (point-min))
2437 (unless (setq from (gnus-article-goto-header "from"))
2440 (insert " [no `from' set]\n"))
2442 (when (setq png (gnus-convert-face-to-png (pop faces)))
2444 (apply 'gnus-create-image png 'png t
2445 (cdr (assq 'png gnus-face-properties-alist))))
2448 (gnus-add-wash-type 'face)
2449 (gnus-add-image 'face image)
2450 (gnus-put-image image nil 'face)))))))))))
2452 (defun article-display-x-face (&optional force)
2453 "Look for an X-Face header and display it if present."
2454 (interactive (list 'force))
2455 (let ((wash-face-p buffer-read-only)) ;; When type `W f'
2456 (gnus-with-article-headers
2457 ;; Delete the old process, if any.
2458 (when (process-status "article-x-face")
2459 (delete-process "article-x-face"))
2460 ;; See the comment in `article-display-face'.
2461 (if (and wash-face-p (memq 'xface gnus-article-wash-types))
2462 ;; We have already displayed X-Faces, so we remove them
2464 (gnus-delete-images 'xface)
2466 (let ((from (message-fetch-field "from"))
2468 (save-current-buffer
2469 (when (and wash-face-p
2470 (gnus-buffer-live-p gnus-original-article-buffer)
2471 (not (re-search-forward "^X-Face:[\t ]*" nil t)))
2472 ;; If type `W f', use gnus-original-article-buffer,
2473 ;; otherwise use the current buffer because displaying
2474 ;; RFC822 parts calls this function too.
2475 (set-buffer gnus-original-article-buffer))
2477 (mail-narrow-to-head)
2478 (and gnus-article-x-face-command
2480 ;; Check whether this face is censored.
2481 (not (and gnus-article-x-face-too-ugly
2483 (setq from (message-fetch-field "from")))
2484 (string-match gnus-article-x-face-too-ugly
2486 (while (gnus-article-goto-header "X-Face")
2487 (push (mail-header-field-value) x-faces)))))
2489 ;; We display the face.
2490 (cond ((functionp gnus-article-x-face-command)
2491 ;; The command is a lisp function, so we call it.
2492 (mapc gnus-article-x-face-command x-faces))
2493 ((stringp gnus-article-x-face-command)
2494 ;; The command is a string, so we interpret the command
2495 ;; as a, well, command, and fork it off.
2496 (let ((process-connection-type nil))
2497 (gnus-set-process-query-on-exit-flag
2499 "article-x-face" nil shell-file-name
2500 shell-command-switch gnus-article-x-face-command)
2502 ;; Sending multiple EOFs to xv doesn't work,
2503 ;; so we only do a single external face.
2505 (insert (car x-faces))
2506 (process-send-region "article-x-face"
2507 (point-min) (point-max)))
2508 (process-send-eof "article-x-face")))
2510 (error "`%s' set to `%s' is not a function"
2511 gnus-article-x-face-command
2512 'gnus-article-x-face-command)))))))))
2514 (defun article-decode-mime-words ()
2515 "Decode all MIME-encoded words in the article."
2517 (gnus-with-article-buffer
2518 (let ((inhibit-point-motion-hooks t)
2519 (mail-parse-charset gnus-newsgroup-charset)
2520 (mail-parse-ignored-charsets
2521 (with-current-buffer gnus-summary-buffer
2522 gnus-newsgroup-ignored-charsets)))
2523 (mail-decode-encoded-word-region (point-min) (point-max)))))
2525 (defun article-decode-charset (&optional prompt)
2526 "Decode charset-encoded text in the article.
2527 If PROMPT (the prefix), prompt for a coding system to use."
2529 (let ((inhibit-point-motion-hooks t) (case-fold-search t)
2530 (inhibit-read-only t)
2531 (mail-parse-charset gnus-newsgroup-charset)
2532 (mail-parse-ignored-charsets
2533 (save-excursion (condition-case nil
2534 (set-buffer gnus-summary-buffer)
2536 gnus-newsgroup-ignored-charsets))
2537 ct cte ctl charset format)
2540 (article-narrow-to-head)
2541 (setq ct (message-fetch-field "Content-Type" t)
2542 cte (message-fetch-field "Content-Transfer-Encoding" t)
2543 ctl (and ct (mail-header-parse-content-type ct))
2546 (mm-read-coding-system "Charset to decode: "))
2548 (mail-content-type-get ctl 'charset)))
2549 format (and ctl (mail-content-type-get ctl 'format)))
2551 (setq cte (mail-header-strip cte)))
2552 (if (and ctl (not (string-match "/" (car ctl))))
2554 (goto-char (point-max)))
2557 (narrow-to-region (point) (point-max))
2558 (when (and (eq mail-parse-charset 'gnus-decoded)
2559 (eq (mm-body-7-or-8) '8bit))
2560 ;; The text code could have been decoded.
2561 (setq charset mail-parse-charset))
2562 (when (and (or (not ctl)
2563 (equal (car ctl) "text/plain"))
2564 (not format)) ;; article with format will decode later.
2566 charset (and cte (intern (downcase
2567 (gnus-strip-whitespace cte))))
2570 (defun article-decode-encoded-words ()
2571 "Remove encoded-word encoding from headers."
2572 (let ((inhibit-point-motion-hooks t)
2573 (mail-parse-charset gnus-newsgroup-charset)
2574 (mail-parse-ignored-charsets
2575 (save-excursion (condition-case nil
2576 (set-buffer gnus-summary-buffer)
2578 gnus-newsgroup-ignored-charsets))
2579 (inhibit-read-only t)
2581 (goto-char (point-min))
2582 (when (search-forward "\n\n" nil 'move)
2589 (memq (char-after) '(?\t ? )))))
2590 (setq start (point))
2592 \\(?:Resent-\\)?\\(?:From\\|Cc\\|To\\|Bcc\\|\\(?:In-\\)?Reply-To\\|Sender\
2593 \\|Mail-Followup-To\\|Mail-Copies-To\\|Approved\\):")
2594 (funcall gnus-decode-address-function start end)
2595 (funcall gnus-decode-header-function start end))
2596 (goto-char (setq end start)))))
2598 (defun article-decode-group-name ()
2599 "Decode group names in Newsgroups, Followup-To and Xref headers."
2600 (let ((inhibit-point-motion-hooks t)
2601 (inhibit-read-only t)
2602 (method (gnus-find-method-for-group gnus-newsgroup-name))
2604 (when (and (or gnus-group-name-charset-method-alist
2605 gnus-group-name-charset-group-alist)
2606 (gnus-buffer-live-p gnus-original-article-buffer))
2608 (article-narrow-to-head)
2609 (dolist (header '("Newsgroups" "Followup-To" "Xref"))
2610 (with-current-buffer gnus-original-article-buffer
2611 (goto-char (point-min)))
2612 (setq regexp (concat "^" header
2613 ":\\([^\n]*\\(?:\n[\t ]+[^\n]+\\)*\\)\n"))
2614 (while (re-search-forward regexp nil t)
2615 (replace-match (save-match-data
2616 (gnus-decode-newsgroups
2617 ;; XXX how to use data in article buffer?
2618 (with-current-buffer gnus-original-article-buffer
2619 (re-search-forward regexp nil t)
2621 gnus-newsgroup-name method))
2623 (goto-char (point-min)))))))
2625 (autoload 'idna-to-unicode "idna")
2627 (defun article-decode-idna-rhs ()
2628 "Decode IDNA strings in RHS in various headers in current buffer.
2629 The following headers are decoded: From:, To:, Cc:, Reply-To:,
2630 Mail-Reply-To: and Mail-Followup-To:."
2633 (let ((inhibit-point-motion-hooks t)
2634 (inhibit-read-only t))
2635 (article-narrow-to-head)
2636 (goto-char (point-min))
2637 (while (re-search-forward "@[^ \t\n\r,>]*\\(xn--[-A-Za-z0-9.]*\\)[ \t\n\r,>]" nil t)
2639 (when (save-match-data
2640 (and (setq ace (match-string 1))
2642 (and (re-search-backward "^[^ \t]" nil t)
2643 (looking-at "From\\|To\\|Cc\\|Reply-To\\|Mail-Reply-To\\|Mail-Followup-To")))
2644 (setq unicode (idna-to-unicode ace))))
2645 (unless (string= ace unicode)
2646 (replace-match unicode nil nil nil 1)))))))))
2648 (defun article-de-quoted-unreadable (&optional force read-charset)
2649 "Translate a quoted-printable-encoded article.
2650 If FORCE, decode the article whether it is marked as quoted-printable
2652 If READ-CHARSET, ask for a coding system."
2653 (interactive (list 'force current-prefix-arg))
2655 (let ((inhibit-read-only t) type charset)
2656 (if (gnus-buffer-live-p gnus-original-article-buffer)
2657 (with-current-buffer gnus-original-article-buffer
2659 (gnus-fetch-field "content-transfer-encoding"))
2660 (let* ((ct (gnus-fetch-field "content-type"))
2661 (ctl (and ct (mail-header-parse-content-type ct))))
2662 (setq charset (and ctl
2663 (mail-content-type-get ctl 'charset)))
2664 (if (stringp charset)
2665 (setq charset (intern (downcase charset)))))))
2667 (setq charset (mm-read-coding-system "Charset: " charset)))
2669 (setq charset gnus-newsgroup-charset))
2671 (and type (let ((case-fold-search t))
2672 (string-match "quoted-printable" type))))
2674 (quoted-printable-decode-region
2675 (point) (point-max) (mm-charset-to-coding-system charset nil t))))))
2677 (defun article-de-base64-unreadable (&optional force read-charset)
2678 "Translate a base64 article.
2679 If FORCE, decode the article whether it is marked as base64 not.
2680 If READ-CHARSET, ask for a coding system."
2681 (interactive (list 'force current-prefix-arg))
2683 (let ((inhibit-read-only t) type charset)
2684 (if (gnus-buffer-live-p gnus-original-article-buffer)
2685 (with-current-buffer gnus-original-article-buffer
2687 (gnus-fetch-field "content-transfer-encoding"))
2688 (let* ((ct (gnus-fetch-field "content-type"))
2689 (ctl (and ct (mail-header-parse-content-type ct))))
2690 (setq charset (and ctl
2691 (mail-content-type-get ctl 'charset)))
2692 (if (stringp charset)
2693 (setq charset (intern (downcase charset)))))))
2695 (setq charset (mm-read-coding-system "Charset: " charset)))
2697 (setq charset gnus-newsgroup-charset))
2699 (and type (let ((case-fold-search t))
2700 (string-match "base64" type))))
2703 (narrow-to-region (point) (point-max))
2704 (base64-decode-region (point-min) (point-max))
2705 (mm-decode-coding-region
2706 (point-min) (point-max)
2707 (mm-charset-to-coding-system charset nil t)))))))
2712 (defun article-decode-HZ ()
2713 "Translate a HZ-encoded article."
2717 (let ((inhibit-read-only t))
2718 (rfc1843-decode-region (point-min) (point-max)))))
2720 (defun article-unsplit-urls ()
2721 "Remove the newlines that some other mailers insert into URLs."
2724 (let ((inhibit-read-only t))
2725 (goto-char (point-min))
2726 (while (re-search-forward
2727 "\\(\\(https?\\|ftp\\)://\\S-+\\) *\n\\(\\S-+\\)" nil t)
2728 (replace-match "\\1\\3" t)))
2729 (when (gmm-called-interactively-p 'any)
2730 (gnus-treat-article nil))))
2732 (defun article-wash-html ()
2733 "Format an HTML article."
2736 (buffer-read-only nil))
2737 (when (gnus-buffer-live-p gnus-original-article-buffer)
2738 (with-current-buffer gnus-original-article-buffer
2739 (setq handles (mm-dissect-buffer t t))))
2741 (delete-region (point) (point-max))
2742 (mm-enable-multibyte)
2743 (mm-inline-text-html handles)))
2745 (defvar gnus-article-browse-html-temp-list nil
2746 "List of temporary files created by `gnus-article-browse-html-parts'.
2747 Internal variable.")
2749 (defcustom gnus-article-browse-delete-temp 'ask
2750 "What to do with temporary files from `gnus-article-browse-html-parts'.
2751 If nil, don't delete temporary files. If it is t, delete them on
2752 exit from the summary buffer. If it is the symbol `file', query
2753 on each file, if it is `ask' ask once when exiting from the
2755 :group 'gnus-article
2756 :version "23.1" ;; No Gnus
2757 :type '(choice (const :tag "Don't delete" nil)
2758 (const :tag "Don't ask" t)
2759 (const :tag "Ask" ask)
2760 (const :tag "Ask for each file" file)))
2762 ;; Cf. mm-postponed-undisplay-list / mm-destroy-postponed-undisplay-list.
2764 (defun gnus-article-browse-delete-temp-files (&optional how)
2765 "Delete temp-files created by `gnus-article-browse-html-parts'."
2766 (when (and gnus-article-browse-html-temp-list
2768 (or how (setq how gnus-article-browse-delete-temp))
2770 (let ((files (length gnus-article-browse-html-temp-list)))
2773 "Delete the temporary HTML file? "
2774 (format "Delete all %s temporary HTML files? "
2776 (setq gnus-article-browse-html-temp-list nil)))
2778 (dolist (file gnus-article-browse-html-temp-list)
2779 (cond ((file-directory-p file)
2780 (when (or (not (eq how 'file))
2783 "Delete temporary HTML file(s) in directory `%s'? "
2784 (file-name-as-directory file))))
2785 (gnus-delete-directory file)))
2786 ((file-exists-p file)
2787 (when (or (not (eq how 'file))
2789 (format "Delete temporary HTML file `%s'? " file)))
2790 (delete-file file)))))
2791 ;; Also remove file from the list when not deleted or if file doesn't
2793 (setq gnus-article-browse-html-temp-list nil))
2794 gnus-article-browse-html-temp-list)
2796 (defun gnus-article-browse-html-save-cid-content (cid handles directory abs)
2797 "Find CID content in HANDLES and save it in a file in DIRECTORY.
2798 Return absolute file name if ABS is non-nil, otherwise relative to
2799 the parent of DIRECTORY."
2803 (dolist (handle handles)
2805 ((not (listp handle)))
2806 ;; Exclude broken handles that `gnus-summary-enter-digest-group'
2808 ((not (or (bufferp (car handle)) (stringp (car handle)))))
2809 ((equal (mm-handle-media-supertype handle) "multipart")
2810 (when (setq file (gnus-article-browse-html-save-cid-content
2811 cid handle directory abs))
2812 (throw 'found file)))
2813 ((equal (concat "<" cid ">") (mm-handle-id handle))
2814 (setq file (or (mm-handle-filename handle)
2816 (make-temp-name "cid")
2817 (car (rassoc (car (mm-handle-type handle))
2818 mailcap-mime-extensions))))
2819 afile (expand-file-name file directory))
2820 (mm-save-part-to-file handle afile)
2821 (throw 'found (if abs
2823 (concat (file-name-nondirectory
2824 (directory-file-name directory))
2827 (defun gnus-article-browse-html-parts (list &optional header)
2828 "View all \"text/html\" parts from LIST.
2829 Recurse into multiparts. The optional HEADER that should be a decoded
2830 message header will be added to the bodies of the \"text/html\" parts."
2831 ;; Internal function used by `gnus-article-browse-html-article'.
2832 (let (type file charset content cid-dir tmp-file showed)
2833 ;; Find and show the html-parts.
2834 (dolist (handle list)
2835 ;; If HTML, show it:
2836 (cond ((not (listp handle)))
2837 ((or (equal (car (setq type (mm-handle-type handle))) "text/html")
2838 (and (equal (car type) "message/external-body")
2840 (setq file (mm-handle-filename handle)))
2841 (or (mm-handle-cache handle)
2842 (condition-case code
2843 (progn (mm-extern-cache-contents handle) t)
2845 (gnus-message 3 "%s" (error-message-string code))
2846 (when (>= gnus-verbose 3) (sit-for 2))
2849 (setq handle (mm-handle-cache handle)
2850 type (mm-handle-type handle))
2851 (equal (car type) "text/html"))))
2852 (setq charset (mail-content-type-get type 'charset)
2853 content (mm-get-part handle))
2855 (if (eq charset 'gnus-decoded)
2856 (mm-enable-multibyte)
2857 (mm-disable-multibyte))
2859 ;; resolve cid contents
2860 (let ((case-fold-search t)
2862 (goto-char (point-min))
2863 (when (re-search-forward "<head[\t\n >]" nil t)
2864 (setq st (match-end 0)
2866 (not (re-search-forward "</head[\t\n >]" nil t))
2867 (re-search-backward "<base[\t\n >]" st t))))
2868 (while (re-search-forward "\
2869 <img[\t\n ]+\\(?:[^\t\n >]+[\t\n ]+\\)*src=\"\\(cid:\\([^\"]+\\)\\)\""
2872 (setq cid-dir (mm-make-temp-file "cid" t))
2873 (add-to-list 'gnus-article-browse-html-temp-list cid-dir))
2876 (when (setq cid-file
2877 (gnus-article-browse-html-save-cid-content
2879 (with-current-buffer gnus-article-buffer
2880 gnus-article-mime-handles)
2884 (if (eq system-type 'cygwin)
2887 (with-output-to-string
2888 (call-process "cygpath" nil
2892 (concat "file://" cid-file))))
2893 (replace-match cid-file nil nil nil 1))))
2894 (unless content (setq content (buffer-string))))
2895 (when (or charset header (not file))
2896 (setq tmp-file (mm-make-temp-file
2897 ;; Do we need to care for 8.3 filenames?
2898 "mm-" nil ".html")))
2899 ;; Add a meta html tag to specify charset and a header.
2902 (let (title eheader body hcharset coding)
2904 (mm-enable-multibyte)
2905 (setq case-fold-search t)
2906 (insert header "\n")
2907 (setq title (message-fetch-field "subject"))
2908 (goto-char (point-min))
2909 (while (re-search-forward "\\(<\\)\\|\\(>\\)\\|\\(&\\)\\|\n"
2911 (replace-match (cond ((match-beginning 1) "<")
2912 ((match-beginning 2) ">")
2913 ((match-beginning 3) "&")
2915 (goto-char (point-min))
2916 (while (re-search-forward "^[\t ]+" nil t)
2919 (delete-region (match-beginning 0)
2922 (goto-char (point-min))
2923 (insert "<div align=\"left\">\n")
2924 (goto-char (point-max))
2925 (insert "</div>\n<hr>\n")
2926 ;; We have to examine charset one by one since
2927 ;; charset specified in parts might be different.
2928 (if (eq charset 'gnus-decoded)
2929 (setq charset 'utf-8
2930 eheader (mm-encode-coding-string (buffer-string)
2933 (mm-encode-coding-string title charset))
2934 body (mm-encode-coding-string content charset))
2935 (setq hcharset (mm-find-mime-charset-region (point-min)
2937 (cond ((= (length hcharset) 1)
2938 (setq hcharset (car hcharset)
2939 coding (mm-charset-to-coding-system
2941 ((> (length hcharset) 1)
2942 (setq hcharset 'utf-8
2948 (mm-charset-to-coding-system charset
2950 (if (eq coding body)
2951 (setq eheader (mm-encode-coding-string
2952 (buffer-string) coding)
2954 (mm-encode-coding-string
2957 (setq charset 'utf-8
2958 eheader (mm-encode-coding-string
2959 (buffer-string) charset)
2961 (mm-encode-coding-string
2963 body (mm-encode-coding-string
2964 (mm-decode-coding-string
2967 (setq charset hcharset
2968 eheader (mm-encode-coding-string
2969 (buffer-string) coding)
2971 (mm-encode-coding-string
2974 (setq eheader (mm-string-as-unibyte (buffer-string))
2977 (mm-disable-multibyte)
2980 (mm-add-meta-html-tag handle charset t))
2982 (goto-char (point-min))
2983 (unless (search-forward "<title>" nil t)
2984 (re-search-forward "<head>\\s-*" nil t)
2985 (insert "<title>" title "</title>\n")))
2986 (goto-char (point-min))
2987 (or (re-search-forward
2988 "<body\\(?:\\s-+[^>]+\\|\\s-*\\)>\\s-*" nil t)
2990 "</head\\(?:\\s-+[^>]+\\|\\s-*\\)>\\s-*" nil t))
2992 (mm-write-region (point-min) (point-max)
2993 tmp-file nil nil nil 'binary t))))
2995 (mm-with-unibyte-buffer
2996 (insert (if (eq charset 'gnus-decoded)
2997 (mm-encode-coding-string content
2998 (setq charset 'utf-8))
3000 (if (or (mm-add-meta-html-tag handle charset)
3002 (mm-write-region (point-min) (point-max)
3003 tmp-file nil nil nil 'binary t)
3004 (setq tmp-file nil))))
3006 (mm-save-part-to-file handle tmp-file)))
3008 (add-to-list 'gnus-article-browse-html-temp-list tmp-file))
3009 (add-hook 'gnus-summary-prepare-exit-hook
3010 'gnus-article-browse-delete-temp-files)
3011 (add-hook 'gnus-exit-gnus-hook
3013 (gnus-article-browse-delete-temp-files t)))
3014 ;; FIXME: Warn if there's an <img> tag?
3015 (browse-url-of-file (or tmp-file (expand-file-name file)))
3017 ;; If multipart, recurse
3018 ((equal (mm-handle-media-supertype handle) "multipart")
3019 (when (gnus-article-browse-html-parts handle header)
3021 ((equal (mm-handle-media-type handle) "message/rfc822")
3022 (mm-with-multibyte-buffer
3023 (mm-insert-part handle)
3024 (setq handle (mm-dissect-buffer t t))
3025 (when (and (bufferp (car handle))
3026 (stringp (car (mm-handle-type handle))))
3027 (setq handle (list handle)))
3029 (article-decode-encoded-words)
3030 (let ((gnus-visible-headers
3031 (or (get 'gnus-visible-headers 'standard-value)
3032 gnus-visible-headers)))
3033 (article-hide-headers))
3034 (goto-char (point-min))
3035 (search-forward "\n\n" nil 'move)
3036 (skip-chars-backward "\t\n ")
3037 (setq header (buffer-substring (point-min) (point)))))
3039 (gnus-article-browse-html-parts handle header)
3040 (mm-destroy-parts handle))
3044 (defun gnus-article-browse-html-article (&optional arg)
3045 "View \"text/html\" parts of the current article with a WWW browser.
3046 Inline images embedded in a message using the cid scheme, as they are
3047 generally considered to be safe, will be processed properly.
3048 The message header is added to the beginning of every html part unless
3049 the prefix argument ARG is given.
3051 Warning: Spammers use links to images (using the http scheme) in HTML
3052 articles to verify whether you have read the message. As
3053 `gnus-article-browse-html-article' passes the HTML content to the
3054 browser without eliminating these \"web bugs\" you should only
3055 use it for mails from trusted senders.
3057 If you always want to display HTML parts in the browser, set
3058 `mm-text-html-renderer' to nil.
3060 This command creates temporary files to pass HTML contents including
3061 images if any to the browser, and deletes them when exiting the group
3063 ;; Cf. `mm-w3m-safe-url-regexp'
3066 (gnus-summary-show-article)
3067 (let ((gnus-visible-headers (or (get 'gnus-visible-headers 'standard-value)
3068 gnus-visible-headers))
3069 ;; As we insert a <hr>, there's no need for the body boundary.
3070 (gnus-treat-body-boundary nil))
3071 (gnus-summary-show-article)))
3072 (with-current-buffer gnus-article-buffer
3073 (let ((header (unless arg
3076 (buffer-substring-no-properties
3077 (goto-char (point-min))
3078 (if (search-forward "\n\n" nil t)
3080 (goto-char (point-max))
3081 (skip-chars-backward "\t\n ")
3084 (set-buffer gnus-original-article-buffer)
3085 (setq parts (mm-dissect-buffer t t))
3086 ;; If singlepart, enforce a list.
3087 (when (and (bufferp (car parts))
3088 (stringp (car (mm-handle-type parts))))
3089 (setq parts (list parts)))
3091 (unless (gnus-article-browse-html-parts parts header)
3092 (gnus-error 3 "Mail doesn't contain a \"text/html\" part!"))
3093 (mm-destroy-parts parts)
3095 (gnus-summary-show-article)))))
3097 (defun article-hide-list-identifiers ()
3098 "Remove list identifiers from the Subject header.
3099 The `gnus-list-identifiers' variable specifies what to do."
3101 (let ((inhibit-point-motion-hooks t)
3102 (regexp (gnus-group-get-list-identifiers gnus-newsgroup-name))
3103 (inhibit-read-only t))
3107 (article-narrow-to-head)
3108 (goto-char (point-min))
3109 (while (re-search-forward
3110 (concat "^Subject: +\\(R[Ee]: +\\)*\\(" regexp " *\\)")
3112 (delete-region (match-beginning 2) (match-end 0))
3113 (beginning-of-line))
3114 (when (re-search-forward
3115 "^Subject: +\\(\\(R[Ee]: +\\)+\\)R[Ee]: +" nil t)
3116 (delete-region (match-beginning 1) (match-end 1))))))))
3118 (defun article-hide-pem (&optional arg)
3119 "Toggle hiding of any PEM headers and signatures in the current article.
3120 If given a negative prefix, always show; if given a positive prefix,
3122 (interactive (gnus-article-hidden-arg))
3123 (unless (gnus-article-check-hidden-text 'pem arg)
3125 (let ((inhibit-read-only t) end)
3126 (goto-char (point-min))
3127 ;; Hide the horrendously ugly "header".
3128 (when (and (search-forward
3129 "\n-----BEGIN PRIVACY-ENHANCED MESSAGE-----\n"
3131 (setq end (1+ (match-beginning 0))))
3132 (gnus-add-wash-type 'pem)
3133 (gnus-article-hide-text-type
3135 (if (search-forward "\n\n" nil t)
3139 ;; Hide the trailer as well
3140 (when (search-forward "\n-----END PRIVACY-ENHANCED MESSAGE-----\n"
3142 (gnus-article-hide-text-type
3143 (match-beginning 0) (match-end 0) 'pem)))))))
3145 (defun article-strip-banner ()
3146 "Strip the banners specified by the `banner' group parameter and by
3147 `gnus-article-address-banner-alist'."
3151 (let ((inhibit-point-motion-hooks t))
3152 (when (gnus-parameter-banner gnus-newsgroup-name)
3153 (article-really-strip-banner
3154 (gnus-parameter-banner gnus-newsgroup-name)))
3155 (when gnus-article-address-banner-alist
3156 ;; Note that the From header is decoded here, so it is
3157 ;; required that the *-extract-address-components function
3158 ;; supports non-ASCII text.
3159 (let ((from (save-restriction
3161 (article-narrow-to-head)
3162 (mail-fetch-field "from"))))
3165 (cadr (funcall gnus-extract-address-components
3168 (dolist (pair gnus-article-address-banner-alist)
3169 (when (string-match (car pair) from)
3171 (article-really-strip-banner (cdr pair)))))))))))))
3173 (defun article-really-strip-banner (banner)
3174 "Strip the banner specified by the argument."
3177 (let ((inhibit-point-motion-hooks t)
3178 (gnus-signature-limit nil)
3179 (inhibit-read-only t))
3182 ((eq banner 'signature)
3183 (when (gnus-article-narrow-to-signature)
3186 (delete-region (point) (point-max))))
3188 (if (setq banner (cdr (assq banner gnus-article-banner-alist)))
3189 (while (re-search-forward banner nil t)
3190 (delete-region (match-beginning 0) (match-end 0)))))
3192 (while (re-search-forward banner nil t)
3193 (delete-region (match-beginning 0) (match-end 0)))))))))
3195 (defun article-babel ()
3196 "Translate article using an online translation service."
3199 (gnus-with-article-buffer
3200 (when (article-goto-body)
3201 (let* ((start (point))
3203 (orig (buffer-substring start end))
3204 (trans (babel-as-string orig)))
3206 (narrow-to-region start end)
3207 (delete-region start end)
3210 (defun article-hide-signature (&optional arg)
3211 "Hide the signature in the current article.
3212 If given a negative prefix, always show; if given a positive prefix,
3214 (interactive (gnus-article-hidden-arg))
3215 (unless (gnus-article-check-hidden-text 'signature arg)
3218 (let ((inhibit-read-only t))
3219 (when (gnus-article-narrow-to-signature)
3220 (gnus-article-hide-text-type
3221 (point-min) (point-max) 'signature))))))
3222 (gnus-set-mode-line 'article))
3224 (defun article-strip-headers-in-body ()
3225 "Strip offensive headers from bodies."
3229 (let ((case-fold-search t))
3230 (when (looking-at "x-no-archive:")
3231 (gnus-delete-line)))))
3233 (defun article-strip-leading-blank-lines ()
3234 "Remove all blank lines from the beginning of the article."
3237 (let ((inhibit-point-motion-hooks t)
3238 (inhibit-read-only t))
3239 (when (article-goto-body)
3240 (while (and (not (eobp))
3241 (looking-at "[ \t]*$"))
3242 (gnus-delete-line))))))
3244 (defun article-narrow-to-head ()
3245 "Narrow the buffer to the head of the message.
3246 Point is left at the beginning of the narrowed-to region."
3248 (goto-char (point-min))
3250 ;; Absolutely no headers displayed.
3254 ((search-forward "\n\n" nil 1)
3256 ;; Nothing but headers.
3259 (goto-char (point-min)))
3261 (defun article-goto-body ()
3262 "Place point at the start of the body."
3263 (goto-char (point-min))
3265 ;; This variable is only bound when dealing with separate
3267 (article-goto-body-goes-to-point-min-p
3269 ((search-forward "\n\n" nil t)
3272 (goto-char (point-max))
3275 (defun article-strip-multiple-blank-lines ()
3276 "Replace consecutive blank lines with one empty line."
3279 (let ((inhibit-point-motion-hooks t)
3280 (inhibit-read-only t))
3281 ;; First make all blank lines empty.
3283 (while (re-search-forward "^[ \t]+$" nil t)
3284 (unless (gnus-annotation-in-region-p
3285 (match-beginning 0) (match-end 0))
3286 (replace-match "" nil t)))
3287 ;; Then replace multiple empty lines with a single empty line.
3289 (while (re-search-forward "\n\n\\(\n+\\)" nil t)
3290 (unless (gnus-annotation-in-region-p
3291 (match-beginning 0) (match-end 0))
3292 (delete-region (match-beginning 1) (match-end 1)))))))
3294 (defun article-strip-leading-space ()
3295 "Remove all white space from the beginning of the lines in the article."
3298 (let ((inhibit-point-motion-hooks t)
3299 (inhibit-read-only t))
3301 (while (re-search-forward "^[ \t]+" nil t)
3302 (replace-match "" t t)))))
3304 (defun article-strip-trailing-space ()
3305 "Remove all white space from the end of the lines in the article."
3308 (let ((inhibit-point-motion-hooks t)
3309 (inhibit-read-only t))
3311 (while (re-search-forward "[ \t]+$" nil t)
3312 (replace-match "" t t)))))
3314 (defun article-strip-blank-lines ()
3315 "Strip leading, trailing and multiple blank lines."
3317 (article-strip-leading-blank-lines)
3318 (article-remove-trailing-blank-lines)
3319 (article-strip-multiple-blank-lines))
3321 (defun article-strip-all-blank-lines ()
3322 "Strip all blank lines."
3325 (let ((inhibit-point-motion-hooks t)
3326 (inhibit-read-only t))
3328 (while (re-search-forward "^[ \t]*\n" nil t)
3329 (replace-match "" t t)))))
3331 (defun gnus-article-narrow-to-signature ()
3332 "Narrow to the signature; return t if a signature is found, else nil."
3333 (let ((inhibit-point-motion-hooks t))
3334 (when (gnus-article-search-signature)
3336 ;; Check whether we have some limits to what we consider
3337 ;; to be a signature.
3338 (let ((limits (if (listp gnus-signature-limit) gnus-signature-limit
3339 (list gnus-signature-limit)))
3341 (while (setq limit (pop limits))
3342 (if (or (and (integerp limit)
3343 (< (- (point-max) (point)) limit))
3345 (< (count-lines (point) (point-max)) limit))
3346 (and (functionp limit)
3348 (and (stringp limit)
3349 (not (re-search-forward limit nil t))))
3350 () ; This limit did not succeed.
3354 (narrow-to-region (point) (point-max))
3357 (defun gnus-article-search-signature ()
3358 "Search the current buffer for the signature separator.
3359 Put point at the beginning of the signature separator."
3360 (let ((cur (point)))
3361 (goto-char (point-max))
3362 (if (if (stringp gnus-signature-separator)
3363 (re-search-backward gnus-signature-separator nil t)
3364 (let ((seps gnus-signature-separator))
3366 (not (re-search-backward (car seps) nil t)))
3373 (defun gnus-article-hidden-arg ()
3374 "Return the current prefix arg as a number, or 0 if no prefix."
3375 (list (if current-prefix-arg
3376 (prefix-numeric-value current-prefix-arg)
3379 (defun gnus-article-check-hidden-text (type arg)
3380 "Return nil if hiding is necessary.
3381 Arg can be nil or a number. nil and positive means hide, negative
3382 means show, 0 means toggle."
3385 (let ((hide (gnus-article-hidden-text-p type)))
3391 (gnus-article-show-hidden-text type)
3394 (if (eq hide 'hidden)
3396 (gnus-article-show-hidden-text type)
3400 (defun gnus-article-hidden-text-p (type)
3401 "Say whether the current buffer contains hidden text of type TYPE."
3402 (let ((pos (text-property-any (point-min) (point-max) 'article-type type)))
3404 (not (get-text-property pos 'invisible))
3405 (not (get-text-property pos 'dummy-invisible)))
3407 (text-property-any (1+ pos) (point-max) 'article-type type)))
3412 (defun gnus-article-show-hidden-text (type &optional _dummy)
3413 "Show all hidden text of type TYPE.
3414 Originally it is hide instead of DUMMY."
3415 (let ((inhibit-read-only t)
3416 (inhibit-point-motion-hooks t))
3417 (gnus-remove-text-properties-when
3419 (point-min) (point-max)
3420 (cons 'article-type (cons type
3421 gnus-hidden-properties)))
3422 (gnus-delete-wash-type type)))
3424 (defconst article-time-units
3425 `((year . ,(* 365.25 24 60 60))
3426 (week . ,(* 7 24 60 60))
3427 (day . ,(* 24 60 60))
3431 "Mapping from time units to seconds.")
3433 (defun gnus-article-forward-header ()
3434 "Move point to the start of the next header.
3435 If the current header is a continuation header, this can be several
3440 (if (looking-at "[ \t]+[^ \t]")
3444 (defun article-treat-date ()
3445 (article-date-ut (if (gnus-buffer-live-p gnus-summary-buffer)
3446 (with-current-buffer gnus-summary-buffer
3447 gnus-article-date-headers)
3448 gnus-article-date-headers)
3451 (defun article-date-ut (&optional type _highlight date-position)
3452 "Convert DATE date to TYPE in the current article.
3453 The default type is `ut'. See `gnus-article-date-headers' for
3455 (interactive (list 'ut t))
3456 (let* ((case-fold-search t)
3457 (inhibit-read-only t)
3458 (inhibit-point-motion-hooks t)
3459 (visible-date (mail-fetch-field "Date"))
3460 pos date bface eface)
3464 (goto-char date-position)
3465 (setq date (get-text-property (point) 'original-date))
3466 (when (looking-at "[^:]+:[\t ]*")
3467 (setq bface (get-text-property (match-beginning 0) 'face)
3468 eface (get-text-property (match-end 0) 'face)))
3469 (delete-region (point)
3471 (gnus-article-forward-header)
3473 (article-transform-date date type bface eface))
3476 (goto-char (point-min))
3477 (while (or (get-text-property (setq pos (point)) 'original-date)
3478 (and (setq pos (next-single-property-change
3479 (point) 'original-date))
3481 (narrow-to-region pos (if (search-forward "\n\n" nil t)
3482 (1+ (match-beginning 0))
3484 (while (setq pos (text-property-not-all pos (point-max)
3485 'gnus-date-type nil))
3486 (setq date (get-text-property pos 'original-date))
3488 (when (looking-at "[^:]+:[\t ]*")
3489 (setq bface (get-text-property (match-beginning 0) 'face)
3490 eface (get-text-property (match-end 0) 'face)))
3491 (delete-region pos (or (text-property-any pos (point-max)
3492 'gnus-date-type nil)
3494 (unless date ;; the 1st time
3495 (goto-char (point-min))
3496 (while (re-search-forward "^Date:[\t ]*" nil t)
3497 (setq date (get-text-property (match-beginning 0)
3499 bface (get-text-property (match-beginning 0) 'face)
3500 eface (get-text-property (match-end 0) 'face))
3501 (delete-region (point-at-bol) (progn
3502 (gnus-article-forward-header)
3504 (when (and (not date)
3506 (setq date visible-date))
3508 (article-transform-date date type bface eface))
3509 (goto-char (point-max))
3512 (defun article-transform-date (date type bface eface)
3513 (dolist (this-type (cond
3523 (add-text-properties
3526 (insert (article-make-date-line date (or this-type 'ut)) "\n")
3528 (list 'original-date date 'gnus-date-type this-type))))
3531 "\\([^:]+:\\)[\t ]*\\(\\(?:[^\t\n ]+[\t ]+\\)*[^\t\n ]+\\)?")
3532 (put-text-property (match-beginning 1) (match-end 1) 'face bface)
3533 (when (match-beginning 2)
3534 (put-text-property (match-beginning 2) (match-end 2) 'face eface))
3535 (while (and (zerop (forward-line 1))
3536 (looking-at "[\t ]+\\(\\(?:[^\t\n ]+[\t ]+\\)*[^\t\n ]+\\)?"))
3537 (when (match-beginning 1)
3538 (put-text-property (match-beginning 1) (match-end 1) 'face eface))))))
3540 (defun article-make-date-line (date type)
3541 "Return a DATE line of TYPE."
3542 (unless (memq type '(local ut original user-defined iso8601 lapsed english
3544 (error "Unknown conversion type: %s" type))
3546 (let ((time (ignore-errors (date-to-time date))))
3548 ;; Convert to the local timezone.
3550 (concat "Date: " (message-make-date time)))
3551 ;; Convert to Universal Time.
3556 (let* ((e (parse-time-string date))
3557 (tm (apply 'encode-time e))
3559 (ls (- (cadr tm) (car (current-time-zone time)))))
3560 (cond ((< ls 0) (list (1- ms) (+ ls 65536)))
3561 ((> ls 65535) (list (1+ ms) (- ls 65536)))
3565 ;; Get the original date from the article.
3566 ((eq type 'original)
3567 (concat "Date: " (if (string-match "\n+$" date)
3568 (substring date 0 (match-beginning 0))
3570 ;; Let the user define the format.
3571 ((eq type 'user-defined)
3572 (let ((format (or (condition-case nil
3573 (with-current-buffer gnus-summary-buffer
3574 gnus-article-time-format)
3576 gnus-article-time-format)))
3577 (if (functionp format)
3578 (funcall format time)
3579 (concat "Date: " (format-time-string format time)))))
3582 (let ((tz (car (current-time-zone time))))
3585 (format-time-string "%Y%m%dT%H%M%S" time)
3586 (format "%s%02d%02d"
3587 (if (> tz 0) "+" "-") (/ (abs tz) 3600)
3588 (/ (% (abs tz) 3600) 60)))))
3589 ;; Do a lapsed format.
3591 (concat "Date: " (article-lapsed-string time)))
3592 ;; A combined date/lapsed format.
3593 ((eq type 'combined-lapsed)
3594 (let ((date-string (article-make-date-line date 'original))
3600 (concat " (" (article-lapsed-string time segments) ")"))
3601 (> (+ (length date-string)
3602 (length lapsed-string))
3605 (setq segments (1- segments)))
3607 (concat date-string lapsed-string)
3609 ;; Display the date in proper English
3611 (let ((dtime (decode-time time)))
3614 (number-to-string (nth 3 dtime))
3615 (let ((digit (% (nth 3 dtime) 10)))
3617 ((memq (nth 3 dtime) '(11 12 13)) "th")
3623 (nth (1- (nth 4 dtime)) gnus-english-month-names)
3625 (number-to-string (nth 5 dtime))
3627 (format "%02d" (nth 2 dtime))
3629 (format "%02d" (nth 1 dtime)))))))
3631 (format "Date: %s (from Gnus)" date))))
3633 (defun article-lapsed-string (time &optional max-segments)
3634 ;; If the date is seriously mangled, the timezone functions are
3635 ;; liable to bug out, so we ignore all errors.
3636 (let* ((now (current-time))
3637 (real-time (subtract-time now time))
3638 (real-sec (and real-time
3639 (+ (* (float (car real-time)) 65536)
3641 (sec (and real-time (abs real-sec)))
3644 (unless max-segments
3645 (setq max-segments (length article-time-units)))
3653 ;; This is a bit convoluted, but basically we go
3654 ;; through the time units for years, weeks, etc,
3655 ;; and divide things to see whether that results
3656 ;; in positive answers.
3659 (if (or (zerop (setq num (ffloor (/ sec (cdr unit)))))
3660 (>= segments max-segments))
3661 ;; The (remaining) seconds are too few to
3662 ;; be divided into this time unit.
3664 ;; It's big enough, so we output it.
3665 (setq sec (- sec (* num (cdr unit))))
3667 (concat (if prev ", " "") (int-to-string
3669 " " (symbol-name (car unit))
3670 (if (> num 1) "s" ""))
3672 segments (1+ segments)))))
3673 article-time-units "")
3674 ;; If dates are odd, then it might appear like the
3675 ;; article was sent in the future.
3678 " in the future"))))))
3680 (defun article-date-local (&optional highlight)
3681 "Convert the current article date to the local timezone."
3682 (interactive (list t))
3683 (article-date-ut 'local highlight))
3685 (defun article-date-english (&optional highlight)
3686 "Convert the current article date to something that is proper English."
3687 (interactive (list t))
3688 (article-date-ut 'english highlight))
3690 (defun article-date-original (&optional highlight)
3691 "Convert the current article date to what it was originally.
3692 This is only useful if you have used some other date conversion
3693 function and want to see what the date was before converting."
3694 (interactive (list t))
3695 (article-date-ut 'original highlight))
3697 (defun article-date-lapsed (&optional highlight)
3698 "Convert the current article date to time lapsed since it was sent."
3699 (interactive (list t))
3700 (article-date-ut 'lapsed highlight))
3702 (defun article-date-combined-lapsed (&optional highlight)
3703 "Convert the current article date to time lapsed since it was sent."
3704 (interactive (list t))
3705 (article-date-ut 'combined-lapsed highlight))
3707 (defun article-update-date-lapsed ()
3708 "Function to be run from a timer to update the lapsed time line."
3710 (let ((buffer (current-buffer)))
3714 (set-buffer (window-buffer w))
3715 (when (derived-mode-p 'gnus-article-mode)
3716 (let ((old-line (count-lines (point-min) (point)))
3717 (old-column (- (point) (line-beginning-position)))
3718 (window-start (window-start w))
3721 (while (setq pos (text-property-not-all pos (point-max)
3722 'gnus-date-type nil))
3723 (setq next (or (next-single-property-change pos
3726 (setq type (get-text-property pos 'gnus-date-type))
3727 (when (memq type '(lapsed combined-lapsed user-defined))
3728 (article-date-ut type t pos)
3729 (setq end (or (next-single-property-change pos
3733 (if (/= window-start next)
3734 (setq window-start nil)
3735 (set-window-start w end)))
3738 (goto-char (point-min))
3739 (when (> old-column 0)
3740 (setq old-line (1- old-line)))
3741 (forward-line old-line)
3743 (when (> (current-column) old-column)
3745 (forward-char old-column)))))
3747 (set-buffer buffer))))
3749 (defun gnus-start-date-timer (&optional n)
3750 "Start a timer to update the Date headers in the article buffers.
3751 The numerical prefix says how frequently (in seconds) the function
3756 (gnus-stop-date-timer)
3757 (setq article-lapsed-timer
3758 (run-at-time 1 n 'article-update-date-lapsed)))
3760 (defun gnus-stop-date-timer ()
3761 "Stop the Date timer."
3763 (when article-lapsed-timer
3764 (nnheader-cancel-timer article-lapsed-timer)
3765 (setq article-lapsed-timer nil)))
3767 (defun article-date-user (&optional highlight)
3768 "Convert the current article date to the user-defined format.
3769 This format is defined by the `gnus-article-time-format' variable."
3770 (interactive (list t))
3771 (article-date-ut 'user highlight))
3773 (defun article-date-iso8601 (&optional highlight)
3774 "Convert the current article date to ISO8601."
3775 (interactive (list t))
3776 (article-date-ut 'iso8601 highlight))
3778 (defmacro gnus-article-save-original-date (&rest forms)
3779 "Save the original date as a text property and evaluate FORMS."
3780 `(let* ((case-fold-search t)
3782 (goto-char (point-min))
3783 (when (and (re-search-forward "^date:[\t\n ]+" nil t)
3786 (date (when (and start
3787 (re-search-forward "[\t ]*\n\\(?:[^\t ]\\|\\'\\)"
3789 (buffer-substring-no-properties start
3790 (match-beginning 0)))))
3791 (goto-char (point-max))
3792 (skip-chars-backward "\n")
3793 (put-text-property (point-min) (point) 'original-date date)
3795 (goto-char (point-max))
3796 (skip-chars-backward "\n")
3797 (put-text-property (point-min) (point) 'original-date date)))
3799 ;; (defun article-show-all ()
3800 ;; "Show all hidden text in the article buffer."
3803 ;; (let ((inhibit-read-only t))
3804 ;; (gnus-article-unhide-text (point-min) (point-max)))))
3806 (defun article-remove-leading-whitespace ()
3807 "Remove excessive whitespace from all headers."
3811 (let ((inhibit-read-only t))
3812 (article-narrow-to-head)
3813 (goto-char (point-min))
3814 (while (re-search-forward "^[^ :]+: \\([ \t]+\\)" nil t)
3815 (delete-region (match-beginning 1) (match-end 1)))))))
3817 (defun article-emphasize (&optional arg)
3818 "Emphasize text according to `gnus-emphasis-alist'."
3819 (interactive (gnus-article-hidden-arg))
3820 (unless (gnus-article-check-hidden-text 'emphasis arg)
3824 (with-current-buffer gnus-summary-buffer
3825 gnus-article-emphasis-alist)
3827 gnus-emphasis-alist))
3828 (inhibit-read-only t)
3829 (props (append '(article-type emphasis)
3830 gnus-hidden-properties))
3831 regexp elem beg invisible visible face)
3834 (while (setq elem (pop alist))
3836 (setq regexp (car elem)
3837 invisible (nth 1 elem)
3838 visible (nth 2 elem)
3840 (while (re-search-forward regexp nil t)
3841 (when (and (match-beginning visible) (match-beginning invisible))
3842 (gnus-article-hide-text
3843 (match-beginning invisible) (match-end invisible) props)
3844 (gnus-article-unhide-text-type
3845 (match-beginning visible) (match-end visible) 'emphasis)
3846 (gnus-put-overlay-excluding-newlines
3847 (match-beginning visible) (match-end visible) 'face face)
3848 (gnus-add-wash-type 'emphasis)
3849 (goto-char (match-end invisible)))))))))
3851 (defun gnus-article-setup-highlight-words (&optional highlight-words)
3852 "Setup newsgroup emphasis alist."
3853 (unless gnus-article-emphasis-alist
3854 (let ((name (and gnus-newsgroup-name
3855 (gnus-group-real-name gnus-newsgroup-name))))
3856 (make-local-variable 'gnus-article-emphasis-alist)
3857 (setq gnus-article-emphasis-alist
3859 (let ((alist gnus-group-highlight-words-alist) elem highlight)
3860 (while (setq elem (pop alist))
3861 (when (and name (string-match (car elem) name))
3863 highlight (copy-sequence (cdr elem)))))
3865 (copy-sequence highlight-words)
3866 (if gnus-newsgroup-name
3867 (copy-sequence (gnus-group-find-parameter
3868 gnus-newsgroup-name 'highlight-words t)))
3869 gnus-emphasis-alist)))))
3871 (defvar gnus-summary-article-menu)
3872 (defvar gnus-summary-post-menu)
3874 ;;; Saving functions.
3876 (defun gnus-article-save (save-buffer file &optional num)
3877 "Save the currently selected article."
3878 (when (or (get gnus-default-article-saver :headers)
3879 (not gnus-save-all-headers))
3880 ;; Remove headers according to `gnus-saved-headers' or the value
3881 ;; of the `:headers' property that the saver function might have.
3882 (let ((gnus-visible-headers
3883 (or (symbol-value (get gnus-default-article-saver :headers))
3884 gnus-saved-headers gnus-visible-headers))
3885 ;; Ignore group parameter. See `article-hide-headers'.
3886 (gnus-summary-buffer nil))
3887 (with-current-buffer save-buffer
3888 (article-hide-headers 1 t))))
3889 (save-window-excursion
3890 (if (not gnus-default-article-saver)
3891 (error "No default saver is defined")
3892 ;; !!! Magic! The saving functions all save
3893 ;; `gnus-save-article-buffer' (or so they think), but we
3894 ;; bind that variable to our save-buffer.
3895 (set-buffer gnus-article-buffer)
3896 (let* ((gnus-save-article-buffer save-buffer)
3899 ((not gnus-prompt-before-saving) 'default)
3900 ((eq gnus-prompt-before-saving 'always) nil)
3902 (gnus-number-of-articles-to-be-saved
3903 (when (eq gnus-prompt-before-saving t)
3905 (set-buffer gnus-article-current-summary)
3906 (funcall gnus-default-article-saver filename)))))
3908 (defun gnus-read-save-file-name (prompt &optional filename
3909 function group headers variable
3912 (funcall function group headers (symbol-value variable)))
3917 ((eq filename 'default)
3923 (when (symbol-value dir-var)
3924 (setq default-name (expand-file-name
3925 (file-name-nondirectory default-name)
3926 (symbol-value dir-var))))
3927 (let* ((split-name (gnus-get-split-value gnus-split-methods))
3930 (if (and gnus-number-of-articles-to-be-saved
3931 (> gnus-number-of-articles-to-be-saved 1))
3932 (format "these %d articles"
3933 gnus-number-of-articles-to-be-saved)
3936 ;; Let the split methods have their say.
3938 ;; No split name was found.
3941 (concat prompt " (default "
3942 (file-name-nondirectory default-name) "): ")
3943 (file-name-directory default-name)
3945 ;; A single group name is returned.
3946 ((stringp split-name)
3948 (funcall function split-name headers
3949 (symbol-value variable)))
3951 (concat prompt " (default "
3952 (file-name-nondirectory default-name) "): ")
3953 (file-name-directory default-name)
3955 ;; A single split name was found
3956 ((= 1 (length split-name))
3957 (let* ((name (expand-file-name
3959 gnus-article-save-directory))
3960 (dir (cond ((file-directory-p name)
3961 (file-name-as-directory name))
3962 ((file-exists-p name) name)
3963 (t gnus-article-save-directory))))
3965 (concat prompt " (default " name "): ")
3967 ;; A list of splits was found.
3969 (setq split-name (nreverse split-name))
3971 (let ((file-name-history
3972 (nconc split-name file-name-history)))
3976 (concat prompt " (`M-p' for defaults): ")
3977 gnus-article-save-directory
3979 gnus-article-save-directory)))
3980 (car (push result file-name-history)))))))
3981 ;; Create the directory.
3982 (gnus-make-directory (file-name-directory file))
3983 ;; If we have read a directory, we append the default file name.
3984 (when (file-directory-p file)
3985 (setq file (expand-file-name (file-name-nondirectory
3987 (file-name-as-directory file))))
3988 ;; Possibly translate some characters.
3989 (nnheader-translate-file-chars file))))))
3990 (gnus-make-directory (file-name-directory result))
3992 (set variable result))
3994 (set dir-var (file-name-directory result)))
3997 (defun gnus-article-archive-name (_group)
3998 "Return the first instance of an \"Archive-name\" in the current buffer."
3999 (let ((case-fold-search t))
4000 (when (re-search-forward "archive-name: *\\([^ \n\t]+\\)[ \t]*$" nil t)
4001 (nnheader-concat gnus-article-save-directory
4002 (match-string 1)))))
4004 (defun gnus-article-nndoc-name (group)
4005 "If GROUP is an nndoc group, return the name of the parent group."
4006 (when (eq (car (gnus-find-method-for-group group)) 'nndoc)
4007 (gnus-group-get-parameter group 'save-article-group)))
4009 (defun gnus-summary-save-in-rmail (&optional filename)
4010 "Append this article to Rmail file.
4011 Optional argument FILENAME specifies file name.
4012 Directory to save to is default to `gnus-article-save-directory'."
4013 (setq filename (gnus-read-save-file-name
4014 "Save %s in rmail file" filename
4015 gnus-rmail-save-name gnus-newsgroup-name
4016 gnus-current-headers 'gnus-newsgroup-last-rmail))
4017 (with-current-buffer gnus-save-article-buffer
4021 ;; Note that unlike gnus-summary-save-in-mail, there is no
4022 ;; check to see if filename is Babyl. Rmail in Emacs 23 does
4024 (gnus-output-to-rmail filename))))
4027 (defun gnus-summary-save-in-mail (&optional filename)
4028 "Append this article to Unix mail file.
4029 Optional argument FILENAME specifies file name.
4030 Directory to save to is default to `gnus-article-save-directory'."
4031 (setq filename (gnus-read-save-file-name
4032 "Save %s in Unix mail file" filename
4033 gnus-mail-save-name gnus-newsgroup-name
4034 gnus-current-headers 'gnus-newsgroup-last-mail))
4035 (with-current-buffer gnus-save-article-buffer
4039 (if (and (file-readable-p filename)
4040 (file-regular-p filename)
4041 (mail-file-babyl-p filename))
4042 (gnus-output-to-rmail filename)
4043 (gnus-output-to-mail filename)))))
4046 (put 'gnus-summary-save-in-file :decode t)
4047 (put 'gnus-summary-save-in-file :headers 'gnus-saved-headers)
4048 (defun gnus-summary-save-in-file (&optional filename overwrite)
4049 "Append this article to file.
4050 Optional argument FILENAME specifies file name.
4051 Directory to save to is default to `gnus-article-save-directory'."
4052 (setq filename (gnus-read-save-file-name
4053 "Save %s in file" filename
4054 gnus-file-save-name gnus-newsgroup-name
4055 gnus-current-headers 'gnus-newsgroup-last-file))
4056 (with-current-buffer gnus-save-article-buffer
4060 (when (and overwrite
4061 (file-exists-p filename))
4062 (delete-file filename))
4063 (gnus-output-to-file filename))))
4066 (put 'gnus-summary-write-to-file :decode t)
4067 (put 'gnus-summary-write-to-file :function 'gnus-summary-save-in-file)
4068 (put 'gnus-summary-write-to-file :headers 'gnus-saved-headers)
4069 (defun gnus-summary-write-to-file (&optional filename)
4070 "Write this article to a file, overwriting it if the file exists.
4071 Optional argument FILENAME specifies file name.
4072 The directory to save in defaults to `gnus-article-save-directory'."
4073 (setq filename (gnus-read-save-file-name
4074 "Save %s in file" filename
4075 gnus-file-save-name gnus-newsgroup-name
4076 gnus-current-headers nil 'gnus-newsgroup-last-directory))
4077 (gnus-summary-save-in-file filename t))
4079 (put 'gnus-summary-save-body-in-file :decode t)
4080 (defun gnus-summary-save-body-in-file (&optional filename overwrite)
4081 "Append this article body to a file.
4082 Optional argument FILENAME specifies file name.
4083 The directory to save in defaults to `gnus-article-save-directory'."
4084 (setq filename (gnus-read-save-file-name
4085 "Save %s body in file" filename
4086 gnus-file-save-name gnus-newsgroup-name
4087 gnus-current-headers 'gnus-newsgroup-last-file))
4088 (with-current-buffer gnus-save-article-buffer
4092 (when (article-goto-body)
4093 (narrow-to-region (point) (point-max)))
4094 (when (and overwrite
4095 (file-exists-p filename))
4096 (delete-file filename))
4097 (gnus-output-to-file filename))))
4100 (put 'gnus-summary-write-body-to-file :decode t)
4101 (put 'gnus-summary-write-body-to-file
4102 :function 'gnus-summary-save-body-in-file)
4103 (defun gnus-summary-write-body-to-file (&optional filename)
4104 "Write this article body to a file, overwriting it if the file exists.
4105 Optional argument FILENAME specifies file name.
4106 The directory to save in defaults to `gnus-article-save-directory'."
4107 (setq filename (gnus-read-save-file-name
4108 "Save %s body in file" filename
4109 gnus-file-save-name gnus-newsgroup-name
4110 gnus-current-headers nil 'gnus-newsgroup-last-directory))
4111 (gnus-summary-save-body-in-file filename t))
4113 (put 'gnus-summary-save-in-pipe :decode t)
4114 (put 'gnus-summary-save-in-pipe :headers 'gnus-saved-headers)
4115 (defun gnus-summary-save-in-pipe (&optional command raw)
4116 "Pipe this article to subprocess COMMAND.
4117 Valid values for COMMAND include:
4119 The executable command name and possibly arguments.
4121 You will be prompted for the command in the minibuffer.
4122 the symbol `default'
4123 It will be replaced with the command which the variable
4124 `gnus-summary-pipe-output-default-command' holds or the command
4125 last used for saving.
4126 Non-nil value for RAW overrides `:decode' and `:headers' properties
4127 and the raw article including all headers will be piped."
4128 (let ((article (gnus-summary-article-number))
4130 (get 'gnus-summary-save-in-pipe :decode)))
4131 save-buffer default)
4133 (if (vectorp (gnus-summary-article-header article))
4134 (save-current-buffer
4135 (gnus-summary-select-article decode decode nil article)
4136 (insert-buffer-substring
4140 gnus-original-article-buffer)
4142 (nnheader-set-temp-buffer " *Gnus Save*"))))
4143 ;; Remove unwanted headers.
4144 (when (and (not raw)
4145 (or (get 'gnus-summary-save-in-pipe :headers)
4146 (not gnus-save-all-headers)))
4147 (let ((gnus-visible-headers
4148 (or (symbol-value (get 'gnus-summary-save-in-pipe
4150 gnus-saved-headers gnus-visible-headers))
4151 (gnus-summary-buffer nil))
4152 (article-hide-headers 1 t))))
4153 (error "%d is not a real article" article))
4154 (error "No article to pipe"))
4155 (setq default (or gnus-summary-pipe-output-default-command
4156 gnus-last-shell-command))
4157 (unless (stringp command)
4159 (if (and (eq command 'default) default)
4161 (gnus-read-shell-command "Shell command on this article: "
4163 (when (string-equal command "")
4165 (setq command default)
4166 (error "A command is required")))
4167 (with-current-buffer save-buffer
4170 (shell-command-on-region (point-min) (point-max) command nil)))
4171 (gnus-kill-buffer save-buffer))
4172 (setq gnus-summary-pipe-output-default-command command))
4174 (defun gnus-summary-pipe-to-muttprint (&optional command)
4175 "Pipe this article to muttprint."
4176 (unless (stringp command)
4177 (setq command (read-string
4178 "Print using command: " gnus-summary-muttprint-program
4179 nil gnus-summary-muttprint-program)))
4180 (let ((gnus-summary-pipe-output-default-command
4181 gnus-summary-pipe-output-default-command))
4182 (gnus-summary-save-in-pipe command))
4183 (setq gnus-summary-muttprint-program command))
4185 ;;; Article file names when saving.
4187 (defun gnus-capitalize-newsgroup (newsgroup)
4188 "Capitalize NEWSGROUP name."
4189 (when (not (zerop (length newsgroup)))
4190 (concat (char-to-string (upcase (aref newsgroup 0)))
4191 (substring newsgroup 1))))
4193 (defun gnus-Numeric-save-name (newsgroup headers &optional last-file)
4194 "Generate file name from NEWSGROUP, HEADERS, and optional LAST-FILE.
4195 If variable `gnus-use-long-file-name' is non-nil, it is ~/News/News.group/num.
4196 Otherwise, it is like ~/News/news/group/num."
4199 (concat (if (gnus-use-long-file-name 'not-save)
4200 (gnus-capitalize-newsgroup newsgroup)
4201 (gnus-newsgroup-directory-form newsgroup))
4202 "/" (int-to-string (mail-header-number headers)))
4203 gnus-article-save-directory)))
4205 (string-equal (file-name-directory default)
4206 (file-name-directory last-file))
4207 (string-match "^[0-9]+$" (file-name-nondirectory last-file)))
4209 (or last-file default))))
4211 (defun gnus-numeric-save-name (newsgroup headers &optional last-file)
4212 "Generate file name from NEWSGROUP, HEADERS, and optional LAST-FILE.
4213 If variable `gnus-use-long-file-name' is non-nil, it is
4214 ~/News/news.group/num. Otherwise, it is like ~/News/news/group/num."
4217 (concat (if (gnus-use-long-file-name 'not-save)
4219 (gnus-newsgroup-directory-form newsgroup))
4220 "/" (int-to-string (mail-header-number headers)))
4221 gnus-article-save-directory)))
4223 (string-equal (file-name-directory default)
4224 (file-name-directory last-file))
4225 (string-match "^[0-9]+$" (file-name-nondirectory last-file)))
4227 (or last-file default))))
4229 (defun gnus-plain-save-name (newsgroup _headers &optional last-file)
4230 "Generate file name from NEWSGROUP, HEADERS, and optional LAST-FILE.
4231 If variable `gnus-use-long-file-name' is non-nil, it is
4232 ~/News/news.group. Otherwise, it is like ~/News/news/group/news."
4235 (if (gnus-use-long-file-name 'not-save)
4238 (expand-file-name "news" (gnus-newsgroup-directory-form newsgroup))
4240 gnus-article-save-directory)))
4242 (defun gnus-sender-save-name (_newsgroup headers &optional _last-file)
4243 "Generate file name from sender."
4244 (let ((from (mail-header-from headers)))
4246 (if (and from (string-match "\\([^ <]+\\)@" from))
4247 (match-string 1 from)
4249 gnus-article-save-directory)))
4251 (defun article-verify-x-pgp-sig ()
4253 ;; <ftp://ftp.isc.org/pub/pgpcontrol/FORMAT>
4255 (if (gnus-buffer-live-p gnus-original-article-buffer)
4256 (let ((sig (with-current-buffer gnus-original-article-buffer
4257 (gnus-fetch-field "X-PGP-Sig")))
4261 (mml2015-clear-verify-function))
4263 (insert-buffer-substring gnus-original-article-buffer)
4264 (setq items (split-string sig))
4265 (message-narrow-to-head)
4266 (let ((inhibit-point-motion-hooks t)
4267 (case-fold-search t))
4268 ;; Don't verify multiple headers.
4269 (setq headers (mapconcat (lambda (header)
4271 (mail-fetch-field header)
4273 (split-string (nth 1 items) ",") "")))
4274 (delete-region (point-min) (point-max))
4275 (insert "-----BEGIN PGP SIGNED MESSAGE-----\n\n")
4276 (insert "X-Signed-Headers: " (nth 1 items) "\n")
4281 (if (looking-at "^-")
4284 (insert "\n-----BEGIN PGP SIGNATURE-----\n")
4285 (insert "Version: " (car items) "\n\n")
4286 (insert (mapconcat 'identity (cddr items) "\n"))
4287 (insert "\n-----END PGP SIGNATURE-----\n")
4288 (let ((mm-security-handle (list (format "multipart/signed"))))
4289 (mml2015-clean-buffer)
4290 (let ((coding-system-for-write (or gnus-newsgroup-charset
4292 (funcall (mml2015-clear-verify-function)))
4294 (or (mm-handle-multipart-ctl-parameter
4295 mm-security-handle 'gnus-details)
4296 (mm-handle-multipart-ctl-parameter
4297 mm-security-handle 'gnus-info)))))
4299 (let ((inhibit-read-only t) bface eface)
4301 (message-narrow-to-head)
4302 (goto-char (point-max))
4304 (setq bface (get-text-property (point-at-bol) 'face)
4305 eface (get-text-property (1- (point-at-eol)) 'face))
4306 (message-remove-header "X-Gnus-PGP-Verify")
4307 (if (re-search-forward "^X-PGP-Sig:" nil t)
4309 (goto-char (point-max)))
4310 (narrow-to-region (point) (point))
4311 (insert "X-Gnus-PGP-Verify: " info "\n")
4312 (goto-char (point-min))
4315 (if (not (looking-at "^[ \t]"))
4319 (goto-char (point-min))
4320 (when (looking-at "\\([^:]+\\): *")
4321 (put-text-property (match-beginning 1) (1+ (match-end 1))
4323 (put-text-property (match-end 0) (point-max)
4324 'face eface)))))))))
4326 (autoload 'canlock-verify "canlock" nil t) ;; for XEmacs.
4328 (defun article-verify-cancel-lock ()
4329 "Verify Cancel-Lock header."
4331 (if (gnus-buffer-live-p gnus-original-article-buffer)
4332 (canlock-verify gnus-original-article-buffer)))
4339 (setq afunc (car func)
4342 gfunc (intern (format "gnus-%s" func))))
4344 (when (fboundp afunc)
4345 `(lambda (&optional interactive &rest args)
4346 ,(documentation afunc t)
4347 (interactive (list t))
4348 (with-current-buffer gnus-article-buffer
4350 (call-interactively ',afunc)
4351 (apply ',afunc args))))))))
4352 '(article-hide-headers
4353 article-verify-x-pgp-sig
4354 article-verify-cancel-lock
4355 article-hide-boring-headers
4356 article-treat-overstrike
4357 article-treat-ansi-sequences
4358 article-fill-long-lines
4359 article-capitalize-sentences
4361 article-remove-leading-whitespace
4362 article-display-x-face
4363 article-display-face
4364 article-de-quoted-unreadable
4365 article-de-base64-unreadable
4368 article-unsplit-urls
4369 article-hide-list-identifiers
4370 article-strip-banner
4373 article-hide-signature
4374 article-strip-headers-in-body
4375 article-remove-trailing-blank-lines
4376 article-strip-leading-blank-lines
4377 article-strip-multiple-blank-lines
4378 article-strip-leading-space
4379 article-strip-trailing-space
4380 article-strip-blank-lines
4381 article-strip-all-blank-lines
4383 article-date-english
4384 article-date-iso8601
4385 article-date-original
4388 article-decode-mime-words
4389 article-decode-charset
4390 article-decode-encoded-words
4393 article-date-combined-lapsed
4395 article-treat-dumbquotes
4396 article-treat-non-ascii
4397 article-normalize-headers
4398 ;;(article-show-all . gnus-article-show-all-headers)
4402 ;;; Gnus article mode
4405 (put 'gnus-article-mode 'mode-class 'special)
4407 (set-keymap-parent gnus-article-mode-map widget-keymap)
4409 (gnus-define-keys gnus-article-mode-map
4410 " " gnus-article-goto-next-page
4411 [?\S-\ ] gnus-article-goto-prev-page
4412 "\177" gnus-article-goto-prev-page
4413 [delete] gnus-article-goto-prev-page
4414 "\C-c^" gnus-article-refer-article
4415 "h" gnus-article-show-summary
4416 "s" gnus-article-show-summary
4417 "\C-c\C-m" gnus-article-mail
4418 "?" gnus-article-describe-briefly
4419 "<" beginning-of-buffer
4421 "\C-c\C-i" gnus-info-find-node
4423 "R" gnus-article-reply-with-original
4424 "F" gnus-article-followup-with-original
4425 "\C-hk" gnus-article-describe-key
4426 "\C-hc" gnus-article-describe-key-briefly
4427 "\C-hb" gnus-article-describe-bindings
4429 "e" gnus-article-read-summary-keys
4430 "\C-d" gnus-article-read-summary-keys
4431 "\M-*" gnus-article-read-summary-keys
4432 "\M-#" gnus-article-read-summary-keys
4433 "\M-^" gnus-article-read-summary-keys
4434 "\M-g" gnus-article-read-summary-keys)
4436 (substitute-key-definition
4437 'undefined 'gnus-article-read-summary-keys gnus-article-mode-map)
4439 (defvar gnus-article-send-map)
4441 (gnus-define-keys (gnus-article-send-map "S" gnus-article-mode-map)
4442 "W" gnus-article-wide-reply-with-original)
4443 (if (featurep 'xemacs)
4444 (set-keymap-default-binding gnus-article-send-map
4445 'gnus-article-read-summary-send-keys)
4446 (define-key gnus-article-send-map [t] 'gnus-article-read-summary-send-keys))
4448 (defun gnus-article-make-menu-bar ()
4449 (unless (boundp 'gnus-article-commands-menu)
4450 (gnus-summary-make-menu-bar))
4451 (unless (boundp 'gnus-article-article-menu)
4453 gnus-article-article-menu gnus-article-mode-map ""
4455 ["Scroll forwards" gnus-article-goto-next-page t]
4456 ["Scroll backwards" gnus-article-goto-prev-page t]
4457 ["Show summary" gnus-article-show-summary t]
4458 ["Fetch Message-ID at point" gnus-article-refer-article t]
4459 ["Mail to address at point" gnus-article-mail t]
4460 ["Send a bug report" gnus-bug t]))
4463 gnus-article-treatment-menu gnus-article-mode-map ""
4464 ;; Fixme: this should use :active (and maybe :visible).
4466 ["Hide headers" gnus-article-hide-headers t]
4467 ["Hide signature" gnus-article-hide-signature t]
4468 ["Hide citation" gnus-article-hide-citation t]
4469 ["Treat overstrike" gnus-article-treat-overstrike t]
4470 ["Treat ANSI sequences" gnus-article-treat-ansi-sequences t]
4471 ["Remove carriage return" gnus-article-remove-cr t]
4472 ["Remove leading whitespace" gnus-article-remove-leading-whitespace t]
4473 ["Remove quoted-unreadable" gnus-article-de-quoted-unreadable t]
4474 ["Remove base64" gnus-article-de-base64-unreadable t]
4475 ["Treat html" gnus-article-wash-html t]
4476 ["Remove newlines from within URLs" gnus-article-unsplit-urls t]
4477 ["Decode HZ" gnus-article-decode-HZ t]))
4479 ;; Note "Commands" menu is defined in gnus-sum.el for consistency
4481 ;; Note "Post" menu is defined in gnus-sum.el for consistency
4483 (gnus-run-hooks 'gnus-article-menu-hook)))
4485 (defvar bookmark-make-record-function)
4486 (defvar shr-put-image-function)
4488 (define-derived-mode gnus-article-mode fundamental-mode "Article"
4489 "Major mode for displaying an article.
4491 All normal editing commands are switched off.
4493 The following commands are available in addition to all summary mode
4495 \\<gnus-article-mode-map>
4496 \\[gnus-article-next-page]\t Scroll the article one page forwards
4497 \\[gnus-article-prev-page]\t Scroll the article one page backwards
4498 \\[gnus-article-refer-article]\t Go to the article referred to by an article id near point
4499 \\[gnus-article-show-summary]\t Display the summary buffer
4500 \\[gnus-article-mail]\t Send a reply to the address near point
4501 \\[gnus-article-describe-briefly]\t Describe the current mode briefly
4502 \\[gnus-info-find-node]\t Go to the Gnus info node"
4503 (gnus-simplify-mode-line)
4504 (make-local-variable 'minor-mode-alist)
4505 (when (gnus-visual-p 'article-menu 'menu)
4506 (gnus-article-make-menu-bar)
4507 (when gnus-summary-tool-bar-map
4508 (set (make-local-variable 'tool-bar-map) gnus-summary-tool-bar-map)))
4509 (gnus-update-format-specifications nil 'article-mode)
4510 (set (make-local-variable 'page-delimiter) gnus-page-delimiter)
4511 (set (make-local-variable 'gnus-page-broken) nil)
4512 (make-local-variable 'gnus-article-current-summary)
4513 (make-local-variable 'gnus-article-mime-handles)
4514 (make-local-variable 'gnus-article-decoded-p)
4515 (make-local-variable 'gnus-article-mime-handle-alist)
4516 (make-local-variable 'gnus-article-wash-types)
4517 (make-local-variable 'gnus-article-image-alist)
4518 (make-local-variable 'gnus-article-charset)
4519 (make-local-variable 'gnus-article-ignored-charsets)
4520 (set (make-local-variable 'bookmark-make-record-function)
4521 'gnus-summary-bookmark-make-record)
4522 ;; Prevent Emacs 22 from displaying non-break space with `nobreak-space'
4524 (set (make-local-variable 'nobreak-char-display) nil)
4525 ;; Enable `gnus-article-remove-images' to delete images shr.el renders.
4526 (set (make-local-variable 'shr-put-image-function) 'gnus-shr-put-image)
4527 (setq cursor-in-non-selected-windows nil)
4528 (gnus-set-default-directory)
4529 (buffer-disable-undo)
4530 (setq buffer-read-only t
4531 show-trailing-whitespace nil)
4532 (mm-enable-multibyte))
4534 (defun gnus-article-setup-buffer ()
4535 "Initialize the article buffer."
4536 (let* ((name (if gnus-single-article-buffer "*Article*"
4538 (gnus-group-decoded-name gnus-newsgroup-name)
4541 (progn (string-match "\\*Article" name)
4542 (concat " *Original Article"
4543 (substring name (match-end 0))))))
4544 (setq gnus-article-buffer name)
4545 (setq gnus-original-article-buffer original)
4546 (setq gnus-article-mime-handle-alist nil)
4547 (with-current-buffer gnus-summary-buffer
4548 ;; This might be a variable local to the summary buffer.
4549 (unless gnus-single-article-buffer
4550 (setq gnus-article-buffer name)
4551 (setq gnus-original-article-buffer original)
4552 (gnus-set-global-variables)))
4553 (gnus-article-setup-highlight-words)
4554 ;; Init original article buffer.
4555 (with-current-buffer (gnus-get-buffer-create gnus-original-article-buffer)
4556 (mm-enable-multibyte)
4557 (setq major-mode 'gnus-original-article-mode)
4558 (make-local-variable 'gnus-original-article))
4559 (if (and (get-buffer name)
4560 (with-current-buffer name
4561 (if gnus-article-edit-mode
4562 (if (y-or-n-p "Article mode edit in progress; discard? ")
4564 (set-buffer-modified-p nil)
4565 (gnus-kill-buffer name)
4568 (error "Action aborted"))
4570 (let ((summary gnus-summary-buffer))
4571 (with-current-buffer name
4572 (set (make-local-variable 'gnus-article-edit-mode) nil)
4573 (gnus-article-stop-animations)
4574 (when gnus-article-mime-handles
4575 (mm-destroy-parts gnus-article-mime-handles)
4576 (setq gnus-article-mime-handles nil))
4577 ;; Set it to nil in article-buffer!
4578 (setq gnus-article-mime-handle-alist nil)
4579 (buffer-disable-undo)
4580 (setq buffer-read-only t)
4581 (unless (derived-mode-p 'gnus-article-mode)
4582 (gnus-article-mode))
4583 (set (make-local-variable 'gnus-summary-buffer) summary)
4584 (setq truncate-lines gnus-article-truncate-lines)
4586 (let ((summary gnus-summary-buffer))
4587 (with-current-buffer (gnus-get-buffer-create name)
4589 (setq truncate-lines gnus-article-truncate-lines)
4590 (set (make-local-variable 'gnus-summary-buffer) summary)
4591 (gnus-summary-set-local-parameters gnus-newsgroup-name)
4592 (when article-lapsed-timer
4593 (gnus-stop-date-timer))
4594 (when gnus-article-update-date-headers
4595 (gnus-start-date-timer gnus-article-update-date-headers))
4596 (current-buffer))))))
4598 (defun gnus-article-stop-animations ()
4599 (dolist (timer (and (boundp 'timer-list)
4601 (when (eq (gnus-timer--function timer) 'image-animate-timeout)
4602 (cancel-timer timer))))
4604 (defun gnus-stop-downloads ()
4605 (when (boundp 'url-queue)
4606 (set (intern "url-queue" obarray) nil)))
4608 ;; Set article window start at LINE, where LINE is the number of lines
4609 ;; from the head of the article.
4610 (defun gnus-article-set-window-start (&optional line)
4611 (let ((article-window (gnus-get-buffer-window gnus-article-buffer t)))
4612 (when article-window
4615 (with-current-buffer gnus-article-buffer
4616 (goto-char (point-min))
4619 (gnus-message 6 "Moved to bookmark")
4620 (search-forward "\n\n" nil t)
4624 (defvar gnus-tmp-internal-hook)
4626 (defun gnus-article-prepare (article &optional all-headers _header)
4627 "Prepare ARTICLE in article mode buffer.
4628 ARTICLE should either be an article number or a Message-ID.
4629 If ARTICLE is an id, HEADER should be the article headers.
4630 If ALL-HEADERS is non-nil, no headers are hidden."
4631 (save-excursion ;FIXME: Shouldn't that be save-current-buffer?
4632 ;; Make sure we start in a summary buffer.
4633 (unless (derived-mode-p 'gnus-summary-mode)
4634 (set-buffer gnus-summary-buffer))
4635 (setq gnus-summary-buffer (current-buffer))
4636 (let* ((summary-buffer (current-buffer))
4637 (gnus-tmp-internal-hook gnus-article-internal-prepare-hook)
4638 (group gnus-newsgroup-name)
4641 (gnus-article-setup-buffer)
4642 (set-buffer gnus-article-buffer)
4643 ;; Deactivate active regions.
4644 (when (and (boundp 'transient-mark-mode)
4645 transient-mark-mode)
4646 (setq mark-active nil))
4647 (if (not (setq result (let ((inhibit-read-only t))
4648 (gnus-request-article-this-buffer
4650 ;; There is no such article.
4652 (when (and (numberp article)
4653 (not (memq article gnus-newsgroup-sparse)))
4654 (setq gnus-article-current
4655 (cons gnus-newsgroup-name article))
4656 (set-buffer gnus-summary-buffer)
4657 (setq gnus-current-article article)
4658 (if (and (memq article gnus-newsgroup-undownloaded)
4659 (not (gnus-online (gnus-find-method-for-group
4660 gnus-newsgroup-name))))
4662 (gnus-summary-set-agent-mark article)
4663 (message "Message marked for downloading"))
4664 (gnus-summary-mark-article article gnus-canceled-mark)
4665 (unless (memq article gnus-newsgroup-sparse)
4666 (gnus-error 1 "No such article (may have expired or been canceled)")))))
4667 (if (or (eq result 'pseudo)
4668 (eq result 'nneething))
4670 (with-current-buffer summary-buffer
4671 (push article gnus-newsgroup-history)
4672 (setq gnus-last-article gnus-current-article
4673 gnus-current-article 0
4674 gnus-current-headers nil
4675 gnus-article-current nil)
4676 (if (eq result 'nneething)
4677 (gnus-configure-windows 'summary)
4678 (gnus-configure-windows 'article))
4679 (gnus-set-global-variables))
4680 (let ((gnus-article-mime-handle-alist-1
4681 gnus-article-mime-handle-alist))
4682 (gnus-set-mode-line 'article)))
4683 ;; The result from the `request' was an actual article -
4684 ;; or at least some text that is now displayed in the
4686 (when (and (numberp article)
4687 (not (eq article gnus-current-article)))
4688 ;; Seems like a new article has been selected.
4689 ;; `gnus-current-article' must be an article number.
4690 (with-current-buffer summary-buffer
4691 (push article gnus-newsgroup-history)
4692 (setq gnus-last-article gnus-current-article
4693 gnus-current-article article
4694 gnus-current-headers
4695 (gnus-summary-article-header gnus-current-article)
4696 gnus-article-current
4697 (cons gnus-newsgroup-name gnus-current-article))
4698 (unless (vectorp gnus-current-headers)
4699 (setq gnus-current-headers nil))
4700 (gnus-summary-goto-subject gnus-current-article)
4701 (when (gnus-summary-show-thread)
4702 ;; If the summary buffer really was folded, the
4703 ;; previous goto may not actually have gone to
4704 ;; the right article, but the thread root instead.
4706 (gnus-summary-goto-subject gnus-current-article))
4707 (gnus-run-hooks 'gnus-mark-article-hook)
4708 (gnus-set-mode-line 'summary)
4709 (when (gnus-visual-p 'article-highlight 'highlight)
4710 (gnus-run-hooks 'gnus-visual-mark-article-hook))
4711 ;; Set the global newsgroup variables here.
4712 (gnus-set-global-variables)
4713 (setq gnus-have-all-headers
4714 (or all-headers gnus-show-all-headers))))
4716 (gnus-configure-windows 'article))
4717 (when (or (numberp article)
4719 (gnus-article-prepare-display)
4721 (goto-char (point-min))
4722 (when gnus-break-pages
4723 (gnus-narrow-to-page)))
4724 (let ((gnus-article-mime-handle-alist-1
4725 gnus-article-mime-handle-alist))
4726 (gnus-set-mode-line 'article))
4730 (set-window-point (get-buffer-window (current-buffer)) (point))
4731 (gnus-configure-windows 'article)
4732 (gnus-run-hooks 'gnus-article-prepare-hook)
4735 (defvar gnus-mime-display-attachment-buttons-in-header)
4738 (defun gnus-article-prepare-display ()
4739 "Make the current buffer look like a nice article."
4740 ;; Hooks for getting information from the article.
4741 ;; This hook must be called before being narrowed.
4742 (let ((gnus-article-buffer (current-buffer))
4744 (inhibit-read-only t))
4745 (unless (derived-mode-p 'gnus-article-mode)
4746 (gnus-article-mode))
4747 (setq buffer-read-only nil
4748 gnus-article-wash-types nil
4749 gnus-article-image-alist nil)
4750 (gnus-run-hooks 'gnus-tmp-internal-hook)
4751 (when gnus-display-mime-function
4752 (funcall gnus-display-mime-function))
4753 ;; Add attachment buttons to the header.
4754 (when gnus-mime-display-attachment-buttons-in-header
4755 (gnus-mime-buttonize-attachments-in-header))))
4758 ;;; Gnus Sticky Article Mode
4761 (define-derived-mode gnus-sticky-article-mode gnus-article-mode "StickyArticle"
4762 "Mode for sticky articles."
4763 ;; Release bindings that won't work.
4764 (substitute-key-definition 'gnus-article-read-summary-keys 'undefined
4765 gnus-sticky-article-mode-map)
4766 (substitute-key-definition 'gnus-article-refer-article 'undefined
4767 gnus-sticky-article-mode-map)
4768 (dolist (k '("e" "h" "s" "F" "R"))
4769 (define-key gnus-sticky-article-mode-map k nil))
4770 (define-key gnus-sticky-article-mode-map "k" 'gnus-kill-sticky-article-buffer)
4771 (define-key gnus-sticky-article-mode-map "q" 'bury-buffer)
4772 (define-key gnus-sticky-article-mode-map "\C-hc" 'describe-key-briefly)
4773 (define-key gnus-sticky-article-mode-map "\C-hk" 'describe-key))
4775 (defun gnus-sticky-article (arg)
4776 "Make the current article sticky.
4777 If a prefix ARG is given, ask for a name for this sticky article buffer."
4779 (gnus-summary-show-thread)
4780 (gnus-summary-select-article nil nil 'pseudo)
4781 (let (new-art-buf-name)
4782 (gnus-eval-in-buffer-window gnus-article-buffer
4783 (setq new-art-buf-name
4787 (read-from-minibuffer "Sticky article buffer name: ")
4788 (gnus-with-article-headers
4789 (gnus-article-goto-header "subject")
4790 (setq new-art-buf-name
4791 (buffer-substring-no-properties
4792 (line-beginning-position) (line-end-position)))
4793 (goto-char (point-min))
4794 (gnus-article-goto-header "from")
4795 (setq new-art-buf-name
4797 new-art-buf-name ", "
4798 (buffer-substring-no-properties
4799 (line-beginning-position) (line-end-position))))
4800 (goto-char (point-min))
4801 (gnus-article-goto-header "date")
4802 (setq new-art-buf-name
4804 new-art-buf-name ", "
4805 (buffer-substring-no-properties
4806 (line-beginning-position) (line-end-position))))))
4808 (if (and (gnus-buffer-live-p new-art-buf-name)
4809 (with-current-buffer new-art-buf-name
4810 (derived-mode-p 'gnus-sticky-article-mode)))
4811 (switch-to-buffer new-art-buf-name)
4812 (setq new-art-buf-name (rename-buffer new-art-buf-name t)))
4813 (gnus-sticky-article-mode))
4814 (setq gnus-article-buffer new-art-buf-name))
4815 (gnus-summary-recenter)
4816 (gnus-summary-position-point))
4818 (defun gnus-kill-sticky-article-buffer (&optional buffer)
4819 "Kill the given sticky article BUFFER.
4820 If none is given, assume the current buffer and kill it if it has
4821 `gnus-sticky-article-mode'."
4824 (setq buffer (current-buffer)))
4825 (with-current-buffer buffer
4826 (when (derived-mode-p 'gnus-sticky-article-mode)
4827 (gnus-kill-buffer buffer))))
4829 (defun gnus-kill-sticky-article-buffers (arg)
4830 "Kill all sticky article buffers.
4831 If a prefix ARG is given, ask for confirmation."
4833 (dolist (buf (gnus-buffers))
4834 (with-current-buffer buf
4835 (when (derived-mode-p 'gnus-sticky-article-mode)
4837 (gnus-kill-buffer buf)
4838 (when (yes-or-no-p (concat "Kill buffer " (buffer-name buf) "? "))
4839 (gnus-kill-buffer buf)))))))
4842 ;;; Gnus MIME viewing functions
4845 (defvar gnus-mime-button-line-format "%{%([%p. %d%T]%)%}%e\n"
4846 "Format of the MIME buttons.
4848 Valid specifiers include:
4850 %T MIME type, along with additional info
4851 %n The `name' parameter
4852 %d The description, if any
4853 %l The length of the encoded part
4854 %p The part identifier number
4855 %e Dots if the part isn't displayed
4857 General format specifiers can also be used. See Info node
4858 `(gnus)Formatting Variables'.")
4860 (defvar gnus-tmp-type)
4861 (defvar gnus-tmp-type-long)
4862 (defvar gnus-tmp-name)
4863 (defvar gnus-tmp-description)
4864 (defvar gnus-tmp-id)
4865 (defvar gnus-tmp-length)
4866 (defvar gnus-tmp-dots)
4867 (defvar gnus-tmp-info)
4868 (defvar gnus-tmp-pressed-details)
4870 (defvar gnus-mime-button-line-format-alist
4871 '((?t gnus-tmp-type ?s)
4872 (?T gnus-tmp-type-long ?s)
4873 (?n gnus-tmp-name ?s)
4874 (?d gnus-tmp-description ?s)
4876 (?l gnus-tmp-length ?d)
4877 (?e gnus-tmp-dots ?s)))
4879 (defvar gnus-mime-button-commands
4880 '((gnus-article-press-button "\r" "Toggle Display")
4881 (gnus-mime-view-part "v" "View Interactively...")
4882 (gnus-mime-view-part-as-type "t" "View As Type...")
4883 (gnus-mime-view-part-as-charset "C" "View As charset...")
4884 (gnus-mime-save-part "o" "Save...")
4885 (gnus-mime-save-part-and-strip "\C-o" "Save and Strip")
4886 (gnus-mime-replace-part "r" "Replace part")
4887 (gnus-mime-delete-part "d" "Delete part")
4888 (gnus-mime-copy-part "c" "View As Text, In Other Buffer")
4889 (gnus-mime-inline-part "i" "View As Text, In This Buffer")
4890 (gnus-mime-view-part-internally "E" "View Internally") ;; Why `E'?
4891 (gnus-mime-view-part-externally "e" "View Externally")
4892 (gnus-mime-print-part "p" "Print")
4893 (gnus-mime-pipe-part "|" "Pipe To Command...")
4894 (gnus-mime-action-on-part "." "Take action on the part...")))
4896 (defun gnus-article-mime-part-status ()
4897 (if gnus-article-mime-handle-alist-1
4898 (if (eq 1 (length gnus-article-mime-handle-alist-1))
4900 (format " (%d parts)" (length gnus-article-mime-handle-alist-1)))
4903 (defvar gnus-mime-button-map
4904 (let ((map (make-sparse-keymap)))
4905 (define-key map gnus-mouse-2 'gnus-article-push-button)
4906 (define-key map gnus-down-mouse-3 'gnus-mime-button-menu)
4907 (dolist (c gnus-mime-button-commands)
4908 (define-key map (cadr c) (car c)))
4912 gnus-mime-button-menu gnus-mime-button-map "MIME button menu."
4914 ,@(mapcar (lambda (c)
4915 (vector (caddr c) (car c) :active t))
4916 gnus-mime-button-commands)))
4918 (defvar gnus-url-button-commands
4919 '((gnus-article-copy-string "u" "Copy URL to kill ring")))
4921 (defvar gnus-url-button-map
4922 (let ((map (make-sparse-keymap)))
4923 (dolist (c gnus-url-button-commands)
4924 (define-key map (cadr c) (car c)))
4928 gnus-url-button-menu gnus-url-button-map "URL button menu."
4930 ,@(mapcar (lambda (c)
4931 (vector (caddr c) (car c) :active t))
4932 gnus-url-button-commands)))
4934 (defmacro gnus-bind-safe-url-regexp (&rest body)
4935 "Bind `mm-w3m-safe-url-regexp' according to `gnus-safe-html-newsgroups'."
4936 `(let ((mm-w3m-safe-url-regexp
4937 (let ((group (if (and (derived-mode-p 'gnus-article-mode)
4939 gnus-article-current-summary))
4940 (with-current-buffer gnus-article-current-summary
4941 gnus-newsgroup-name)
4942 gnus-newsgroup-name)))
4943 (if (cond ((not group)
4944 ;; Maybe we're in a mml-preview buffer
4945 ;; and no group is selected.
4947 ((stringp gnus-safe-html-newsgroups)
4948 (string-match gnus-safe-html-newsgroups group))
4949 ((consp gnus-safe-html-newsgroups)
4950 (member group gnus-safe-html-newsgroups)))
4952 mm-w3m-safe-url-regexp))))
4955 (defun gnus-mime-button-menu (event prefix)
4956 "Construct a context-sensitive menu of MIME commands."
4957 (interactive "e\nP")
4958 (save-window-excursion
4959 (let ((pos (event-start event)))
4960 (select-window (posn-window pos))
4961 (goto-char (posn-point pos))
4962 (gnus-article-check-buffer)
4963 (popup-menu gnus-mime-button-menu nil prefix))))
4965 (defun gnus-mime-view-all-parts (&optional handles)
4966 "View all the MIME parts."
4968 (with-current-buffer gnus-article-buffer
4969 (let ((handles (or handles gnus-article-mime-handles))
4970 (mail-parse-charset gnus-newsgroup-charset)
4971 (mail-parse-ignored-charsets
4972 (with-current-buffer gnus-summary-buffer
4973 gnus-newsgroup-ignored-charsets)))
4975 (mm-remove-parts handles)
4976 (goto-char (point-min))
4977 (or (search-forward "\n\n") (goto-char (point-max)))
4978 (let ((inhibit-read-only t))
4979 (delete-region (point) (point-max))
4980 (gnus-bind-safe-url-regexp (mm-display-parts handles)))))))
4982 (defun gnus-article-jump-to-part (n)
4983 "Jump to MIME part N."
4985 (let ((parts (with-current-buffer gnus-article-buffer
4986 (length gnus-article-mime-handle-alist))))
4988 (error "No such part"))
4989 (pop-to-buffer gnus-article-buffer)
4991 (setq n (if (= parts 1)
4993 (read-number (format "Jump to part (1..%s): " parts)))))
4994 (unless (and (integerp n) (<= n parts) (>= n 1))
4997 (gnus-message 7 "Invalid part `%s', using %s instead."
5000 (gnus-message 9 "Jumping to part %s." n)
5001 (cond ((>= gnus-auto-select-part 1)
5002 (while (and (<= n parts)
5003 (not (gnus-article-goto-part n)))
5005 ((< gnus-auto-select-part 0)
5006 (while (and (>= n 1)
5007 (not (gnus-article-goto-part n)))
5010 (gnus-article-goto-part n)))))
5012 (defvar gnus-mime-buttonized-part-id nil
5013 "ID of a mime part that should be buttonized.
5014 `gnus-mime-save-part-and-strip' and `gnus-mime-delete-part' bind it.")
5017 (defsubst gnus-article-edit-part (handles &optional current-id)
5018 "Edit an article in order to delete a mime part.
5019 This function is exclusively used by `gnus-mime-save-part-and-strip'
5020 and `gnus-mime-delete-part', and not provided at run-time normally."
5021 (gnus-article-edit-article
5023 (buffer-disable-undo)
5024 (let ((mail-parse-charset (or gnus-article-charset
5025 ',gnus-newsgroup-charset))
5026 (mail-parse-ignored-charsets
5027 (or gnus-article-ignored-charsets
5028 ',gnus-newsgroup-ignored-charsets))
5029 (mbl mml-buffer-list))
5030 (setq mml-buffer-list nil)
5031 ;; A new text must be inserted before deleting existing ones
5032 ;; at the end so as not to move existing markers of which
5033 ;; the insertion type is t.
5037 (goto-char (point-max))
5038 (insert-buffer-substring gnus-original-article-buffer)))
5039 (mime-to-mml ',handles)
5040 (setq gnus-article-mime-handles nil)
5041 (let ((mbl1 mml-buffer-list))
5042 (setq mml-buffer-list mbl)
5043 (set (make-local-variable 'mml-buffer-list) mbl1))
5044 (gnus-make-local-hook 'kill-buffer-hook)
5045 (add-hook 'kill-buffer-hook 'mml-destroy-buffers t t)))
5046 `(lambda (no-highlight)
5047 (let ((mail-parse-charset (or gnus-article-charset
5048 ',gnus-newsgroup-charset))
5049 (message-options message-options)
5050 (message-options-set-recipient)
5051 (mail-parse-ignored-charsets
5052 (or gnus-article-ignored-charsets
5053 ',gnus-newsgroup-ignored-charsets)))
5055 (mml-destroy-buffers)
5056 (remove-hook 'kill-buffer-hook
5057 'mml-destroy-buffers t)
5058 (kill-local-variable 'mml-buffer-list))
5059 (gnus-summary-edit-article-done
5060 ,(or (mail-header-references gnus-current-headers) "")
5061 ,(gnus-group-read-only-p)
5062 ,gnus-summary-buffer no-highlight))
5064 ;; Force buttonizing this part.
5065 (let ((gnus-mime-buttonized-part-id current-id))
5066 (gnus-article-edit-done))
5067 (gnus-configure-windows 'article)
5069 (when (and current-id (integerp gnus-auto-select-part))
5070 (gnus-article-jump-to-part
5071 (min (max (+ current-id gnus-auto-select-part) 1)
5072 (with-current-buffer gnus-article-buffer
5073 (length gnus-article-mime-handle-alist)))))))
5075 (defun gnus-mime-replace-part (file)
5076 "Replace MIME part under point with an external body."
5077 ;; Useful if file has already been saved to disk
5080 (read-file-name "Replace MIME part with file: "
5081 (or mm-default-directory default-directory)
5083 (gnus-mime-save-part-and-strip file))
5085 (defun gnus-mime-save-part-and-strip (&optional file)
5086 "Save the MIME part under point then replace it with an external body.
5087 If FILE is given, use it for the external part."
5089 (gnus-article-check-buffer)
5090 (when (gnus-group-read-only-p)
5091 (error "The current group does not support deleting of parts"))
5092 (when (mm-complicated-handles gnus-article-mime-handles)
5094 The current article has a complicated MIME structure, giving up..."))
5095 (let* ((data (get-text-property (point) 'gnus-data))
5096 (id (get-text-property (point) 'gnus-part))
5097 (handles gnus-article-mime-handles))
5100 (and data (mm-save-part data "Delete MIME part and save to: "))))
5102 (with-current-buffer (mm-handle-buffer data)
5104 (insert "Content-Type: " (mm-handle-media-type data))
5105 (mml-insert-parameter-string (cdr (mm-handle-type data))
5107 ;; Add a filename for the sake of saving the part again.
5108 (mml-insert-parameter
5109 (mail-header-encode-parameter "name" (file-name-nondirectory file)))
5111 (insert "Content-ID: " (message-make-message-id) "\n")
5112 (insert "Content-Transfer-Encoding: binary\n")
5115 (cdr (mm-make-handle nil
5116 `("message/external-body"
5117 (access-type . "LOCAL-FILE")
5119 ;; (set-buffer gnus-summary-buffer)
5120 (gnus-article-edit-part handles id))))
5122 ;; A function like `gnus-summary-save-parts' (`X m', `<MIME> <Extract all
5123 ;; parts...>') but with stripping would be nice.
5125 (defun gnus-mime-delete-part ()
5126 "Delete the MIME part under point.
5127 Replace it with some information about the removed part."
5129 (gnus-article-check-buffer)
5130 (when (gnus-group-read-only-p)
5131 (error "The current group does not support deleting of parts"))
5132 (when (mm-complicated-handles gnus-article-mime-handles)
5134 The current article has a complicated MIME structure, giving up..."))
5135 (when (or gnus-expert-user
5136 (gnus-yes-or-no-p "\
5137 Deleting parts may malfunction or destroy the article; continue? "))
5138 (let* ((data (get-text-property (point) 'gnus-data))
5139 (id (get-text-property (point) 'gnus-part))
5140 (handles gnus-article-mime-handles)
5142 (let ((desc (mm-handle-description data)))
5144 (mail-decode-encoded-word-string desc))))
5145 (filename (or (mm-handle-filename data) "(none)"))
5146 (type (mm-handle-media-type data)))
5148 (error "No MIME part under point"))
5149 (with-current-buffer (mm-handle-buffer data)
5150 (let ((bsize (buffer-size)))
5155 "| The following attachment has been deleted:\n"
5157 "| Type: " type "\n"
5158 "| Filename: " filename "\n"
5159 "| Size (encoded): " (format "%s byte%s\n"
5160 bsize (if (= bsize 1)
5164 (concat "| Description: " description "\n"))
5167 (cdr (mm-make-handle
5168 nil `("text/plain" (charset . gnus-decoded)) nil nil
5170 (format "Deleted attachment (%s bytes)" bsize))))))
5171 ;; (set-buffer gnus-summary-buffer)
5172 (gnus-article-edit-part handles id))))
5174 (defun gnus-mime-save-part ()
5175 "Save the MIME part under point."
5177 (gnus-article-check-buffer)
5178 (let ((data (get-text-property (point) 'gnus-data)))
5180 (mm-save-part data))))
5182 (defun gnus-mime-pipe-part (&optional cmd)
5183 "Pipe the MIME part under point to a process.
5184 Use CMD as the process."
5186 (gnus-article-check-buffer)
5187 (let ((data (get-text-property (point) 'gnus-data)))
5189 (mm-pipe-part data cmd))))
5191 (defun gnus-mime-view-part ()
5192 "Interactively choose a viewing method for the MIME part under point."
5194 (gnus-article-check-buffer)
5195 (let ((data (get-text-property (point) 'gnus-data)))
5197 (setq gnus-article-mime-handles
5199 gnus-article-mime-handles (setq data (copy-sequence data))))
5200 (mm-interactively-view-part data))))
5202 (defun gnus-mime-view-part-as-type-internal ()
5203 (gnus-article-check-buffer)
5204 (let* ((handle (get-text-property (point) 'gnus-data))
5206 ;; Content-Type: foo/bar; name=...
5207 (mail-content-type-get (mm-handle-type handle) 'name)
5208 ;; Content-Disposition: attachment; filename=...
5209 (cdr (assq 'filename (cdr (mm-handle-disposition handle))))))
5210 (def-type (and name (mm-default-file-encoding name))))
5211 (or (and def-type (cons def-type 0))
5213 (equal (mm-handle-media-supertype handle) "text")
5214 '("text/plain" . 0))
5215 '("application/octet-stream" . 0))))
5217 (defun gnus-mime-view-part-as-type (&optional mime-type pred)
5218 "Choose a MIME media type, and view the part as such.
5219 If non-nil, PRED is a predicate to use during completion to limit the
5220 available media-types."
5224 (let ((default (gnus-mime-view-part-as-type-internal)))
5225 (gnus-completing-read
5228 (gnus-remove-if-not pred (mailcap-mime-types))
5229 (mailcap-mime-types))
5232 (gnus-article-check-buffer)
5233 (let ((handle (get-text-property (point) 'gnus-data)))
5235 (when (equal (mm-handle-media-type handle) "message/external-body")
5236 (unless (mm-handle-cache handle)
5237 (mm-extern-cache-contents handle))
5238 (setq handle (mm-handle-cache handle)))
5240 (mm-make-handle (mm-handle-buffer handle)
5241 (cons mime-type (cdr (mm-handle-type handle)))
5242 (mm-handle-encoding handle)
5243 (mm-handle-undisplayer handle)
5244 (mm-handle-disposition handle)
5245 (mm-handle-description handle)
5247 (mm-handle-id handle)))
5248 (setq gnus-article-mime-handles
5249 (mm-merge-handles gnus-article-mime-handles handle))
5250 (when (mm-handle-displayed-p handle)
5251 (mm-remove-part handle))
5252 (gnus-mm-display-part handle))))
5254 (defun gnus-mime-copy-part (&optional handle arg)
5255 "Put the MIME part under point into a new buffer.
5256 If `auto-compression-mode' is enabled, compressed files like .gz and .bz2
5258 (interactive (list nil current-prefix-arg))
5259 (gnus-article-check-buffer)
5261 (setq handle (get-text-property (point) 'gnus-data)))
5263 (let ((filename (mm-handle-filename handle))
5264 contents dont-decode charset coding-system)
5265 (mm-with-unibyte-buffer
5266 (mm-insert-part handle)
5267 (setq contents (or (condition-case nil
5268 (mm-decompress-buffer filename nil 'sig)
5270 (setq dont-decode t)
5273 (setq filename (cond (filename (file-name-nondirectory filename))
5274 (dont-decode "*raw data*")
5279 (unless (setq charset (mail-content-type-get
5280 (mm-handle-type handle) 'charset))
5281 (unless (setq coding-system (mm-with-unibyte-buffer
5283 (mm-find-buffer-file-coding-system)))
5284 (setq charset gnus-newsgroup-charset))))
5286 (setq charset (or (cdr (assq arg
5287 gnus-summary-show-article-charset-alist))
5288 (mm-read-coding-system "Charset: ")))))
5289 (switch-to-buffer (generate-new-buffer filename))
5290 (if (or coding-system
5292 (setq coding-system (mm-charset-to-coding-system
5294 (not (eq coding-system 'ascii))))
5296 (mm-enable-multibyte)
5297 (insert (mm-decode-coding-string contents coding-system))
5298 (setq buffer-file-coding-system
5299 (if (boundp 'last-coding-system-used)
5300 (symbol-value 'last-coding-system-used)
5302 (mm-disable-multibyte)
5304 (setq buffer-file-coding-system mm-binary-coding-system))
5305 ;; We do it this way to make `normal-mode' set the appropriate mode.
5308 (setq buffer-file-name (expand-file-name filename))
5310 (setq buffer-file-name nil))
5311 (goto-char (point-min)))))
5313 (defun gnus-mime-print-part (&optional handle filename)
5314 "Print the MIME part under point."
5315 (interactive (list nil (ps-print-preprint current-prefix-arg)))
5316 (gnus-article-check-buffer)
5317 (let* ((handle (or handle (get-text-property (point) 'gnus-data)))
5318 (contents (and handle (mm-get-part handle)))
5319 (file (mm-make-temp-file (expand-file-name "mm." mm-tmp-directory)))
5320 (printer (mailcap-mime-info (mm-handle-media-type handle) "print")))
5325 (mm-save-part-to-file handle file)
5326 (call-process shell-file-name nil
5327 (generate-new-buffer " *mm*")
5329 shell-command-switch
5331 printer file (mm-handle-type handle))))
5335 (gnus-print-buffer))
5336 (ps-despool filename)))))
5338 (defun gnus-mime-inline-part (&optional handle arg)
5339 "Insert the MIME part under point into the current buffer.
5340 Compressed files like .gz and .bz2 are decompressed."
5341 (interactive (list nil current-prefix-arg))
5342 (gnus-article-check-buffer)
5343 (let* ((inhibit-read-only t)
5345 (btn ;; position where the MIME button exists
5347 (if (eq handle (get-text-property b 'gnus-data))
5350 (or (text-property-any (point) (point-max) 'gnus-data handle)
5351 (text-property-any (point-min) (point) 'gnus-data handle)))
5352 (setq handle (get-text-property b 'gnus-data))
5358 (setq start (next-single-property-change btn 'gnus-data
5360 btn (previous-single-property-change start
5363 (if (and (not arg) (mm-handle-undisplayer handle))
5365 (setq b (copy-marker b)
5366 btn (copy-marker btn))
5367 (mm-remove-part handle))
5371 (if (mm-handle-undisplayer handle)
5372 (mm-remove-part handle)))
5373 ((mm-handle-undisplayer handle)
5374 (mm-remove-part handle)))
5377 ;; This is a header button.
5379 (mm-display-inline handle))
5380 ;; Toggle the button appearance between `[button]...' and `[button]'.
5382 (setq btn (prog1 (marker-position btn)
5383 (set-marker btn nil))))
5385 (let ((displayed-p (mm-handle-displayed-p handle)))
5386 (gnus-insert-mime-button handle (get-text-property btn 'gnus-part)
5388 (if (featurep 'emacs)
5391 (next-single-property-change (point) 'gnus-data nil (point-max)))
5392 (let* ((end (next-single-property-change (point) 'gnus-data))
5393 (annots (annotations-at (or end (point-max)))))
5394 (delete-region (point)
5396 (if annots (1+ end) end)
5398 (dolist (annot annots)
5399 (set-extent-endpoints annot (point) (point)))))
5400 (setq start (point))
5401 (if (search-backward "\n\n" nil t)
5404 (unless (or displayed-p (eolp))
5405 ;; Add extra newline.
5406 (insert (propertize (buffer-substring (1- start) start)
5407 'gnus-undeletable t))))
5408 ;; We're in the article header.
5410 (dolist (ovl (gnus-overlays-in btn (point)))
5411 (gnus-overlay-put ovl 'gnus-button-attachment-extra t)
5412 (gnus-overlay-put ovl 'face nil))
5414 (message-narrow-to-field)
5415 (let ((gnus-treatment-function-alist
5416 '((gnus-treat-highlight-headers
5417 gnus-article-highlight-headers))))
5418 (gnus-treat-article 'head)))))
5420 (setq b (prog1 (marker-position b)
5421 (set-marker b nil))))
5424 (defun gnus-mime-set-charset-parameters (handle charset)
5425 "Set CHARSET to parameters in HANDLE.
5426 CHARSET may either be a string or a symbol."
5427 (unless (stringp charset)
5428 (setq charset (symbol-name charset)))
5429 (if (stringp (car handle))
5430 (dolist (h (cdr handle))
5431 (gnus-mime-set-charset-parameters h charset))
5432 (let* ((type (mm-handle-type (if (equal (mm-handle-media-type handle)
5433 "message/external-body")
5435 (unless (mm-handle-cache handle)
5436 (mm-extern-cache-contents handle))
5437 (mm-handle-cache handle))
5439 (param (assq 'charset (cdr type))))
5441 (setcdr param charset)
5442 (setcdr type (cons (cons 'charset charset) (cdr type)))))))
5444 (defun gnus-mime-view-part-as-charset (&optional handle arg)
5445 "Insert the MIME part under point into the current buffer using the
5447 (interactive (list nil current-prefix-arg))
5448 (gnus-article-check-buffer)
5449 (let ((handle (or handle (get-text-property (point) 'gnus-data)))
5450 (fun (get-text-property (point) 'gnus-callback))
5451 (gnus-newsgroup-ignored-charsets 'gnus-all)
5452 charset form preferred parts)
5459 gnus-summary-show-article-charset-alist))
5460 (mm-read-coding-system "Charset: "))))
5461 (if (mm-handle-undisplayer handle)
5462 (mm-remove-part handle)))
5463 (gnus-mime-set-charset-parameters handle charset)
5464 (when (and (consp (setq form (cdr-safe fun)))
5465 (setq form (ignore-errors
5466 (assq 'gnus-mime-display-alternative form)))
5467 (setq preferred (caddr form))
5469 (when (eq (car preferred) 'quote)
5470 (setq preferred (cadr preferred)))
5471 (not (equal preferred
5472 (get-text-property (point) 'gnus-data))))
5473 (setq parts (get-text-property (point) 'gnus-part))
5474 (setq parts (cdr (assq parts
5475 gnus-article-mime-handle-alist)))
5476 (equal (mm-handle-media-type parts) "multipart/alternative")
5477 (setq parts (reverse (cdr parts))))
5479 (list 'quote (or (cadr (member preferred parts))
5481 (funcall fun handle)))))
5483 (defun gnus-mime-view-part-externally (&optional handle)
5484 "View the MIME part under point with an external viewer."
5486 (gnus-article-check-buffer)
5487 (let* ((handle (or handle (get-text-property (point) 'gnus-data)))
5488 (mm-inlined-types nil)
5489 (mail-parse-charset gnus-newsgroup-charset)
5490 (mail-parse-ignored-charsets
5491 (with-current-buffer gnus-summary-buffer
5492 gnus-newsgroup-ignored-charsets))
5493 (type (mm-handle-media-type handle))
5494 (method (mailcap-mime-info type))
5495 (mm-enable-external t))
5496 (if (not (stringp method))
5497 (gnus-mime-view-part-as-type
5498 nil (lambda (type) (stringp (mailcap-mime-info type))))
5500 (mm-display-part handle nil t)))))
5502 (defun gnus-mime-view-part-internally (&optional handle)
5503 "View the MIME part under point with an internal viewer.
5504 If no internal viewer is available, use an external viewer."
5506 (gnus-article-check-buffer)
5507 (let* ((handle (or handle (get-text-property (point) 'gnus-data)))
5508 (mm-inlined-types '(".*"))
5509 (mm-inline-large-images t)
5510 (mail-parse-charset gnus-newsgroup-charset)
5511 (mail-parse-ignored-charsets
5512 (with-current-buffer gnus-summary-buffer
5513 gnus-newsgroup-ignored-charsets))
5514 (inhibit-read-only t))
5515 (if (not (mm-inlinable-p handle))
5516 (gnus-mime-view-part-as-type
5517 nil (lambda (type) (mm-inlinable-p handle type)))
5519 (gnus-bind-safe-url-regexp
5520 (mm-display-part handle nil t))))))
5522 (defun gnus-mime-action-on-part (&optional action)
5523 "Do something with the MIME attachment at \(point\)."
5525 (list (gnus-completing-read "Action" (mapcar 'car gnus-mime-action-alist) t)))
5526 (gnus-article-check-buffer)
5527 (let ((action-pair (assoc action gnus-mime-action-alist)))
5529 (funcall (cdr action-pair)))))
5531 (defun gnus-article-part-wrapper (n function &optional no-handle interactive)
5532 "Call FUNCTION on MIME part N.
5533 Unless NO-HANDLE, call FUNCTION with N-th MIME handle as its only argument.
5534 If INTERACTIVE, call FUNCTION interactively."
5536 ;; Check whether the article is displayed.
5537 (unless (and (gnus-buffer-live-p gnus-article-buffer)
5538 (setq window (get-buffer-window gnus-article-buffer t))
5539 (frame-visible-p (setq frame (window-frame window))))
5540 (error "No article is displayed"))
5541 (with-current-buffer gnus-article-buffer
5542 ;; Check whether the article displays the right contents.
5543 (unless (with-current-buffer gnus-summary-buffer
5544 (eq gnus-current-article (gnus-summary-article-number)))
5545 (error "You should select the right article first"))
5547 (setq n (prefix-numeric-value n))
5549 (setq n (or (get-text-property pt 'gnus-part)
5551 (get-text-property (1- pt) 'gnus-part))
5552 (get-text-property (prog2
5558 (or (and (setq pt (previous-single-property-change
5561 (next-single-property-change (point) 'gnus-part)
5565 ;; Check whether the specified part exists.
5566 (when (> n (length gnus-article-mime-handle-alist))
5567 (error "No such part")))
5570 ;; To select the window is needed so that the cursor
5571 ;; might be visible on the MIME button.
5572 (select-window (prog1
5574 (setq window (selected-window))
5575 ;; Article may be displayed in the other frame.
5576 (gnus-select-frame-set-input-focus
5579 (setq frame (selected-frame))))))
5580 (when (gnus-article-goto-part n)
5581 ;; We point the cursor and the arrow at the MIME button
5582 ;; when the `function' prompt the user for something.
5583 (unless (and (pos-visible-in-window-p)
5584 (> (count-lines (point) (window-end))
5585 (/ (1- (window-height)) 3)))
5586 (recenter (/ (1- (window-height)) 3)))
5587 (let ((cursor-in-non-selected-windows t)
5588 (overlay-arrow-string "=>")
5589 (overlay-arrow-position (point-marker)))
5592 ((and no-handle interactive)
5593 (call-interactively function))
5598 function (get-text-property (point) 'gnus-data)))
5601 (get-text-property (point) 'gnus-data))))
5602 (set-marker overlay-arrow-position nil)
5603 (unless gnus-auto-select-part
5604 (gnus-select-frame-set-input-focus frame)
5605 (select-window window))))
5607 (if gnus-inhibit-mime-unbuttonizing
5608 ;; This is the default though the program shouldn't reach here.
5609 (error "No such part")
5610 ;; The part which doesn't have the MIME button is selected.
5611 ;; So, we display all the buttons and redo it.
5612 (let ((gnus-inhibit-mime-unbuttonizing t))
5613 (gnus-summary-show-article)
5614 (gnus-article-part-wrapper n function no-handle))))))
5616 (defun gnus-article-pipe-part (n)
5617 "Pipe MIME part N, which is the numerical prefix."
5619 (gnus-article-part-wrapper n 'mm-pipe-part))
5621 (defun gnus-article-save-part (n)
5622 "Save MIME part N, which is the numerical prefix."
5624 (gnus-article-part-wrapper n 'mm-save-part))
5626 (defun gnus-article-interactively-view-part (n)
5627 "View MIME part N interactively, which is the numerical prefix."
5629 (gnus-article-part-wrapper n 'mm-interactively-view-part))
5631 (defun gnus-article-copy-part (n)
5632 "Copy MIME part N, which is the numerical prefix."
5634 (gnus-article-part-wrapper n 'gnus-mime-copy-part))
5636 (defun gnus-article-view-part-as-charset (n)
5637 "View MIME part N using a specified charset.
5638 N is the numerical prefix."
5640 (gnus-article-part-wrapper n 'gnus-mime-view-part-as-charset))
5642 (defun gnus-article-view-part-externally (n)
5643 "View MIME part N externally, which is the numerical prefix."
5645 (gnus-article-part-wrapper n 'gnus-mime-view-part-externally))
5647 (defun gnus-article-inline-part (n)
5648 "Inline MIME part N, which is the numerical prefix."
5650 (gnus-article-part-wrapper n 'gnus-mime-inline-part))
5652 (defun gnus-article-save-part-and-strip (n)
5653 "Save MIME part N and replace it with an external body.
5654 N is the numerical prefix."
5656 (gnus-article-part-wrapper n 'gnus-mime-save-part-and-strip t))
5658 (defun gnus-article-replace-part (n)
5659 "Replace MIME part N with an external body.
5660 N is the numerical prefix."
5662 (gnus-article-part-wrapper n 'gnus-mime-replace-part t t))
5664 (defun gnus-article-delete-part (n)
5665 "Delete MIME part N and add some information about the removed part.
5666 N is the numerical prefix."
5668 (gnus-article-part-wrapper n 'gnus-mime-delete-part t))
5670 (defun gnus-article-view-part-as-type (n)
5671 "Choose a MIME media type, and view part N as such.
5672 N is the numerical prefix."
5674 (gnus-article-part-wrapper n 'gnus-mime-view-part-as-type t))
5676 (defun gnus-article-mime-match-handle-first (condition)
5679 (dolist (ihandle gnus-article-mime-handle-alist)
5681 ((functionp condition)
5682 (funcall condition (cdr ihandle)))
5683 ((eq condition 'undisplayed)
5684 (not (or (mm-handle-undisplayer (cdr ihandle))
5685 (equal (mm-handle-media-type (cdr ihandle))
5686 "multipart/alternative"))))
5687 ((eq condition 'undisplayed-alternative)
5688 (not (mm-handle-undisplayer (cdr ihandle))))
5690 (gnus-article-goto-part (car ihandle))
5691 (or (not n) (< (car ihandle) n)))
5692 (setq n (car ihandle))))
5696 (defun gnus-article-view-part (&optional n)
5697 "View MIME part N, which is the numerical prefix.
5698 If the part is already shown, hide the part. If N is nil, view
5701 (with-current-buffer gnus-article-buffer
5702 (or (numberp n) (setq n (gnus-article-mime-match-handle-first
5703 gnus-article-mime-match-handle-function)))
5704 (when (> n (length gnus-article-mime-handle-alist))
5705 (error "No such part"))
5706 (let ((handle (cdr (assq n gnus-article-mime-handle-alist))))
5707 (when (gnus-article-goto-part n)
5708 (if (equal (car handle) "multipart/alternative")
5710 (beginning-of-line) ;; Make it toggle subparts
5711 (gnus-article-press-button))
5712 (when (eq (gnus-mm-display-part handle) 'internal)
5713 (gnus-set-window-start)))))))
5715 (defsubst gnus-article-mime-total-parts ()
5716 (if (bufferp (car gnus-article-mime-handles))
5718 (1- (length gnus-article-mime-handles))))
5720 (defun gnus-mm-display-part (handle)
5721 "Display HANDLE and fix MIME button."
5722 (let ((id (get-text-property (point) 'gnus-part))
5724 (inhibit-read-only t)
5725 (window (selected-window))
5726 (mail-parse-charset gnus-newsgroup-charset)
5727 (mail-parse-ignored-charsets
5728 (if (gnus-buffer-live-p gnus-summary-buffer)
5729 (with-current-buffer gnus-summary-buffer
5730 gnus-newsgroup-ignored-charsets)
5735 (let ((win (gnus-get-buffer-window (current-buffer) t)))
5739 (setq start (next-single-property-change point 'gnus-data
5741 point (previous-single-property-change start 'gnus-data))
5742 (if (mm-handle-displayed-p handle)
5743 ;; This will remove the part.
5744 (setq point (copy-marker point)
5745 retval (mm-display-part handle))
5746 (let ((part (or (and (mm-inlinable-p handle)
5747 (mm-inlined-p handle)
5750 (gnus-bind-safe-url-regexp
5751 (setq retval (mm-display-part handle)))
5752 (unless (zerop (buffer-size))
5753 (buffer-string))))))
5756 ;; This is a header button.
5758 (cond ((stringp part)
5760 (narrow-to-region (point)
5763 (unless (bolp) (insert "\n"))
5765 (gnus-treat-article nil id
5766 (gnus-article-mime-total-parts)
5767 (mm-handle-media-type handle))
5768 (mm-handle-set-undisplayer
5771 (let ((inhibit-read-only t))
5772 (delete-region ,(copy-marker (point-min) t)
5773 ,(point-max-marker)))))))
5775 (mm-display-inline handle))))))
5776 (when (markerp point)
5777 (setq point (prog1 (marker-position point)
5778 (set-marker point nil))))
5780 ;; Toggle the button appearance between `[button]...' and `[button]'.
5781 (let ((displayed-p (mm-handle-displayed-p handle)))
5782 (gnus-insert-mime-button handle id (list displayed-p))
5783 (if (featurep 'emacs)
5786 (next-single-property-change (point) 'gnus-data nil (point-max)))
5787 (let* ((end (next-single-property-change (point) 'gnus-data))
5788 (annots (annotations-at (or end (point-max)))))
5789 (delete-region (point)
5791 (if annots (1+ end) end)
5793 (dolist (annot annots)
5794 (set-extent-endpoints annot (point) (point)))))
5795 (setq start (point))
5796 (if (search-backward "\n\n" nil t)
5799 (unless (or displayed-p (eolp))
5800 ;; Add extra newline.
5801 (insert (propertize (buffer-substring (1- start) start)
5802 'gnus-undeletable t))))
5803 ;; We're in the article header.
5805 (dolist (ovl (gnus-overlays-in point (point)))
5806 (gnus-overlay-put ovl 'gnus-button-attachment-extra t)
5807 (gnus-overlay-put ovl 'face nil))
5809 (message-narrow-to-field)
5810 (let ((gnus-treatment-function-alist
5811 '((gnus-treat-highlight-headers
5812 gnus-article-highlight-headers))))
5813 (gnus-treat-article 'head)))))
5815 (if (window-live-p window)
5816 (select-window window)))
5819 (defun gnus-article-goto-part (n)
5820 "Go to MIME part N."
5821 (when gnus-break-pages
5825 (let ((start (or (text-property-any (point) (point-max) 'gnus-part n)
5826 ;; There may be header buttons.
5827 (text-property-any (point-min) (point) 'gnus-part n)))
5828 part handle end next handles)
5831 (if (setq handle (get-text-property start 'gnus-data))
5833 ;; Go to the displayed subpart, assuming this is
5834 ;; multipart/alternative.
5837 (while (and (not handle)
5840 (setq next (text-property-not-all part end
5843 handle (get-text-property part 'gnus-data))
5844 (push (cons handle part) handles)
5845 (unless (mm-handle-displayed-p handle)
5847 part (text-property-any part end 'gnus-data nil))))
5849 ;; No subpart is displayed, so we find preferred one.
5851 (cdr (assq (mm-preferred-alternative
5852 (nreverse (mapcar 'car handles)))
5855 (goto-char (1+ part))
5857 (when gnus-break-pages
5858 (gnus-narrow-to-page))))
5860 (defun gnus-insert-mime-button (handle id &optional displayed)
5861 (let ((gnus-tmp-name
5862 (or (mm-handle-filename handle)
5863 (mail-content-type-get (mm-handle-type handle) 'url)
5866 (gnus-tmp-type (mm-handle-media-type handle))
5867 (gnus-tmp-description (or (mm-handle-description handle) ""))
5869 (if (if displayed (car displayed)
5870 (mm-handle-displayed-p handle))
5872 (gnus-tmp-length (with-current-buffer (mm-handle-buffer handle)
5874 gnus-tmp-type-long b e)
5875 (when (string-match ".*/" gnus-tmp-name)
5876 (setq gnus-tmp-name (replace-match "" t t gnus-tmp-name)))
5877 (setq gnus-tmp-type-long (concat gnus-tmp-type
5878 (and (not (equal gnus-tmp-name ""))
5879 (concat "; " gnus-tmp-name))))
5880 (unless (equal gnus-tmp-description "")
5881 (setq gnus-tmp-type-long (concat " --- " gnus-tmp-type-long)))
5884 gnus-mime-button-line-format gnus-mime-button-line-format-alist
5885 `(keymap ,gnus-mime-button-map
5886 gnus-callback gnus-mm-display-part
5887 gnus-part ,gnus-tmp-id
5888 article-type annotation
5892 ;; Exclude a newline.
5895 (when gnus-article-button-face
5896 (gnus-overlay-put (gnus-make-overlay b e nil t)
5897 'face gnus-article-button-face))
5898 (widget-convert-button
5901 :action 'gnus-widget-press-button
5902 :button-keymap gnus-mime-button-map
5905 ;; Needed to properly clear the message due to a bug in
5906 ;; wid-edit (XEmacs only).
5907 (if (boundp 'help-echo-owns-message)
5908 (setq help-echo-owns-message t))
5910 "%S: %s the MIME part; %S: more options"
5911 (aref gnus-mouse-2 0)
5912 (if (mm-handle-displayed-p (widget-get widget :mime-handle))
5914 (aref gnus-down-mouse-3 0))))))
5916 (defun gnus-widget-press-button (elems _el)
5917 (goto-char (widget-get elems :from))
5918 (gnus-article-press-button))
5920 (defvar gnus-displaying-mime nil)
5922 (defun gnus-display-mime (&optional ihandles)
5923 "Display the MIME parts."
5925 (save-selected-window
5926 (let ((window (get-buffer-window gnus-article-buffer))
5929 (select-window window)
5930 ;; We have to do this since selecting the window
5931 ;; may change the point. So we set the window point.
5932 (set-window-point window point)))
5933 (let ((handles ihandles)
5934 (inhibit-read-only t))
5936 ((setq handles (mm-dissect-buffer nil gnus-article-loose-mime))
5937 (when gnus-article-emulate-mime
5938 (mm-uu-dissect-text-parts handles)))
5939 (gnus-article-emulate-mime
5940 (setq handles (mm-uu-dissect))))
5941 (when (and (not ihandles)
5942 (not gnus-displaying-mime))
5943 ;; Top-level call; we clean up.
5944 (when gnus-article-mime-handles
5945 (mm-destroy-parts gnus-article-mime-handles)
5946 (setq gnus-article-mime-handle-alist nil));; A trick.
5947 (setq gnus-article-mime-handles handles)
5948 ;; We allow users to glean info from the handles.
5949 (when gnus-article-mime-part-function
5950 (gnus-mime-part-function handles)))
5952 (or (not (stringp (car handles)))
5955 (when (and (not ihandles)
5956 (not gnus-displaying-mime))
5957 ;; Clean up for mime parts.
5959 (delete-region (point) (point-max)))
5960 (let ((gnus-displaying-mime t))
5961 (gnus-mime-display-part handles)))
5964 (narrow-to-region (point) (point-max))
5965 (gnus-treat-article nil 1 1 "text/plain")
5968 ;; Highlight the headers.
5972 (narrow-to-region (point-min) (point))
5973 (gnus-article-save-original-date
5974 (gnus-treat-article 'head)))))))
5975 ;; Cope with broken MIME messages.
5976 (goto-char (point-max))
5980 (defcustom gnus-mime-display-multipart-as-mixed nil
5981 "Display \"multipart\" parts as \"multipart/mixed\".
5983 If t, it overrides nil values of
5984 `gnus-mime-display-multipart-alternative-as-mixed' and
5985 `gnus-mime-display-multipart-related-as-mixed'."
5986 :group 'gnus-article-mime
5989 (defcustom gnus-mime-display-multipart-alternative-as-mixed nil
5990 "Display \"multipart/alternative\" parts as \"multipart/mixed\"."
5992 :group 'gnus-article-mime
5995 (defcustom gnus-mime-display-multipart-related-as-mixed nil
5996 "Display \"multipart/related\" parts as \"multipart/mixed\".
5998 If displaying \"text/html\" is discouraged \(see
5999 `mm-discouraged-alternatives'\) images or other material inside a
6000 \"multipart/related\" part might be overlooked when this variable is nil."
6002 :group 'gnus-article-mime
6005 (defcustom gnus-mime-display-attachment-buttons-in-header t
6006 "Add attachment buttons in the end of the header of an article.
6007 Since MIME attachments tend to be put at the end of an article, we may
6008 overlook them if there is a huge body. This option offers you a copy
6009 of all non-inlinable MIME parts as buttons shown in front of an article.
6010 If nil, don't show those extra buttons."
6012 :group 'gnus-article-mime
6015 (defun gnus-mime-display-part (handle)
6017 ;; Maybe a broken MIME message.
6020 ((not (stringp (car handle)))
6021 (gnus-mime-display-single handle))
6022 ;; User-defined multipart
6023 ((cdr (assoc (car handle) gnus-mime-multipart-functions))
6024 (funcall (cdr (assoc (car handle) gnus-mime-multipart-functions))
6026 ;; multipart/alternative
6027 ((and (equal (car handle) "multipart/alternative")
6028 (not (or gnus-mime-display-multipart-as-mixed
6029 gnus-mime-display-multipart-alternative-as-mixed)))
6030 (let ((id (1+ (length gnus-article-mime-handle-alist))))
6031 (push (cons id handle) gnus-article-mime-handle-alist)
6032 (gnus-mime-display-alternative (cdr handle) nil nil id)))
6033 ;; multipart/related
6034 ((and (equal (car handle) "multipart/related")
6035 (not (or gnus-mime-display-multipart-as-mixed
6036 gnus-mime-display-multipart-related-as-mixed)))
6037 (gnus-mime-display-part (cadr handle)))
6038 ((equal (car handle) "multipart/signed")
6039 (gnus-add-wash-type 'signed)
6040 (gnus-mime-display-security handle))
6041 ((equal (car handle) "multipart/encrypted")
6042 (gnus-add-wash-type 'encrypted)
6043 (gnus-mime-display-security handle))
6044 ;; Other multiparts are handled like multipart/mixed.
6046 (gnus-mime-display-mixed (cdr handle)))))
6048 (defun gnus-mime-part-function (handles)
6049 (if (stringp (car handles))
6050 (mapcar 'gnus-mime-part-function (cdr handles))
6051 (funcall gnus-article-mime-part-function handles)))
6053 (defun gnus-mime-display-mixed (handles)
6054 (mapcar 'gnus-mime-display-part handles))
6056 (defun gnus-mime-display-single (handle)
6057 (let ((type (mm-handle-media-type handle))
6058 (ignored gnus-ignored-mime-types)
6064 (when (string-match (pop ignored) type)
6065 (throw 'ignored nil)))
6066 (if (and (not (and (if (gnus-buffer-live-p gnus-summary-buffer)
6067 (with-current-buffer gnus-summary-buffer
6068 gnus-inhibit-images)
6069 gnus-inhibit-images)
6070 (string-match "\\`image/" type)))
6071 (setq not-attachment
6072 (and (not (mm-inline-override-p handle))
6073 (or (not (mm-handle-disposition handle))
6074 (equal (car (mm-handle-disposition handle))
6076 (mm-attachment-override-p handle))))
6077 (mm-automatic-display-p handle)
6079 (mm-inlinable-p handle)
6080 (mm-inlined-p handle))
6081 (mm-automatic-external-display-p type)))
6083 (when (equal (mm-handle-media-supertype handle) "text")
6085 (let ((id (car (rassq handle gnus-article-mime-handle-alist)))
6088 (setq id (1+ (length gnus-article-mime-handle-alist)))
6089 (push (cons id handle) gnus-article-mime-handle-alist))
6091 (equal (mm-handle-media-supertype handle) "message"))
6094 (cond ((not (bolp)) 2)
6095 ((or (bobp) (eq (char-before (1- (point))) ?\n)) 0)
6097 (when (or (not display)
6098 (not (gnus-unbuttonized-mime-type-p type))
6099 (eq id gnus-mime-buttonized-part-id))
6100 (gnus-insert-mime-button
6101 handle id (list (or display (and not-attachment text)))))
6105 (let ((mail-parse-charset gnus-newsgroup-charset)
6106 (mail-parse-ignored-charsets
6107 (save-excursion (condition-case ()
6108 (set-buffer gnus-summary-buffer)
6110 gnus-newsgroup-ignored-charsets)))
6111 (gnus-bind-safe-url-regexp (mm-display-part handle t))))
6112 ((and text not-attachment)
6113 (mm-display-inline handle)))
6114 (goto-char (point-max))
6115 (if (string-match "\\`image/" type)
6116 (gnus-article-insert-newline)
6118 (= (skip-chars-backward "\n") -1)
6119 (unless (eobp) (forward-char 1)))
6120 (gnus-article-insert-newline)
6121 (put-text-property (point) (point-max) 'gnus-undeletable t))
6122 (goto-char (point-max)))
6126 (narrow-to-region beg (point))
6127 (if (eq handle gnus-article-mime-handles)
6128 ;; The format=flowed case.
6129 (gnus-treat-article nil 1 1 (mm-handle-media-type handle))
6130 ;; Don't count signature parts that are never displayed.
6131 ;; The part number should be re-calculated supposing this
6132 ;; might be a message/rfc822 part.
6134 (dolist (part gnus-article-mime-handles)
6135 (unless (or (stringp part)
6136 (equal (car (mm-handle-type part))
6137 "application/pgp-signature"))
6138 (push part handles)))
6140 nil (length (memq handle handles)) (length handles)
6141 (mm-handle-media-type handle)))))))))))
6143 (defun gnus-unbuttonized-mime-type-p (type)
6144 "Say whether TYPE is to be unbuttonized."
6145 (unless gnus-inhibit-mime-unbuttonizing
6147 (let ((types gnus-unbuttonized-mime-types))
6149 (when (string-match (pop types) type)
6150 (throw 'found t)))))
6152 (let ((types gnus-buttonized-mime-types))
6154 (when (string-match (pop types) type)
6155 (throw 'found t)))))))))
6157 (defun gnus-article-insert-newline ()
6158 "Insert a newline, but mark it as undeletable."
6159 (gnus-put-text-property
6160 (point) (progn (insert "\n") (point)) 'gnus-undeletable t))
6162 (defun gnus-mime-display-alternative (handles &optional preferred ibegend id)
6163 (let* ((preferred (or preferred (mm-preferred-alternative handles)))
6166 handle (inhibit-read-only t) from begend not-pref)
6167 (save-window-excursion
6170 (narrow-to-region (car ibegend)
6173 (goto-char (car ibegend))
6176 (delete-region (point-min) (point-max))
6177 (mm-remove-parts handles))
6178 (setq begend (list (point-marker)))
6180 (unless (setq not-pref (cadr (member preferred ihandles)))
6181 (setq not-pref (car ihandles)))
6184 (not (gnus-unbuttonized-mime-type-p
6185 "multipart/alternative")))
6186 (gnus-add-text-properties
6189 (insert (format "%d. " id))
6193 (unless ,(not ibegend)
6194 (setq gnus-article-mime-handle-alist
6195 ',gnus-article-mime-handle-alist))
6196 (gnus-mime-display-alternative
6197 ',ihandles ',not-pref ',begend ,id))
6198 keymap ,gnus-mime-button-map
6199 ,gnus-mouse-face-prop ,gnus-article-mouse-face
6200 face ,gnus-article-button-face
6202 article-type multipart
6204 (widget-convert-button 'link from (point)
6205 :action 'gnus-widget-press-button
6206 :button-keymap gnus-widget-button-keymap)
6208 (while (setq handle (pop handles))
6209 (gnus-add-text-properties
6212 (insert (format "(%c) %-18s"
6213 (if (equal handle preferred) ?* ? )
6214 (mm-handle-media-type handle)))
6218 (unless ,(not ibegend)
6219 (setq gnus-article-mime-handle-alist
6220 ',gnus-article-mime-handle-alist))
6221 (gnus-mime-display-alternative
6222 ',ihandles ',handle ',begend ,id))
6223 keymap ,gnus-mime-button-map
6224 ,gnus-mouse-face-prop ,gnus-article-mouse-face
6225 face ,gnus-article-button-face
6229 (widget-convert-button 'link from (point)
6230 :action 'gnus-widget-press-button
6231 :button-keymap gnus-widget-button-keymap)
6235 (if (stringp (car preferred))
6236 (gnus-display-mime preferred)
6237 (let ((mail-parse-charset gnus-newsgroup-charset)
6238 (mail-parse-ignored-charsets
6239 (with-current-buffer gnus-summary-buffer
6240 gnus-newsgroup-ignored-charsets)))
6241 (gnus-bind-safe-url-regexp (mm-display-part preferred))
6245 (narrow-to-region (car begend) (point-max))
6247 nil (length gnus-article-mime-handle-alist)
6248 (gnus-article-mime-total-parts)
6249 (mm-handle-media-type preferred))))))
6250 (goto-char (point-max))
6251 (setcdr begend (point-marker)))))
6254 ;; Redraw attachment buttons in the header.
6255 (when gnus-mime-display-attachment-buttons-in-header
6256 (gnus-mime-buttonize-attachments-in-header)))
6258 (defconst gnus-article-wash-status-strings
6259 (let ((alist '((cite "c" "Possible hidden citation text"
6260 " " "All citation text visible")
6261 (headers "h" "Hidden headers"
6262 " " "All headers visible.")
6263 (pgp "p" "Encrypted or signed message status hidden"
6264 " " "No hidden encryption nor digital signature status")
6265 (signature "s" "Signature has been hidden"
6266 " " "Signature is visible")
6267 (overstrike "o" "Overstrike (^H) characters applied"
6268 " " "No overstrike characters applied")
6269 (emphasis "e" "/*_Emphasis_*/ characters applied"
6270 " " "No /*_emphasis_*/ characters applied")))
6272 (dolist (entry alist result)
6273 (let ((key (nth 0 entry))
6274 (on (copy-sequence (nth 1 entry)))
6275 (on-help (nth 2 entry))
6276 (off (copy-sequence (nth 3 entry)))
6277 (off-help (nth 4 entry)))
6278 (put-text-property 0 1 'help-echo on-help on)
6279 (put-text-property 0 1 'help-echo off-help off)
6280 (push (list key on off) result))))
6281 "Alist of strings describing wash status in the mode line.
6282 Each entry has the form (KEY ON OF), where the KEY is a symbol
6283 representing the particular washing function, ON is the string to use
6284 in the article mode line when the washing function is active, and OFF
6285 is the string to use when it is inactive.")
6287 (defun gnus-article-wash-status-entry (key value)
6288 (let ((entry (assoc key gnus-article-wash-status-strings)))
6289 (if value (nth 1 entry) (nth 2 entry))))
6291 (defun gnus-article-wash-status ()
6292 "Return a string which display status of article washing."
6293 (with-current-buffer gnus-article-buffer
6294 (let ((cite (memq 'cite gnus-article-wash-types))
6295 (headers (memq 'headers gnus-article-wash-types))
6296 (boring (memq 'boring-headers gnus-article-wash-types))
6297 (pgp (memq 'pgp gnus-article-wash-types))
6298 (pem (memq 'pem gnus-article-wash-types))
6299 (signed (memq 'signed gnus-article-wash-types))
6300 (encrypted (memq 'encrypted gnus-article-wash-types))
6301 (signature (memq 'signature gnus-article-wash-types))
6302 (overstrike (memq 'overstrike gnus-article-wash-types))
6303 (emphasis (memq 'emphasis gnus-article-wash-types)))
6305 (gnus-article-wash-status-entry 'cite cite)
6306 (gnus-article-wash-status-entry 'headers (or headers boring))
6307 (gnus-article-wash-status-entry 'pgp (or pgp pem signed encrypted))
6308 (gnus-article-wash-status-entry 'signature signature)
6309 (gnus-article-wash-status-entry 'overstrike overstrike)
6310 (gnus-article-wash-status-entry 'emphasis emphasis)))))
6312 (defun gnus-add-wash-type (type)
6313 "Add a washing of TYPE to the current status."
6314 (add-to-list 'gnus-article-wash-types type))
6316 (defun gnus-delete-wash-type (type)
6317 "Add a washing of TYPE to the current status."
6318 (setq gnus-article-wash-types (delq type gnus-article-wash-types)))
6320 (defun gnus-add-image (category image)
6321 "Add IMAGE of CATEGORY to the list of displayed images."
6322 (let ((entry (assq category gnus-article-image-alist)))
6324 (setq entry (list category))
6325 (push entry gnus-article-image-alist))
6326 (nconc entry (list image))))
6328 (defun gnus-delete-images (category)
6329 "Delete all images in CATEGORY."
6330 (let ((entry (assq category gnus-article-image-alist)))
6331 (dolist (image (cdr entry))
6332 (gnus-remove-image image category))
6333 (setq gnus-article-image-alist (delq entry gnus-article-image-alist))
6334 (gnus-delete-wash-type category)))
6336 (defalias 'gnus-article-hide-headers-if-wanted 'gnus-article-maybe-hide-headers)
6338 (defun gnus-article-maybe-hide-headers ()
6339 "Hide unwanted headers if `gnus-have-all-headers' is nil.
6340 Provided for backwards compatibility."
6341 (when (and (or (not (gnus-buffer-live-p gnus-summary-buffer))
6342 (not (with-current-buffer gnus-summary-buffer
6343 gnus-have-all-headers)))
6344 (not gnus-inhibit-hiding))
6345 (gnus-article-hide-headers)))
6347 (declare-function shr-put-image "shr" (data alt &optional flags))
6349 (defun gnus-shr-put-image (data alt &optional flags)
6350 "Put image DATA with a string ALT. Enable image to be deleted."
6351 (let ((image (if flags
6352 (shr-put-image data (propertize (or alt "*")
6353 'gnus-image-category 'shr)
6355 ;; Old `shr-put-image' doesn't take the optional `flags'
6357 (shr-put-image data (propertize (or alt "*")
6358 'gnus-image-category 'shr)))))
6360 (gnus-add-image 'shr image))))
6362 (defun gnus-article-mime-handles (&optional alist id all)
6364 (let ((i 1) newid flat)
6365 (dolist (handle alist flat)
6366 (setq newid (append id (list i))
6368 (if (stringp (car handle))
6369 (setq flat (nconc flat (gnus-article-mime-handles
6370 (cdr handle) newid all)))
6371 (delq (rassq handle all) all)
6372 (setq flat (nconc flat (list (cons newid handle)))))))
6373 (let ((flat (list nil)))
6374 ;; Assume that elements of `gnus-article-mime-handle-alist'
6375 ;; are in the decreasing order, but unnumbered subsidiaries
6376 ;; in each element are in the increasing order.
6377 (dolist (handle (reverse gnus-article-mime-handle-alist))
6378 (if (stringp (cadr handle))
6379 (setq flat (nconc flat (gnus-article-mime-handles
6380 (cddr handle) (list (car handle)) flat)))
6381 (delq (rassq (cdr handle) flat) flat)
6382 (setq flat (nconc flat (list (cons (list (car handle))
6384 (setq flat (cdr flat))
6385 (mapc (lambda (handle)
6387 ;; This is a hidden (i.e. unnumbered) handle.
6390 (1+ (caar gnus-article-mime-handle-alist)))
6391 (push handle gnus-article-mime-handle-alist))
6392 (setcar handle (caar handle))))
6396 (defun gnus-mime-buttonize-attachments-in-header (&optional interactive)
6397 "Show attachments as buttons in the end of the header of an article.
6398 This function toggles the display when called interactively. Note that
6399 buttons to be added to the header are only the ones that aren't inlined
6400 in the body. Use `gnus-header-face-alist' to highlight buttons."
6401 (interactive (list t))
6402 (gnus-with-article-buffer
6403 (let ((case-fold-search t) buttons handle type st)
6407 (article-narrow-to-head)
6408 ;; Header buttons exist?
6409 (while (and (not buttons)
6410 (re-search-forward "^attachments?:[\n ]+" nil t))
6411 (when (get-char-property (match-end 0)
6412 'gnus-button-attachment-extra)
6413 (setq buttons (match-beginning 0))))
6416 ;; Delete header buttons.
6417 (delete-region buttons (if (re-search-forward "^[^ ]" nil t)
6420 (unless (and interactive buttons)
6423 (dolist (button (gnus-article-mime-handles))
6424 (setq handle (cdr button)
6425 type (mm-handle-media-type handle))
6426 (when (or (and (if (gnus-buffer-live-p gnus-summary-buffer)
6427 (with-current-buffer gnus-summary-buffer
6428 gnus-inhibit-images)
6429 gnus-inhibit-images)
6430 (string-match "\\`image/" type))
6431 (mm-inline-override-p handle)
6432 (and (mm-handle-disposition handle)
6433 (not (equal (car (mm-handle-disposition handle))
6435 (not (mm-attachment-override-p handle)))
6436 (not (mm-automatic-display-p handle))
6437 (not (or (and (mm-inlinable-p handle)
6438 (mm-inlined-p handle))
6439 (mm-automatic-external-display-p type))))
6440 (push button buttons)))
6442 ;; Add header buttons.
6445 (narrow-to-region (point) (point))
6446 (insert "Attachment" (if (cdr buttons) "s" "") ":")
6447 (dolist (button (nreverse buttons))
6450 (mm-handle-set-undisplayer (setq handle (cdr button)) nil)
6451 (gnus-insert-mime-button handle (car button))
6452 (skip-chars-backward "\t\n ")
6453 (delete-region (point) (point-max))
6454 (when (> (current-column) (window-width))
6459 (dolist (ovl (gnus-overlays-in (point-min) (point)))
6460 (gnus-overlay-put ovl 'gnus-button-attachment-extra t)
6461 (gnus-overlay-put ovl 'face nil))
6462 (let ((gnus-treatment-function-alist
6463 '((gnus-treat-highlight-headers
6464 gnus-article-highlight-headers))))
6465 (gnus-treat-article 'head)))))))))
6469 (defun gnus-output-to-file (file-name)
6470 "Append the current article to a file named FILE-NAME.
6471 If `gnus-article-save-coding-system' is non-nil, it is used to encode
6472 text and used as the value of the coding cookie which is added to the
6473 top of a file. Otherwise, this function saves a raw article without
6475 (let* ((artbuf (current-buffer))
6476 (file-name-coding-system nnmail-pathname-coding-system)
6477 (coding gnus-article-save-coding-system)
6478 (coding-system-for-read (if coding
6479 nil ;; Rely on the coding cookie.
6480 mm-text-coding-system))
6481 (coding-system-for-write (or coding
6482 mm-text-coding-system-for-write
6483 mm-text-coding-system))
6484 (exists (file-exists-p file-name)))
6487 (insert-file-contents file-name)
6488 (goto-char (point-min))
6489 ;; Remove the existing coding cookie.
6490 (when (looking-at "X-Gnus-Coding-System: .+\n\n")
6491 (delete-region (match-beginning 0) (match-end 0))))
6492 (goto-char (point-max))
6493 (insert-buffer-substring artbuf)
6494 ;; Append newline at end of the buffer as separator, and then
6496 (goto-char (point-max))
6499 ;; If the coding system is not suitable to encode the text,
6500 ;; ask a user for a proper one.
6501 (when (fboundp 'select-safe-coding-system)
6502 (setq coding (coding-system-base
6503 (save-window-excursion
6504 (select-safe-coding-system (point-min) (point-max)
6506 (setq coding-system-for-write
6507 (or (cdr (assq coding '((mule-utf-8 . utf-8))))
6509 (goto-char (point-min))
6510 ;; Add the coding cookie.
6511 (insert (format "X-Gnus-Coding-System: -*- coding: %s; -*-\n\n"
6512 coding-system-for-write)))
6515 (write-region (point-min) (point-max) file-name nil 'no-message)
6516 (message "Appended to %s" file-name))
6517 (write-region (point-min) (point-max) file-name))))
6520 (defun gnus-narrow-to-page (&optional arg)
6521 "Narrow the article buffer to a page.
6522 If given a numerical ARG, move forward ARG pages."
6524 (setq arg (if arg (prefix-numeric-value arg) 0))
6525 (with-current-buffer gnus-article-buffer
6527 ;; Remove any old next/prev buttons.
6528 (when (gnus-visual-p 'page-marker)
6529 (let ((inhibit-read-only t))
6530 (gnus-remove-text-with-property 'gnus-prev)
6531 (gnus-remove-text-with-property 'gnus-next)))
6533 (when (save-excursion
6535 (if (re-search-backward page-delimiter nil 'move (abs arg))
6537 (setq nd (match-beginning 0)
6539 (when (re-search-backward page-delimiter nil t)
6540 (setq st (match-end 0))))
6541 (when (re-search-forward page-delimiter nil t)
6542 (setq nd (match-beginning 0)
6545 (if (re-search-forward page-delimiter nil 'move arg)
6547 (setq st (match-end 0)
6549 (when (re-search-forward page-delimiter nil t)
6550 (setq nd (match-beginning 0))))
6551 (when (re-search-backward page-delimiter nil t)
6552 (setq st (match-end 0)
6555 (when (re-search-backward page-delimiter nil t)
6556 (goto-char (setq st (match-end 0))))
6557 (when (re-search-forward page-delimiter nil t)
6558 (setq nd (match-beginning 0)))
6560 (setq gnus-page-broken t)
6561 (when pt (goto-char pt))
6562 (narrow-to-region (or st (point-min)) (or nd (point-max)))
6563 (when (gnus-visual-p 'page-marker)
6567 (gnus-insert-next-page-button))
6570 (gnus-insert-prev-page-button))))))))
6572 ;; Article mode commands
6574 (defun gnus-article-goto-next-page ()
6575 "Show the next page of the article."
6577 (when (gnus-article-next-page)
6578 (goto-char (point-min))
6579 (gnus-article-read-summary-keys nil (gnus-character-to-event ?n))))
6582 (defun gnus-article-goto-prev-page ()
6583 "Show the previous page of the article."
6585 (if (save-restriction (widen) (bobp)) ;; Real beginning-of-buffer?
6586 (gnus-article-read-summary-keys nil (gnus-character-to-event ?p))
6587 (gnus-article-prev-page nil)))
6589 ;; This is cleaner but currently breaks `gnus-pick-mode':
6591 ;; (defun gnus-article-goto-next-page ()
6592 ;; "Show the next page of the article."
6594 ;; (gnus-eval-in-buffer-window gnus-summary-buffer
6595 ;; (gnus-summary-next-page)))
6597 ;; (defun gnus-article-goto-prev-page ()
6598 ;; "Show the next page of the article."
6600 ;; (gnus-eval-in-buffer-window gnus-summary-buffer
6601 ;; (gnus-summary-prev-page)))
6603 (defun gnus-article-next-page (&optional lines)
6604 "Show the next page of the current article.
6605 If end of article, return non-nil. Otherwise return nil.
6606 Argument LINES specifies lines to be scrolled up."
6608 (move-to-window-line (if (featurep 'xemacs) -1 (- -1 scroll-margin)))
6609 (if (and (not (and gnus-article-over-scroll
6610 (> (count-lines (window-start) (point-max))
6611 (if (featurep 'xemacs)
6612 (or lines (1- (window-height)))
6613 (+ (or lines (1- (window-height))) scroll-margin)))))
6616 (and (pos-visible-in-window-p) ;Not continuation line.
6617 (>= (point) (point-max)))))
6618 ;; Nothing in this page.
6619 (if (or (not gnus-page-broken)
6624 (eobp)))) ;Real end-of-buffer?
6626 (when gnus-article-over-scroll
6627 (gnus-article-next-page-1 lines))
6629 (gnus-narrow-to-page 1) ;Go to next page.
6631 ;; More in this page.
6632 (gnus-article-next-page-1 lines)
6635 (defun gnus-article-beginning-of-window ()
6636 "Move point to the beginning of the window.
6637 In Emacs, the point is placed at the line number which `scroll-margin'
6639 (if (featurep 'xemacs)
6640 (move-to-window-line 0)
6641 ;; There is an obscure bug in Emacs that makes it impossible to
6642 ;; scroll past big pictures in the article buffer. Try to fix
6643 ;; this by adding a sanity check by counting the lines visible.
6644 (when (> (count-lines (window-start) (window-end)) 30)
6645 (move-to-window-line
6646 (min (max 0 scroll-margin)
6647 (max 1 (- (window-height)
6648 (if mode-line-format 1 0)
6649 (if header-line-format 1 0)
6652 (defvar scroll-in-place)
6654 (defun gnus-article-next-page-1 (lines)
6656 (let ((scroll-in-place nil)
6657 (auto-window-vscroll nil))
6660 ;; Long lines may cause an end-of-buffer error.
6661 (goto-char (point-max))))
6662 (gnus-article-beginning-of-window))
6664 (defun gnus-article-prev-page (&optional lines)
6665 "Show previous page of current article.
6666 Argument LINES specifies lines to be scrolled down."
6668 (move-to-window-line 0)
6669 (if (and gnus-page-broken
6671 (not (save-restriction (widen) (bobp)))) ;Real beginning-of-buffer?
6673 (gnus-narrow-to-page -1) ;Go to previous page.
6674 (goto-char (point-max))
6675 (recenter (if gnus-article-over-scroll
6677 (max (if (featurep 'xemacs)
6679 (+ lines scroll-margin))
6681 (- (window-height) 2))
6685 (let ((scroll-in-place nil))
6686 (scroll-down lines))
6687 (beginning-of-buffer
6688 (goto-char (point-min))))
6689 (gnus-article-beginning-of-window))))
6691 (defun gnus-article-only-boring-p ()
6692 "Decide whether there is only boring text remaining in the article.
6693 Something \"interesting\" is a word of at least two letters that does
6694 not have a face in `gnus-article-boring-faces'."
6695 (when (and gnus-article-skip-boring
6696 (boundp 'gnus-article-boring-faces)
6697 (symbol-value 'gnus-article-boring-faces))
6699 (let ((inhibit-point-motion-hooks t))
6701 (while (re-search-forward "\\b\\w\\w" nil t)
6703 (when (not (gnus-intersection
6704 (gnus-faces-at (point))
6705 (symbol-value 'gnus-article-boring-faces)))
6706 (throw 'only-boring nil)))
6707 (throw 'only-boring t))))))
6709 (defun gnus-article-refer-article ()
6710 "Read article specified by message-id around point."
6713 (re-search-backward "[ \t]\\|^" (point-at-bol) t)
6714 (re-search-forward "<?news:<?\\|<" (point-at-eol) t)
6715 (if (re-search-forward "[^@ ]+@[^ \t>]+" (point-at-eol) t)
6716 (let ((msg-id (concat "<" (match-string 0) ">")))
6717 (set-buffer gnus-summary-buffer)
6718 (gnus-summary-refer-article msg-id))
6719 (error "No references around point"))))
6721 (defun gnus-article-show-summary ()
6722 "Reconfigure windows to show summary buffer."
6724 (if (not (gnus-buffer-live-p gnus-summary-buffer))
6725 (error "There is no summary buffer for this article buffer")
6726 (gnus-article-set-globals)
6727 (gnus-configure-windows 'article)
6728 (gnus-summary-goto-subject gnus-current-article)
6729 (gnus-summary-position-point)))
6731 (defun gnus-article-describe-briefly ()
6732 "Describe article mode commands briefly."
6734 (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")))
6736 (defun gnus-article-check-buffer ()
6737 "Beep if not in an article buffer."
6738 (unless (derived-mode-p 'gnus-article-mode)
6739 (error "Command invoked outside of a Gnus article buffer")))
6741 (defvar gnus-pick-mode)
6743 (defun gnus-article-read-summary-keys (&optional _arg key not-restore-window)
6744 "Read a summary buffer key sequence and execute it from the article buffer."
6746 (gnus-article-check-buffer)
6748 '("q" "Q" "c" "r" "\C-c\C-f" "m" "a" "f"
6749 "Zc" "ZC" "ZE" "ZQ" "ZZ" "Zn" "ZR" "ZG" "ZN" "ZP"
6750 "=" "^" "\M-^" "|"))
6752 '("A " "A<" "A>" "AM" "AP" "AR" "AT" "A\C-?" "A\M-\r" "A\r" "Ab" "Ae"
6753 "An" "Ap" [?A (meta return)] [?A delete]))
6757 (with-current-buffer gnus-article-current-summary
6758 (let (gnus-pick-mode)
6759 (setq unread-command-events (nconc unread-command-events
6760 (list (or key last-command-event)))
6761 keys (if (featurep 'xemacs)
6762 (events-to-keys (read-key-sequence nil t))
6763 (read-key-sequence nil t)))))
6768 ((eq (aref keys (1- (length keys))) ?\C-h)
6769 (gnus-article-describe-bindings (substring keys 0 -1)))
6770 ((or (member keys nosaves)
6771 (member keys nosave-but-article)
6772 (member keys nosave-in-article))
6774 (save-window-excursion
6775 (pop-to-buffer gnus-article-current-summary)
6776 ;; We disable the pick minor mode commands.
6777 (let (gnus-pick-mode)
6778 (setq func (key-binding keys t))))
6782 (unless (member keys nosave-in-article)
6783 (set-buffer gnus-article-current-summary))
6784 (when (and (symbolp func)
6785 (get func 'disabled))
6786 (error "Function %s disabled" func))
6787 (call-interactively func)
6788 (setq new-sum-point (point)))
6789 (when (member keys nosave-but-article)
6790 (pop-to-buffer gnus-article-buffer))))
6792 ;; These commands should restore window configuration.
6793 (let ((obuf (current-buffer))
6794 (owin (current-window-configuration))
6795 win func in-buffer selected new-sum-start new-sum-hscroll err)
6796 (cond (not-restore-window
6797 (pop-to-buffer gnus-article-current-summary)
6798 (setq win (selected-window)))
6799 ((setq win (get-buffer-window gnus-article-current-summary))
6800 (select-window win))
6802 (let ((summary-buffer gnus-article-current-summary))
6803 (gnus-configure-windows 'article)
6804 (unless (setq win (get-buffer-window summary-buffer 'visible))
6805 (let ((gnus-buffer-configuration
6806 '((article ((vertical 1.0
6807 (summary 0.25 point)
6809 (gnus-configure-windows 'article))
6810 (setq win (get-buffer-window summary-buffer 'visible)))
6811 (gnus-select-frame-set-input-focus (window-frame win))
6812 (select-window win))))
6813 (setq in-buffer (current-buffer))
6814 ;; We disable the pick minor mode commands.
6815 (setq func (let (gnus-pick-mode)
6816 (key-binding keys t)))
6817 (when (get func 'disabled)
6818 (error "Function %s disabled" func))
6821 (condition-case code
6823 (call-interactively func)
6829 (when (eq win (selected-window))
6830 (setq new-sum-point (point)
6831 new-sum-start (window-start win)
6832 new-sum-hscroll (window-hscroll win)))
6833 (when (or (eq in-buffer (current-buffer))
6834 (when (eq obuf (current-buffer))
6835 (set-buffer in-buffer)
6837 (setq selected (ignore-errors (gnus-summary-select-article)))
6839 (unless not-restore-window
6840 (set-window-configuration owin))
6841 (when (and (eq selected 'old)
6843 (set-window-start (get-buffer-window (current-buffer))
6845 (set-window-point (get-buffer-window (current-buffer))
6846 (if (article-goto-body)
6849 (when (and (not not-restore-window)
6852 (with-current-buffer (window-buffer win)
6853 (derived-mode-p 'gnus-summary-mode)))
6854 (set-window-point win new-sum-point)
6855 (set-window-start win new-sum-start)
6856 (set-window-hscroll win new-sum-hscroll))))
6857 (set-window-configuration owin)
6859 (signal (car err) (cdr err))
6862 (defun gnus-article-read-summary-send-keys ()
6864 (let ((unread-command-events (list (gnus-character-to-event ?S))))
6865 (gnus-article-read-summary-keys)))
6867 (defun gnus-article-describe-key (key)
6868 "Display documentation of the function invoked by KEY.
6869 KEY is a string or a vector."
6870 (interactive (list (let ((cursor-in-echo-area t)) ;; better for XEmacs.
6871 (read-key-sequence "Describe key: "))))
6872 (gnus-article-check-buffer)
6873 (if (memq (key-binding key t) '(gnus-article-read-summary-keys
6874 gnus-article-read-summary-send-keys))
6875 (with-current-buffer gnus-article-current-summary
6876 (setq unread-command-events
6877 (if (featurep 'xemacs)
6879 (mapcar (lambda (x) (if (and (integerp x) (>= x 128))
6880 (list 'meta (- x 128))
6883 (let ((cursor-in-echo-area t)
6885 (describe-key (read-key-sequence nil t))))
6886 (describe-key key)))
6888 (defun gnus-article-describe-key-briefly (key &optional insert)
6889 "Display documentation of the function invoked by KEY.
6890 KEY is a string or a vector."
6891 (interactive (list (let ((cursor-in-echo-area t)) ;; better for XEmacs.
6892 (read-key-sequence "Describe key: "))
6893 current-prefix-arg))
6894 (gnus-article-check-buffer)
6895 (if (memq (key-binding key t) '(gnus-article-read-summary-keys
6896 gnus-article-read-summary-send-keys))
6897 (with-current-buffer gnus-article-current-summary
6898 (setq unread-command-events
6899 (if (featurep 'xemacs)
6901 (mapcar (lambda (x) (if (and (integerp x) (>= x 128))
6902 (list 'meta (- x 128))
6905 (let ((cursor-in-echo-area t)
6907 (describe-key-briefly (read-key-sequence nil t) insert)))
6908 (describe-key-briefly key insert)))
6910 ;;`gnus-agent-mode' in gnus-agent.el will define it.
6911 (defvar gnus-agent-summary-mode)
6912 (defvar gnus-draft-mode)
6913 (defvar help-xref-stack-item)
6914 (defvar help-xref-following)
6916 (defun gnus-article-describe-bindings (&optional prefix)
6917 "Show a list of all defined keys, and their definitions.
6918 The optional argument PREFIX, if non-nil, should be a key sequence;
6919 then we display only bindings that start with that prefix."
6921 (gnus-article-check-buffer)
6922 (let ((keymap (copy-keymap gnus-article-mode-map))
6923 (map (copy-keymap gnus-article-send-map))
6924 (sumkeys (where-is-internal 'gnus-article-read-summary-keys))
6926 (define-key keymap "S" map)
6927 (define-key map [t] nil)
6928 (with-current-buffer gnus-article-current-summary
6931 (if (setq parent (keymap-parent gnus-article-mode-map))
6933 (setq parent (copy-keymap parent))
6934 (set-keymap-parent parent (current-local-map)))
6935 (current-local-map)))
6936 (set-keymap-parent map (key-binding "S"))
6937 (let (key def gnus-pick-mode)
6939 (setq key (pop sumkeys))
6940 (cond ((and (vectorp key) (= (length key) 1)
6941 (consp (setq def (aref key 0)))
6942 (numberp (car def)) (numberp (cdr def)))
6943 (when (< (max (car def) (cdr def)) 128)
6947 (nreverse (gnus-uncompress-range def)))
6949 ((setq def (key-binding key))
6950 (unless (eq def 'undefined)
6951 (define-key keymap key def))))))
6952 (when (boundp 'gnus-agent-summary-mode)
6953 (setq agent gnus-agent-summary-mode))
6954 (when (boundp 'gnus-draft-mode)
6955 (setq draft gnus-draft-mode)))
6957 (use-local-map keymap)
6958 (set (make-local-variable 'gnus-agent-summary-mode) agent)
6959 (set (make-local-variable 'gnus-draft-mode) draft)
6960 (describe-bindings prefix))
6961 (let ((item `((lambda (prefix)
6962 (with-current-buffer ,(current-buffer)
6963 (gnus-article-describe-bindings prefix)))
6965 ;; Loading `help-mode' here is necessary if `describe-bindings'
6966 ;; is replaced with something, e.g. `helm-descbinds'.
6967 (require 'help-mode)
6968 (with-current-buffer (let (help-xref-following) (help-buffer))
6969 (setq help-xref-stack-item item)))))
6971 (defun gnus-article-reply-with-original (&optional wide)
6972 "Start composing a reply mail to the current message.
6973 The text in the region will be yanked. If the region isn't active,
6974 the entire article will be yanked."
6976 (let ((article (cdr gnus-article-current))
6978 (if (not (gnus-region-active-p))
6979 (with-current-buffer gnus-summary-buffer
6980 (gnus-summary-reply (list (list article)) wide))
6981 (setq contents (buffer-substring (point) (mark t)))
6982 ;; Deactivate active regions.
6983 (when (and (boundp 'transient-mark-mode)
6984 transient-mark-mode)
6985 (setq mark-active nil))
6986 (with-current-buffer gnus-summary-buffer
6988 (list (list article contents)) wide)))))
6990 (defun gnus-article-wide-reply-with-original ()
6991 "Start composing a wide reply mail to the current message.
6992 The text in the region will be yanked. If the region isn't active,
6993 the entire article will be yanked."
6995 (gnus-article-reply-with-original t))
6997 (defun gnus-article-followup-with-original ()
6998 "Compose a followup to the current article.
6999 The text in the region will be yanked. If the region isn't active,
7000 the entire article will be yanked."
7002 (let ((article (cdr gnus-article-current))
7004 (if (not (gnus-region-active-p))
7005 (with-current-buffer gnus-summary-buffer
7006 (gnus-summary-followup (list (list article))))
7007 (setq contents (buffer-substring (point) (mark t)))
7008 ;; Deactivate active regions.
7009 (when (and (boundp 'transient-mark-mode)
7010 transient-mark-mode)
7011 (setq mark-active nil))
7012 (with-current-buffer gnus-summary-buffer
7013 (gnus-summary-followup
7014 (list (list article contents)))))))
7016 (defun gnus-article-hide (&optional arg force)
7017 "Hide all the gruft in the current article.
7018 This means that signatures, cited text and (some) headers will be
7020 If given a prefix, show the hidden text instead."
7021 (interactive (append (gnus-article-hidden-arg) (list 'force)))
7022 (gnus-article-hide-headers arg)
7023 (gnus-article-hide-list-identifiers arg)
7024 (gnus-article-hide-citation-maybe arg force)
7025 (gnus-article-hide-signature arg))
7027 (defun gnus-check-group-server ()
7028 ;; Make sure the connection to the server is alive.
7029 (unless (gnus-server-opened
7030 (gnus-find-method-for-group gnus-newsgroup-name))
7031 (gnus-check-server (gnus-find-method-for-group gnus-newsgroup-name))
7032 (gnus-request-group gnus-newsgroup-name t)))
7035 (autoload 'nneething-get-file-name "nneething"))
7037 (defun gnus-request-article-this-buffer (article group)
7038 "Get an article and insert it into this buffer."
7039 (let (do-update-line sparse-header)
7043 (gnus-kill-all-overlays)
7044 (setq group (or group gnus-newsgroup-name))
7046 ;; Using `gnus-request-article' directly will insert the article into
7047 ;; `nntp-server-buffer' - so we'll save some time by not having to
7048 ;; copy it from the server buffer into the article buffer.
7050 ;; We only request an article by message-id when we do not have the
7051 ;; headers for it, so we'll have to get those.
7052 (when (stringp article)
7053 (gnus-read-header article))
7055 ;; If the article number is negative, that means that this article
7056 ;; doesn't belong in this newsgroup (possibly), so we find its
7057 ;; message-id and request it by id instead of number.
7058 (when (and (numberp article)
7060 (get-buffer gnus-summary-buffer)
7061 (gnus-buffer-exists-p gnus-summary-buffer))
7062 (with-current-buffer gnus-summary-buffer
7063 (let ((header (gnus-summary-article-header article)))
7066 ((memq article gnus-newsgroup-sparse)
7067 ;; This is a sparse gap article.
7068 (setq do-update-line article)
7069 (setq article (mail-header-id header))
7070 (setq sparse-header (gnus-read-header article))
7071 (setq gnus-newsgroup-sparse
7072 (delq article gnus-newsgroup-sparse)))
7074 ;; It's a real article.
7075 (setq article (mail-header-id header)))
7077 ;; It is an extracted pseudo-article.
7078 (setq article 'pseudo)
7079 (gnus-request-pseudo-article header))))
7081 (let ((method (gnus-find-method-for-group
7082 gnus-newsgroup-name)))
7083 (when (and (eq (car method) 'nneething)
7085 (let ((dir (nneething-get-file-name
7086 (mail-header-id header))))
7087 (when (and (stringp dir)
7088 (file-directory-p dir))
7089 (setq article 'nneething)
7090 (gnus-group-enter-directory dir))))))))
7093 ;; Refuse to select canceled articles.
7094 ((and (numberp article)
7096 (get-buffer gnus-summary-buffer)
7097 (gnus-buffer-exists-p gnus-summary-buffer)
7098 (eq (cdr (with-current-buffer gnus-summary-buffer
7099 (assq article gnus-newsgroup-reads)))
7100 gnus-canceled-mark))
7102 ;; We first check `gnus-original-article-buffer'.
7103 ((and (get-buffer gnus-original-article-buffer)
7105 (with-current-buffer gnus-original-article-buffer
7106 (and (equal (car gnus-original-article) group)
7107 (eq (cdr gnus-original-article) article))))
7108 ;; `insert-buffer-substring' would incorrectly use the
7109 ;; equivalent of string-make-multibyte which amount to decoding
7110 ;; with locale-coding-system, causing failure of
7111 ;; subsequent decoding.
7112 (insert (mm-string-to-multibyte
7113 (with-current-buffer gnus-original-article-buffer
7114 (buffer-substring (point-min) (point-max)))))
7116 ;; Check the backlog.
7117 ((and gnus-keep-backlog
7118 (gnus-backlog-request-article group article (current-buffer)))
7120 ;; Check asynchronous pre-fetch.
7121 ((gnus-async-request-fetched-article group article (current-buffer))
7122 (gnus-async-prefetch-next group article gnus-summary-buffer)
7123 (when (and (numberp article) gnus-keep-backlog)
7124 (gnus-backlog-enter-article group article (current-buffer)))
7127 ((and gnus-use-cache
7129 (gnus-cache-request-article article group))
7131 ;; Check the agent cache.
7132 ((gnus-agent-request-article article group)
7134 ;; Get the article and put into the article buffer.
7135 ((or (stringp article)
7137 (let ((gnus-override-method gnus-override-method)
7138 (methods (and (stringp article)
7139 (with-current-buffer gnus-summary-buffer
7140 (gnus-refer-article-methods))))
7141 (backend (car (gnus-find-method-for-group
7142 gnus-newsgroup-name)))
7144 (inhibit-read-only t))
7145 (when (and (null gnus-override-method)
7147 (setq gnus-override-method (pop methods)))
7150 (gnus-kill-all-overlays)
7151 (let ((gnus-newsgroup-name group))
7152 (gnus-check-group-server))
7154 ((gnus-request-article article group (current-buffer))
7155 (when (numberp article)
7156 (gnus-async-prefetch-next group article
7157 gnus-summary-buffer)
7158 (when gnus-keep-backlog
7159 (gnus-backlog-enter-article
7160 group article (current-buffer)))
7161 (when (and gnus-agent
7162 (gnus-agent-group-covered-p group))
7163 (gnus-agent-store-article article group)))
7164 (setq result 'article))
7166 (setq gnus-override-method (pop methods)))
7167 ((not (string-match "^400 "
7168 (nnheader-get-report backend)))
7169 ;; If we get 400 server disconnect, reconnect and
7170 ;; retry; otherwise, assume the article has expired.
7171 (setq result 'done))))
7172 (and (eq result 'article) 'article)))
7176 ;; Associate this article with the current summary buffer.
7177 (setq gnus-article-current-summary gnus-summary-buffer)
7179 ;; Take the article from the original article buffer
7180 ;; and place it in the buffer it's supposed to be in.
7181 (when (and (get-buffer gnus-article-buffer)
7182 (equal (buffer-name (current-buffer))
7183 (buffer-name (get-buffer gnus-article-buffer))))
7185 (if (get-buffer gnus-original-article-buffer)
7186 (set-buffer gnus-original-article-buffer)
7187 (set-buffer (gnus-get-buffer-create gnus-original-article-buffer))
7188 (buffer-disable-undo)
7189 (setq major-mode 'gnus-original-article-mode)
7190 (setq buffer-read-only t))
7191 (let ((inhibit-read-only t))
7193 (insert-buffer-substring gnus-article-buffer))
7194 (setq gnus-original-article (cons group article)))
7197 (run-hooks 'gnus-article-decode-hook)
7198 ;; Mark article as decoded or not.
7199 (setq gnus-article-decoded-p gnus-article-decode-hook))
7201 ;; Update sparse articles.
7202 (when (and do-update-line
7203 (or (numberp article)
7205 (let ((buf (current-buffer)))
7206 (set-buffer gnus-summary-buffer)
7207 (gnus-summary-update-article do-update-line sparse-header)
7208 (gnus-summary-goto-subject do-update-line nil t)
7209 (set-window-point (gnus-get-buffer-window (current-buffer) t)
7211 (set-buffer buf))))))
7213 (defun gnus-block-private-groups (group)
7214 (if (or (gnus-news-group-p group)
7215 (gnus-member-of-valid 'global group))
7216 ;; Block nothing in news groups.
7218 ;; Block everything anywhere else.
7221 (defun gnus-blocked-images ()
7222 (if (functionp gnus-blocked-images)
7223 (funcall gnus-blocked-images gnus-newsgroup-name)
7224 gnus-blocked-images))
7230 (defcustom gnus-article-edit-mode-hook nil
7231 "Hook run in article edit mode buffers."
7232 :group 'gnus-article-various
7235 (defvar gnus-article-edit-done-function nil)
7237 (defvar gnus-article-edit-mode-map nil)
7239 ;; Should we be using derived.el for this?
7240 (unless gnus-article-edit-mode-map
7241 (setq gnus-article-edit-mode-map (make-keymap))
7242 (set-keymap-parent gnus-article-edit-mode-map text-mode-map)
7244 (gnus-define-keys gnus-article-edit-mode-map
7245 "\C-c?" describe-mode
7246 "\C-c\C-c" gnus-article-edit-done
7247 "\C-c\C-k" gnus-article-edit-exit
7248 "\C-c\C-f\C-t" message-goto-to
7249 "\C-c\C-f\C-o" message-goto-from
7250 "\C-c\C-f\C-b" message-goto-bcc
7251 ;;"\C-c\C-f\C-w" message-goto-fcc
7252 "\C-c\C-f\C-c" message-goto-cc
7253 "\C-c\C-f\C-s" message-goto-subject
7254 "\C-c\C-f\C-r" message-goto-reply-to
7255 "\C-c\C-f\C-n" message-goto-newsgroups
7256 "\C-c\C-f\C-d" message-goto-distribution
7257 "\C-c\C-f\C-f" message-goto-followup-to
7258 "\C-c\C-f\C-m" message-goto-mail-followup-to
7259 "\C-c\C-f\C-k" message-goto-keywords
7260 "\C-c\C-f\C-u" message-goto-summary
7261 "\C-c\C-f\C-i" message-insert-or-toggle-importance
7262 "\C-c\C-f\C-a" message-generate-unsubscribed-mail-followup-to
7263 "\C-c\C-b" message-goto-body
7264 "\C-c\C-i" message-goto-signature
7266 "\C-c\C-t" message-insert-to
7267 "\C-c\C-n" message-insert-newsgroups
7268 "\C-c\C-o" message-sort-headers
7269 "\C-c\C-e" message-elide-region
7270 "\C-c\C-v" message-delete-not-region
7271 "\C-c\C-z" message-kill-to-signature
7272 "\M-\r" message-newline-and-reformat
7273 "\C-c\C-a" mml-attach-file
7274 "\C-a" message-beginning-of-line
7276 "\M-;" comment-region)
7278 (gnus-define-keys (gnus-article-edit-wash-map
7279 "\C-c\C-w" gnus-article-edit-mode-map)
7280 "f" gnus-article-edit-full-stops))
7283 gnus-article-edit-mode-field-menu gnus-article-edit-mode-map ""
7285 ["Fetch To" message-insert-to t]
7286 ["Fetch Newsgroups" message-insert-newsgroups t]
7288 ["To" message-goto-to t]
7289 ["From" message-goto-from t]
7290 ["Subject" message-goto-subject t]
7291 ["Cc" message-goto-cc t]
7292 ["Reply-To" message-goto-reply-to t]
7293 ["Summary" message-goto-summary t]
7294 ["Keywords" message-goto-keywords t]
7295 ["Newsgroups" message-goto-newsgroups t]
7296 ["Followup-To" message-goto-followup-to t]
7297 ["Mail-Followup-To" message-goto-mail-followup-to t]
7298 ["Distribution" message-goto-distribution t]
7299 ["Body" message-goto-body t]
7300 ["Signature" message-goto-signature t]))
7302 (define-derived-mode gnus-article-edit-mode message-mode "Article Edit"
7303 "Major mode for editing articles.
7304 This is an extended text-mode.
7306 \\{gnus-article-edit-mode-map}"
7307 (make-local-variable 'gnus-article-edit-done-function)
7308 (make-local-variable 'gnus-prev-winconf)
7309 (set (make-local-variable 'font-lock-defaults)
7310 '(message-font-lock-keywords t))
7311 (set (make-local-variable 'mail-header-separator) "")
7312 (set (make-local-variable 'gnus-article-edit-mode) t)
7313 (easy-menu-add message-mode-field-menu message-mode-map)
7315 (setq buffer-read-only nil)
7316 (buffer-enable-undo)
7319 (defun gnus-article-edit (&optional force)
7320 "Edit the current article.
7321 This will have permanent effect only in mail groups.
7322 If FORCE is non-nil, allow editing of articles even in read-only
7325 (when (and (not force)
7326 (gnus-group-read-only-p))
7327 (error "The current newsgroup does not support article editing"))
7328 (gnus-article-date-original)
7329 (gnus-article-edit-article
7331 `(lambda (no-highlight)
7333 (gnus-summary-edit-article-done
7334 ,(or (mail-header-references gnus-current-headers) "")
7335 ,(gnus-group-read-only-p) ,gnus-summary-buffer no-highlight))))
7337 (defun gnus-article-edit-article (start-func exit-func &optional quiet)
7338 "Start editing the contents of the current article buffer."
7339 (let ((winconf (current-window-configuration)))
7340 (set-buffer gnus-article-buffer)
7341 (let ((message-auto-save-directory
7342 ;; Don't associate the article buffer with a draft file.
7344 (gnus-article-edit-mode))
7345 (funcall start-func)
7346 (set-buffer-modified-p nil)
7347 (gnus-configure-windows 'edit-article)
7348 (setq gnus-article-edit-done-function exit-func)
7349 (setq gnus-prev-winconf winconf)
7351 (gnus-message 6 "C-c C-c to end edits"))))
7353 (defun gnus-article-edit-done (&optional arg)
7354 "Update the article edits and exit."
7356 (let ((func gnus-article-edit-done-function)
7357 (buf (current-buffer))
7358 (start (window-start))
7359 (winconf gnus-prev-winconf))
7360 (widen) ;; Widen it in case that users narrowed the buffer.
7363 ;; The cache and backlog have to be flushed somewhat.
7364 (when gnus-keep-backlog
7365 (gnus-backlog-remove-article
7366 (car gnus-article-current) (cdr gnus-article-current)))
7367 ;; Flush original article as well.
7368 (gnus-flush-original-article-buffer)
7369 (when gnus-use-cache
7370 (gnus-cache-update-article
7371 (car gnus-article-current) (cdr gnus-article-current)))
7372 ;; We remove all text props from the article buffer.
7373 (kill-all-local-variables)
7374 (set-text-properties (point-min) (point-max) nil)
7376 (set-window-configuration winconf)
7378 (set-window-start (get-buffer-window buf) start)
7379 (set-window-point (get-buffer-window buf) (point)))
7380 (gnus-summary-show-article))
7382 (defun gnus-flush-original-article-buffer ()
7383 (when (get-buffer gnus-original-article-buffer)
7384 (with-current-buffer gnus-original-article-buffer
7385 (setq gnus-original-article nil))))
7387 (defun gnus-article-edit-exit ()
7388 "Exit the article editing without updating."
7390 (when (or (not (buffer-modified-p))
7391 (yes-or-no-p "Article modified; kill anyway? "))
7392 (let ((curbuf (current-buffer))
7394 (window-start (window-start)))
7396 (if (gnus-buffer-live-p gnus-original-article-buffer)
7397 (insert-buffer-substring gnus-original-article-buffer))
7398 (let ((winconf gnus-prev-winconf))
7399 (kill-all-local-variables)
7401 (set-window-configuration winconf)
7402 ;; Tippy-toe some to make sure that point remains where it was.
7403 (save-current-buffer
7405 (set-window-start (get-buffer-window (current-buffer)) window-start)
7407 (gnus-summary-show-article)))
7409 (defun gnus-article-edit-full-stops ()
7410 "Interactively repair spacing at end of sentences."
7413 (goto-char (point-min))
7414 (search-forward-regexp "^$" nil t)
7415 (let ((case-fold-search nil))
7416 (query-replace-regexp "\\([.!?][])}]* \\)\\([[({A-Z]\\)" "\\1 \\2"))))
7419 ;;; Article highlights
7422 ;; Written by Per Abrahamsen <abraham@iesd.auc.dk>.
7424 ;;; Internal Variables:
7426 (defcustom gnus-button-url-regexp
7428 "\\b\\(\\(www\\.\\|\\(s?https?\\|ftp\\|file\\|gopher\\|"
7429 "nntp\\|news\\|telnet\\|wais\\|mailto\\|info\\):\\)"
7430 "\\(//[-a-z0-9_.]+:[0-9]*\\)?"
7431 (if (string-match "[[:digit:]]" "1") ;; Support POSIX?
7432 (let ((chars "-a-z0-9_=#$@~%&*+\\/[:word:]")
7436 ;; Match paired parentheses, e.g. in Wikipedia URLs:
7437 ;; http://thread.gmane.org/47B4E3B2.3050402@gmail.com
7438 "[" chars punct "]+" "(" "[" chars punct "]+" "[" chars "]*)"
7439 "\\(?:" "[" chars punct "]+" "[" chars "]" "\\)?"
7441 "[" chars punct "]+" "[" chars "]"
7443 (concat ;; XEmacs 21.4 doesn't support POSIX.
7444 "\\([-a-z0-9_=!?#$@~%&*+\\/:;.,]\\|\\w\\)+"
7445 "\\([-a-z0-9_=#$@~%&*+\\/]\\|\\w\\)"))
7447 "Regular expression that matches URLs."
7449 :group 'gnus-article-buttons
7452 (defcustom gnus-button-valid-fqdn-regexp
7453 message-valid-fqdn-regexp
7454 "Regular expression that matches a valid FQDN."
7456 :group 'gnus-article-buttons
7459 ;; Regexp suggested by Felix Wiemann in <87oeuomcz9.fsf@news2.ososo.de>
7460 (defcustom gnus-button-valid-localpart-regexp
7461 "[a-z0-9$%(*-=?[_][^<>\")!;:,{}\n\t @]*"
7462 "Regular expression that matches a localpart of mail addresses or MIDs."
7464 :group 'gnus-article-buttons
7467 (defcustom gnus-button-man-handler 'manual-entry
7468 "Function to use for displaying man pages.
7469 The function must take at least one argument with a string naming the
7472 :type '(choice (function-item :tag "Man" manual-entry)
7473 (function-item :tag "Woman" woman)
7474 (function :tag "Other"))
7475 :group 'gnus-article-buttons)
7477 (defcustom gnus-button-mid-or-mail-regexp
7478 (concat "\\b\\(<?" gnus-button-valid-localpart-regexp "@"
7479 gnus-button-valid-fqdn-regexp
7481 "Regular expression that matches a message ID or a mail address."
7483 :group 'gnus-article-buttons
7486 (defcustom gnus-button-prefer-mid-or-mail 'gnus-button-mid-or-mail-heuristic
7487 "What to do when the button on a string as \"foo123@bar.invalid\" is pushed.
7488 Strings like this can be either a message ID or a mail address. If it is one
7489 of the symbols `mid' or `mail', Gnus will always assume that the string is a
7490 message ID or a mail address, respectively. If this variable is set to the
7491 symbol `ask', always query the user what do do. If it is a function, this
7492 function will be called with the string as its only argument. The function
7493 must return `mid', `mail', `invalid' or `ask'."
7495 :group 'gnus-article-buttons
7496 :type '(choice (function-item :tag "Heuristic function"
7497 gnus-button-mid-or-mail-heuristic)
7502 (defcustom gnus-button-mid-or-mail-heuristic-alist
7503 '((-10.0 . ".+\\$.+@")
7506 (-5.0 . "\\+[^+]*\\+.*@") ;; # two plus signs
7507 (-5.0 . "@[Nn][Ee][Ww][Ss]") ;; /\@news/i
7508 (-5.0 . "@.*[Dd][Ii][Aa][Ll][Uu][Pp]") ;; /\@.*dialup/i;
7509 (-1.0 . "^[^a-z]+@")
7511 (-5.0 . "\\.[0-9][0-9]+.*@") ;; "\.[0-9]{2,}.*\@"
7512 (-5.0 . "[a-z].*[A-Z].*[a-z].*[A-Z].*@") ;; "([a-z].*[A-Z].*){2,}\@"
7513 (-3.0 . "[A-Z][A-Z][a-z][a-z].*@")
7514 (-5.0 . "\\...?.?@") ;; (-5.0 . "\..{1,3}\@")
7517 (-1.0 . "^[0-9][0-9]")
7519 ;; -3.0 /^[0-9][0-9a-fA-F]{2,2}/;
7520 (-3.0 . "^[0-9][0-9a-fA-F][0-9a-fA-F][^0-9a-fA-F]")
7521 ;; -5.0 /^[0-9][0-9a-fA-F]{3,3}/;
7522 (-5.0 . "^[0-9][0-9a-fA-F][0-9a-fA-F][0-9a-fA-F][^0-9a-fA-F]")
7524 (-3.0 . "[0-9][0-9][0-9][0-9][0-9][^0-9].*@") ;; "[0-9]{5,}.*\@"
7525 (-3.0 . "[0-9][0-9][0-9][0-9][0-9][0-9][0-9][0-9][^0-9].*@")
7528 . "[0-9][0-9][0-9][0-9][0-9][0-9][0-9][0-9][0-9][0-9][0-9][0-9].*@")
7530 ;; compensation for TDMA dated mail addresses:
7531 (25.0 . "-dated-[0-9][0-9][0-9][0-9][0-9][0-9][0-9][0-9]+.*@")
7533 (-20.0 . "\\.fsf@") ;; Gnus
7536 (-20.0 . "^alpine\\.")
7537 (-20.0 . "_-_") ;; Subject change in thread
7539 (-20.0 . "\\.ln@") ;; leafnode
7540 (-30.0 . "@ID-[0-9]+\\.[a-zA-Z]+\\.dfncis\\.de")
7541 (-30.0 . "@4[Aa][Xx]\\.com") ;; Forte Agent
7543 ;; (5.0 . "") ;; $local_part_len <= 7
7544 (10.0 . "^[^0-9]+@")
7545 (3.0 . "^[^0-9]+[0-9][0-9]?[0-9]?@")
7546 ;; ^[^0-9]+[0-9]{1,3}\@ digits only at end of local part
7549 (2.0 . "[a-z][a-z][._-][A-Z][a-z].*@")
7551 (0.5 . "^[A-Z][a-z]")
7552 (0.5 . "^[A-Z][a-z][a-z]")
7553 (1.5 . "^[A-Z][a-z][A-Z][a-z][^a-z]") ;; ^[A-Z][a-z]{3,3}
7554 (2.0 . "^[A-Z][a-z][A-Z][a-z][a-z][^a-z]")) ;; ^[A-Z][a-z]{4,4}
7555 "An alist of \(RATE . REGEXP\) pairs for `gnus-button-mid-or-mail-heuristic'.
7557 A negative RATE indicates a message IDs, whereas a positive indicates a mail
7558 address. The REGEXP is processed with `case-fold-search' set to nil."
7560 :group 'gnus-article-buttons
7561 :type '(repeat (cons (number :tag "Rate")
7562 (regexp :tag "Regexp"))))
7564 (defun gnus-button-mid-or-mail-heuristic (mid-or-mail)
7565 "Guess whether MID-OR-MAIL is a message ID or a mail address.
7566 Returns `mid' if MID-OR-MAIL is a message IDs, `mail' if it's a mail
7567 address, `ask' if unsure and `invalid' if the string is invalid."
7568 (let ((case-fold-search nil)
7569 (list gnus-button-mid-or-mail-heuristic-alist)
7570 (result 0) rate regexp lpartlen elem)
7572 (length (gnus-replace-in-string mid-or-mail "^\\(.*\\)@.*$" "\\1")))
7573 (gnus-message 8 "`%s', length of local part=`%s'." mid-or-mail lpartlen)
7574 ;; Certain special cases...
7577 "^0[0-9]+-[0-9][0-9][0-9][0-9]@t-online\\.de$\\|"
7578 "^[0-9]+\\.[0-9]+@compuserve\\|"
7579 "@public\\.gmane\\.org")
7581 (gnus-message 8 "`%s' is a known mail address." mid-or-mail)
7582 (setq result 'mail))
7583 (when (string-match "@.*@\\| " mid-or-mail)
7584 (gnus-message 8 "`%s' is invalid." mid-or-mail)
7585 (setq result 'invalid))
7586 ;; Nothing more to do, if result is not a number here...
7587 (when (numberp result)
7589 (setq elem (car list)
7593 (when (string-match regexp mid-or-mail)
7594 (setq result (+ result rate))
7596 9 "`%s' matched `%s', rate `%s', result `%s'."
7597 mid-or-mail regexp rate result)))
7598 (when (<= lpartlen 7)
7599 (setq result (+ result 5.0))
7600 (gnus-message 9 "`%s' matched (<= lpartlen 7), result `%s'."
7601 mid-or-mail result))
7602 (when (>= lpartlen 12)
7603 (gnus-message 9 "`%s' matched (>= lpartlen 12)" mid-or-mail)
7605 ((string-match "[0-9][^0-9]+[0-9].*@" mid-or-mail)
7606 ;; Long local part should contain realname if e-mail address,
7607 ;; too many digits: message-id.
7608 ;; $score -= 5.0 + 0.1 * $local_part_len;
7609 (setq rate (* -1.0 (+ 5.0 (* 0.1 lpartlen))))
7610 (setq result (+ result rate))
7612 9 "Many digits in `%s', rate `%s', result `%s'."
7613 mid-or-mail rate result))
7614 ((string-match "[^aeiouy][^aeiouy][^aeiouy][^aeiouy]+.*\@"
7616 ;; Too few vowels [^aeiouy]{4,}.*\@
7617 (setq result (+ result -5.0))
7619 9 "Few vowels in `%s', rate `%s', result `%s'."
7620 mid-or-mail -5.0 result))
7622 (setq result (+ result 5.0))
7624 9 "`%s', rate `%s', result `%s'." mid-or-mail 5.0 result)))))
7625 (gnus-message 8 "`%s': Final rate is `%s'." mid-or-mail result)
7626 ;; Maybe we should make this a customizable alist: (condition . 'result)
7628 ((symbolp result) result)
7629 ;; Now convert number into proper results:
7630 ((< result -10.0) 'mid)
7631 ((> result 10.0) 'mail)
7634 (defun gnus-button-handle-mid-or-mail (mid-or-mail)
7635 (let* ((pref gnus-button-prefer-mid-or-mail) guessed
7636 (url-mid (concat "news" ":" mid-or-mail))
7637 (url-mailto (concat "mailto" ":" mid-or-mail)))
7638 (gnus-message 9 "mid-or-mail=%s" mid-or-mail)
7639 (when (fboundp pref)
7641 ;; get rid of surrounding angles...
7643 (gnus-replace-in-string mid-or-mail "^<\\|>$" "")))
7644 (if (or (eq 'mid guessed) (eq 'mail guessed))
7648 (save-window-excursion
7649 (if (y-or-n-p (concat "Is <" mid-or-mail "> a mail address? "))
7652 (cond ((eq pref 'mid)
7653 (gnus-message 8 "calling `gnus-button-handle-news' %s" url-mid)
7654 (gnus-button-handle-news url-mid))
7656 (gnus-message 8 "calling `gnus-url-mailto' %s" url-mailto)
7657 (gnus-url-mailto url-mailto))
7658 (t (gnus-message 3 "Invalid string.")))))
7660 (defun gnus-button-handle-custom (fun arg)
7661 "Call function FUN on argument ARG.
7662 Both FUN and ARG are supposed to be strings. ARG will be passed
7663 as a symbol to FUN."
7664 (funcall (intern fun)
7665 (if (string-match "^customize-apropos" fun)
7669 (defvar gnus-button-handle-describe-prefix "^\\(C-h\\|<?[Ff]1>?\\)")
7671 (defun gnus-button-handle-describe-function (url)
7672 "Call `describe-function' when pushing the corresponding URL button."
7675 (gnus-replace-in-string url gnus-button-handle-describe-prefix ""))))
7677 (defun gnus-button-handle-describe-variable (url)
7678 "Call `describe-variable' when pushing the corresponding URL button."
7681 (gnus-replace-in-string url gnus-button-handle-describe-prefix ""))))
7683 (defun gnus-button-handle-symbol (url)
7684 "Display help on variable or function.
7685 Calls `describe-variable' or `describe-function'."
7686 (let ((sym (intern url)))
7688 ((fboundp sym) (describe-function sym))
7689 ((boundp sym) (describe-variable sym))
7690 (t (gnus-message 3 "`%s' is not a known function of variable." url)))))
7692 (defun gnus-button-handle-describe-key (url)
7693 "Call `describe-key' when pushing the corresponding URL button."
7695 (gnus-replace-in-string url gnus-button-handle-describe-prefix ""))
7696 (keys (ignore-errors (eval `(kbd ,key-string)))))
7699 (gnus-message 3 "Invalid key sequence in button: %s" key-string))))
7701 (defun gnus-button-handle-apropos (url)
7702 "Call `apropos' when pushing the corresponding URL button."
7703 (apropos (gnus-replace-in-string url gnus-button-handle-describe-prefix "")))
7705 (defun gnus-button-handle-apropos-command (url)
7706 "Call `apropos' when pushing the corresponding URL button."
7708 (gnus-replace-in-string url gnus-button-handle-describe-prefix "")))
7710 (defun gnus-button-handle-apropos-variable (url)
7711 "Call `apropos' when pushing the corresponding URL button."
7713 (if (fboundp 'apropos-variable) 'apropos-variable 'apropos)
7714 (gnus-replace-in-string url gnus-button-handle-describe-prefix "")))
7716 (defun gnus-button-handle-apropos-documentation (url)
7717 "Call `apropos' when pushing the corresponding URL button."
7719 (if (fboundp 'apropos-documentation) 'apropos-documentation 'apropos)
7720 (gnus-replace-in-string url gnus-button-handle-describe-prefix "")))
7722 (defun gnus-button-handle-library (url)
7723 "Call `locate-library' when pushing the corresponding URL button."
7724 (gnus-message 9 "url=`%s'" url)
7725 (let* ((lib (locate-library url))
7726 (file (gnus-replace-in-string (or lib "") "\.elc" ".el")))
7728 (gnus-message 1 "Cannot locale library `%s'." url)
7729 (find-file-read-only file))))
7731 (defcustom gnus-button-man-level 5
7732 "*Integer that says how many man-related buttons Gnus will show.
7733 The higher the number, the more buttons will appear and the more false
7734 positives are possible. Note that you can set this variable local to
7735 specific groups. Setting it higher in Unix groups is probably a good idea.
7736 See Info node `(gnus)Group Parameters' and the variable `gnus-parameters' on
7737 how to set variables in specific groups."
7739 :group 'gnus-article-buttons
7740 :link '(custom-manual "(gnus)Group Parameters")
7743 (defcustom gnus-button-emacs-level 5
7744 "*Integer that says how many emacs-related buttons Gnus will show.
7745 The higher the number, the more buttons will appear and the more false
7746 positives are possible. Note that you can set this variable local to
7747 specific groups. Setting it higher in Emacs or Gnus related groups is
7748 probably a good idea. See Info node `(gnus)Group Parameters' and the variable
7749 `gnus-parameters' on how to set variables in specific groups."
7751 :group 'gnus-article-buttons
7752 :link '(custom-manual "(gnus)Group Parameters")
7755 (defcustom gnus-button-message-level 5
7756 "*Integer that says how many buttons for news or mail messages will appear.
7757 The higher the number, the more buttons will appear and the more false
7758 positives are possible."
7759 ;; mail addresses, MIDs, URLs for news, ...
7761 :group 'gnus-article-buttons
7764 (defcustom gnus-button-browse-level 5
7765 "*Integer that says how many buttons for browsing will appear.
7766 The higher the number, the more buttons will appear and the more false
7767 positives are possible."
7768 ;; stuff handled by `browse-url' or `gnus-button-embedded-url'
7770 :group 'gnus-article-buttons
7773 (defcustom gnus-button-alist
7774 '(("<\\(url:[>\n\t ]*?\\)?\\(nntp\\|news\\):[>\n\t ]*\\([^>\n\t ]*@[^>\n\t ]*\\)>"
7775 0 (>= gnus-button-message-level 0) gnus-button-handle-news 3)
7776 ((concat "\\b\\(nntp\\|news\\):\\("
7777 gnus-button-valid-localpart-regexp "@[a-z0-9.-]+[a-z]\\)")
7778 0 t gnus-button-handle-news 2)
7779 ("\\(\\b<\\(url:[>\n\t ]*\\)?\\(nntp\\|news\\):[>\n\t ]*\\(//\\)?\\([^>\n\t ]*\\)>\\)"
7780 1 (>= gnus-button-message-level 0) gnus-button-fetch-group 5)
7781 ("\\b\\(nntp\\|news\\):\\(//\\)?\\([^'\">\n\t ]+\\)"
7782 0 (>= gnus-button-message-level 0) gnus-button-fetch-group 3)
7783 ;; RFC 2392 (Don't allow `/' in domain part --> CID)
7784 ("\\bmid:\\(//\\)?\\([^'\">\n\t ]+@[^'\">\n\t /]+\\)"
7785 0 (>= gnus-button-message-level 0) gnus-button-message-id 2)
7786 ("\\bin\\( +article\\| +message\\)? +\\(<\\([^\n @<>]+@[^\n @<>]+\\)>\\)"
7787 2 (>= gnus-button-message-level 0) gnus-button-message-id 3)
7788 ("\\b\\(mid\\|message-id\\):? +\\(<\\([^\n @<>]+@[^\n @<>]+\\)>\\)"
7789 2 (>= gnus-button-message-level 0) gnus-button-message-id 3)
7790 ("\\(<URL: *\\)mailto: *\\([^> \n\t]+\\)>"
7791 0 (>= gnus-button-message-level 0) gnus-url-mailto 2)
7792 ;; RFC 2368 (The mailto URL scheme)
7793 ("\\bmailto:\\([-a-z.@_+0-9%=?&/]+\\)"
7794 0 (>= gnus-button-message-level 0) gnus-url-mailto 1)
7795 ("\\bmailto:\\([^ \n\t]+\\)"
7796 0 (>= gnus-button-message-level 0) gnus-url-mailto 1)
7797 ;; Info Konqueror style <info:/foo/bar baz>.
7798 ;; Must come before " Gnus home-grown style".
7799 ("\\binfo://?\\([^'\">\n\t]+\\)"
7800 0 (>= gnus-button-emacs-level 1) gnus-button-handle-info-url 1)
7801 ;; Info, Gnus home-grown style (deprecated) <info://foo/bar+baz>
7802 ("\\binfo://\\([^'\">\n\t ]+\\)"
7803 0 (>= gnus-button-emacs-level 1) gnus-button-handle-info-url 1)
7804 ;; Info GNOME style <info:foo#bar_baz>
7805 ("\\binfo:\\([^('\n\t\r \"><][^'\n\t\r \"><]*\\)"
7806 0 (>= gnus-button-emacs-level 1) gnus-button-handle-info-url-gnome 1)
7807 ;; Info KDE style <info:(foo)bar baz>
7808 ("<\\(info:\\(([^)]+)[^>\n\r]*\\)\\)>"
7809 1 (>= gnus-button-emacs-level 1) gnus-button-handle-info-url-kde 2)
7810 ("\\((Info-goto-node\\|(info\\)[ \t\n]*\\(\"[^\"]*\"\\))" 0
7811 (>= gnus-button-emacs-level 1) gnus-button-handle-info-url 2)
7812 ("\\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,]*\\)\\)?"
7813 ;; Info links like `C-h i d m Gnus RET' or `C-h i d m Gnus RET i partial RET'
7814 0 (>= gnus-button-emacs-level 1) gnus-button-handle-info-keystrokes 0)
7816 ("M-x[ \t\n]\\(customize-[^ ]+\\)[ \t\n]RET[ \t\n]\\([^ ]+\\)[ \t\n]RET\\>" 0
7817 (>= gnus-button-emacs-level 1) gnus-button-handle-custom 1 2)
7818 ;; Emacs help commands
7819 ("M-x[ \t\n]+apropos[ \t\n]+RET[ \t\n]+\\([^ \t\n]+\\)[ \t\n]+RET\\>"
7820 ;; regexp doesn't match arguments containing ` '.
7821 0 (>= gnus-button-emacs-level 1) gnus-button-handle-apropos 1)
7822 ("M-x[ \t\n]+apropos-command[ \t\n]+RET[ \t\n]+\\([^ \t\n]+\\)[ \t\n]+RET\\>"
7823 0 (>= gnus-button-emacs-level 1) gnus-button-handle-apropos-command 1)
7824 ("M-x[ \t\n]+apropos-variable[ \t\n]+RET[ \t\n]+\\([^ \t\n]+\\)[ \t\n]+RET\\>"
7825 0 (>= gnus-button-emacs-level 1) gnus-button-handle-apropos-variable 1)
7826 ("M-x[ \t\n]+apropos-documentation[ \t\n]+RET[ \t\n]+\\([^ \t\n]+\\)[ \t\n]+RET\\>"
7827 0 (>= gnus-button-emacs-level 1) gnus-button-handle-apropos-documentation 1)
7828 ;; The following entries may lead to many false positives so don't enable
7829 ;; them by default (use a high button level).
7830 ("/\\([a-z][-a-z0-9]+\\.el\\)\\>[^.?]"
7831 ;; Exclude [.?] for URLs in gmane.emacs.cvs
7832 1 (>= gnus-button-emacs-level 8) gnus-button-handle-library 1)
7833 ("`\\([a-z][-a-z0-9]+\\.el\\)'"
7834 1 (>= gnus-button-emacs-level 8) gnus-button-handle-library 1)
7835 ("`\\([a-z][a-z0-9]+-[a-z0-9]+-[-a-z0-9]*[a-z]\\|\\(gnus\\|message\\)-[-a-z]+\\)'"
7836 0 (>= gnus-button-emacs-level 8) gnus-button-handle-symbol 1)
7837 ("`\\([a-z][a-z0-9]+-[a-z]+\\)'"
7838 0 (>= gnus-button-emacs-level 9) gnus-button-handle-symbol 1)
7839 ("(setq[ \t\n]+\\([a-z][a-z0-9]+-[-a-z0-9]+\\)[ \t\n]+.+)"
7840 1 (>= gnus-button-emacs-level 7) gnus-button-handle-describe-variable 1)
7841 ("\\bM-x[ \t\n]+\\([^ \t\n]+\\)[ \t\n]+RET\\>"
7842 1 (>= gnus-button-emacs-level 7) gnus-button-handle-describe-function 1)
7843 ("\\b\\(C-h\\|<?[Ff]1>?\\)[ \t\n]+f[ \t\n]+\\([^ \t\n]+\\)[ \t\n]+RET\\>"
7844 0 (>= gnus-button-emacs-level 1) gnus-button-handle-describe-function 2)
7845 ("\\b\\(C-h\\|<?[Ff]1>?\\)[ \t\n]+v[ \t\n]+\\([^ \t\n]+\\)[ \t\n]+RET\\>"
7846 0 (>= gnus-button-emacs-level 1) gnus-button-handle-describe-variable 2)
7847 ("`\\(\\(C-h\\|<?[Ff]1>?\\)[ \t\n]+k[ \t\n]+\\([^']+\\)\\)'"
7848 ;; Unlike the other regexps we really have to require quoting
7849 ;; here to determine where it ends.
7850 1 (>= gnus-button-emacs-level 1) gnus-button-handle-describe-key 3)
7851 ;; This is how URLs _should_ be embedded in text (RFC 1738, RFC 2396)...
7852 ("<URL: *\\([^\n<>]*\\)>"
7853 1 (>= gnus-button-browse-level 0) gnus-button-embedded-url 1)
7854 ;; RFC 2396 (2.4.3., delims) ...
7855 ("\"URL: *\\([^\n\"]*\\)\""
7856 1 (>= gnus-button-browse-level 0) gnus-button-embedded-url 1)
7858 (gnus-button-url-regexp
7859 0 (>= gnus-button-browse-level 0) browse-url 0)
7861 ("\\b\\([a-z][a-z]+([1-9])\\)\\W"
7862 0 (and (>= gnus-button-man-level 1) (< gnus-button-man-level 3))
7863 gnus-button-handle-man 1)
7864 ;; more man pages: resolv.conf(5), iso_8859-1(7), xterm(1x)
7865 ("\\b\\([a-z][-_.a-z0-9]+([1-9])\\)\\W"
7866 0 (and (>= gnus-button-man-level 3) (< gnus-button-man-level 5))
7867 gnus-button-handle-man 1)
7868 ;; even more: Apache::PerlRun(3pm), PDL::IO::FastRaw(3pm),
7869 ;; SoWWWAnchor(3iv), XSelectInput(3X11), X(1), X(7)
7870 ("\\b\\(\\(?:[a-z][-+_.:a-z0-9]+([1-9][X1a-z]*)\\)\\|\\b\\(?:X([1-9])\\)\\)\\W"
7871 0 (>= gnus-button-man-level 5) gnus-button-handle-man 1)
7872 ;; Recognizing patches to .el files. This is somewhat obscure,
7873 ;; but considering the percentage of Gnus users who hack Emacs
7875 ("^--- \\([^ .]+\\.el\\).*\n.*\n@@ -?\\([0-9]+\\)" 1
7876 (>= gnus-button-message-level 4) gnus-button-patch 1 2)
7877 ("^\\*\\*\\* \\([^ .]+\\.el\\).*\n.*\n\\*+\n\\*\\*\\* \\([0-9]+\\)" 1
7878 (>= gnus-button-message-level 4) gnus-button-patch 1 2)
7879 ;; MID or mail: To avoid too many false positives we don't try to catch
7880 ;; all kind of allowed MIDs or mail addresses. Domain part must contain
7881 ;; at least one dot. TLD must contain two or three chars or be a know TLD
7882 ;; (info|name|...). Put this entry near the _end_ of `gnus-button-alist'
7883 ;; so that non-ambiguous entries (see above) match first.
7884 (gnus-button-mid-or-mail-regexp
7885 0 (>= gnus-button-message-level 5) gnus-button-handle-mid-or-mail 1))
7886 "*Alist of regexps matching buttons in article bodies.
7888 Each entry has the form (REGEXP BUTTON FORM CALLBACK PAR...), where
7889 REGEXP: is the string (case insensitive) matching text around the button (can
7890 also be Lisp expression evaluating to a string),
7891 BUTTON: is the number of the regexp grouping actually matching the button,
7892 FORM: is a Lisp expression which must eval to true for the button to
7894 CALLBACK: is the function to call when the user push this button, and each
7895 PAR: is a number of a regexp grouping whose text will be passed to CALLBACK.
7897 CALLBACK can also be a variable, in that case the value of that
7898 variable it the real callback function."
7899 :group 'gnus-article-buttons
7900 :type '(repeat (list (choice regexp variable sexp)
7901 (integer :tag "Button")
7903 (function :tag "Callback")
7906 (integer :tag "Regexp group")))))
7907 (put 'gnus-button-alist 'risky-local-variable t)
7909 (defcustom gnus-header-button-alist
7910 '(("^\\(References\\|Message-I[Dd]\\|^In-Reply-To\\):" "<[^<>]+>"
7911 0 (>= gnus-button-message-level 0) gnus-button-message-id 0)
7912 ("^\\(From\\|Reply-To\\):" ": *\\(.+\\)$"
7913 1 (>= gnus-button-message-level 0) gnus-button-reply 1)
7914 ("^\\(Cc\\|To\\):" "[^ \t\n<>,()\"]+@[^ \t\n<>,()\"]+"
7915 0 (>= gnus-button-message-level 0) gnus-msg-mail 0)
7916 ("^X-[Uu][Rr][Ll]:" gnus-button-url-regexp
7917 0 (>= gnus-button-browse-level 0) browse-url 0)
7918 ("^Subject:" gnus-button-url-regexp
7919 0 (>= gnus-button-browse-level 0) browse-url 0)
7920 ("^[^:]+:" gnus-button-url-regexp
7921 0 (>= gnus-button-browse-level 0) browse-url 0)
7922 ("^OpenPGP:.*url=" gnus-button-url-regexp
7923 0 (>= gnus-button-browse-level 0) gnus-button-openpgp 0)
7924 ("^[^:]+:" "\\bmailto:\\([-a-z.@_+0-9%=?&/]+\\)"
7925 0 (>= gnus-button-message-level 0) gnus-url-mailto 1)
7926 ("^[^:]+:" "\\(<\\(url: \\)?\\(nntp\\|news\\):\\([^>\n ]*\\)>\\)"
7927 1 (>= gnus-button-message-level 0) gnus-button-message-id 4))
7928 "*Alist of headers and regexps to match buttons in article heads.
7930 This alist is very similar to `gnus-button-alist', except that each
7931 alist has an additional HEADER element first in each entry:
7933 \(HEADER REGEXP BUTTON FORM CALLBACK PAR)
7935 HEADER is a regexp to match a header. For a fuller explanation, see
7936 `gnus-button-alist'."
7937 :group 'gnus-article-buttons
7938 :group 'gnus-article-headers
7939 :type '(repeat (list (regexp :tag "Header")
7940 (choice regexp variable)
7941 (integer :tag "Button")
7943 (function :tag "Callback")
7946 (integer :tag "Regexp group")))))
7947 (put 'gnus-header-button-alist 'risky-local-variable t)
7951 (defun gnus-article-push-button (event)
7952 "Check text under the mouse pointer for a callback function.
7953 If the text under the mouse pointer has a `gnus-callback' property,
7954 call it with the value of the `gnus-data' text property."
7956 (set-buffer (window-buffer (posn-window (event-start event))))
7957 (let* ((pos (posn-point (event-start event)))
7958 (data (get-text-property pos 'gnus-data))
7959 (fun (get-text-property pos 'gnus-callback)))
7962 (funcall fun data))))
7964 (defun gnus-article-press-button ()
7965 "Check text at point for a callback function.
7966 If the text at point has a `gnus-callback' property,
7967 call it with the value of the `gnus-data' text property."
7969 (let ((data (get-text-property (point) 'gnus-data))
7970 (fun (get-text-property (point) 'gnus-callback)))
7972 (funcall fun data))))
7974 (defun gnus-article-highlight (&optional force)
7975 "Highlight current article.
7976 This function calls `gnus-article-highlight-headers',
7977 `gnus-article-highlight-citation',
7978 `gnus-article-highlight-signature', and `gnus-article-add-buttons' to
7979 do the highlighting. See the documentation for those functions."
7980 (interactive (list 'force))
7981 (gnus-article-highlight-headers)
7982 (gnus-article-highlight-citation force)
7983 (gnus-article-highlight-signature)
7984 (gnus-article-add-buttons)
7985 (gnus-article-add-buttons-to-head))
7987 (defun gnus-article-highlight-some (&optional _force)
7988 "Highlight current article.
7989 This function calls `gnus-article-highlight-headers',
7990 `gnus-article-highlight-signature', and `gnus-article-add-buttons' to
7991 do the highlighting. See the documentation for those functions."
7992 (interactive (list 'force))
7993 (gnus-article-highlight-headers)
7994 (gnus-article-highlight-signature)
7995 (gnus-article-add-buttons))
7997 (defun gnus-article-highlight-headers ()
7998 "Highlight article headers as specified by `gnus-header-face-alist'."
8000 (gnus-with-article-headers
8001 (let (regexp header-face field-face from hpoints fpoints)
8002 (dolist (entry gnus-header-face-alist)
8003 (goto-char (point-min))
8004 (setq regexp (concat "^\\("
8005 (if (string-equal "" (nth 0 entry))
8009 header-face (nth 1 entry)
8010 field-face (nth 2 entry))
8011 (while (and (re-search-forward regexp nil t)
8015 (unless (search-forward ":" nil t)
8017 (when (and header-face
8018 (not (memq (point) hpoints)))
8019 (push (point) hpoints)
8020 (gnus-put-text-property from (point) 'face header-face))
8021 (when (and field-face
8022 (not (memq (setq from (point)) fpoints)))
8024 (if (re-search-forward "^[^ \t]" nil t)
8026 (goto-char (point-max)))
8027 (gnus-put-text-property from (point) 'face field-face)))))))
8029 (defun gnus-article-highlight-signature ()
8030 "Highlight the signature in an article.
8031 It does this by highlighting everything after
8032 `gnus-signature-separator' using the face `gnus-signature'."
8034 (gnus-with-article-buffer
8035 (let ((inhibit-point-motion-hooks t))
8037 (when (and gnus-signature-face
8038 (gnus-article-narrow-to-signature))
8039 (gnus-overlay-put (gnus-make-overlay (point-min) (point-max) nil t)
8040 'face gnus-signature-face)
8042 (gnus-article-search-signature)
8043 (let ((start (match-beginning 0))
8044 (end (set-marker (make-marker) (1+ (match-end 0)))))
8045 (gnus-article-add-button start (1- end) 'gnus-signature-toggle
8048 (defun gnus-button-in-region-p (b e prop)
8049 "Say whether PROP exists in the region."
8050 (text-property-not-all b e prop nil))
8052 (defun gnus-article-add-buttons ()
8053 "Find external references in the article and make buttons of them.
8054 \"External references\" are things like Message-IDs and URLs, as
8055 specified by `gnus-button-alist'."
8057 (gnus-with-article-buffer
8058 (let ((inhibit-point-motion-hooks t)
8059 (case-fold-search t)
8060 (alist gnus-button-alist)
8062 ;; We skip the headers.
8065 (while (setq entry (pop alist))
8066 (setq regexp (eval (car entry)))
8068 (while (re-search-forward regexp nil t)
8069 (let ((start (match-beginning (nth 1 entry)))
8070 (end (match-end (nth 1 entry)))
8071 (from (match-beginning 0)))
8072 (when (and (eval (nth 2 entry))
8073 (not (gnus-button-in-region-p
8074 start end 'gnus-callback)))
8075 ;; That optional form returned non-nil, so we add the
8077 (setq from (set-marker (make-marker) from))
8078 (unless (and (eq (car entry) 'gnus-button-url-regexp)
8079 (gnus-article-extend-url-button from start end))
8080 (gnus-article-add-button start end
8081 'gnus-button-push (list from entry))
8082 (gnus-put-text-property
8084 'gnus-string (buffer-substring-no-properties
8087 (defun gnus-article-extend-url-button (beg start end)
8088 "Extend url button if url is folded into two or more lines.
8089 Return non-nil if button is extended. BEG is a marker that points to
8090 the beginning position of a text containing url. START and END are
8091 the endpoints of a url button before it is extended. The concatenated
8092 url is put as the `gnus-button-url' overlay property on the button."
8093 (let ((opoint (point))
8094 (points (list start end))
8099 (not (looking-at "[\t ]*[\">]")))
8103 "\\(?:\"\\|\\(<\\)\\)[\t ]*\\(?:url[\t ]*:[\t ]*\\)?\\'"
8104 (buffer-substring (point-at-bol) start)))
8106 (setq url (list (buffer-substring start end))
8107 delim (if (match-beginning 1) ">" "\""))
8109 (setq regexp (concat
8110 (when (and (looking-at
8111 message-cite-prefix-regexp)
8112 (< (match-end 0) start))
8113 (regexp-quote (match-string 0)))
8115 \[\t ]*\\(?:\\([^\t\n \">]+\\)[\t ]*$\\|\\([^\t\n \">]*\\)[\t ]*"
8119 (and (looking-at regexp)
8122 (push (or (match-string 2)
8125 (push (setq end (or (match-end 2)
8128 (push (or (match-beginning 2)
8129 (match-beginning 1))
8131 (match-beginning 2)))
8132 (let (gnus-article-mouse-face widget-mouse-face)
8134 (gnus-article-add-button (pop points) (pop points)
8136 (list beg (assq 'gnus-button-url-regexp
8137 gnus-button-alist)))))
8138 (let ((overlay (gnus-make-overlay start end)))
8139 (gnus-overlay-put overlay 'evaporate t)
8140 (gnus-overlay-put overlay 'gnus-button-url
8141 (list (mapconcat 'identity (nreverse url) "")))
8142 (when gnus-article-mouse-face
8143 (gnus-overlay-put overlay 'mouse-face gnus-article-mouse-face)))
8145 (goto-char opoint))))
8147 ;; Add buttons to the head of an article.
8148 (defun gnus-article-add-buttons-to-head ()
8149 "Add buttons to the head of the article."
8151 (gnus-with-article-headers
8153 (dolist (entry gnus-header-button-alist)
8154 ;; Each alist entry.
8155 (goto-char (point-min))
8156 (while (re-search-forward (car entry) nil t)
8157 ;; Each header matching the entry.
8158 (setq beg (match-beginning 0))
8159 (setq end (or (and (re-search-forward "^[^ \t]" nil t)
8160 (match-beginning 0))
8163 (while (re-search-forward (eval (nth 1 entry)) end t)
8164 ;; Each match within a header.
8165 (let* ((entry (cdr entry))
8166 (start (match-beginning (nth 1 entry)))
8167 (end (match-end (nth 1 entry)))
8168 (form (nth 2 entry)))
8169 (goto-char (match-end 0))
8171 (gnus-article-add-button
8172 start end (nth 3 entry)
8173 (buffer-substring (match-beginning (nth 4 entry))
8174 (match-end (nth 4 entry)))))))
8175 (goto-char end))))))
8177 ;;; External functions:
8179 (defun gnus-article-add-button (from to fun &optional data text)
8180 "Create a button between FROM and TO with callback FUN and data DATA."
8181 (when gnus-article-button-face
8182 (gnus-overlay-put (gnus-make-overlay from to nil t)
8183 'face gnus-article-button-face))
8184 (gnus-add-text-properties
8186 (nconc (and gnus-article-mouse-face
8187 (list gnus-mouse-face-prop gnus-article-mouse-face))
8188 (list 'gnus-callback fun)
8189 (and data (list 'gnus-data data))))
8190 (widget-convert-button 'link from to :action 'gnus-widget-press-button
8191 :help-echo (or text "Follow the link")
8192 :keymap gnus-url-button-map
8193 :button-keymap gnus-widget-button-keymap))
8195 (defun gnus-article-copy-string ()
8196 "Copy the string in the button to the kill ring."
8198 (gnus-article-check-buffer)
8199 (let ((data (get-text-property (point) 'gnus-string)))
8203 (copy-region-as-kill (point-min) (point-max))
8204 (message "Copied %s" data)))))
8206 ;;; Internal functions:
8208 (defun gnus-article-set-globals ()
8209 (with-current-buffer gnus-summary-buffer
8210 (gnus-set-global-variables)))
8212 (defun gnus-signature-toggle (end)
8213 (gnus-with-article-buffer
8214 (let ((inhibit-point-motion-hooks t))
8215 (if (text-property-any end (point-max) 'article-type 'signature)
8217 (gnus-delete-wash-type 'signature)
8218 (gnus-remove-text-properties-when
8219 'article-type 'signature end (point-max)
8220 (cons 'article-type (cons 'signature
8221 gnus-hidden-properties))))
8222 (gnus-add-wash-type 'signature)
8223 (gnus-add-text-properties-when
8224 'article-type nil end (point-max)
8225 (cons 'article-type (cons 'signature
8226 gnus-hidden-properties)))))
8227 (let ((gnus-article-mime-handle-alist-1 gnus-article-mime-handle-alist))
8228 (gnus-set-mode-line 'article))))
8230 (defun gnus-button-push (marker-and-entry)
8231 ;; Push button starting at MARKER.
8233 (let* ((marker (car marker-and-entry))
8234 (entry (cadr marker-and-entry))
8235 (regexp (car entry))
8236 (inhibit-point-motion-hooks t))
8238 ;; This is obviously true, or something bad is happening :)
8239 ;; But we need it to have the match-data
8240 (when (looking-at (or (if (symbolp regexp)
8241 (symbol-value regexp)
8243 (let ((fun (nth 3 entry))
8244 (args (or (and (eq (car entry) 'gnus-button-url-regexp)
8245 (get-char-property marker 'gnus-button-url))
8246 (mapcar (lambda (group)
8247 (let ((string (match-string group)))
8248 (set-text-properties
8249 0 (length string) nil string)
8251 (nthcdr 4 entry)))))
8257 (fboundp (symbol-value fun)))
8258 (apply (symbol-value fun) args))
8260 (gnus-message 1 "You must define `%S' to use this button"
8261 (cons fun args)))))))))
8263 (defun gnus-parse-news-url (url)
8264 (let (scheme server port group message-id articles)
8267 (goto-char (point-min))
8268 (when (looking-at "\\([A-Za-z]+\\):")
8269 (setq scheme (match-string 1))
8270 (goto-char (match-end 0)))
8271 (when (looking-at "//\\([^:/]+\\)\\(:?\\)\\([0-9]+\\)?/")
8272 (setq server (match-string 1))
8273 (setq port (if (stringp (match-string 3))
8274 (string-to-number (match-string 3))
8276 (goto-char (match-end 0)))
8279 ((looking-at "\\(.*@.*\\)")
8280 (setq message-id (match-string 1)))
8281 ((looking-at "\\([^/]+\\)/\\([-0-9]+\\)")
8282 (setq group (match-string 1)
8283 articles (split-string (match-string 2) "-")))
8284 ((looking-at "\\([^/]+\\)/?")
8285 (setq group (match-string 1)))
8287 (error "Unknown news URL syntax"))))
8288 (list scheme server port group message-id articles)))
8290 (defvar nntp-port-number)
8292 (defun gnus-button-handle-news (url)
8294 (destructuring-bind (_scheme server port group message-id _articles)
8295 (gnus-parse-news-url url)
8298 (with-current-buffer gnus-summary-buffer
8300 (let ((gnus-refer-article-method
8301 (nconc (list (list 'nntp server))
8302 gnus-refer-article-method))
8303 (nntp-port-number (or port "nntp")))
8304 (gnus-message 7 "Fetching %s with %s"
8305 message-id gnus-refer-article-method)
8306 (gnus-summary-refer-article message-id))
8307 (gnus-summary-refer-article message-id))))
8309 (gnus-button-fetch-group url)))))
8311 (defun gnus-button-patch (library line)
8312 "Visit an Emacs Lisp library LIBRARY on line LINE."
8314 (let ((file (locate-library (file-name-nondirectory library))))
8316 (error "Couldn't find library %s" library))
8318 (goto-char (point-min))
8319 (forward-line (1- (string-to-number line)))))
8321 (defun gnus-button-handle-man (url)
8323 (gnus-message 9 "`%s' `%s'" gnus-button-man-handler url)
8324 (when (eq gnus-button-man-handler 'woman)
8325 (setq url (gnus-replace-in-string url "([1-9][X1a-z]*).*\\'" "")))
8326 (gnus-message 9 "`%s' `%s'" gnus-button-man-handler url)
8327 (funcall gnus-button-man-handler url))
8329 (defun gnus-button-handle-info-url (url)
8330 "Fetch an info URL."
8331 (setq url (mm-subst-char-in-string ?+ ?\ url))
8333 ((string-match "^\\([^:/]+\\)?/\\(.*\\)" url)
8334 (gnus-info-find-node
8335 (concat "(" (or (gnus-url-unhex-string (match-string 1 url))
8337 ")" (gnus-url-unhex-string (match-string 2 url)))))
8338 ((string-match "([^)\"]+)[^\"]+" url)
8340 (gnus-replace-in-string
8341 (gnus-replace-in-string url "[\n\t ]+" " ") "\"" ""))
8342 (gnus-info-find-node url))
8343 (t (error "Can't parse %s" url))))
8345 (defun gnus-button-handle-info-url-gnome (url)
8346 "Fetch GNOME style info URL."
8347 (setq url (mm-subst-char-in-string ?_ ?\ url))
8348 (if (string-match "\\([^#]+\\)#?\\(.*\\)" url)
8349 (gnus-info-find-node
8351 (gnus-url-unhex-string
8352 (match-string 1 url))
8354 (or (gnus-url-unhex-string
8355 (match-string 2 url))
8357 (error "Can't parse %s" url)))
8359 (defun gnus-button-handle-info-url-kde (url)
8360 "Fetch KDE style info URL."
8361 (gnus-info-find-node (gnus-url-unhex-string url)))
8363 ;; (info) will autoload info.el
8364 (declare-function Info-menu "info" (menu-item &optional fork))
8365 (declare-function Info-index-next "info" (num))
8367 (defun gnus-button-handle-info-keystrokes (url)
8368 "Call `info' when pushing the corresponding URL button."
8369 ;; For links like `C-h i d m gnus RET part RET , ,', `C-h i d m CC Mode RET'.
8370 (let (node indx comma)
8372 (concat "\\b\\(C-h\\|<?[Ff]1>?\\)[ \t\n]+i[ \t\n]+d?[ \t\n]?m[ \t\n]+"
8373 "\\([^ ]+ ?[^ ]+\\)[ \t\n]+RET"
8374 "\\([ \t\n]+i[ \t\n]+[^ ]+ ?[^ ]+[ \t\n]+RET\\>"
8375 "\\(?:[ \t\n,]*\\)\\)?")
8377 (setq node (match-string 2 url)
8378 indx (match-string 3 url))
8379 (error "Can't parse %s" url))
8383 (when (> (length indx) 0)
8384 (string-match (concat "[ \t\n]+i[ \t\n]+\\([^ ]+ ?[^ ]+\\)[ \t\n]+RET\\>"
8387 (setq comma (match-string 2 indx))
8388 (setq indx (match-string 1 indx))
8391 (dotimes (i (with-temp-buffer
8393 ;; Note: the XEmacs version of `how-many' takes
8394 ;; no optional argument.
8395 (goto-char (point-min))
8397 (Info-index-next 1)))
8400 (autoload 'pgg-snarf-keys-region "pgg")
8401 ;; Called after pgg-snarf-keys-region, which autoloads pgg.el.
8402 (declare-function pgg-display-output-buffer "pgg" (start end status))
8404 (defun gnus-button-openpgp (url)
8405 "Retrieve and add an OpenPGP key given URL from an OpenPGP header."
8407 (mm-url-insert-file-contents-external url)
8408 (pgg-snarf-keys-region (point-min) (point-max))
8409 (pgg-display-output-buffer nil nil nil)))
8411 (defun gnus-button-message-id (message-id)
8413 (with-current-buffer gnus-summary-buffer
8414 (gnus-summary-refer-article message-id)))
8416 (defun gnus-button-fetch-group (address &rest _ignore)
8417 "Fetch GROUP specified by ADDRESS."
8418 (when (string-match "\\`\\(nntp\\|news\\):\\(//\\)?\\(.*\\)\\'"
8420 ;; Allow to use `gnus-button-fetch-group' in `browse-url-browser-function'
8421 ;; for nntp:// and news://
8422 (setq address (match-string 3 address)))
8423 (if (not (string-match "[:/]" address))
8424 ;; This is just a simple group url.
8425 (gnus-group-read-ephemeral-group address gnus-select-method)
8428 "^\\([^:/]+\\)\\(:\\([^/]+\\)\\)?/\\([^/]+\\)\\(/\\([0-9]+\\)\\)?"
8430 (error "Can't parse %s" address)
8431 (gnus-group-read-ephemeral-group
8432 (match-string 4 address)
8433 `(nntp ,(match-string 1 address)
8434 (nntp-address ,(match-string 1 address))
8435 (nntp-port-number ,(if (match-end 3)
8436 (match-string 3 address)
8439 (and (match-end 6) (list (string-to-number (match-string 6 address))))))))
8441 (defun gnus-url-parse-query-string (query &optional downcase)
8442 (let (retval pairs cur key val)
8443 (setq pairs (split-string query "&"))
8445 (setq cur (car pairs)
8447 (if (not (string-match "=" cur))
8449 (setq key (gnus-url-unhex-string (substring cur 0 (match-beginning 0)))
8450 val (gnus-url-unhex-string (substring cur (match-end 0) nil) t))
8452 (setq key (downcase key)))
8453 (setq cur (assoc key retval))
8455 (setcdr cur (cons val (cdr cur)))
8456 (setq retval (cons (list key val) retval)))))
8459 (defun gnus-url-mailto (url)
8460 ;; Send mail to someone
8461 (setq url (replace-regexp-in-string "\n" " " url))
8462 (when (string-match "mailto:/*\\(.*\\)" url)
8463 (setq url (substring url (match-beginning 1) nil)))
8464 (let* ((args (gnus-url-parse-query-string
8465 (if (string-match "^\\?" url)
8467 (if (string-match "^\\([^?]+\\)\\?\\(.*\\)" url)
8468 (concat "to=" (match-string 1 url) "&"
8469 (match-string 2 url))
8470 (concat "to=" url)))))
8471 (subject (cdr-safe (assoc "subject" args)))
8475 (setq func (intern-soft (concat "message-goto-" (downcase (caar args)))))
8478 (message-position-on-field (caar args)))
8479 (insert (gnus-replace-in-string
8480 (mapconcat 'identity (reverse (cdar args)) ", ")
8482 (setq args (cdr args)))
8485 (message-goto-subject))))
8487 (defun gnus-button-embedded-url (address)
8488 "Activate ADDRESS with `browse-url'."
8489 (browse-url (gnus-strip-whitespace address)))
8491 ;;; Next/prev buttons in the article buffer.
8493 (defvar gnus-next-page-line-format "%{%(Next page...%)%}\n")
8494 (defvar gnus-prev-page-line-format "%{%(Previous page...%)%}\n")
8496 (defvar gnus-prev-page-map
8497 (let ((map (make-sparse-keymap)))
8498 (define-key map gnus-mouse-2 'gnus-button-prev-page)
8499 (define-key map "\r" 'gnus-button-prev-page)
8502 (defvar gnus-next-page-map
8503 (let ((map (make-sparse-keymap)))
8504 (define-key map gnus-mouse-2 'gnus-button-next-page)
8505 (define-key map "\r" 'gnus-button-next-page)
8508 (defun gnus-insert-prev-page-button ()
8510 (inhibit-read-only t))
8512 gnus-prev-page-line-format nil
8513 `(keymap ,gnus-prev-page-map
8515 gnus-callback gnus-article-button-prev-page
8516 article-type annotation))
8518 ;; Exclude a newline.
8521 (when gnus-article-button-face
8522 (gnus-overlay-put (gnus-make-overlay b e nil t)
8523 'face gnus-article-button-face))
8524 (widget-convert-button
8526 :action 'gnus-button-prev-page
8527 :button-keymap gnus-prev-page-map)))
8529 (defun gnus-button-next-page (&optional _args _more-args)
8530 "Go to the next page."
8532 (let ((win (selected-window)))
8533 (select-window (gnus-get-buffer-window gnus-article-buffer t))
8534 (gnus-article-next-page)
8535 (select-window win)))
8537 (defun gnus-button-prev-page (&optional _args _more-args)
8538 "Go to the prev page."
8540 (let ((win (selected-window)))
8541 (select-window (gnus-get-buffer-window gnus-article-buffer t))
8542 (gnus-article-prev-page)
8543 (select-window win)))
8545 (defun gnus-insert-next-page-button ()
8547 (inhibit-read-only t))
8548 (gnus-eval-format gnus-next-page-line-format nil
8549 `(keymap ,gnus-next-page-map
8551 gnus-callback gnus-article-button-next-page
8552 article-type annotation))
8554 ;; Exclude a newline.
8557 (when gnus-article-button-face
8558 (gnus-overlay-put (gnus-make-overlay b e nil t)
8559 'face gnus-article-button-face))
8560 (widget-convert-button
8562 :action 'gnus-button-next-page
8563 :button-keymap gnus-next-page-map)))
8565 (defun gnus-article-button-next-page (_arg)
8566 "Go to the next page."
8568 (let ((win (selected-window)))
8569 (select-window (gnus-get-buffer-window gnus-article-buffer t))
8570 (gnus-article-next-page)
8571 (select-window win)))
8573 (defun gnus-article-button-prev-page (_arg)
8574 "Go to the prev page."
8576 (let ((win (selected-window)))
8577 (select-window (gnus-get-buffer-window gnus-article-buffer t))
8578 (gnus-article-prev-page)
8579 (select-window win)))
8581 (defvar gnus-decode-header-methods
8582 '(mail-decode-encoded-word-region)
8583 "List of methods used to decode headers.
8585 This variable is a list of FUNCTION or (REGEXP . FUNCTION). If item
8586 is FUNCTION, FUNCTION will be applied to all newsgroups. If item is a
8587 \(REGEXP . FUNCTION), FUNCTION will be only apply to the newsgroups
8588 whose names match REGEXP.
8591 \((\"chinese\" . gnus-decode-encoded-word-region-by-guess)
8592 mail-decode-encoded-word-region
8593 (\"chinese\" . rfc1843-decode-region))
8596 (defvar gnus-decode-header-methods-cache nil)
8598 (defun gnus-multi-decode-header (start end)
8599 "Apply the functions from `gnus-encoded-word-methods' that match."
8600 (unless (and gnus-decode-header-methods-cache
8601 (eq gnus-newsgroup-name
8602 (car gnus-decode-header-methods-cache)))
8603 (setq gnus-decode-header-methods-cache (list gnus-newsgroup-name))
8604 (dolist (x gnus-decode-header-methods)
8606 (nconc gnus-decode-header-methods-cache (list x))
8607 (if (and gnus-newsgroup-name
8608 (string-match (car x) gnus-newsgroup-name))
8609 (nconc gnus-decode-header-methods-cache
8611 (let ((xlist gnus-decode-header-methods-cache))
8614 (narrow-to-region start end)
8616 (funcall (pop xlist) (point-min) (point-max))))))
8619 ;;; Treatment top-level handling.
8622 (defvar gnus-inhibit-article-treatments nil)
8624 ;; Dynamic variables.
8625 (defvar part-number) ;FIXME: Lacks a "gnus-" prefix.
8626 (defvar total-parts) ;FIXME: Lacks a "gnus-" prefix.
8627 (defvar gnus-treat-type)
8628 (defvar gnus-treat-condition)
8629 (defvar gnus-treat-length)
8631 (defun gnus-treat-article (condition
8632 &optional part-num total type)
8633 (let ((gnus-treat-condition condition)
8634 (part-number part-num)
8636 (gnus-treat-type type)
8637 (gnus-treat-length (- (point-max) (point-min)))
8638 (alist gnus-treatment-function-alist)
8639 (article-goto-body-goes-to-point-min-p t)
8643 (let ((list gnus-article-treat-types))
8645 (when (string-match (pop list) type)
8646 (throw 'found t)))))))
8647 (highlightp (gnus-visual-p 'article-highlight 'highlight))
8649 (gnus-run-hooks 'gnus-part-display-hook)
8650 (dolist (elem alist)
8653 (when (gnus-buffer-live-p gnus-summary-buffer)
8654 (set-buffer gnus-summary-buffer))
8655 (symbol-value (car elem))))
8656 (when (and (or (consp val)
8658 (or (not gnus-inhibit-article-treatments)
8659 (eq gnus-treat-condition 'head))
8660 (gnus-treat-predicate val)
8661 (or (not (get (car elem) 'highlight))
8664 (funcall (cadr elem)))))))
8666 (defun gnus-treat-predicate (val)
8670 (gnus-treat-condition
8671 (eq gnus-treat-condition val))
8673 (stringp (car val)))
8674 (apply 'gnus-or (mapcar `(lambda (s)
8675 (string-match s ,(or gnus-newsgroup-name "")))
8678 (let ((pred (pop val)))
8681 (apply 'gnus-or (mapcar 'gnus-treat-predicate val)))
8683 (apply 'gnus-and (mapcar 'gnus-treat-predicate val)))
8685 (not (gnus-treat-predicate (car val))))
8687 (equal (car val) gnus-treat-type))
8691 (error "%S is not a valid predicate" pred)))))
8699 (eq part-number total-parts))
8701 (< gnus-treat-length val))
8703 (error "%S is not a valid value" val))))
8705 (defun gnus-article-encrypt-body (protocol &optional n)
8706 "Encrypt the article body."
8709 (or gnus-article-encrypt-protocol
8710 (gnus-completing-read "Encrypt protocol"
8711 (mapcar 'car gnus-article-encrypt-protocol-alist)
8713 current-prefix-arg))
8714 ;; User might hit `K E' instead of `K e', so prompt once.
8715 (when (and gnus-article-encrypt-protocol
8717 (unless (gnus-y-or-n-p "Really encrypt article(s)? ")
8718 (error "Encrypt aborted")))
8719 (let ((func (cdr (assoc protocol gnus-article-encrypt-protocol-alist))))
8721 (error "Can't find the encrypt protocol %s" protocol))
8722 (if (member gnus-newsgroup-name '("nndraft:delayed"
8725 (error "Can't encrypt the article in group %s"
8726 gnus-newsgroup-name))
8727 (gnus-summary-iterate n
8728 (with-current-buffer gnus-summary-buffer
8729 (let ((mail-parse-charset gnus-newsgroup-charset)
8730 (mail-parse-ignored-charsets gnus-newsgroup-ignored-charsets)
8731 (summary-buffer gnus-summary-buffer)
8733 (gnus-set-global-variables)
8734 (when (gnus-group-read-only-p)
8735 (error "The current newsgroup does not support article encrypt"))
8736 (gnus-summary-show-article t)
8738 (or (mail-header-references gnus-current-headers) ""))
8739 (set-buffer gnus-article-buffer)
8740 (let* ((inhibit-read-only t)
8742 (mapcar (lambda (field)
8743 (and (save-restriction
8744 (message-narrow-to-head)
8745 (goto-char (point-min))
8746 (search-forward field nil t))
8748 (message-narrow-to-field)
8750 (delete-region (point-min) (point-max))
8752 '("Content-Type:" "Content-Transfer-Encoding:"
8753 "Content-Disposition:"))))
8754 (message-narrow-to-head)
8755 (message-remove-header "MIME-Version")
8756 (goto-char (point-max))
8757 (setq point (point))
8758 (insert (apply 'concat headers))
8760 (narrow-to-region point (point-max))
8761 (let ((message-options message-options))
8762 (message-options-set 'message-sender user-mail-address)
8763 (message-options-set 'message-recipients user-mail-address)
8764 (message-options-set 'message-sign-encrypt 'not)
8766 (goto-char (point-min))
8767 (insert "MIME-Version: 1.0\n")
8769 (gnus-summary-edit-article-done
8770 references nil summary-buffer t))
8771 (when gnus-keep-backlog
8772 (gnus-backlog-remove-article
8773 (car gnus-article-current) (cdr gnus-article-current)))
8774 (gnus-flush-original-article-buffer)
8775 (when gnus-use-cache
8776 (gnus-cache-update-article
8777 (car gnus-article-current) (cdr gnus-article-current))))))))
8779 (defvar gnus-mime-security-button-line-format "%{%([[%t:%i]%D]%)%}\n"
8780 "The following specs can be used:
8781 %t The security MIME type
8784 %D Details if button is pressed")
8786 (defvar gnus-mime-security-button-end-line-format "%{%([[End of %t]%D]%)%}\n"
8787 "The following specs can be used:
8788 %t The security MIME type
8791 %D Details if button is pressed")
8793 (defvar gnus-mime-security-button-line-format-alist
8794 '((?t gnus-tmp-type ?s)
8795 (?i gnus-tmp-info ?s)
8796 (?d gnus-tmp-details ?s)
8797 (?D gnus-tmp-pressed-details ?s)))
8799 (defvar gnus-mime-security-button-commands
8800 '((gnus-article-press-button "\r" "Show Detail")
8804 (gnus-mime-security-save-part "o" "Save...")
8813 (gnus-mime-security-pipe-part "|" "Pipe To Command...")
8816 (defvar gnus-mime-security-button-map
8817 (let ((map (make-sparse-keymap)))
8818 (define-key map gnus-mouse-2 'gnus-article-push-button)
8819 (define-key map gnus-down-mouse-3 'gnus-mime-security-button-menu)
8820 (dolist (c gnus-mime-security-button-commands)
8821 (define-key map (cadr c) (car c)))
8825 gnus-mime-security-button-menu gnus-mime-security-button-map
8826 "Security button menu."
8830 (unless (eq (car c) 'undefined)
8831 (vector (caddr c) (car c) :active t)))
8832 gnus-mime-security-button-commands))))
8834 (defun gnus-mime-security-button-menu (event prefix)
8835 "Construct a context-sensitive menu of security commands."
8836 (interactive "e\nP")
8837 (save-window-excursion
8838 (let ((pos (event-start event)))
8839 (select-window (posn-window pos))
8840 (goto-char (posn-point pos))
8841 (gnus-article-check-buffer)
8842 (popup-menu gnus-mime-security-button-menu nil prefix))))
8844 (defvar gnus-mime-security-details-buffer nil)
8846 (defvar gnus-mime-security-button-pressed nil)
8848 (defvar gnus-mime-security-show-details-inline t
8849 "If non-nil, show details in the article buffer.")
8851 (defun gnus-mime-security-verify-or-decrypt (handle)
8852 (mm-remove-parts (cdr handle))
8853 (let ((region (mm-handle-multipart-ctl-parameter handle 'gnus-region))
8854 point (inhibit-read-only t))
8856 (goto-char (car region)))
8857 (setq point (point))
8858 (with-current-buffer (mm-handle-multipart-original-buffer handle)
8859 (let* ((mm-verify-option 'known)
8860 (mm-decrypt-option 'known)
8861 (nparts (mm-possibly-verify-or-decrypt (cdr handle) handle)))
8862 (unless (eq nparts (cdr handle))
8863 (mm-destroy-parts (cdr handle))
8864 (setcdr handle nparts))))
8865 (gnus-mime-display-security handle)
8867 (delete-region (point) (cdr region))
8868 (set-marker (car region) nil)
8869 (set-marker (cdr region) nil))
8872 (defun gnus-mime-security-show-details (handle)
8873 (let ((details (mm-handle-multipart-ctl-parameter handle 'gnus-details)))
8875 (gnus-message 5 "No details.")
8876 (if gnus-mime-security-show-details-inline
8877 (let ((gnus-mime-security-button-pressed
8878 (not (get-text-property (point) 'gnus-mime-details)))
8879 (gnus-mime-security-button-line-format
8880 (get-text-property (point) 'gnus-line-format))
8881 (inhibit-read-only t))
8883 (while (eq (get-text-property (point) 'gnus-line-format)
8884 gnus-mime-security-button-line-format)
8888 (narrow-to-region (point) (point))
8889 (gnus-insert-mime-security-button handle))
8890 (delete-region (point)
8891 (or (text-property-not-all
8894 gnus-mime-security-button-line-format)
8897 (if (gnus-buffer-live-p gnus-mime-security-details-buffer)
8898 (with-current-buffer gnus-mime-security-details-buffer
8901 (setq gnus-mime-security-details-buffer
8902 (gnus-get-buffer-create "*MIME Security Details*")))
8903 (with-current-buffer gnus-mime-security-details-buffer
8905 (goto-char (point-min)))
8906 (pop-to-buffer gnus-mime-security-details-buffer)))))
8908 (defun gnus-mime-security-press-button (handle)
8910 (if (mm-handle-multipart-ctl-parameter handle 'gnus-info)
8911 (gnus-mime-security-show-details handle)
8912 (gnus-mime-security-verify-or-decrypt handle))))
8914 (defun gnus-insert-mime-security-button (handle &optional _displayed)
8915 (let* ((protocol (mm-handle-multipart-ctl-parameter handle 'protocol))
8918 (or (nth 2 (assoc protocol mm-verify-function-alist))
8919 (nth 2 (assoc protocol mm-decrypt-function-alist))
8921 (if (equal (car handle) "multipart/signed")
8922 " Signed" " Encrypted")
8925 (or (mm-handle-multipart-ctl-parameter handle 'gnus-info)
8928 (mm-handle-multipart-ctl-parameter handle 'gnus-details))
8929 gnus-tmp-pressed-details
8931 (setq gnus-tmp-details
8932 (if gnus-tmp-details
8933 (concat "\n" gnus-tmp-details)
8935 (setq gnus-tmp-pressed-details
8936 (if gnus-mime-security-button-pressed gnus-tmp-details ""))
8941 gnus-mime-security-button-line-format
8942 gnus-mime-security-button-line-format-alist
8943 `(keymap ,gnus-mime-security-button-map
8944 gnus-callback gnus-mime-security-press-button
8945 gnus-line-format ,gnus-mime-security-button-line-format
8946 gnus-mime-details ,gnus-mime-security-button-pressed
8947 article-type annotation
8950 ;; Exclude a newline.
8953 (when gnus-article-button-face
8954 (gnus-overlay-put (gnus-make-overlay b e nil t)
8955 'face gnus-article-button-face))
8956 (widget-convert-button
8959 :action 'gnus-widget-press-button
8960 :button-keymap gnus-mime-security-button-map
8963 ;; Needed to properly clear the message due to a bug in
8964 ;; wid-edit (XEmacs only).
8965 (when (boundp 'help-echo-owns-message)
8966 (setq help-echo-owns-message t))
8968 "%S: show detail; %S: more options"
8969 (aref gnus-mouse-2 0)
8970 (aref gnus-down-mouse-3 0))))))
8972 (defun gnus-mime-display-security (handle)
8974 (narrow-to-region (point) (point))
8975 (unless (gnus-unbuttonized-mime-type-p (car handle))
8976 (gnus-insert-mime-security-button handle))
8977 (gnus-mime-display-part (cadr handle))
8980 (unless (gnus-unbuttonized-mime-type-p (car handle))
8981 (let ((gnus-mime-security-button-line-format
8982 gnus-mime-security-button-end-line-format))
8983 (gnus-insert-mime-security-button handle)))
8984 (mm-set-handle-multipart-parameter
8985 handle 'gnus-region (cons (point-min-marker) (point-max-marker)))
8986 (goto-char (point-max))))
8988 (defun gnus-mime-security-run-function (function)
8989 "Run FUNCTION with the security part under point."
8990 (gnus-article-check-buffer)
8991 (let ((data (get-text-property (point) 'gnus-data))
8993 (when (and (stringp (car-safe data))
8994 (setq buffer (mm-handle-multipart-original-buffer data))
8995 (setq handle (cadr data)))
8996 (if (bufferp (mm-handle-buffer handle))
8998 (setq handle (cons buffer (copy-sequence (cdr handle))))
8999 (mm-handle-set-undisplayer handle nil))
9000 (setq handle (mm-make-handle
9002 (mm-handle-multipart-ctl-parameter handle 'protocol)
9003 nil nil nil nil nil nil)))
9004 (funcall function handle))))
9006 (defun gnus-mime-security-save-part ()
9007 "Save the security part under point."
9009 (gnus-mime-security-run-function 'mm-save-part))
9011 (defun gnus-mime-security-pipe-part ()
9012 "Pipe the security part under point to a process."
9014 (gnus-mime-security-run-function 'mm-pipe-part))
9020 (run-hooks 'gnus-art-load-hook)
9022 ;;; gnus-art.el ends here