1 ;;; gnus-art.el --- article mode commands for Gnus
3 ;; Copyright (C) 1996-2016 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)
46 (autoload 'gnus-msg-mail "gnus-msg" nil t)
47 (autoload 'gnus-button-mailto "gnus-msg")
48 (autoload 'gnus-button-reply "gnus-msg" nil t)
49 (autoload 'parse-time-string "parse-time" nil nil)
50 (autoload 'ansi-color-apply-on-region "ansi-color")
51 (autoload 'mm-url-insert-file-contents-external "mm-url")
52 (autoload 'mm-extern-cache-contents "mm-extern")
53 (autoload 'url-expand-file-name "url-expand")
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 ;; We use to have `intangible' here as well, but Emacs's command loop moves
259 ;; point out of invisible text anyway, so `intangible' is clearly not
260 ;; needed there. And XEmacs doesn't handle `intangible' anyway.
262 "Property list to use for hiding text."
264 :group 'gnus-article-hiding)
266 ;; Fixme: This isn't the right thing for mixed graphical and non-graphical
267 ;; frames in a session.
268 (defcustom gnus-article-x-face-command
269 (if (featurep 'xemacs)
270 (if (or (gnus-image-type-available-p 'xface)
271 (gnus-image-type-available-p 'pbm))
272 'gnus-display-x-face-in-from
274 '/* Format_version=1, Width=48, Height=48, Depth=1, Valid_bits_per_item=16 */'\
275 ; uncompface; } | icontopbm | ee -")
276 (if (gnus-image-type-available-p 'pbm)
277 'gnus-display-x-face-in-from
279 '/* Format_version=1, Width=48, Height=48, Depth=1, Valid_bits_per_item=16 */'\
280 ; uncompface; } | icontopbm | display -"))
281 "*String or function to be executed to display an X-Face header.
282 If it is a string, the command will be executed in a sub-shell
283 asynchronously. The compressed face will be piped to this command."
284 :type `(choice string
285 (function-item gnus-display-x-face-in-from)
289 :group 'gnus-article-washing)
291 (defcustom gnus-article-x-face-too-ugly nil
292 "Regexp matching posters whose face shouldn't be shown automatically."
293 :type '(choice regexp (const nil))
294 :group 'gnus-article-washing)
296 (defcustom gnus-article-banner-alist nil
297 "Banner alist for stripping.
299 ((egroups . \"^[ \\t\\n]*-------------------+\\\\( \\\\(e\\\\|Yahoo! \\\\)Groups Sponsor -+\\\\)?....\\n\\\\(.+\\n\\\\)+\"))"
301 :type '(repeat (cons symbol regexp))
302 :group 'gnus-article-washing)
304 (gnus-define-group-parameter
307 "Alist of regexps (to match group names) and banner."
308 :variable-group gnus-article-washing
310 '(choice :tag "Banner"
312 (const :tag "Remove signature" signature)
313 (symbol :tag "Item in `gnus-article-banner-alist'" none)
315 (const :tag "None" nil))
317 "If non-nil, specify how to remove `banners' from articles.
319 Symbol `signature' means to remove signatures delimited by
320 `gnus-signature-separator'. Any other symbol is used to look up a
321 regular expression to match the banner in `gnus-article-banner-alist'.
322 A string is used as a regular expression to match the banner
325 (defcustom gnus-article-address-banner-alist nil
326 "Alist of mail addresses and banners.
327 Each element has the form (ADDRESS . BANNER), where ADDRESS is a regexp
328 to match a mail address in the From: header, BANNER is one of a symbol
329 `signature', an item in `gnus-article-banner-alist', a regexp and nil.
330 If ADDRESS matches author's mail address, it will remove things like
331 advertisements. For example:
333 \((\"@yoo-hoo\\\\.co\\\\.jp\\\\\\='\" . \"\\n_+\\nDo You Yoo-hoo!\\\\?\\n.*\\n.*\\n\"))
337 (regexp :tag "Address")
338 (choice :tag "Banner" :value nil
339 (const :tag "Remove signature" signature)
340 (symbol :tag "Item in `gnus-article-banner-alist'" none)
342 (const :tag "None" nil))))
344 :group 'gnus-article-washing)
346 (defmacro gnus-emphasis-custom-with-format (&rest body)
348 \\(\\s-\\|^\\|\\=\\|[-\"]\\|\\s(\\)\\(%s\\(\\w+\\(\\s-+\\w+\\)*[.,]?\\)%s\\)\
349 \\(\\([-,.;:!?\"]\\|\\s)\\)+\\s-\\|[?!.]\\s-\\|\\s)\\|\\s-\\)"))
352 (defun gnus-emphasis-custom-value-to-external (value)
353 (gnus-emphasis-custom-with-format
354 (if (consp (car value))
355 (list (format format (car (car value)) (cdr (car value)))
357 (if (nth 1 value) 2 3)
361 (defun gnus-emphasis-custom-value-to-internal (value)
362 (gnus-emphasis-custom-with-format
363 (let ((regexp (concat "\\`"
364 (format (regexp-quote format)
365 "\\([^()]+\\)" "\\([^()]+\\)")
368 (if (string-match regexp (setq pattern (car value)))
369 (list (cons (match-string 1 pattern) (match-string 2 pattern))
374 (defcustom gnus-emphasis-alist
376 '(("\\*" "\\*" bold nil 2)
379 ("_/" "/_" underline-italic)
380 ("_\\*" "\\*_" underline-bold)
381 ("\\*/" "/\\*" bold-italic)
382 ("_\\*/" "/\\*_" underline-bold-italic))))
384 (gnus-emphasis-custom-with-format
385 (mapcar (lambda (spec)
386 (list (format format (car spec) (cadr spec))
389 (intern (format "gnus-emphasis-%s" (nth 2 spec)))))
391 '(;; I've never seen anyone use this strikethru convention whereas I've
392 ;; several times seen it triggered by normal text. --Stef
393 ;; Miles suggests that this form is sometimes used but for italics,
394 ;; so maybe we should map it to `italic'.
395 ;; ("\\(\\s-\\|^\\)\\(-\\(\\(\\w\\|-[^-]\\)+\\)-\\)\\(\\s-\\|[?!.,;]\\)"
396 ;; 2 3 gnus-emphasis-strikethru)
397 ("\\(\\s-\\|^\\)\\(_\\(\\(\\w\\|_[^_]\\)+\\)_\\)\\(\\s-\\|[?!.,;]\\)"
398 2 3 gnus-emphasis-underline))))
399 "*Alist that says how to fontify certain phrases.
400 Each item looks like this:
402 (\"_\\\\(\\\\w+\\\\)_\" 0 1 \\='underline)
404 The first element is a regular expression to be matched. The second
405 is a number that says what regular expression grouping used to find
406 the entire emphasized word. The third is a number that says what
407 regexp grouping should be displayed and highlighted. The fourth
408 is the face used for highlighting."
412 :format "%[Customizing Style%]\n%v"
414 (group :tag "Default"
415 :value ("" 0 0 default)
418 (let ((value (widget-get
419 (cadr (widget-get (widget-get widget :parent)
422 (if (not (eq (nth 2 value) 'default))
426 (gnus-emphasis-custom-value-to-external value))))
427 (widget-group-value-create widget))
429 (integer :format "Match group: %v")
430 (integer :format "Emphasize group: %v")
433 :value (("_" . "_") nil default)
435 (regexp :format "Start regexp: %v")
436 (regexp :format "End regexp: %v"))
437 (boolean :format "Show start and end patterns: %[%v%]\n"
438 :on " On " :off " Off ")
440 :get (lambda (symbol)
441 (mapcar 'gnus-emphasis-custom-value-to-internal
442 (default-value symbol)))
443 :set (lambda (symbol value)
444 (set-default symbol (mapcar 'gnus-emphasis-custom-value-to-external
446 :group 'gnus-article-emphasis)
448 (defcustom gnus-emphasize-whitespace-regexp "^[ \t]+\\|[ \t]*\n"
449 "A regexp to describe whitespace which should not be emphasized.
450 Typical values are \"^[ \\t]+\\\\|[ \\t]*\\n\" and \"[ \\t]+\\\\|[ \\t]*\\n\".
451 The former avoids underlining of leading and trailing whitespace,
452 and the latter avoids underlining any whitespace at all."
454 :group 'gnus-article-emphasis
457 (defface gnus-emphasis-bold '((t (:bold t)))
458 "Face used for displaying strong emphasized text (*word*)."
459 :group 'gnus-article-emphasis)
461 (defface gnus-emphasis-italic '((t (:italic t)))
462 "Face used for displaying italic emphasized text (/word/)."
463 :group 'gnus-article-emphasis)
465 (defface gnus-emphasis-underline '((t (:underline t)))
466 "Face used for displaying underlined emphasized text (_word_)."
467 :group 'gnus-article-emphasis)
469 (defface gnus-emphasis-underline-bold '((t (:bold t :underline t)))
470 "Face used for displaying underlined bold emphasized text (_*word*_)."
471 :group 'gnus-article-emphasis)
473 (defface gnus-emphasis-underline-italic '((t (:italic t :underline t)))
474 "Face used for displaying underlined italic emphasized text (_/word/_)."
475 :group 'gnus-article-emphasis)
477 (defface gnus-emphasis-bold-italic '((t (:bold t :italic t)))
478 "Face used for displaying bold italic emphasized text (/*word*/)."
479 :group 'gnus-article-emphasis)
481 (defface gnus-emphasis-underline-bold-italic
482 '((t (:bold t :italic t :underline t)))
483 "Face used for displaying underlined bold italic emphasized text.
484 Example: (_/*word*/_)."
485 :group 'gnus-article-emphasis)
487 (defface gnus-emphasis-strikethru (if (featurep 'xemacs)
488 '((t (:strikethru t)))
489 '((t (:strike-through t))))
490 "Face used for displaying strike-through text (-word-)."
491 :group 'gnus-article-emphasis)
493 (defface gnus-emphasis-highlight-words
494 '((t (:background "black" :foreground "yellow")))
495 "Face used for displaying highlighted words."
496 :group 'gnus-article-emphasis)
498 (defcustom gnus-article-time-format "%a, %d %b %Y %T %Z"
499 "Format for display of Date headers in article bodies.
500 See `format-time-string' for the possible values.
502 The variable can also be function, which should return a complete Date
503 header. The function is called with one argument, the time, which can
504 be fed to `format-time-string'."
505 :type '(choice string function)
506 :link '(custom-manual "(gnus)Article Date")
507 :group 'gnus-article-washing)
509 (defcustom gnus-save-all-headers t
510 "*If non-nil, don't remove any headers before saving.
511 This will be overridden by the `:headers' property that the symbol of
512 the saver function, which is specified by `gnus-default-article-saver',
514 :group 'gnus-article-saving
517 (defcustom gnus-prompt-before-saving 'always
518 "*This variable says how much prompting is to be done when saving articles.
519 If it is nil, no prompting will be done, and the articles will be
520 saved to the default files. If this variable is `always', each and
521 every article that is saved will be preceded by a prompt, even when
522 saving large batches of articles. If this variable is neither nil not
523 `always', there the user will be prompted once for a file name for
524 each invocation of the saving commands."
525 :group 'gnus-article-saving
526 :type '(choice (item always)
527 (item :tag "never" nil)
528 (sexp :tag "once" :format "%t\n" :value t)))
530 (defcustom gnus-saved-headers gnus-visible-headers
531 "Headers to keep if `gnus-save-all-headers' is nil.
532 If `gnus-save-all-headers' is non-nil, this variable will be ignored.
533 If that variable is nil, however, all headers that match this regexp
534 will be kept while the rest will be deleted before saving. This and
535 `gnus-save-all-headers' will be overridden by the `:headers' property
536 that the symbol of the saver function, which is specified by
537 `gnus-default-article-saver', might have."
538 :group 'gnus-article-saving
541 ;; Note that "Rmail format" is mbox since Emacs 23, but Babyl before.
542 (defcustom gnus-default-article-saver 'gnus-summary-save-in-rmail
543 "A function to save articles in your favorite format.
544 The function will be called by way of the `gnus-summary-save-article'
545 command, and friends such as `gnus-summary-save-article-rmail'.
547 Gnus provides the following functions:
549 * gnus-summary-save-in-rmail (Rmail format)
550 * gnus-summary-save-in-mail (Unix mail format)
551 * gnus-summary-save-in-folder (MH folder)
552 * gnus-summary-save-in-file (article format)
553 * gnus-summary-save-body-in-file (article body)
554 * gnus-summary-save-in-vm (use VM's folder format)
555 * gnus-summary-write-to-file (article format -- overwrite)
556 * gnus-summary-write-body-to-file (article body -- overwrite)
557 * gnus-summary-save-in-pipe (article format)
559 The symbol of each function may have the following properties:
562 The value non-nil means save decoded articles. This is meaningful
563 only with `gnus-summary-save-in-file', `gnus-summary-save-body-in-file',
564 `gnus-summary-write-to-file', `gnus-summary-write-body-to-file', and
565 `gnus-summary-save-in-pipe'.
568 The value specifies an alternative function which appends, not
569 overwrites, articles to a file. This implies that when saving many
570 articles at a time, `gnus-prompt-before-saving' is bound to t and all
571 articles are saved in a single file. This is meaningful only with
572 `gnus-summary-write-to-file' and `gnus-summary-write-body-to-file'.
575 The value specifies the symbol of a variable of which the value
576 specifies headers to be saved. If it is omitted,
577 `gnus-save-all-headers' and `gnus-saved-headers' control what
578 headers should be saved."
579 :group 'gnus-article-saving
580 :type '(radio (function-item gnus-summary-save-in-rmail)
581 (function-item gnus-summary-save-in-mail)
582 (function-item gnus-summary-save-in-folder)
583 (function-item gnus-summary-save-in-file)
584 (function-item gnus-summary-save-body-in-file)
585 (function-item gnus-summary-save-in-vm)
586 (function-item gnus-summary-write-to-file)
587 (function-item gnus-summary-write-body-to-file)
588 (function-item gnus-summary-save-in-pipe)
591 (defcustom gnus-article-save-coding-system
592 (or (and (mm-coding-system-p 'utf-8) 'utf-8)
593 (and (mm-coding-system-p 'iso-2022-7bit) 'iso-2022-7bit)
594 (and (mm-coding-system-p 'emacs-mule) 'emacs-mule)
595 (and (mm-coding-system-p 'escape-quoted) 'escape-quoted))
596 "Coding system used to save decoded articles to a file.
598 The recommended coding systems are `utf-8', `iso-2022-7bit' and so on,
599 which can safely encode any characters in text. This is used by the
602 * gnus-summary-save-article-file
603 * gnus-summary-save-article-body-file
604 * gnus-summary-write-article-file
605 * gnus-summary-write-article-body-file
607 and the functions to which you may set `gnus-default-article-saver':
609 * gnus-summary-save-in-file
610 * gnus-summary-save-body-in-file
611 * gnus-summary-write-to-file
612 * gnus-summary-write-body-to-file
614 Those commands and functions save just text displayed in the article
615 buffer to a file if the value of this variable is non-nil. Note that
616 buttonized MIME parts will be lost in a saved file in that case.
617 Otherwise, raw articles will be saved."
618 :group 'gnus-article-saving
620 :format "%{%t%}:\n %[Value Menu%] %v"
621 (const :tag "Save raw articles" nil)
624 (lambda (arg) (if (mm-coding-system-p (nth 3 arg)) arg))
625 '((const :tag "UTF-8" utf-8)
626 (const :tag "iso-2022-7bit" iso-2022-7bit)
627 (const :tag "Emacs internal" emacs-mule)
628 (const :tag "escape-quoted" escape-quoted))))
629 (symbol :tag "Coding system")))
631 (defcustom gnus-rmail-save-name 'gnus-plain-save-name
632 "A function generating a file name to save articles in Rmail format.
633 The function is called with NEWSGROUP, HEADERS, and optional LAST-FILE."
634 :group 'gnus-article-saving
637 (defcustom gnus-mail-save-name 'gnus-plain-save-name
638 "A function generating a file name to save articles in Unix mail format.
639 The function is called with NEWSGROUP, HEADERS, and optional LAST-FILE."
640 :group 'gnus-article-saving
643 (defcustom gnus-folder-save-name 'gnus-folder-save-name
644 "A function generating a file name to save articles in MH folder.
645 The function is called with NEWSGROUP, HEADERS, and optional LAST-FOLDER."
646 :group 'gnus-article-saving
649 (defcustom gnus-file-save-name 'gnus-numeric-save-name
650 "A function generating a file name to save articles in article format.
651 The function is called with NEWSGROUP, HEADERS, and optional
653 :group 'gnus-article-saving
656 (defcustom gnus-split-methods
657 '((gnus-article-archive-name)
658 (gnus-article-nndoc-name))
659 "*Variable used to suggest where articles are to be saved.
660 For instance, if you would like to save articles related to Gnus in
661 the file \"gnus-stuff\", and articles related to VM in \"vm-stuff\",
662 you could set this variable to something like:
664 ((\"^Subject:.*gnus\\|^Newsgroups:.*gnus\" \"gnus-stuff\")
665 (\"^Subject:.*vm\\|^Xref:.*vm\" \"vm-stuff\"))
667 This variable is an alist where the key is the match and the
668 value is a list of possible files to save in if the match is
671 If the match is a string, it is used as a regexp match on the
672 article. If the match is a symbol, that symbol will be funcalled
673 from the buffer of the article to be saved with the newsgroup as the
674 parameter. If it is a list, it will be evalled in the same buffer.
676 If this form or function returns a string, this string will be used as a
677 possible file name; and if it returns a non-nil list, that list will be
678 used as possible file names."
679 :group 'gnus-article-saving
680 :type '(repeat (choice (list :value (fun) function)
681 (cons :value ("" "") regexp (repeat string))
684 (defcustom gnus-page-delimiter "^\^L"
685 "*Regexp describing what to use as article page delimiters.
686 The default value is \"^\^L\", which is a form linefeed at the
687 beginning of a line."
689 :group 'gnus-article-various)
691 (defcustom gnus-article-mode-line-format "Gnus: %g %S%m"
692 "*The format specification for the article mode line.
693 See `gnus-summary-mode-line-format' for a closer description.
695 The following additional specs are available:
697 %w The article washing status.
698 %m The number of MIME parts in the article."
701 :group 'gnus-article-various)
703 (defcustom gnus-article-mode-hook nil
704 "*A hook for Gnus article mode."
706 :group 'gnus-article-various)
708 (when (featurep 'xemacs)
709 ;; Extracted from gnus-xmas-define in order to preserve user settings
710 (when (fboundp 'turn-off-scroll-in-place)
711 (add-hook 'gnus-article-mode-hook 'turn-off-scroll-in-place))
712 ;; Extracted from gnus-xmas-redefine in order to preserve user settings
713 (add-hook 'gnus-article-mode-hook 'gnus-xmas-article-menu-add))
715 (defcustom gnus-article-menu-hook nil
716 "*Hook run after the creation of the article mode menu."
718 :group 'gnus-article-various)
720 (defcustom gnus-article-prepare-hook nil
721 "*A hook called after an article has been prepared in the article buffer."
723 :group 'gnus-article-various)
725 (defcustom gnus-copy-article-ignored-headers nil
726 "List of headers to be removed when copying an article.
727 Each element is a regular expression."
728 :version "23.1" ;; No Gnus
729 :type '(repeat regexp)
730 :group 'gnus-article-various)
732 (make-obsolete-variable 'gnus-article-hide-pgp-hook nil
733 "Gnus 5.10 (Emacs 22.1)")
736 '((t (:weight bold)))
737 "Face used for highlighting a button in the article buffer."
738 :group 'gnus-article-buttons)
740 (defcustom gnus-article-button-face 'gnus-button
741 "Face used for highlighting buttons in the article buffer.
743 An article button is a piece of text that you can activate by pressing
744 `RET' or `mouse-2' above it."
746 :group 'gnus-article-buttons)
748 (defcustom gnus-article-mouse-face 'highlight
749 "Face used for mouse highlighting in the article buffer.
751 Article buttons will be displayed in this face when the cursor is
754 :group 'gnus-article-buttons)
756 (defcustom gnus-signature-face 'gnus-signature
757 "Face used for highlighting a signature in the article buffer.
758 Obsolete; use the face `gnus-signature' for customizations instead."
760 :group 'gnus-article-highlight
761 :group 'gnus-article-signature)
763 (defface gnus-signature
766 "Face used for highlighting a signature in the article buffer."
767 :group 'gnus-article-highlight
768 :group 'gnus-article-signature)
769 ;; backward-compatibility alias
770 (put 'gnus-signature-face 'face-alias 'gnus-signature)
771 (put 'gnus-signature-face 'obsolete-face "22.1")
773 (defface gnus-header-from
776 (:foreground "PaleGreen1"))
779 (:foreground "red3"))
782 "Face used for displaying from headers."
783 :group 'gnus-article-headers
784 :group 'gnus-article-highlight)
785 ;; backward-compatibility alias
786 (put 'gnus-header-from-face 'face-alias 'gnus-header-from)
787 (put 'gnus-header-from-face 'obsolete-face "22.1")
789 (defface gnus-header-subject
792 (:foreground "SeaGreen1"))
795 (:foreground "red4"))
797 (:bold t :italic t)))
798 "Face used for displaying subject headers."
799 :group 'gnus-article-headers
800 :group 'gnus-article-highlight)
801 ;; backward-compatibility alias
802 (put 'gnus-header-subject-face 'face-alias 'gnus-header-subject)
803 (put 'gnus-header-subject-face 'obsolete-face "22.1")
805 (defface gnus-header-newsgroups
808 (:foreground "yellow" :italic t))
811 (:foreground "MidnightBlue" :italic t))
814 "Face used for displaying newsgroups headers.
815 In the default setup this face is only used for crossposted
817 :group 'gnus-article-headers
818 :group 'gnus-article-highlight)
819 ;; backward-compatibility alias
820 (put 'gnus-header-newsgroups-face 'face-alias 'gnus-header-newsgroups)
821 (put 'gnus-header-newsgroups-face 'obsolete-face "22.1")
823 (defface gnus-header-name
826 (:foreground "SpringGreen2"))
829 (:foreground "maroon"))
832 "Face used for displaying header names."
833 :group 'gnus-article-headers
834 :group 'gnus-article-highlight)
835 ;; backward-compatibility alias
836 (put 'gnus-header-name-face 'face-alias 'gnus-header-name)
837 (put 'gnus-header-name-face 'obsolete-face "22.1")
839 (defface gnus-header-content
842 (:foreground "SpringGreen1" :italic t))
845 (:foreground "indianred4" :italic t))
847 (:italic t))) "Face used for displaying header content."
848 :group 'gnus-article-headers
849 :group 'gnus-article-highlight)
850 ;; backward-compatibility alias
851 (put 'gnus-header-content-face 'face-alias 'gnus-header-content)
852 (put 'gnus-header-content-face 'obsolete-face "22.1")
854 (defcustom gnus-header-face-alist
855 '(("From" nil gnus-header-from)
856 ("Subject" nil gnus-header-subject)
857 ("Newsgroups:.*," nil gnus-header-newsgroups)
858 ("" gnus-header-name gnus-header-content))
859 "*Controls highlighting of article headers.
861 An alist of the form (HEADER NAME CONTENT).
863 HEADER is a regular expression which should match the name of a
864 header and NAME and CONTENT are either face names or nil.
866 The name of each header field will be displayed using the face
867 specified by the first element in the list where HEADER matches
868 the header name and NAME is non-nil. Similarly, the content will
869 be displayed by the first non-nil matching CONTENT face."
870 :group 'gnus-article-headers
871 :group 'gnus-article-highlight
872 :type '(repeat (list (regexp :tag "Header")
874 (item :tag "skip" nil)
875 (face :value default))
876 (choice :tag "Content"
877 (item :tag "skip" nil)
878 (face :value default)))))
880 (defcustom gnus-face-properties-alist (if (featurep 'xemacs)
881 '((xface . (:face gnus-x-face)))
882 '((pbm . (:face gnus-x-face))
884 "Alist of image types and properties applied to Face and X-Face images.
887 ;; Specify the altitude of Face images in the From header.
888 \(setq gnus-face-properties-alist
889 \\='((pbm . (:face gnus-x-face :ascent 80))
890 (png . (:ascent 80))))
892 ;; Show Face images as pressed buttons.
893 \(setq gnus-face-properties-alist
894 \\='((pbm . (:face gnus-x-face :relief -2))
895 (png . (:relief -2))))
897 See the manual for the valid properties for various image types.
898 Currently, `pbm' is used for X-Face images and `png' is used for Face
899 images in Emacs. Only the `:face' property is effective on the `xface'
900 image type in XEmacs if it is built with the libcompface library."
901 :version "23.1" ;; No Gnus
902 :group 'gnus-article-headers
903 :type '(repeat (cons :format "%v" (symbol :tag "Image type") plist)))
905 (defcustom gnus-article-decode-hook
906 '(article-decode-charset article-decode-encoded-words
907 article-decode-group-name article-decode-idna-rhs)
908 "*Hook run to decode charsets in articles."
909 :group 'gnus-article-headers
912 (defcustom gnus-display-mime-function 'gnus-display-mime
913 "Function to display MIME articles."
914 :group 'gnus-article-mime
917 (defvar gnus-decode-header-function 'mail-decode-encoded-word-region
918 "Function used to decode headers.")
920 (defvar gnus-decode-address-function 'mail-decode-encoded-address-region
921 "Function used to decode addresses.")
923 (defvar gnus-article-dumbquotes-map
943 "Table for MS-to-Latin1 translation.")
945 (defcustom gnus-ignored-mime-types nil
946 "List of MIME types that should be ignored by Gnus."
948 :group 'gnus-article-mime
949 :type '(repeat regexp))
951 (defcustom gnus-unbuttonized-mime-types '(".*/.*")
952 "List of MIME types that should not be given buttons when rendered inline.
953 See also `gnus-buttonized-mime-types' which may override this variable.
954 This variable is only used when `gnus-inhibit-mime-unbuttonizing' is nil."
956 :group 'gnus-article-mime
957 :type '(repeat regexp))
959 (defcustom gnus-buttonized-mime-types nil
960 "List of MIME types that should be given buttons when rendered inline.
961 If set, this variable overrides `gnus-unbuttonized-mime-types'.
962 To see e.g. security buttons you could set this to
963 `(\"multipart/signed\")'. You could also add \"multipart/alternative\" to
964 this list to display radio buttons that allow you to choose one of two
965 media types those mails include. See also `mm-discouraged-alternatives'.
966 This variable is only used when `gnus-inhibit-mime-unbuttonizing' is nil."
968 :group 'gnus-article-mime
969 :type '(repeat regexp))
971 (defcustom gnus-inhibit-mime-unbuttonizing nil
972 "If non-nil, all MIME parts get buttons.
973 When nil (the default value), then some MIME parts do not get buttons,
974 as described by the variables `gnus-buttonized-mime-types' and
975 `gnus-unbuttonized-mime-types'."
977 :group 'gnus-article-mime
980 (defcustom gnus-body-boundary-delimiter "_"
981 "String used to delimit header and body.
982 This variable is used by `gnus-article-treat-body-boundary' which can
983 be controlled by `gnus-treat-body-boundary'."
985 :group 'gnus-article-various
986 :type '(choice (item :tag "None" :value nil)
989 (defcustom gnus-picon-databases '("/usr/lib/picon" "/usr/local/faces"
991 "Defines the location of the faces database.
992 For information on obtaining this database of pretty pictures, please
993 see http://www.cs.indiana.edu/picons/ftp/index.html"
995 :type '(repeat directory)
996 :link '(url-link :tag "download"
997 "http://www.cs.indiana.edu/picons/ftp/index.html")
998 :link '(custom-manual "(gnus)Picons")
1001 (defun gnus-picons-installed-p ()
1002 "Say whether picons are installed on your machine."
1003 (let ((installed nil))
1004 (dolist (database gnus-picon-databases)
1005 (when (file-exists-p database)
1006 (setq installed t)))
1009 (defcustom gnus-article-mime-part-function nil
1010 "Function called with a MIME handle as the argument.
1011 This is meant for people who want to do something automatic based
1012 on parts -- for instance, adding Vcard info to a database."
1013 :group 'gnus-article-mime
1014 :type '(choice (const nil)
1017 (defcustom gnus-mime-multipart-functions nil
1018 "An alist of MIME types to functions to display them."
1020 :group 'gnus-article-mime
1021 :type '(repeat (cons :format "%v" (string :tag "MIME type") function)))
1023 (defcustom gnus-article-date-headers '(combined-lapsed)
1024 "A list of Date header formats to display.
1025 Valid formats are `ut' (universal time), `local' (local time
1026 zone), `english' (readable English), `lapsed' (elapsed time),
1027 `combined-lapsed' (both the original date and the elapsed time),
1028 `original' (the original date header), `iso8601' (ISO8601
1029 format), and `user-defined' (a user-defined format defined by the
1030 `gnus-article-time-format' variable).
1032 You have as many date headers as you want in the article buffer.
1033 Some of these headers are updated automatically. See
1034 `gnus-article-update-date-headers' for details."
1036 :group 'gnus-article-headers
1038 (const :tag "Universal time (UT)" ut)
1039 (const :tag "Local time zone" local)
1040 (const :tag "Readable English" english)
1041 (const :tag "Elapsed time" lapsed)
1042 (const :tag "Original and elapsed time" combined-lapsed)
1043 (const :tag "Original date header" original)
1044 (const :tag "ISO8601 format" iso8601)
1045 (const :tag "User-defined" user-defined)))
1047 (defcustom gnus-article-update-date-headers nil
1048 "A number that says how often to update the date header (in seconds).
1049 If nil, don't update it at all."
1051 :group 'gnus-article-headers
1053 (item :tag "Don't update" :value nil)
1056 (defcustom gnus-article-mime-match-handle-function 'undisplayed-alternative
1057 "Function called with a MIME handle as the argument.
1058 This is meant for people who want to view first matched part.
1059 For `undisplayed-alternative' (default), the first undisplayed
1060 part or alternative part is used. For `undisplayed', the first
1061 undisplayed part is used. For a function, the first part which
1062 the function return t is used. For nil, the first part is
1065 :group 'gnus-article-mime
1067 (item :tag "first" :value nil)
1068 (item :tag "undisplayed" :value undisplayed)
1069 (item :tag "undisplayed or alternative"
1070 :value undisplayed-alternative)
1073 (defcustom gnus-mime-action-alist
1074 '(("save to file" . gnus-mime-save-part)
1075 ("save and strip" . gnus-mime-save-part-and-strip)
1076 ("replace with file" . gnus-mime-replace-part)
1077 ("delete part" . gnus-mime-delete-part)
1078 ("display as text" . gnus-mime-inline-part)
1079 ("view the part" . gnus-mime-view-part)
1080 ("pipe to command" . gnus-mime-pipe-part)
1081 ("toggle display" . gnus-article-press-button)
1082 ("toggle display" . gnus-article-view-part-as-charset)
1083 ("view as type" . gnus-mime-view-part-as-type)
1084 ("view internally" . gnus-mime-view-part-internally)
1085 ("view externally" . gnus-mime-view-part-externally))
1086 "An alist of actions that run on the MIME attachment."
1087 :group 'gnus-article-mime
1088 :type '(repeat (cons (string :tag "name")
1091 (defcustom gnus-auto-select-part 1
1092 "Advance to next MIME part when deleting or stripping parts.
1094 When 0, point will be placed on the same part as before. When
1095 positive (negative), move point forward (backwards) this many
1096 parts. When nil, redisplay article."
1097 :version "23.1" ;; No Gnus
1098 :group 'gnus-article-mime
1099 :type '(choice (const nil :tag "Redisplay article.")
1100 (const 1 :tag "Next part.")
1101 (const 0 :tag "Current part.")
1105 ;;; The treatment variables
1108 (defvar gnus-part-display-hook nil
1109 "Hook called on parts that are to receive treatment.")
1111 (defvar gnus-article-treat-custom
1112 '(choice (const :tag "Off" nil)
1114 (const :tag "Header" head)
1115 (const :tag "First" first)
1116 (const :tag "Last" last)
1117 (integer :tag "Less")
1118 (repeat :tag "Groups" regexp)
1119 (sexp :tag "Predicate")))
1121 (defvar gnus-article-treat-head-custom
1122 '(choice (const :tag "Off" nil)
1123 (const :tag "Header" head)))
1125 (defvar gnus-article-treat-types '("text/plain" "text/x-verbatim"
1126 "text/x-patch" "text/html")
1127 "Part types eligible for treatment.")
1129 (defvar gnus-inhibit-treatment nil
1130 "Whether to inhibit treatment.")
1132 (defcustom gnus-treat-highlight-signature '(or t (typep "text/x-vcard"))
1133 "Highlight the signature.
1134 Valid values are nil, t, `head', `first', `last', an integer or a
1135 predicate. See Info node `(gnus)Customizing Articles'."
1136 :group 'gnus-article-treat
1137 :link '(custom-manual "(gnus)Customizing Articles")
1138 :type gnus-article-treat-custom)
1139 (put 'gnus-treat-highlight-signature 'highlight t)
1141 (defcustom gnus-treat-buttonize '(and 100000 (typep "text/plain"))
1143 Valid values are nil, t, `head', `first', `last', an integer or a
1144 predicate. See Info node `(gnus)Customizing Articles'."
1145 :group 'gnus-article-treat
1146 :link '(custom-manual "(gnus)Customizing Articles")
1147 :type gnus-article-treat-custom)
1148 (put 'gnus-treat-buttonize 'highlight t)
1150 (defcustom gnus-treat-buttonize-head 'head
1151 "Add buttons to the head.
1152 Valid values are nil, t, `head', `first', `last', an integer or a
1153 predicate. See Info node `(gnus)Customizing Articles'."
1154 :group 'gnus-article-treat
1155 :link '(custom-manual "(gnus)Customizing Articles")
1156 :type gnus-article-treat-head-custom)
1157 (put 'gnus-treat-buttonize-head 'highlight t)
1159 (defcustom gnus-treat-date 'head
1160 "Display dates according to the `gnus-article-date-headers' variable.
1161 Valid values are nil, t, `head', `first', `last', an integer or a
1162 predicate. See Info node `(gnus)Customizing Articles'."
1164 :group 'gnus-article-treat
1165 :link '(custom-manual "(gnus)Customizing Articles")
1166 :type gnus-article-treat-head-custom)
1168 (defcustom gnus-treat-emphasize 50000
1170 Valid values are nil, t, `head', `first', `last', an integer or a
1171 predicate. See Info node `(gnus)Customizing Articles'."
1172 :group 'gnus-article-treat
1173 :link '(custom-manual "(gnus)Customizing Articles")
1174 :type gnus-article-treat-custom)
1175 (put 'gnus-treat-emphasize 'highlight t)
1177 (defcustom gnus-treat-strip-cr nil
1178 "Remove carriage returns.
1179 Valid values are nil, t, `head', `first', `last', an integer or a
1180 predicate. See Info node `(gnus)Customizing Articles'."
1182 :group 'gnus-article-treat
1183 :link '(custom-manual "(gnus)Customizing Articles")
1184 :type gnus-article-treat-custom)
1186 (defcustom gnus-treat-unsplit-urls nil
1187 "Remove newlines from within URLs.
1188 Valid values are nil, t, `head', `first', `last', an integer or a
1189 predicate. See Info node `(gnus)Customizing Articles'."
1191 :group 'gnus-article-treat
1192 :link '(custom-manual "(gnus)Customizing Articles")
1193 :type gnus-article-treat-custom)
1195 (defcustom gnus-treat-leading-whitespace nil
1196 "Remove leading whitespace in headers.
1197 Valid values are nil, t, `head', `first', `last', an integer or a
1198 predicate. See Info node `(gnus)Customizing Articles'."
1200 :group 'gnus-article-treat
1201 :link '(custom-manual "(gnus)Customizing Articles")
1202 :type gnus-article-treat-custom)
1204 (defcustom gnus-treat-hide-headers 'head
1206 Valid values are nil, t, `head', `first', `last', an integer or a
1207 predicate. See Info node `(gnus)Customizing Articles'."
1208 :group 'gnus-article-treat
1209 :link '(custom-manual "(gnus)Customizing Articles")
1210 :type gnus-article-treat-head-custom)
1212 (defcustom gnus-treat-hide-boring-headers nil
1213 "Hide boring headers.
1214 Valid values are nil, t, `head', `first', `last', an integer or a
1215 predicate. See Info node `(gnus)Customizing Articles'."
1216 :group 'gnus-article-treat
1217 :link '(custom-manual "(gnus)Customizing Articles")
1218 :type gnus-article-treat-head-custom)
1220 (defcustom gnus-treat-hide-signature nil
1221 "Hide the signature.
1222 Valid values are nil, t, `head', `first', `last', an integer or a
1223 predicate. See Info node `(gnus)Customizing Articles'."
1224 :group 'gnus-article-treat
1225 :link '(custom-manual "(gnus)Customizing Articles")
1226 :type gnus-article-treat-custom)
1228 (defcustom gnus-treat-fill-article nil
1230 Valid values are nil, t, `head', `first', `last', an integer or a
1231 predicate. See Info node `(gnus)Customizing Articles'."
1232 :group 'gnus-article-treat
1233 :link '(custom-manual "(gnus)Customizing Articles")
1234 :type gnus-article-treat-custom)
1236 (defcustom gnus-treat-hide-citation nil
1238 Valid values are nil, t, `head', `first', `last', an integer or a
1239 predicate. See Info node `(gnus)Customizing Articles'.
1241 See `gnus-article-highlight-citation' for variables used to
1242 control what it hides."
1243 :group 'gnus-article-treat
1244 :link '(custom-manual "(gnus)Customizing Articles")
1245 :type gnus-article-treat-custom)
1247 (defcustom gnus-treat-hide-citation-maybe nil
1248 "Hide cited text according to certain conditions.
1249 Valid values are nil, t, `head', `first', `last', an integer or a
1250 predicate. See Info node `(gnus)Customizing Articles'.
1252 See `gnus-cite-hide-percentage' and `gnus-cite-hide-absolute' for
1253 how to control what it hides."
1254 :group 'gnus-article-treat
1255 :link '(custom-manual "(gnus)Customizing Articles")
1256 :type gnus-article-treat-custom)
1258 (defcustom gnus-treat-strip-list-identifiers 'head
1259 "Strip list identifiers from `gnus-list-identifiers'.
1260 Valid values are nil, t, `head', `first', `last', an integer or a
1261 predicate. See Info node `(gnus)Customizing Articles'."
1263 :group 'gnus-article-treat
1264 :link '(custom-manual "(gnus)Customizing Articles")
1265 :type gnus-article-treat-custom)
1267 (gnus-define-group-parameter
1270 "Alist of regexps and correspondent identifiers."
1271 :variable-group gnus-article-washing
1273 '(choice :tag "Identifier"
1275 (symbol :tag "Item in `gnus-list-identifiers'" none)
1277 (const :tag "None" nil))
1279 "If non-nil, specify how to remove `identifiers' from articles' subject.
1281 Any symbol is used to look up a regular expression to match the
1282 banner in `gnus-list-identifiers'. A string is used as a regular
1283 expression to match the identifier directly.")
1285 (make-obsolete-variable 'gnus-treat-strip-pgp nil
1286 "Gnus 5.10 (Emacs 22.1)")
1288 (defcustom gnus-treat-strip-pem nil
1289 "Strip PEM signatures.
1290 Valid values are nil, t, `head', `first', `last', an integer or a
1291 predicate. See Info node `(gnus)Customizing Articles'."
1292 :group 'gnus-article-treat
1293 :link '(custom-manual "(gnus)Customizing Articles")
1294 :type gnus-article-treat-custom)
1296 (defcustom gnus-treat-strip-banner t
1297 "Strip banners from articles.
1298 The banner to be stripped is specified in the `banner' group parameter.
1299 Valid values are nil, t, `head', `first', `last', an integer or a
1300 predicate. See Info node `(gnus)Customizing Articles'."
1301 :group 'gnus-article-treat
1302 :link '(custom-manual "(gnus)Customizing Articles")
1303 :type gnus-article-treat-custom)
1305 (defcustom gnus-treat-highlight-headers 'head
1306 "Highlight the headers.
1307 Valid values are nil, t, `head', `first', `last', an integer or a
1308 predicate. See Info node `(gnus)Customizing Articles'."
1309 :group 'gnus-article-treat
1310 :link '(custom-manual "(gnus)Customizing Articles")
1311 :type gnus-article-treat-head-custom)
1312 (put 'gnus-treat-highlight-headers 'highlight t)
1314 (defcustom gnus-treat-highlight-citation t
1315 "Highlight cited text.
1316 Valid values are nil, t, `head', `first', `last', an integer or a
1317 predicate. See Info node `(gnus)Customizing Articles'."
1318 :group 'gnus-article-treat
1319 :link '(custom-manual "(gnus)Customizing Articles")
1320 :type gnus-article-treat-custom)
1321 (put 'gnus-treat-highlight-citation 'highlight t)
1323 (defcustom gnus-treat-strip-headers-in-body t
1324 "Strip the X-No-Archive header line from the beginning of the body.
1325 Valid values are nil, t, `head', `first', `last', an integer or a
1326 predicate. See Info node `(gnus)Customizing Articles'."
1328 :group 'gnus-article-treat
1329 :link '(custom-manual "(gnus)Customizing Articles")
1330 :type gnus-article-treat-custom)
1332 (defcustom gnus-treat-strip-trailing-blank-lines nil
1333 "Strip trailing blank lines.
1334 Valid values are nil, t, `head', `first', `last', an integer or a
1335 predicate. See Info node `(gnus)Customizing Articles'.
1337 When set to t, it also strips trailing blanks in all MIME parts.
1338 Consider to use `last' instead."
1339 :group 'gnus-article-treat
1340 :link '(custom-manual "(gnus)Customizing Articles")
1341 :type gnus-article-treat-custom)
1343 (defcustom gnus-treat-strip-leading-blank-lines nil
1344 "Strip leading blank lines.
1345 Valid values are nil, t, `head', `first', `last', an integer or a
1346 predicate. See Info node `(gnus)Customizing Articles'.
1348 When set to t, it also strips trailing blanks in all MIME parts."
1349 :group 'gnus-article-treat
1350 :link '(custom-manual "(gnus)Customizing Articles")
1351 :type gnus-article-treat-custom)
1353 (defcustom gnus-treat-strip-multiple-blank-lines nil
1354 "Strip multiple blank lines.
1355 Valid values are nil, t, `head', `first', `last', an integer or a
1356 predicate. See Info node `(gnus)Customizing Articles'."
1357 :group 'gnus-article-treat
1358 :link '(custom-manual "(gnus)Customizing Articles")
1359 :type gnus-article-treat-custom)
1361 (defcustom gnus-treat-unfold-headers 'head
1362 "Unfold folded header lines.
1363 Valid values are nil, t, `head', `first', `last', an integer or a
1364 predicate. See Info node `(gnus)Customizing Articles'."
1366 :group 'gnus-article-treat
1367 :link '(custom-manual "(gnus)Customizing Articles")
1368 :type gnus-article-treat-custom)
1370 (defcustom gnus-article-unfold-long-headers nil
1371 "If non-nil, allow unfolding headers even if the header is long.
1372 If it is a regexp, only long headers matching this regexp are unfolded.
1373 If it is t, all long headers are unfolded.
1375 This variable has no effect if `gnus-treat-unfold-headers' is nil."
1376 :version "23.1" ;; No Gnus
1377 :group 'gnus-article-treat
1378 :type '(choice (const nil)
1379 (const :tag "all" t)
1382 (defcustom gnus-treat-fold-headers nil
1384 Valid values are nil, t, `head', `first', `last', an integer or a
1385 predicate. See Info node `(gnus)Customizing Articles'."
1387 :group 'gnus-article-treat
1388 :link '(custom-manual "(gnus)Customizing Articles")
1389 :type gnus-article-treat-custom)
1391 (defcustom gnus-treat-fold-newsgroups 'head
1392 "Fold the Newsgroups and Followup-To headers.
1393 Valid values are nil, t, `head', `first', `last', an integer or a
1394 predicate. See Info node `(gnus)Customizing Articles'."
1396 :group 'gnus-article-treat
1397 :link '(custom-manual "(gnus)Customizing Articles")
1398 :type gnus-article-treat-custom)
1400 (defcustom gnus-treat-overstrike t
1401 "Treat overstrike highlighting.
1402 Valid values are nil, t, `head', `first', `last', an integer or a
1403 predicate. See Info node `(gnus)Customizing Articles'."
1404 :group 'gnus-article-treat
1405 :link '(custom-manual "(gnus)Customizing Articles")
1406 :type gnus-article-treat-custom)
1407 (put 'gnus-treat-overstrike 'highlight t)
1409 (defcustom gnus-treat-ansi-sequences (if (locate-library "ansi-color") t)
1410 "Treat ANSI SGR control sequences.
1411 Valid values are nil, t, `head', `first', `last', an integer or a
1412 predicate. See Info node `(gnus)Customizing Articles'."
1413 :group 'gnus-article-treat
1414 :link '(custom-manual "(gnus)Customizing Articles")
1415 :type gnus-article-treat-custom)
1417 (make-obsolete-variable 'gnus-treat-display-xface
1418 'gnus-treat-display-x-face "Emacs 22.1")
1420 (defcustom gnus-treat-display-x-face
1421 (and (not noninteractive)
1422 (gnus-image-type-available-p 'xbm)
1423 (if (featurep 'xemacs)
1426 (and (string-match "^0x" (shell-command-to-string "uncompface"))
1427 (executable-find "icontopbm"))
1428 ;; shell-command-to-string may signal an error, e.g. if
1429 ;; shell-file-name is not found.
1432 "Display X-Face headers.
1433 Valid values are nil and `head'.
1434 See Info node `(gnus)Customizing Articles' and Info node
1435 `(gnus)X-Face' for details."
1436 :group 'gnus-article-treat
1438 :link '(custom-manual "(gnus)Customizing Articles")
1439 :link '(custom-manual "(gnus)X-Face")
1440 :type gnus-article-treat-head-custom
1441 :set (lambda (symbol value)
1444 (cond ((or (boundp symbol) (get symbol 'saved-value))
1446 ((boundp 'gnus-treat-display-xface)
1448 ** gnus-treat-display-xface is an obsolete variable;\
1449 use gnus-treat-display-x-face instead")
1450 (default-value 'gnus-treat-display-xface))
1451 ((get 'gnus-treat-display-xface 'saved-value)
1453 ** gnus-treat-display-xface is an obsolete variable;\
1454 use gnus-treat-display-x-face instead")
1455 (eval (car (get 'gnus-treat-display-xface 'saved-value))))
1458 (put 'gnus-treat-display-x-face 'highlight t)
1460 (defcustom gnus-treat-display-face
1461 (and (not noninteractive)
1462 (gnus-image-type-available-p 'png)
1464 "Display Face headers.
1465 Valid values are nil, t, `head', `first', `last', an integer or a
1466 predicate. See Info node `(gnus)Customizing Articles' and Info
1467 node `(gnus)Face' for details."
1468 :group 'gnus-article-treat
1470 :link '(custom-manual "(gnus)Customizing Articles")
1471 :link '(custom-manual "(gnus)X-Face")
1472 :type gnus-article-treat-head-custom)
1473 (put 'gnus-treat-display-face 'highlight t)
1475 (defcustom gnus-treat-display-smileys (gnus-image-type-available-p 'xpm)
1477 Valid values are nil, t, `head', `first', `last', an integer or a
1478 predicate. See Info node `(gnus)Customizing Articles' and Info
1479 node `(gnus)Smileys' for details."
1480 :group 'gnus-article-treat
1482 :link '(custom-manual "(gnus)Customizing Articles")
1483 :link '(custom-manual "(gnus)Smileys")
1484 :type gnus-article-treat-custom)
1485 (put 'gnus-treat-display-smileys 'highlight t)
1487 (defcustom gnus-treat-from-picon
1488 (if (and (gnus-image-type-available-p 'xpm)
1489 (gnus-picons-installed-p))
1491 "Display picons in the From header.
1492 Valid values are nil, t, `head', `first', `last', an integer or a
1493 predicate. See Info node `(gnus)Customizing Articles' and Info
1494 node `(gnus)Picons' for details."
1496 :group 'gnus-article-treat
1498 :link '(custom-manual "(gnus)Customizing Articles")
1499 :link '(custom-manual "(gnus)Picons")
1500 :type gnus-article-treat-head-custom)
1501 (put 'gnus-treat-from-picon 'highlight t)
1503 (defcustom gnus-treat-mail-picon
1504 (if (and (gnus-image-type-available-p 'xpm)
1505 (gnus-picons-installed-p))
1507 "Display picons in To and Cc headers.
1508 Valid values are nil, t, `head', `first', `last', an integer or a
1509 predicate. See Info node `(gnus)Customizing Articles' and Info
1510 node `(gnus)Picons' for details."
1512 :group 'gnus-article-treat
1514 :link '(custom-manual "(gnus)Customizing Articles")
1515 :link '(custom-manual "(gnus)Picons")
1516 :type gnus-article-treat-head-custom)
1517 (put 'gnus-treat-mail-picon 'highlight t)
1519 (defcustom gnus-treat-newsgroups-picon
1520 (if (and (gnus-image-type-available-p 'xpm)
1521 (gnus-picons-installed-p))
1523 "Display picons in the Newsgroups and Followup-To headers.
1524 Valid values are nil, t, `head', `first', `last', an integer or a
1525 predicate. See Info node `(gnus)Customizing Articles' and Info
1526 node `(gnus)Picons' for details."
1528 :group 'gnus-article-treat
1530 :link '(custom-manual "(gnus)Customizing Articles")
1531 :link '(custom-manual "(gnus)Picons")
1532 :type gnus-article-treat-head-custom)
1533 (put 'gnus-treat-newsgroups-picon 'highlight t)
1535 (defcustom gnus-treat-from-gravatar nil
1536 "Display gravatars in the From header.
1537 Valid values are nil, t, `head', `first', `last', an integer or a
1538 predicate. See Info node `(gnus)Customizing Articles' and Info
1539 node `(gnus)Gravatars' for details."
1541 :group 'gnus-article-treat
1542 :group 'gnus-gravatar
1543 :link '(custom-manual "(gnus)Customizing Articles")
1544 :link '(custom-manual "(gnus)Gravatars")
1545 :type gnus-article-treat-head-custom)
1546 (put 'gnus-treat-from-gravatar 'highlight t)
1548 (defcustom gnus-treat-mail-gravatar nil
1549 "Display gravatars in To and Cc headers.
1550 Valid values are nil, t, `head', `first', `last', an integer or a
1551 predicate. See Info node `(gnus)Customizing Articles' and Info
1552 node `(gnus)Gravatars' for details."
1554 :group 'gnus-article-treat
1555 :group 'gnus-gravatar
1556 :link '(custom-manual "(gnus)Customizing Articles")
1557 :link '(custom-manual "(gnus)Gravatars")
1558 :type gnus-article-treat-head-custom)
1559 (put 'gnus-treat-mail-gravatar 'highlight t)
1561 (defcustom gnus-treat-body-boundary
1562 (if (or gnus-treat-newsgroups-picon
1563 gnus-treat-mail-picon
1564 gnus-treat-from-picon
1565 gnus-treat-from-gravatar
1566 gnus-treat-mail-gravatar)
1567 ;; If there's much decoration, the user might prefer a boundary.
1570 "Draw a boundary at the end of the headers.
1571 Valid values are nil and `head'.
1572 See Info node `(gnus)Customizing Articles' for details."
1574 :group 'gnus-article-treat
1575 :link '(custom-manual "(gnus)Customizing Articles")
1576 :type gnus-article-treat-head-custom)
1578 (defcustom gnus-treat-capitalize-sentences nil
1579 "Capitalize sentence-starting words.
1580 Valid values are nil, t, `head', `first', `last', an integer or a
1581 predicate. See Info node `(gnus)Customizing Articles'."
1583 :group 'gnus-article-treat
1584 :link '(custom-manual "(gnus)Customizing Articles")
1585 :type gnus-article-treat-custom)
1587 (defcustom gnus-treat-wash-html nil
1589 Valid values are nil, t, `head', `first', `last', an integer or a
1590 predicate. See Info node `(gnus)Customizing Articles'."
1592 :group 'gnus-article-treat
1593 :link '(custom-manual "(gnus)Customizing Articles")
1594 :type gnus-article-treat-custom)
1596 (defcustom gnus-treat-fill-long-lines '(typep "text/plain")
1598 Valid values are nil, t, `head', `first', `last', an integer or a
1599 predicate. See Info node `(gnus)Customizing Articles'."
1601 :group 'gnus-article-treat
1602 :link '(custom-manual "(gnus)Customizing Articles")
1603 :type gnus-article-treat-custom)
1605 (defcustom gnus-treat-x-pgp-sig nil
1607 To automatically treat X-PGP-Sig, set it to head.
1608 Valid values are nil, t, `head', `first', `last', an integer or a
1609 predicate. See Info node `(gnus)Customizing Articles'."
1611 :group 'gnus-article-treat
1612 :group 'mime-security
1613 :link '(custom-manual "(gnus)Customizing Articles")
1614 :type gnus-article-treat-custom)
1616 (defvar gnus-article-encrypt-protocol-alist
1617 '(("PGP" . mml2015-self-encrypt)))
1619 ;; Set to nil if more than one protocol added to
1620 ;; gnus-article-encrypt-protocol-alist.
1621 (defcustom gnus-article-encrypt-protocol "PGP"
1622 "The protocol used for encrypt articles.
1623 It is a string, such as \"PGP\". If nil, ask user."
1626 :group 'mime-security)
1628 (defvar idna-program)
1630 (defcustom gnus-use-idna (and (mm-coding-system-p 'utf-8)
1634 (invalid-operation))
1636 (executable-find idna-program))
1637 "Whether IDNA decoding of headers is used when viewing messages.
1638 This requires GNU Libidn, and by default only enabled if it is found."
1640 :group 'gnus-article-headers
1643 (defcustom gnus-article-over-scroll nil
1644 "If non-nil, allow scrolling the article buffer even when there no more text."
1646 :group 'gnus-article
1649 (defcustom gnus-inhibit-images nil
1650 "Non-nil means inhibit displaying of images inline in the article body."
1652 :group 'gnus-article
1655 (defcustom gnus-blocked-images 'gnus-block-private-groups
1656 "Images that have URLs matching this regexp will be blocked.
1657 This can also be a function to be evaluated. If so, it will be
1658 called with the group name as the parameter, and should return a
1662 :type '(choice (const :tag "Allow all" nil)
1663 (regexp :tag "Regular expression")
1664 (function :tag "Use a function")))
1666 ;;; Internal variables
1668 (defvar gnus-english-month-names
1669 '("January" "February" "March" "April" "May" "June" "July" "August"
1670 "September" "October" "November" "December"))
1672 (defvar article-goto-body-goes-to-point-min-p nil)
1673 (defvar gnus-article-wash-types nil)
1674 (defvar gnus-article-emphasis-alist nil)
1675 (defvar gnus-article-image-alist nil)
1677 (defvar gnus-article-mime-handle-alist-1 nil)
1678 (defvar gnus-treatment-function-alist
1679 '((gnus-treat-strip-cr gnus-article-remove-cr)
1680 (gnus-treat-x-pgp-sig gnus-article-verify-x-pgp-sig)
1681 (gnus-treat-strip-banner gnus-article-strip-banner)
1682 (gnus-treat-strip-headers-in-body gnus-article-strip-headers-in-body)
1683 (gnus-treat-highlight-signature gnus-article-highlight-signature)
1684 (gnus-treat-buttonize gnus-article-add-buttons)
1685 (gnus-treat-fill-article gnus-article-fill-cited-article)
1686 (gnus-treat-fill-long-lines gnus-article-fill-cited-long-lines)
1687 (gnus-treat-unsplit-urls gnus-article-unsplit-urls)
1688 (gnus-treat-display-x-face gnus-article-display-x-face)
1689 (gnus-treat-display-face gnus-article-display-face)
1690 (gnus-treat-hide-headers gnus-article-maybe-hide-headers)
1691 (gnus-treat-hide-boring-headers gnus-article-hide-boring-headers)
1692 (gnus-treat-hide-signature gnus-article-hide-signature)
1693 (gnus-treat-strip-list-identifiers gnus-article-hide-list-identifiers)
1694 (gnus-treat-leading-whitespace gnus-article-remove-leading-whitespace)
1695 (gnus-treat-from-picon gnus-treat-from-picon)
1696 (gnus-treat-mail-picon gnus-treat-mail-picon)
1697 (gnus-treat-newsgroups-picon gnus-treat-newsgroups-picon)
1698 (gnus-treat-strip-pem gnus-article-hide-pem)
1699 (gnus-treat-date gnus-article-treat-date)
1700 (gnus-treat-from-gravatar gnus-treat-from-gravatar)
1701 (gnus-treat-mail-gravatar gnus-treat-mail-gravatar)
1702 (gnus-treat-highlight-headers gnus-article-highlight-headers)
1703 (gnus-treat-highlight-signature gnus-article-highlight-signature)
1704 (gnus-treat-strip-trailing-blank-lines
1705 gnus-article-remove-trailing-blank-lines)
1706 (gnus-treat-strip-leading-blank-lines
1707 gnus-article-strip-leading-blank-lines)
1708 (gnus-treat-strip-multiple-blank-lines
1709 gnus-article-strip-multiple-blank-lines)
1710 (gnus-treat-overstrike gnus-article-treat-overstrike)
1711 (gnus-treat-ansi-sequences gnus-article-treat-ansi-sequences)
1712 (gnus-treat-unfold-headers gnus-article-treat-unfold-headers)
1713 (gnus-treat-fold-newsgroups gnus-article-treat-fold-newsgroups)
1714 (gnus-treat-fold-headers gnus-article-treat-fold-headers)
1715 (gnus-treat-buttonize-head gnus-article-add-buttons-to-head)
1716 (gnus-treat-display-smileys gnus-treat-smiley)
1717 (gnus-treat-capitalize-sentences gnus-article-capitalize-sentences)
1718 (gnus-treat-wash-html gnus-article-wash-html)
1719 (gnus-treat-emphasize gnus-article-emphasize)
1720 (gnus-treat-hide-citation gnus-article-hide-citation)
1721 (gnus-treat-hide-citation-maybe gnus-article-hide-citation-maybe)
1722 (gnus-treat-highlight-citation gnus-article-highlight-citation)
1723 (gnus-treat-body-boundary gnus-article-treat-body-boundary)))
1725 (defvar gnus-article-mime-handle-alist nil)
1726 (defvar article-lapsed-timer nil)
1727 (defvar gnus-article-current-summary nil)
1729 (defvar gnus-article-mode-syntax-table
1730 (let ((table (copy-syntax-table text-mode-syntax-table)))
1731 ;; This causes the citation match run O(2^n).
1732 ;; (modify-syntax-entry ?- "w" table)
1733 (modify-syntax-entry ?> ")<" table)
1734 (modify-syntax-entry ?< "(>" table)
1735 ;; make M-. in article buffers work for `foo' strings
1736 (modify-syntax-entry ?' " " table)
1737 (modify-syntax-entry ?` " " table)
1739 "Syntax table used in article mode buffers.
1740 Initialized from `text-mode-syntax-table'.")
1742 (defvar gnus-save-article-buffer nil)
1744 (defvar gnus-number-of-articles-to-be-saved nil)
1746 (defvar gnus-inhibit-hiding nil)
1748 (defvar gnus-article-edit-mode nil)
1750 ;;; Macros for dealing with the article buffer.
1752 (defmacro gnus-with-article-headers (&rest forms)
1753 `(with-current-buffer gnus-article-buffer
1755 (let ((inhibit-read-only t)
1756 (inhibit-point-motion-hooks t)
1757 (case-fold-search t))
1758 (article-narrow-to-head)
1761 (put 'gnus-with-article-headers 'lisp-indent-function 0)
1762 (put 'gnus-with-article-headers 'edebug-form-spec '(body))
1764 (defmacro gnus-with-article-buffer (&rest forms)
1765 `(when (buffer-live-p (get-buffer gnus-article-buffer))
1766 (with-current-buffer gnus-article-buffer
1767 (let ((inhibit-read-only t))
1770 (put 'gnus-with-article-buffer 'lisp-indent-function 0)
1771 (put 'gnus-with-article-buffer 'edebug-form-spec '(body))
1773 (defun gnus-article-goto-header (header)
1774 "Go to HEADER, which is a regular expression."
1775 (re-search-forward (concat "^\\(" header "\\):") nil t))
1777 (defsubst gnus-article-hide-text (b e props)
1778 "Set text PROPS on the B to E region."
1779 (gnus-add-text-properties-when 'article-type nil b e props))
1781 (defsubst gnus-article-unhide-text (b e)
1782 "Remove hidden text properties from region between B and E."
1783 (remove-text-properties b e gnus-hidden-properties))
1785 (defun gnus-article-hide-text-type (b e type)
1786 "Hide text of TYPE between B and E."
1787 (gnus-add-wash-type type)
1788 (gnus-article-hide-text
1789 b e (cons 'article-type (cons type gnus-hidden-properties))))
1791 (defun gnus-article-unhide-text-type (b e type)
1792 "Unhide text of TYPE between B and E."
1793 (gnus-delete-wash-type type)
1794 (remove-text-properties
1795 b e (cons 'article-type (cons type gnus-hidden-properties))))
1797 (defun gnus-article-delete-text-of-type (type)
1798 "Delete text of TYPE in the current buffer."
1800 (let ((b (point-min)))
1801 (if (eq type 'multipart)
1802 ;; Remove MIME buttons associated with multipart/alternative parts.
1805 (while (if (get-text-property (point) 'gnus-part)
1807 (when (setq b (next-single-property-change (point)
1812 (skip-chars-forward "\n")
1813 (when (eq (get-text-property b 'article-type) 'multipart)
1814 (delete-region b (point)))))
1815 (while (setq b (text-property-any b (point-max) 'article-type type))
1817 b (or (text-property-not-all b (point-max) 'article-type type)
1820 (defun gnus-article-delete-invisible-text ()
1821 "Delete all invisible text in the current buffer."
1823 (let ((b (point-min)))
1824 (while (setq b (text-property-any b (point-max) 'invisible t))
1826 b (or (text-property-not-all b (point-max) 'invisible t)
1829 (defsubst gnus-article-header-rank ()
1830 "Give the rank of the string HEADER as given by `gnus-sorted-header-list'."
1831 (let ((list gnus-sorted-header-list)
1834 (if (looking-at (car list))
1836 (setq list (cdr list))
1840 (defun article-hide-headers (&optional _arg _delete)
1841 "Hide unwanted headers and possibly sort them as well."
1843 ;; This function might be inhibited.
1844 (unless gnus-inhibit-hiding
1845 (let ((inhibit-read-only t)
1846 (case-fold-search t)
1847 (max (1+ (length gnus-sorted-header-list)))
1848 (inhibit-point-motion-hooks t)
1849 (cur (current-buffer))
1850 ignored visible beg)
1852 ;; `gnus-ignored-headers' and `gnus-visible-headers' may be
1853 ;; group parameters, so we should go to the summary buffer.
1856 (progn (set-buffer gnus-summary-buffer) t)
1858 (setq ignored (when (not gnus-visible-headers)
1859 (cond ((stringp gnus-ignored-headers)
1860 gnus-ignored-headers)
1861 ((listp gnus-ignored-headers)
1862 (mapconcat 'identity
1863 gnus-ignored-headers
1865 visible (cond ((stringp gnus-visible-headers)
1866 gnus-visible-headers)
1867 ((and gnus-visible-headers
1868 (listp gnus-visible-headers))
1869 (mapconcat 'identity
1870 gnus-visible-headers
1874 ;; First we narrow to just the headers.
1875 (article-narrow-to-head)
1876 ;; Hide any "From " lines at the beginning of (mail) articles.
1877 (while (looking-at "From ")
1880 (delete-region (point-min) (point)))
1881 ;; Then treat the rest of the header lines.
1882 ;; Then we use the two regular expressions
1883 ;; `gnus-ignored-headers' and `gnus-visible-headers' to
1884 ;; select which header lines is to remain visible in the
1886 (while (re-search-forward "^[^ \t:]*:" nil t)
1888 ;; Mark the rank of the header.
1890 (point) (1+ (point)) 'message-rank
1891 (if (or (and visible (looking-at visible))
1893 (not (looking-at ignored))))
1894 (gnus-article-header-rank)
1897 (message-sort-headers-1)
1898 (when (setq beg (text-property-any
1899 (point-min) (point-max) 'message-rank (+ 2 max)))
1900 ;; We delete the unwanted headers.
1901 (gnus-add-wash-type 'headers)
1902 (add-text-properties (point-min) (+ 5 (point-min))
1903 '(article-type headers dummy-invisible t))
1904 (delete-region beg (point-max))))))))
1906 (defun article-hide-boring-headers (&optional arg)
1907 "Toggle hiding of headers that aren't very interesting.
1908 If given a negative prefix, always show; if given a positive prefix,
1910 (interactive (gnus-article-hidden-arg))
1911 (when (and (not (gnus-article-check-hidden-text 'boring-headers arg))
1912 (not gnus-show-all-headers))
1915 (let ((inhibit-read-only t)
1916 (inhibit-point-motion-hooks t))
1917 (article-narrow-to-head)
1918 (dolist (elem gnus-boring-article-headers)
1919 (goto-char (point-min))
1921 ;; Hide empty headers.
1923 (while (re-search-forward "^[^: \t]+:[ \t]*\n[^ \t]" nil t)
1925 (gnus-article-hide-text-type
1929 (if (re-search-forward "^[^ \t]" nil t)
1933 ;; Hide boring Newsgroups header.
1934 ((eq elem 'newsgroups)
1935 (when (gnus-string-equal
1936 (gnus-fetch-field "newsgroups")
1937 (gnus-group-real-name
1938 (if (boundp 'gnus-newsgroup-name)
1941 (gnus-article-hide-header "newsgroups")))
1942 ((eq elem 'to-address)
1943 (let ((to (message-fetch-field "to"))
1945 (gnus-parameter-to-address
1946 (if (boundp 'gnus-newsgroup-name)
1947 gnus-newsgroup-name ""))))
1948 (when (and to to-address
1951 ;; only one address in To
1952 (nth 1 (mail-extract-address-components to))
1954 (gnus-article-hide-header "to"))))
1956 (let ((to (message-fetch-field "to"))
1958 (gnus-parameter-to-list
1959 (if (boundp 'gnus-newsgroup-name)
1960 gnus-newsgroup-name ""))))
1961 (when (and to to-list
1964 ;; only one address in To
1965 (nth 1 (mail-extract-address-components to))
1967 (gnus-article-hide-header "to"))))
1969 (let ((cc (message-fetch-field "cc"))
1971 (gnus-parameter-to-list
1972 (if (boundp 'gnus-newsgroup-name)
1973 gnus-newsgroup-name ""))))
1974 (when (and cc to-list
1977 ;; only one address in CC
1978 (nth 1 (mail-extract-address-components cc))
1980 (gnus-article-hide-header "cc"))))
1981 ((eq elem 'followup-to)
1982 (when (gnus-string-equal
1983 (message-fetch-field "followup-to")
1984 (message-fetch-field "newsgroups"))
1985 (gnus-article-hide-header "followup-to")))
1986 ((eq elem 'reply-to)
1987 (if (gnus-group-find-parameter
1988 gnus-newsgroup-name 'broken-reply-to)
1989 (gnus-article-hide-header "reply-to")
1990 (let ((from (message-fetch-field "from"))
1991 (reply-to (message-fetch-field "reply-to")))
1998 (lambda (x) (downcase (cadr x)))
1999 (mail-extract-address-components from t))
2002 (lambda (x) (downcase (cadr x)))
2003 (mail-extract-address-components reply-to t))
2005 (gnus-article-hide-header "reply-to")))))
2007 (let ((date (with-current-buffer gnus-original-article-buffer
2008 ;; If date in `gnus-article-buffer' is localized
2009 ;; (`gnus-treat-date-user-defined'),
2010 ;; `days-between' might fail.
2011 (message-fetch-field "date"))))
2013 (< (days-between (current-time-string) date)
2015 (gnus-article-hide-header "date"))))
2017 (let ((to (message-fetch-field "to"))
2018 (cc (message-fetch-field "cc")))
2019 (when (> (length to) 1024)
2020 (gnus-article-hide-header "to"))
2021 (when (> (length cc) 1024)
2022 (gnus-article-hide-header "cc"))))
2026 (goto-char (point-min))
2027 (while (re-search-forward "^to:" nil t)
2028 (setq to-count (1+ to-count)))
2029 (when (> to-count 1)
2030 (while (> to-count 0)
2031 (goto-char (point-min))
2033 (re-search-forward "^to:" nil nil to-count)
2035 (narrow-to-region (point) (point-max))
2036 (gnus-article-hide-header "to"))
2037 (setq to-count (1- to-count))))
2038 (goto-char (point-min))
2039 (while (re-search-forward "^cc:" nil t)
2040 (setq cc-count (1+ cc-count)))
2041 (when (> cc-count 1)
2042 (while (> cc-count 0)
2043 (goto-char (point-min))
2045 (re-search-forward "^cc:" nil nil cc-count)
2047 (narrow-to-region (point) (point-max))
2048 (gnus-article-hide-header "cc"))
2049 (setq cc-count (1- cc-count)))))))))))))
2051 (defun gnus-article-hide-header (header)
2053 (goto-char (point-min))
2054 (when (re-search-forward (concat "^" header ":") nil t)
2055 (gnus-article-hide-text-type
2059 (if (re-search-forward "^[^ \t]" nil t)
2064 (defvar gnus-article-normalized-header-length 40
2065 "Length of normalized headers.")
2067 (defun article-normalize-headers ()
2068 "Make all header lines 40 characters long."
2070 (let ((inhibit-read-only t)
2074 (article-narrow-to-head)
2077 ((< (setq column (- (point-at-eol) (point)))
2078 gnus-article-normalized-header-length)
2080 (insert (make-string
2081 (- gnus-article-normalized-header-length column)
2083 ((> column gnus-article-normalized-header-length)
2084 (gnus-put-text-property
2086 (forward-char gnus-article-normalized-header-length)
2093 (forward-line 1))))))
2095 (defun article-treat-dumbquotes ()
2096 "Translate M****s*** sm*rtq**t*s and other symbols into proper text.
2097 Note that this function guesses whether a character is a sm*rtq**t* or
2098 not, so it should only be used interactively.
2100 Sm*rtq**t*s are M****s***'s unilateral extension to the
2101 iso-8859-1 character map in an attempt to provide more quoting
2102 characters. If you see something like \\222 or \\264 where
2103 you're expecting some kind of apostrophe or quotation mark, then
2106 (article-translate-strings gnus-article-dumbquotes-map))
2108 (defvar org-entities)
2110 (defun article-treat-non-ascii ()
2111 "Translate many Unicode characters into their ASCII equivalents."
2113 (require 'org-entities)
2114 (let ((table (make-char-table (if (featurep 'xemacs) 'generic))))
2115 (dolist (elem org-entities)
2116 (when (and (listp elem)
2117 (= (length (nth 6 elem)) 1))
2118 (if (featurep 'xemacs)
2119 (put-char-table (aref (nth 6 elem) 0) (nth 4 elem) table)
2120 (set-char-table-range table (aref (nth 6 elem) 0) (nth 4 elem)))))
2122 (when (article-goto-body)
2123 (let ((inhibit-read-only t)
2126 (if (not (setq replace (if (featurep 'xemacs)
2127 (get-char-table (following-char) table)
2128 (aref table (following-char)))))
2131 (setq props (text-properties-at (point)))
2133 (add-text-properties (point) (progn (insert replace) (point))
2135 (insert replace)))))))))
2137 (defun article-translate-strings (map)
2138 "Translate all string in the body of the article according to MAP.
2139 MAP is an alist where the elements are on the form (\"from\" \"to\")."
2141 (when (article-goto-body)
2142 (let ((inhibit-read-only t))
2144 (let ((from (car elem))
2148 (while (search-forward from nil t)
2151 (if (eq (following-char) from)
2155 (forward-char 1)))))))))))
2157 (defun article-treat-overstrike ()
2158 "Translate overstrikes into bold text."
2161 (when (article-goto-body)
2162 (let ((inhibit-read-only t))
2163 (while (search-forward "\b" nil t)
2164 (let ((next (char-after))
2165 (previous (char-after (- (point) 2))))
2166 ;; We do the boldification/underlining by hiding the
2167 ;; overstrikes and putting the proper text property
2171 (gnus-article-hide-text-type (- (point) 2) (point) 'overstrike)
2172 (put-text-property (point) (1+ (point)) 'face 'bold))
2174 (gnus-article-hide-text-type
2175 (1- (point)) (1+ (point)) 'overstrike)
2177 (- (point) 2) (1- (point)) 'face 'underline))
2179 (gnus-article-hide-text-type (- (point) 2) (point) 'overstrike)
2181 (point) (1+ (point)) 'face 'underline)))))))))
2183 (defun article-treat-ansi-sequences ()
2184 "Translate ANSI SGR control sequences into overlays or extents."
2187 (when (article-goto-body)
2188 (let ((inhibit-read-only t))
2189 (ansi-color-apply-on-region (point) (point-max))))))
2191 (defun gnus-article-treat-unfold-headers ()
2192 "Unfold folded message headers.
2193 Only the headers that fit into the current window width will be
2196 (gnus-with-article-headers
2200 (mail-header-narrow-to-field)
2201 (let* ((header (buffer-string))
2203 (or (equal gnus-article-unfold-long-headers t)
2204 (and (stringp gnus-article-unfold-long-headers)
2205 (string-match gnus-article-unfold-long-headers
2209 (goto-char (point-min))
2210 (while (re-search-forward "\n[\t ]" nil t)
2211 (replace-match " " t t)))
2212 (setq length (- (point-max) (point-min) 1))
2213 (when (or unfoldable
2214 (< length (window-width)))
2215 (while (re-search-forward "\n[\t ]" nil t)
2216 (replace-match " " t t))))
2217 (goto-char (point-max)))))))
2219 (defun gnus-article-treat-fold-headers ()
2220 "Fold message headers."
2222 (gnus-with-article-headers
2225 (mail-header-narrow-to-field)
2226 (mail-header-fold-field)
2227 (goto-char (point-max))))))
2229 (defun gnus-treat-smiley ()
2230 "Toggle display of textual emoticons (\"smileys\") as small graphical icons."
2232 (gnus-with-article-buffer
2233 (if (memq 'smiley gnus-article-wash-types)
2234 (gnus-delete-images 'smiley)
2236 (let ((images (smiley-region (point) (point-max))))
2238 (gnus-add-wash-type 'smiley)
2239 (dolist (image images)
2240 (gnus-add-image 'smiley image)))))))
2242 (defun gnus-article-remove-images ()
2243 "Remove all images from the article buffer."
2245 (gnus-with-article-buffer
2248 (dolist (elem gnus-article-image-alist)
2249 (gnus-delete-images (car elem))))))
2251 (autoload 'w3m-toggle-inline-images "w3m")
2253 (defun gnus-article-show-images ()
2254 "Show any images that are in the HTML-rendered article buffer.
2255 This only works if the article in question is HTML."
2257 (gnus-with-article-buffer
2260 (if (eq mm-text-html-renderer 'w3m)
2261 (w3m-toggle-inline-images)
2262 (dolist (region (gnus-find-text-property-region (point-min) (point-max)
2264 (destructuring-bind (start end function) region
2265 (funcall function (get-text-property start 'image-url)
2268 (defun gnus-article-treat-fold-newsgroups ()
2269 "Unfold folded message headers.
2270 Only the headers that fit into the current window width will be
2273 (gnus-with-article-headers
2274 (while (gnus-article-goto-header "newsgroups\\|followup-to")
2276 (mail-header-narrow-to-field)
2277 (while (re-search-forward ", *" nil t)
2278 (replace-match ", " t t))
2279 (mail-header-fold-field)
2280 (goto-char (point-max))))))
2282 (defcustom gnus-article-truncate-lines (default-value 'truncate-lines)
2283 "Value of `truncate-lines' in Gnus Article buffer.
2284 Valid values are nil, t, `head', `first', `last', an integer or a
2285 predicate. See Info node `(gnus)Customizing Articles'."
2286 :version "23.1" ;; No Gnus
2287 :group 'gnus-article
2288 ;; :link '(custom-manual "(gnus)Customizing Articles")
2291 (defun gnus-article-toggle-truncate-lines (&optional arg)
2292 "Toggle whether to fold or truncate long lines in article the buffer.
2293 If ARG is non-nil and not a number, toggle
2294 `gnus-article-truncate-lines' too. If ARG is a number, truncate
2295 long lines if and only if arg is positive."
2298 ((and (numberp arg) (> arg 0))
2299 (setq gnus-article-truncate-lines t))
2301 (setq gnus-article-truncate-lines nil))
2303 (setq gnus-article-truncate-lines
2304 (not gnus-article-truncate-lines))))
2305 (gnus-with-article-buffer
2307 ((and (numberp arg) (> arg 0))
2308 (setq truncate-lines nil))
2310 (setq truncate-lines t)))
2311 ;; In versions of Emacs 22 (CVS) before 2006-05-26,
2312 ;; `toggle-truncate-lines' needs an argument.
2313 (toggle-truncate-lines)))
2315 (defun gnus-article-treat-body-boundary ()
2316 "Place a boundary line at the end of the headers."
2318 (when (and gnus-body-boundary-delimiter
2319 (> (length gnus-body-boundary-delimiter) 0))
2320 (gnus-with-article-headers
2321 (goto-char (point-max))
2322 (let ((start (point)))
2323 (insert "X-Boundary: ")
2324 (gnus-add-text-properties start (point) gnus-hidden-properties)
2325 (insert (let (str (max (window-width)))
2326 (if (featurep 'xemacs)
2327 (setq max (1- max)))
2328 (while (>= max (length str))
2329 (setq str (concat str gnus-body-boundary-delimiter)))
2330 (substring str 0 max))
2332 (gnus-put-text-property start (point) 'gnus-decoration 'header)))))
2334 (defun article-fill-long-lines ()
2335 "Fill lines that are wider than the window width."
2338 (let ((inhibit-read-only t)
2339 (width (window-width (get-buffer-window (current-buffer)))))
2342 (let ((adaptive-fill-mode nil)) ;Why? -sm
2345 (when (>= (current-column) (min fill-column width))
2346 (narrow-to-region (min (1+ (point)) (point-max))
2348 (let ((goback (point-marker)))
2349 (fill-paragraph nil)
2350 (goto-char (marker-position goback)))
2352 (forward-line 1)))))))
2354 (defun article-capitalize-sentences ()
2355 "Capitalize the first word in each sentence."
2358 (let ((inhibit-read-only t)
2359 (paragraph-start "^[\n\^L]"))
2363 (forward-sentence)))))
2365 (defun article-remove-cr ()
2366 "Remove trailing CRs and then translate remaining CRs into LFs."
2369 (let ((inhibit-read-only t))
2370 (goto-char (point-min))
2371 (while (re-search-forward "\r+$" nil t)
2372 (replace-match "" t t))
2373 (goto-char (point-min))
2374 (while (search-forward "\r" nil t)
2375 (replace-match "\n" t t)))))
2377 (defun article-remove-trailing-blank-lines ()
2378 "Remove all trailing blank lines from the article."
2381 (let ((inhibit-read-only t))
2382 (goto-char (point-max))
2386 (while (and (not (bobp))
2387 (looking-at "^[ \t]*$")
2388 (not (gnus-annotation-in-region-p
2389 (point) (point-at-eol))))
2394 (defvar gnus-face-properties-alist)
2396 (defun article-display-face (&optional force)
2397 "Display any Face headers in the header."
2398 (interactive (list 'force))
2399 (let ((wash-face-p buffer-read-only))
2400 (gnus-with-article-headers
2401 ;; When displaying parts, this function can be called several times on
2402 ;; the same article, without any intended toggle semantic (as typing `W
2403 ;; D d' would have). So face deletion must occur only when we come from
2404 ;; an interactive command, that is when the *Article* buffer is
2406 (if (and wash-face-p (memq 'face gnus-article-wash-types))
2407 (gnus-delete-images 'face)
2408 (let ((from (message-fetch-field "from"))
2410 (save-current-buffer
2411 (when (and wash-face-p
2412 (gnus-buffer-live-p gnus-original-article-buffer)
2413 (not (re-search-forward "^Face:[\t ]*" nil t)))
2414 (set-buffer gnus-original-article-buffer))
2416 (mail-narrow-to-head)
2418 ;; Check whether this face is censored.
2419 (not (and gnus-article-x-face-too-ugly
2421 (setq from (message-fetch-field "from")))
2422 (string-match gnus-article-x-face-too-ugly
2424 (while (gnus-article-goto-header "Face")
2425 (push (mail-header-field-value) faces)))))
2427 (goto-char (point-min))
2429 (unless (setq from (gnus-article-goto-header "from"))
2432 (insert " [no 'from' set]\n"))
2434 (when (setq png (gnus-convert-face-to-png (pop faces)))
2436 (apply 'gnus-create-image png 'png t
2437 (cdr (assq 'png gnus-face-properties-alist))))
2440 (gnus-add-wash-type 'face)
2441 (gnus-add-image 'face image)
2442 (gnus-put-image image nil 'face)))))))))))
2444 (defun article-display-x-face (&optional force)
2445 "Look for an X-Face header and display it if present."
2446 (interactive (list 'force))
2447 (let ((wash-face-p buffer-read-only)) ;; When type `W f'
2448 (gnus-with-article-headers
2449 ;; Delete the old process, if any.
2450 (when (process-status "article-x-face")
2451 (delete-process "article-x-face"))
2452 ;; See the comment in `article-display-face'.
2453 (if (and wash-face-p (memq 'xface gnus-article-wash-types))
2454 ;; We have already displayed X-Faces, so we remove them
2456 (gnus-delete-images 'xface)
2458 (let ((from (message-fetch-field "from"))
2460 (save-current-buffer
2461 (when (and wash-face-p
2462 (gnus-buffer-live-p gnus-original-article-buffer)
2463 (not (re-search-forward "^X-Face:[\t ]*" nil t)))
2464 ;; If type `W f', use gnus-original-article-buffer,
2465 ;; otherwise use the current buffer because displaying
2466 ;; RFC822 parts calls this function too.
2467 (set-buffer gnus-original-article-buffer))
2469 (mail-narrow-to-head)
2470 (and gnus-article-x-face-command
2472 ;; Check whether this face is censored.
2473 (not (and gnus-article-x-face-too-ugly
2475 (setq from (message-fetch-field "from")))
2476 (string-match gnus-article-x-face-too-ugly
2478 (while (gnus-article-goto-header "X-Face")
2479 (push (mail-header-field-value) x-faces)))))
2481 ;; We display the face.
2482 (cond ((functionp gnus-article-x-face-command)
2483 ;; The command is a lisp function, so we call it.
2484 (mapc gnus-article-x-face-command x-faces))
2485 ((stringp gnus-article-x-face-command)
2486 ;; The command is a string, so we interpret the command
2487 ;; as a, well, command, and fork it off.
2488 (let ((process-connection-type nil))
2489 (gnus-set-process-query-on-exit-flag
2491 "article-x-face" nil shell-file-name
2492 shell-command-switch gnus-article-x-face-command)
2494 ;; Sending multiple EOFs to xv doesn't work,
2495 ;; so we only do a single external face.
2497 (insert (car x-faces))
2498 (process-send-region "article-x-face"
2499 (point-min) (point-max)))
2500 (process-send-eof "article-x-face")))
2502 (error "`%s' set to `%s' is not a function"
2503 gnus-article-x-face-command
2504 'gnus-article-x-face-command)))))))))
2506 (defun article-decode-mime-words ()
2507 "Decode all MIME-encoded words in the article."
2509 (gnus-with-article-buffer
2510 (let ((inhibit-point-motion-hooks t)
2511 (mail-parse-charset gnus-newsgroup-charset)
2512 (mail-parse-ignored-charsets
2513 (with-current-buffer gnus-summary-buffer
2514 gnus-newsgroup-ignored-charsets)))
2515 (mail-decode-encoded-word-region (point-min) (point-max)))))
2517 (defun article-decode-charset (&optional prompt)
2518 "Decode charset-encoded text in the article.
2519 If PROMPT (the prefix), prompt for a coding system to use."
2521 (let ((inhibit-point-motion-hooks t) (case-fold-search t)
2522 (inhibit-read-only t)
2523 (mail-parse-charset gnus-newsgroup-charset)
2524 (mail-parse-ignored-charsets
2525 (save-excursion (condition-case nil
2526 (set-buffer gnus-summary-buffer)
2528 gnus-newsgroup-ignored-charsets))
2529 ct cte ctl charset format)
2532 (article-narrow-to-head)
2533 (setq ct (message-fetch-field "Content-Type" t)
2534 cte (message-fetch-field "Content-Transfer-Encoding" t)
2535 ctl (and ct (mail-header-parse-content-type ct))
2538 (mm-read-coding-system "Charset to decode: "))
2540 (mail-content-type-get ctl 'charset)))
2541 format (and ctl (mail-content-type-get ctl 'format)))
2543 (setq cte (mail-header-strip cte)))
2544 (if (and ctl (not (string-match "/" (car ctl))))
2546 (goto-char (point-max)))
2549 (narrow-to-region (point) (point-max))
2550 (when (and (eq mail-parse-charset 'gnus-decoded)
2551 (eq (mm-body-7-or-8) '8bit))
2552 ;; The text code could have been decoded.
2553 (setq charset mail-parse-charset))
2554 (when (and (or (not ctl)
2555 (equal (car ctl) "text/plain"))
2556 (not format)) ;; article with format will decode later.
2558 charset (and cte (intern (downcase
2559 (gnus-strip-whitespace cte))))
2562 (defun article-decode-encoded-words ()
2563 "Remove encoded-word encoding from headers."
2564 (let ((inhibit-point-motion-hooks t)
2565 (mail-parse-charset gnus-newsgroup-charset)
2566 (mail-parse-ignored-charsets
2567 (save-excursion (condition-case nil
2568 (set-buffer gnus-summary-buffer)
2570 gnus-newsgroup-ignored-charsets))
2571 (inhibit-read-only t)
2573 (goto-char (point-min))
2574 (when (search-forward "\n\n" nil 'move)
2581 (memq (char-after) '(?\t ? )))))
2582 (setq start (point))
2584 \\(?:Resent-\\)?\\(?:From\\|Cc\\|To\\|Bcc\\|\\(?:In-\\)?Reply-To\\|Sender\
2585 \\|Mail-Followup-To\\|Mail-Copies-To\\|Approved\\):")
2586 (funcall gnus-decode-address-function start end)
2587 (funcall gnus-decode-header-function start end))
2588 (goto-char (setq end start)))))
2590 (defun article-decode-group-name ()
2591 "Decode group names in Newsgroups, Followup-To and Xref headers."
2592 (let ((inhibit-point-motion-hooks t)
2593 (inhibit-read-only t)
2594 (method (gnus-find-method-for-group gnus-newsgroup-name))
2596 (when (and (or gnus-group-name-charset-method-alist
2597 gnus-group-name-charset-group-alist)
2598 (gnus-buffer-live-p gnus-original-article-buffer))
2600 (article-narrow-to-head)
2601 (dolist (header '("Newsgroups" "Followup-To" "Xref"))
2602 (with-current-buffer gnus-original-article-buffer
2603 (goto-char (point-min)))
2604 (setq regexp (concat "^" header
2605 ":\\([^\n]*\\(?:\n[\t ]+[^\n]+\\)*\\)\n"))
2606 (while (re-search-forward regexp nil t)
2607 (replace-match (save-match-data
2608 (gnus-decode-newsgroups
2609 ;; XXX how to use data in article buffer?
2610 (with-current-buffer gnus-original-article-buffer
2611 (re-search-forward regexp nil t)
2613 gnus-newsgroup-name method))
2615 (goto-char (point-min)))))))
2617 (autoload 'idna-to-unicode "idna")
2619 (defun article-decode-idna-rhs ()
2620 "Decode IDNA strings in RHS in various headers in current buffer.
2621 The following headers are decoded: From:, To:, Cc:, Reply-To:,
2622 Mail-Reply-To: and Mail-Followup-To:."
2625 (let ((inhibit-point-motion-hooks t)
2626 (inhibit-read-only t))
2627 (article-narrow-to-head)
2628 (goto-char (point-min))
2629 (while (re-search-forward "@[^ \t\n\r,>]*\\(xn--[-A-Za-z0-9.]*\\)[ \t\n\r,>]" nil t)
2631 (when (save-match-data
2632 (and (setq ace (match-string 1))
2634 (and (re-search-backward "^[^ \t]" nil t)
2635 (looking-at "From\\|To\\|Cc\\|Reply-To\\|Mail-Reply-To\\|Mail-Followup-To")))
2636 (setq unicode (idna-to-unicode ace))))
2637 (unless (string= ace unicode)
2638 (replace-match unicode nil nil nil 1)))))))))
2640 (defun article-de-quoted-unreadable (&optional force read-charset)
2641 "Translate a quoted-printable-encoded article.
2642 If FORCE, decode the article whether it is marked as quoted-printable
2644 If READ-CHARSET, ask for a coding system."
2645 (interactive (list 'force current-prefix-arg))
2647 (let ((inhibit-read-only t) type charset)
2648 (if (gnus-buffer-live-p gnus-original-article-buffer)
2649 (with-current-buffer gnus-original-article-buffer
2651 (gnus-fetch-field "content-transfer-encoding"))
2652 (let* ((ct (gnus-fetch-field "content-type"))
2653 (ctl (and ct (mail-header-parse-content-type ct))))
2654 (setq charset (and ctl
2655 (mail-content-type-get ctl 'charset)))
2656 (if (stringp charset)
2657 (setq charset (intern (downcase charset)))))))
2659 (setq charset (mm-read-coding-system "Charset: " charset)))
2661 (setq charset gnus-newsgroup-charset))
2663 (and type (let ((case-fold-search t))
2664 (string-match "quoted-printable" type))))
2666 (quoted-printable-decode-region
2667 (point) (point-max) (mm-charset-to-coding-system charset nil t))))))
2669 (defun article-de-base64-unreadable (&optional force read-charset)
2670 "Translate a base64 article.
2671 If FORCE, decode the article whether it is marked as base64 not.
2672 If READ-CHARSET, ask for a coding system."
2673 (interactive (list 'force current-prefix-arg))
2675 (let ((inhibit-read-only t) type charset)
2676 (if (gnus-buffer-live-p gnus-original-article-buffer)
2677 (with-current-buffer gnus-original-article-buffer
2679 (gnus-fetch-field "content-transfer-encoding"))
2680 (let* ((ct (gnus-fetch-field "content-type"))
2681 (ctl (and ct (mail-header-parse-content-type ct))))
2682 (setq charset (and ctl
2683 (mail-content-type-get ctl 'charset)))
2684 (if (stringp charset)
2685 (setq charset (intern (downcase charset)))))))
2687 (setq charset (mm-read-coding-system "Charset: " charset)))
2689 (setq charset gnus-newsgroup-charset))
2691 (and type (let ((case-fold-search t))
2692 (string-match "base64" type))))
2695 (narrow-to-region (point) (point-max))
2696 (base64-decode-region (point-min) (point-max))
2697 (mm-decode-coding-region
2698 (point-min) (point-max)
2699 (mm-charset-to-coding-system charset nil t)))))))
2704 (defun article-decode-HZ ()
2705 "Translate a HZ-encoded article."
2709 (let ((inhibit-read-only t))
2710 (rfc1843-decode-region (point-min) (point-max)))))
2712 (defun article-unsplit-urls ()
2713 "Remove the newlines that some other mailers insert into URLs."
2716 (let ((inhibit-read-only t))
2717 (goto-char (point-min))
2718 (while (re-search-forward
2719 "\\(\\(https?\\|ftp\\)://\\S-+\\) *\n\\(\\S-+\\)" nil t)
2720 (replace-match "\\1\\3" t)))
2721 (when (gmm-called-interactively-p 'any)
2722 (gnus-treat-article nil))))
2724 (defun article-wash-html ()
2725 "Format an HTML article."
2728 (buffer-read-only nil))
2729 (when (gnus-buffer-live-p gnus-original-article-buffer)
2730 (with-current-buffer gnus-original-article-buffer
2731 (setq handles (mm-dissect-buffer t t))))
2733 (delete-region (point) (point-max))
2734 (mm-enable-multibyte)
2735 (mm-inline-text-html handles)))
2737 (defvar gnus-article-browse-html-temp-list nil
2738 "List of temporary files created by `gnus-article-browse-html-parts'.
2739 Internal variable.")
2741 (defcustom gnus-article-browse-delete-temp 'ask
2742 "What to do with temporary files from `gnus-article-browse-html-parts'.
2743 If nil, don't delete temporary files. If it is t, delete them on
2744 exit from the summary buffer. If it is the symbol `file', query
2745 on each file, if it is `ask' ask once when exiting from the
2747 :group 'gnus-article
2748 :version "23.1" ;; No Gnus
2749 :type '(choice (const :tag "Don't delete" nil)
2750 (const :tag "Don't ask" t)
2751 (const :tag "Ask" ask)
2752 (const :tag "Ask for each file" file)))
2754 ;; Cf. mm-postponed-undisplay-list / mm-destroy-postponed-undisplay-list.
2756 (defun gnus-article-browse-delete-temp-files (&optional how)
2757 "Delete temp-files created by `gnus-article-browse-html-parts'."
2758 (when (and gnus-article-browse-html-temp-list
2760 (or how (setq how gnus-article-browse-delete-temp))
2762 (let ((files (length gnus-article-browse-html-temp-list)))
2765 "Delete the temporary HTML file? "
2766 (format "Delete all %s temporary HTML files? "
2768 (setq gnus-article-browse-html-temp-list nil)))
2770 (dolist (file gnus-article-browse-html-temp-list)
2771 (cond ((file-directory-p file)
2772 (when (or (not (eq how 'file))
2774 (gnus-format-message
2775 "Delete temporary HTML file(s) in directory `%s'? "
2776 (file-name-as-directory file))))
2777 (gnus-delete-directory file)))
2778 ((file-exists-p file)
2779 (when (or (not (eq how 'file))
2781 (format "Delete temporary HTML file `%s'? " file)))
2782 (delete-file file)))))
2783 ;; Also remove file from the list when not deleted or if file doesn't
2785 (setq gnus-article-browse-html-temp-list nil))
2786 gnus-article-browse-html-temp-list)
2788 (defun gnus-article-browse-html-save-cid-content (cid handles directory)
2789 "Find CID content in HANDLES and save it in a file in DIRECTORY.
2790 Return file name relative to the parent of DIRECTORY."
2794 (dolist (handle handles)
2796 ((not (listp handle)))
2797 ;; Exclude broken handles that `gnus-summary-enter-digest-group'
2799 ((not (or (bufferp (car handle)) (stringp (car handle)))))
2800 ((equal (mm-handle-media-supertype handle) "multipart")
2801 (when (setq file (gnus-article-browse-html-save-cid-content
2802 cid handle directory))
2803 (throw 'found file)))
2804 ((equal (concat "<" cid ">") (mm-handle-id handle))
2805 (setq file (or (mm-handle-filename handle)
2807 (make-temp-name "cid")
2808 (car (rassoc (car (mm-handle-type handle))
2809 mailcap-mime-extensions))))
2810 afile (expand-file-name file directory))
2811 (mm-save-part-to-file handle afile)
2812 (throw 'found (concat (file-name-nondirectory
2813 (directory-file-name directory))
2816 (defun gnus-article-browse-html-parts (list &optional header)
2817 "View all \"text/html\" parts from LIST.
2818 Recurse into multiparts. The optional HEADER that should be a decoded
2819 message header will be added to the bodies of the \"text/html\" parts."
2820 ;; Internal function used by `gnus-article-browse-html-article'.
2821 (let (type file charset content cid-dir tmp-file showed)
2822 ;; Find and show the html-parts.
2823 (dolist (handle list)
2824 ;; If HTML, show it:
2825 (cond ((not (listp handle)))
2826 ((or (equal (car (setq type (mm-handle-type handle))) "text/html")
2827 (and (equal (car type) "message/external-body")
2829 (setq file (mm-handle-filename handle)))
2830 (or (mm-handle-cache handle)
2831 (condition-case code
2832 (progn (mm-extern-cache-contents handle) t)
2834 (gnus-message 3 "%s" (error-message-string code))
2835 (when (>= gnus-verbose 3) (sit-for 2))
2838 (setq handle (mm-handle-cache handle)
2839 type (mm-handle-type handle))
2840 (equal (car type) "text/html"))))
2841 (setq charset (mail-content-type-get type 'charset)
2842 content (mm-get-part handle))
2844 (if (eq charset 'gnus-decoded)
2845 (mm-enable-multibyte)
2846 (mm-disable-multibyte))
2848 ;; resolve cid contents
2849 (let ((case-fold-search t)
2850 st base regexp cid-file)
2851 (goto-char (point-min))
2852 (when (and (re-search-forward "<head[\t\n >]" nil t)
2854 (setq st (match-end 0))
2855 (re-search-forward "</head[\t\n >]" nil t))
2856 (re-search-backward "<base\
2857 \\(?:[\t\n ]+[^\t\n >]+\\)*[\t\n ]+href=\"\\([^\"]+\\)\"[^>]*>" st t))
2858 (setq base (match-string 1))
2859 (replace-match "<!--\\&-->")
2861 (dolist (tag '(("a" . "href") ("form" . "action")
2863 (setq regexp (concat "<" (car tag)
2864 "\\(?:[\t\n ]+[^\t\n >]+\\)*[\t\n ]+"
2865 (cdr tag) "=\"\\([^\"]+\\)"))
2866 (while (re-search-forward regexp nil t)
2870 (url-expand-file-name (match-string 1)
2872 (error (match-string 1)))
2873 (delete-region (match-beginning 1)
2876 (while (re-search-forward "\
2877 <img[\t\n ]+\\(?:[^\t\n >]+[\t\n ]+\\)*src=\"\\(cid:\\([^\"]+\\)\\)\""
2880 (setq cid-dir (mm-make-temp-file "cid" t))
2881 (add-to-list 'gnus-article-browse-html-temp-list cid-dir))
2884 (when (setq cid-file
2885 (gnus-article-browse-html-save-cid-content
2887 (with-current-buffer gnus-article-buffer
2888 gnus-article-mime-handles)
2890 (replace-match cid-file nil nil nil 1))))
2891 (unless content (setq content (buffer-string))))
2892 (when (or charset header (not file))
2893 (setq tmp-file (mm-make-temp-file
2894 ;; Do we need to care for 8.3 filenames?
2895 "mm-" nil ".html")))
2896 ;; Add a meta html tag to specify charset and a header.
2899 (let (title eheader body hcharset coding)
2901 (mm-enable-multibyte)
2902 (setq case-fold-search t)
2903 (insert header "\n")
2904 (setq title (message-fetch-field "subject"))
2905 (goto-char (point-min))
2906 (while (re-search-forward "\\(<\\)\\|\\(>\\)\\|\\(&\\)\\|\n"
2908 (replace-match (cond ((match-beginning 1) "<")
2909 ((match-beginning 2) ">")
2910 ((match-beginning 3) "&")
2912 (goto-char (point-min))
2913 (while (re-search-forward "^[\t ]+" nil t)
2916 (delete-region (match-beginning 0)
2919 (goto-char (point-min))
2920 (insert "<div align=\"left\">\n")
2921 (goto-char (point-max))
2922 (insert "</div>\n<hr>\n")
2923 ;; We have to examine charset one by one since
2924 ;; charset specified in parts might be different.
2925 (if (eq charset 'gnus-decoded)
2926 (setq charset 'utf-8
2927 eheader (mm-encode-coding-string (buffer-string)
2930 (mm-encode-coding-string title charset))
2931 body (mm-encode-coding-string content charset))
2932 (setq hcharset (mm-find-mime-charset-region (point-min)
2934 (cond ((= (length hcharset) 1)
2935 (setq hcharset (car hcharset)
2936 coding (mm-charset-to-coding-system
2938 ((> (length hcharset) 1)
2939 (setq hcharset 'utf-8
2945 (mm-charset-to-coding-system charset
2947 (if (eq coding body)
2948 (setq eheader (mm-encode-coding-string
2949 (buffer-string) coding)
2951 (mm-encode-coding-string
2954 (setq charset 'utf-8
2955 eheader (mm-encode-coding-string
2956 (buffer-string) charset)
2958 (mm-encode-coding-string
2960 body (mm-encode-coding-string
2961 (mm-decode-coding-string
2964 (setq charset hcharset
2965 eheader (mm-encode-coding-string
2966 (buffer-string) coding)
2968 (mm-encode-coding-string
2971 (setq eheader (mm-string-as-unibyte (buffer-string))
2974 (mm-disable-multibyte)
2977 (mm-add-meta-html-tag handle charset t))
2979 (goto-char (point-min))
2980 (unless (search-forward "<title>" nil t)
2981 (re-search-forward "<head>\\s-*" nil t)
2982 (insert "<title>" title "</title>\n")))
2983 (goto-char (point-min))
2984 (or (re-search-forward
2985 "<body\\(?:\\s-+[^>]+\\|\\s-*\\)>\\s-*" nil t)
2987 "</head\\(?:\\s-+[^>]+\\|\\s-*\\)>\\s-*" nil t))
2989 (mm-write-region (point-min) (point-max)
2990 tmp-file nil nil nil 'binary t))))
2992 (mm-with-unibyte-buffer
2993 (insert (if (eq charset 'gnus-decoded)
2994 (mm-encode-coding-string content
2995 (setq charset 'utf-8))
2997 (if (or (mm-add-meta-html-tag handle charset)
2999 (mm-write-region (point-min) (point-max)
3000 tmp-file nil nil nil 'binary t)
3001 (setq tmp-file nil))))
3003 (mm-save-part-to-file handle tmp-file)))
3005 (add-to-list 'gnus-article-browse-html-temp-list tmp-file))
3006 (add-hook 'gnus-summary-prepare-exit-hook
3007 'gnus-article-browse-delete-temp-files)
3008 (add-hook 'gnus-exit-gnus-hook
3010 (gnus-article-browse-delete-temp-files t)))
3011 ;; FIXME: Warn if there's an <img> tag?
3012 (browse-url-of-file (or tmp-file (expand-file-name file)))
3014 ;; If multipart, recurse
3015 ((equal (mm-handle-media-supertype handle) "multipart")
3016 (when (gnus-article-browse-html-parts handle header)
3018 ((equal (mm-handle-media-type handle) "message/rfc822")
3019 (mm-with-multibyte-buffer
3020 (mm-insert-part handle)
3021 (setq handle (mm-dissect-buffer t t))
3022 (when (and (bufferp (car handle))
3023 (stringp (car (mm-handle-type handle))))
3024 (setq handle (list handle)))
3026 (article-decode-encoded-words)
3027 (let ((gnus-visible-headers
3028 (or (get 'gnus-visible-headers 'standard-value)
3029 gnus-visible-headers)))
3030 (article-hide-headers))
3031 (goto-char (point-min))
3032 (search-forward "\n\n" nil 'move)
3033 (skip-chars-backward "\t\n ")
3034 (setq header (buffer-substring (point-min) (point)))))
3036 (gnus-article-browse-html-parts handle header)
3037 (mm-destroy-parts handle))
3041 (defun gnus-article-browse-html-article (&optional arg)
3042 "View \"text/html\" parts of the current article with a WWW browser.
3043 Inline images embedded in a message using the cid scheme, as they are
3044 generally considered to be safe, will be processed properly.
3045 The message header is added to the beginning of every html part unless
3046 the prefix argument ARG is given.
3048 Warning: Spammers use links to images (using the http scheme) in HTML
3049 articles to verify whether you have read the message. As
3050 `gnus-article-browse-html-article' passes the HTML content to the
3051 browser without eliminating these \"web bugs\" you should only
3052 use it for mails from trusted senders.
3054 If you always want to display HTML parts in the browser, set
3055 `mm-text-html-renderer' to nil.
3057 This command creates temporary files to pass HTML contents including
3058 images if any to the browser, and deletes them when exiting the group
3060 ;; Cf. `mm-w3m-safe-url-regexp'
3063 (gnus-summary-show-article)
3064 (let ((gnus-visible-headers (or (get 'gnus-visible-headers 'standard-value)
3065 gnus-visible-headers))
3066 ;; As we insert a <hr>, there's no need for the body boundary.
3067 (gnus-treat-body-boundary nil))
3068 (gnus-summary-show-article)))
3069 (with-current-buffer gnus-article-buffer
3070 (let ((header (unless arg
3073 (buffer-substring-no-properties
3074 (goto-char (point-min))
3075 (if (search-forward "\n\n" nil t)
3077 (goto-char (point-max))
3078 (skip-chars-backward "\t\n ")
3081 (set-buffer gnus-original-article-buffer)
3082 (setq parts (mm-dissect-buffer t t))
3083 ;; If singlepart, enforce a list.
3084 (when (and (bufferp (car parts))
3085 (stringp (car (mm-handle-type parts))))
3086 (setq parts (list parts)))
3088 (unless (gnus-article-browse-html-parts parts header)
3089 (gnus-error 3 "Mail doesn't contain a \"text/html\" part!"))
3090 (mm-destroy-parts parts)
3092 (gnus-summary-show-article)))))
3094 (defun article-hide-list-identifiers ()
3095 "Remove list identifiers from the Subject header.
3096 The `gnus-list-identifiers' variable specifies what to do."
3098 (let ((inhibit-point-motion-hooks t)
3099 (regexp (gnus-group-get-list-identifiers gnus-newsgroup-name))
3100 (inhibit-read-only t))
3104 (article-narrow-to-head)
3105 (goto-char (point-min))
3106 (while (re-search-forward
3107 (concat "^Subject: +\\(R[Ee]: +\\)*\\(" regexp " *\\)")
3109 (delete-region (match-beginning 2) (match-end 0))
3110 (beginning-of-line))
3111 (when (re-search-forward
3112 "^Subject: +\\(\\(R[Ee]: +\\)+\\)R[Ee]: +" nil t)
3113 (delete-region (match-beginning 1) (match-end 1))))))))
3115 (defun article-hide-pem (&optional arg)
3116 "Toggle hiding of any PEM headers and signatures in the current article.
3117 If given a negative prefix, always show; if given a positive prefix,
3119 (interactive (gnus-article-hidden-arg))
3120 (unless (gnus-article-check-hidden-text 'pem arg)
3122 (let ((inhibit-read-only t) end)
3123 (goto-char (point-min))
3124 ;; Hide the horrendously ugly "header".
3125 (when (and (search-forward
3126 "\n-----BEGIN PRIVACY-ENHANCED MESSAGE-----\n"
3128 (setq end (1+ (match-beginning 0))))
3129 (gnus-add-wash-type 'pem)
3130 (gnus-article-hide-text-type
3132 (if (search-forward "\n\n" nil t)
3136 ;; Hide the trailer as well
3137 (when (search-forward "\n-----END PRIVACY-ENHANCED MESSAGE-----\n"
3139 (gnus-article-hide-text-type
3140 (match-beginning 0) (match-end 0) 'pem)))))))
3142 (defun article-strip-banner ()
3143 "Strip the banners specified by the `banner' group parameter and by
3144 `gnus-article-address-banner-alist'."
3148 (let ((inhibit-point-motion-hooks t))
3149 (when (gnus-parameter-banner gnus-newsgroup-name)
3150 (article-really-strip-banner
3151 (gnus-parameter-banner gnus-newsgroup-name)))
3152 (when gnus-article-address-banner-alist
3153 ;; Note that the From header is decoded here, so it is
3154 ;; required that the *-extract-address-components function
3155 ;; supports non-ASCII text.
3156 (let ((from (save-restriction
3158 (article-narrow-to-head)
3159 (mail-fetch-field "from"))))
3162 (cadr (funcall gnus-extract-address-components
3165 (dolist (pair gnus-article-address-banner-alist)
3166 (when (string-match (car pair) from)
3168 (article-really-strip-banner (cdr pair)))))))))))))
3170 (defun article-really-strip-banner (banner)
3171 "Strip the banner specified by the argument."
3174 (let ((inhibit-point-motion-hooks t)
3175 (gnus-signature-limit nil)
3176 (inhibit-read-only t))
3179 ((eq banner 'signature)
3180 (when (gnus-article-narrow-to-signature)
3183 (delete-region (point) (point-max))))
3185 (if (setq banner (cdr (assq banner gnus-article-banner-alist)))
3186 (while (re-search-forward banner nil t)
3187 (delete-region (match-beginning 0) (match-end 0)))))
3189 (while (re-search-forward banner nil t)
3190 (delete-region (match-beginning 0) (match-end 0)))))))))
3192 (defun article-babel ()
3193 "Translate article using an online translation service."
3196 (gnus-with-article-buffer
3197 (when (article-goto-body)
3198 (let* ((start (point))
3200 (orig (buffer-substring start end))
3201 (trans (babel-as-string orig)))
3203 (narrow-to-region start end)
3204 (delete-region start end)
3207 (defun article-hide-signature (&optional arg)
3208 "Hide the signature in the current article.
3209 If given a negative prefix, always show; if given a positive prefix,
3211 (interactive (gnus-article-hidden-arg))
3212 (unless (gnus-article-check-hidden-text 'signature arg)
3215 (let ((inhibit-read-only t))
3216 (when (gnus-article-narrow-to-signature)
3217 (gnus-article-hide-text-type
3218 (point-min) (point-max) 'signature))))))
3219 (gnus-set-mode-line 'article))
3221 (defun article-strip-headers-in-body ()
3222 "Strip offensive headers from bodies."
3226 (let ((case-fold-search t))
3227 (when (looking-at "x-no-archive:")
3228 (gnus-delete-line)))))
3230 (defun article-strip-leading-blank-lines ()
3231 "Remove all blank lines from the beginning of the article."
3234 (let ((inhibit-point-motion-hooks t)
3235 (inhibit-read-only t))
3236 (when (article-goto-body)
3237 (while (and (not (eobp))
3238 (looking-at "[ \t]*$"))
3239 (gnus-delete-line))))))
3241 (defun article-narrow-to-head ()
3242 "Narrow the buffer to the head of the message.
3243 Point is left at the beginning of the narrowed-to region."
3245 (goto-char (point-min))
3247 ;; Absolutely no headers displayed.
3251 ((search-forward "\n\n" nil 1)
3253 ;; Nothing but headers.
3256 (goto-char (point-min)))
3258 (defun article-goto-body ()
3259 "Place point at the start of the body."
3260 (goto-char (point-min))
3262 ;; This variable is only bound when dealing with separate
3264 (article-goto-body-goes-to-point-min-p
3266 ((search-forward "\n\n" nil t)
3269 (goto-char (point-max))
3272 (defun article-strip-multiple-blank-lines ()
3273 "Replace consecutive blank lines with one empty line."
3276 (let ((inhibit-point-motion-hooks t)
3277 (inhibit-read-only t))
3278 ;; First make all blank lines empty.
3280 (while (re-search-forward "^[ \t]+$" nil t)
3281 (unless (gnus-annotation-in-region-p
3282 (match-beginning 0) (match-end 0))
3283 (replace-match "" nil t)))
3284 ;; Then replace multiple empty lines with a single empty line.
3286 (while (re-search-forward "\n\n\\(\n+\\)" nil t)
3287 (unless (gnus-annotation-in-region-p
3288 (match-beginning 0) (match-end 0))
3289 (delete-region (match-beginning 1) (match-end 1)))))))
3291 (defun article-strip-leading-space ()
3292 "Remove all white space from the beginning of the lines in the article."
3295 (let ((inhibit-point-motion-hooks t)
3296 (inhibit-read-only t))
3298 (while (re-search-forward "^[ \t]+" nil t)
3299 (replace-match "" t t)))))
3301 (defun article-strip-trailing-space ()
3302 "Remove all white space from the end of the lines in the article."
3305 (let ((inhibit-point-motion-hooks t)
3306 (inhibit-read-only t))
3308 (while (re-search-forward "[ \t]+$" nil t)
3309 (replace-match "" t t)))))
3311 (defun article-strip-blank-lines ()
3312 "Strip leading, trailing and multiple blank lines."
3314 (article-strip-leading-blank-lines)
3315 (article-remove-trailing-blank-lines)
3316 (article-strip-multiple-blank-lines))
3318 (defun article-strip-all-blank-lines ()
3319 "Strip all blank lines."
3322 (let ((inhibit-point-motion-hooks t)
3323 (inhibit-read-only t))
3325 (while (re-search-forward "^[ \t]*\n" nil t)
3326 (replace-match "" t t)))))
3328 (defun gnus-article-narrow-to-signature ()
3329 "Narrow to the signature; return t if a signature is found, else nil."
3330 (let ((inhibit-point-motion-hooks t))
3331 (when (gnus-article-search-signature)
3333 ;; Check whether we have some limits to what we consider
3334 ;; to be a signature.
3335 (let ((limits (if (listp gnus-signature-limit) gnus-signature-limit
3336 (list gnus-signature-limit)))
3338 (while (setq limit (pop limits))
3339 (if (or (and (integerp limit)
3340 (< (- (point-max) (point)) limit))
3342 (< (count-lines (point) (point-max)) limit))
3343 (and (functionp limit)
3345 (and (stringp limit)
3346 (not (re-search-forward limit nil t))))
3347 () ; This limit did not succeed.
3351 (narrow-to-region (point) (point-max))
3354 (defun gnus-article-search-signature ()
3355 "Search the current buffer for the signature separator.
3356 Put point at the beginning of the signature separator."
3357 (let ((cur (point)))
3358 (goto-char (point-max))
3359 (if (if (stringp gnus-signature-separator)
3360 (re-search-backward gnus-signature-separator nil t)
3361 (let ((seps gnus-signature-separator))
3363 (not (re-search-backward (car seps) nil t)))
3370 (defun gnus-article-hidden-arg ()
3371 "Return the current prefix arg as a number, or 0 if no prefix."
3372 (list (if current-prefix-arg
3373 (prefix-numeric-value current-prefix-arg)
3376 (defun gnus-article-check-hidden-text (type arg)
3377 "Return nil if hiding is necessary.
3378 Arg can be nil or a number. nil and positive means hide, negative
3379 means show, 0 means toggle."
3382 (let ((hide (gnus-article-hidden-text-p type)))
3388 (gnus-article-show-hidden-text type)
3391 (if (eq hide 'hidden)
3393 (gnus-article-show-hidden-text type)
3397 (defun gnus-article-hidden-text-p (type)
3398 "Say whether the current buffer contains hidden text of type TYPE."
3399 (let ((pos (text-property-any (point-min) (point-max) 'article-type type)))
3401 (not (get-text-property pos 'invisible))
3402 (not (get-text-property pos 'dummy-invisible)))
3404 (text-property-any (1+ pos) (point-max) 'article-type type)))
3409 (defun gnus-article-show-hidden-text (type &optional _dummy)
3410 "Show all hidden text of type TYPE.
3411 Originally it is hide instead of DUMMY."
3412 (let ((inhibit-read-only t)
3413 (inhibit-point-motion-hooks t))
3414 (gnus-remove-text-properties-when
3416 (point-min) (point-max)
3417 (cons 'article-type (cons type
3418 gnus-hidden-properties)))
3419 (gnus-delete-wash-type type)))
3421 (defconst article-time-units
3422 `((year . ,(* 365.25 24 60 60))
3423 (week . ,(* 7 24 60 60))
3424 (day . ,(* 24 60 60))
3428 "Mapping from time units to seconds.")
3430 (defun gnus-article-forward-header ()
3431 "Move point to the start of the next header.
3432 If the current header is a continuation header, this can be several
3437 (if (looking-at "[ \t]+[^ \t]")
3441 (defun article-treat-date ()
3442 (article-date-ut (if (gnus-buffer-live-p gnus-summary-buffer)
3443 (with-current-buffer gnus-summary-buffer
3444 gnus-article-date-headers)
3445 gnus-article-date-headers)
3448 (defun article-date-ut (&optional type _highlight date-position)
3449 "Convert DATE date to TYPE in the current article.
3450 The default type is `ut'. See `gnus-article-date-headers' for
3452 (interactive (list 'ut t))
3453 (let* ((case-fold-search t)
3454 (inhibit-read-only t)
3455 (inhibit-point-motion-hooks t)
3456 (visible-date (mail-fetch-field "Date"))
3457 pos date bface eface)
3461 (goto-char date-position)
3462 (setq date (get-text-property (point) 'original-date))
3463 (when (looking-at "[^:]+:[\t ]*")
3464 (setq bface (get-text-property (match-beginning 0) 'face)
3465 eface (get-text-property (match-end 0) 'face)))
3466 (delete-region (point)
3468 (gnus-article-forward-header)
3470 (article-transform-date date type bface eface))
3473 (goto-char (point-min))
3474 (while (or (get-text-property (setq pos (point)) 'original-date)
3475 (and (setq pos (next-single-property-change
3476 (point) 'original-date))
3478 (narrow-to-region pos (if (search-forward "\n\n" nil t)
3479 (1+ (match-beginning 0))
3481 (while (setq pos (text-property-not-all pos (point-max)
3482 'gnus-date-type nil))
3483 (setq date (get-text-property pos 'original-date))
3485 (when (looking-at "[^:]+:[\t ]*")
3486 (setq bface (get-text-property (match-beginning 0) 'face)
3487 eface (get-text-property (match-end 0) 'face)))
3488 (delete-region pos (or (text-property-any pos (point-max)
3489 'gnus-date-type nil)
3491 (unless date ;; the 1st time
3492 (goto-char (point-min))
3493 (while (re-search-forward "^Date:[\t ]*" nil t)
3494 (setq date (get-text-property (match-beginning 0)
3496 bface (get-text-property (match-beginning 0) 'face)
3497 eface (get-text-property (match-end 0) 'face))
3498 (delete-region (point-at-bol) (progn
3499 (gnus-article-forward-header)
3501 (when (and (not date)
3503 (setq date visible-date))
3505 (article-transform-date date type bface eface))
3506 (goto-char (point-max))
3509 (defun article-transform-date (date type bface eface)
3510 (dolist (this-type (cond
3520 (add-text-properties
3523 (insert (article-make-date-line date (or this-type 'ut)) "\n")
3525 (list 'original-date date 'gnus-date-type this-type))))
3528 "\\([^:]+:\\)[\t ]*\\(\\(?:[^\t\n ]+[\t ]+\\)*[^\t\n ]+\\)?")
3529 (put-text-property (match-beginning 1) (match-end 1) 'face bface)
3530 (when (match-beginning 2)
3531 (put-text-property (match-beginning 2) (match-end 2) 'face eface))
3532 (while (and (zerop (forward-line 1))
3533 (looking-at "[\t ]+\\(\\(?:[^\t\n ]+[\t ]+\\)*[^\t\n ]+\\)?"))
3534 (when (match-beginning 1)
3535 (put-text-property (match-beginning 1) (match-end 1) 'face eface))))))
3537 (defun article-make-date-line (date type)
3538 "Return a DATE line of TYPE."
3539 (unless (memq type '(local ut original user-defined iso8601 lapsed english
3541 (error "Unknown conversion type: %s" type))
3543 (let ((time (ignore-errors (date-to-time date))))
3545 ;; Convert to the local timezone.
3547 (concat "Date: " (message-make-date time)))
3548 ;; Convert to Universal Time.
3553 (let* ((e (parse-time-string date))
3554 (tm (apply 'encode-time e))
3556 (ls (- (cadr tm) (car (current-time-zone time)))))
3557 (cond ((< ls 0) (list (1- ms) (+ ls 65536)))
3558 ((> ls 65535) (list (1+ ms) (- ls 65536)))
3562 ;; Get the original date from the article.
3563 ((eq type 'original)
3564 (concat "Date: " (if (string-match "\n+$" date)
3565 (substring date 0 (match-beginning 0))
3567 ;; Let the user define the format.
3568 ((eq type 'user-defined)
3569 (let ((format (or (condition-case nil
3570 (with-current-buffer gnus-summary-buffer
3571 gnus-article-time-format)
3573 gnus-article-time-format)))
3574 (if (functionp format)
3575 (funcall format time)
3576 (concat "Date: " (format-time-string format time)))))
3579 (let ((tz (car (current-time-zone time))))
3582 (format-time-string "%Y%m%dT%H%M%S" time)
3583 (format "%s%02d%02d"
3584 (if (> tz 0) "+" "-") (/ (abs tz) 3600)
3585 (/ (% (abs tz) 3600) 60)))))
3586 ;; Do a lapsed format.
3588 (concat "Date: " (article-lapsed-string time)))
3589 ;; A combined date/lapsed format.
3590 ((eq type 'combined-lapsed)
3591 (let ((date-string (article-make-date-line date 'original))
3597 (concat " (" (article-lapsed-string time segments) ")"))
3598 (> (+ (length date-string)
3599 (length lapsed-string))
3602 (setq segments (1- segments)))
3604 (concat date-string lapsed-string)
3606 ;; Display the date in proper English
3608 (let ((dtime (decode-time time)))
3611 (number-to-string (nth 3 dtime))
3612 (let ((digit (% (nth 3 dtime) 10)))
3614 ((memq (nth 3 dtime) '(11 12 13)) "th")
3620 (nth (1- (nth 4 dtime)) gnus-english-month-names)
3622 (number-to-string (nth 5 dtime))
3624 (format "%02d" (nth 2 dtime))
3626 (format "%02d" (nth 1 dtime)))))))
3628 (format "Date: %s (from Gnus)" date))))
3630 (defun article-lapsed-string (time &optional max-segments)
3631 ;; If the date is seriously mangled, the timezone functions are
3632 ;; liable to bug out, so we ignore all errors.
3633 (let* ((now (current-time))
3634 (real-time (subtract-time now time))
3635 (real-sec (and real-time
3636 (+ (* (float (car real-time)) 65536)
3638 (sec (and real-time (abs real-sec)))
3641 (unless max-segments
3642 (setq max-segments (length article-time-units)))
3650 ;; This is a bit convoluted, but basically we go
3651 ;; through the time units for years, weeks, etc,
3652 ;; and divide things to see whether that results
3653 ;; in positive answers.
3656 (if (or (zerop (setq num (ffloor (/ sec (cdr unit)))))
3657 (>= segments max-segments))
3658 ;; The (remaining) seconds are too few to
3659 ;; be divided into this time unit.
3661 ;; It's big enough, so we output it.
3662 (setq sec (- sec (* num (cdr unit))))
3664 (concat (if prev ", " "") (int-to-string
3666 " " (symbol-name (car unit))
3667 (if (> num 1) "s" ""))
3669 segments (1+ segments)))))
3670 article-time-units "")
3671 ;; If dates are odd, then it might appear like the
3672 ;; article was sent in the future.
3675 " in the future"))))))
3677 (defun article-date-local (&optional highlight)
3678 "Convert the current article date to the local timezone."
3679 (interactive (list t))
3680 (article-date-ut 'local highlight))
3682 (defun article-date-english (&optional highlight)
3683 "Convert the current article date to something that is proper English."
3684 (interactive (list t))
3685 (article-date-ut 'english highlight))
3687 (defun article-date-original (&optional highlight)
3688 "Convert the current article date to what it was originally.
3689 This is only useful if you have used some other date conversion
3690 function and want to see what the date was before converting."
3691 (interactive (list t))
3692 (article-date-ut 'original highlight))
3694 (defun article-date-lapsed (&optional highlight)
3695 "Convert the current article date to time lapsed since it was sent."
3696 (interactive (list t))
3697 (article-date-ut 'lapsed highlight))
3699 (defun article-date-combined-lapsed (&optional highlight)
3700 "Convert the current article date to time lapsed since it was sent."
3701 (interactive (list t))
3702 (article-date-ut 'combined-lapsed highlight))
3704 (defun article-update-date-lapsed ()
3705 "Function to be run from a timer to update the lapsed time line."
3707 (let ((buffer (current-buffer)))
3711 (set-buffer (window-buffer w))
3712 (when (derived-mode-p 'gnus-article-mode)
3713 (let ((old-line (count-lines (point-min) (point)))
3714 (old-column (- (point) (line-beginning-position)))
3715 (window-start (window-start w))
3718 (while (setq pos (text-property-not-all pos (point-max)
3719 'gnus-date-type nil))
3720 (setq next (or (next-single-property-change pos
3723 (setq type (get-text-property pos 'gnus-date-type))
3724 (when (memq type '(lapsed combined-lapsed user-defined))
3725 (article-date-ut type t pos)
3726 (setq end (or (next-single-property-change pos
3730 (if (/= window-start next)
3731 (setq window-start nil)
3732 (set-window-start w end)))
3735 (goto-char (point-min))
3736 (when (> old-column 0)
3737 (setq old-line (1- old-line)))
3738 (forward-line old-line)
3740 (when (> (current-column) old-column)
3742 (forward-char old-column)))))
3744 (set-buffer buffer))))
3746 (defun gnus-start-date-timer (&optional n)
3747 "Start a timer to update the Date headers in the article buffers.
3748 The numerical prefix says how frequently (in seconds) the function
3753 (gnus-stop-date-timer)
3754 (setq article-lapsed-timer
3755 (run-at-time 1 n 'article-update-date-lapsed)))
3757 (defun gnus-stop-date-timer ()
3758 "Stop the Date timer."
3760 (when article-lapsed-timer
3761 (nnheader-cancel-timer article-lapsed-timer)
3762 (setq article-lapsed-timer nil)))
3764 (defun article-date-user (&optional highlight)
3765 "Convert the current article date to the user-defined format.
3766 This format is defined by the `gnus-article-time-format' variable."
3767 (interactive (list t))
3768 (article-date-ut 'user highlight))
3770 (defun article-date-iso8601 (&optional highlight)
3771 "Convert the current article date to ISO8601."
3772 (interactive (list t))
3773 (article-date-ut 'iso8601 highlight))
3775 (defmacro gnus-article-save-original-date (&rest forms)
3776 "Save the original date as a text property and evaluate FORMS."
3777 `(let* ((case-fold-search t)
3779 (goto-char (point-min))
3780 (when (and (re-search-forward "^date:[\t\n ]+" nil t)
3783 (date (when (and start
3784 (re-search-forward "[\t ]*\n\\(?:[^\t ]\\|\\'\\)"
3786 (buffer-substring-no-properties start
3787 (match-beginning 0)))))
3788 (goto-char (point-max))
3789 (skip-chars-backward "\n")
3790 (put-text-property (point-min) (point) 'original-date date)
3792 (goto-char (point-max))
3793 (skip-chars-backward "\n")
3794 (put-text-property (point-min) (point) 'original-date date)))
3796 ;; (defun article-show-all ()
3797 ;; "Show all hidden text in the article buffer."
3800 ;; (let ((inhibit-read-only t))
3801 ;; (gnus-article-unhide-text (point-min) (point-max)))))
3803 (defun article-remove-leading-whitespace ()
3804 "Remove excessive whitespace from all headers."
3808 (let ((inhibit-read-only t))
3809 (article-narrow-to-head)
3810 (goto-char (point-min))
3811 (while (re-search-forward "^[^ :]+: \\([ \t]+\\)" nil t)
3812 (delete-region (match-beginning 1) (match-end 1)))))))
3814 (defun article-emphasize (&optional arg)
3815 "Emphasize text according to `gnus-emphasis-alist'."
3816 (interactive (gnus-article-hidden-arg))
3817 (unless (gnus-article-check-hidden-text 'emphasis arg)
3821 (with-current-buffer gnus-summary-buffer
3822 gnus-article-emphasis-alist)
3824 gnus-emphasis-alist))
3825 (inhibit-read-only t)
3826 (props (append '(article-type emphasis)
3827 gnus-hidden-properties))
3828 regexp elem beg invisible visible face)
3831 (while (setq elem (pop alist))
3833 (setq regexp (car elem)
3834 invisible (nth 1 elem)
3835 visible (nth 2 elem)
3837 (while (re-search-forward regexp nil t)
3838 (when (and (match-beginning visible) (match-beginning invisible))
3839 (gnus-article-hide-text
3840 (match-beginning invisible) (match-end invisible) props)
3841 (gnus-article-unhide-text-type
3842 (match-beginning visible) (match-end visible) 'emphasis)
3843 (gnus-put-overlay-excluding-newlines
3844 (match-beginning visible) (match-end visible) 'face face)
3845 (gnus-add-wash-type 'emphasis)
3846 (goto-char (match-end invisible)))))))))
3848 (defun gnus-article-setup-highlight-words (&optional highlight-words)
3849 "Setup newsgroup emphasis alist."
3850 (unless gnus-article-emphasis-alist
3851 (let ((name (and gnus-newsgroup-name
3852 (gnus-group-real-name gnus-newsgroup-name))))
3853 (make-local-variable 'gnus-article-emphasis-alist)
3854 (setq gnus-article-emphasis-alist
3856 (let ((alist gnus-group-highlight-words-alist) elem highlight)
3857 (while (setq elem (pop alist))
3858 (when (and name (string-match (car elem) name))
3860 highlight (copy-sequence (cdr elem)))))
3862 (copy-sequence highlight-words)
3863 (if gnus-newsgroup-name
3864 (copy-sequence (gnus-group-find-parameter
3865 gnus-newsgroup-name 'highlight-words t)))
3866 gnus-emphasis-alist)))))
3868 (defvar gnus-summary-article-menu)
3869 (defvar gnus-summary-post-menu)
3871 ;;; Saving functions.
3873 (defun gnus-article-save (save-buffer file &optional num)
3874 "Save the currently selected article."
3875 (when (or (get gnus-default-article-saver :headers)
3876 (not gnus-save-all-headers))
3877 ;; Remove headers according to `gnus-saved-headers' or the value
3878 ;; of the `:headers' property that the saver function might have.
3879 (let ((gnus-visible-headers
3880 (or (symbol-value (get gnus-default-article-saver :headers))
3881 gnus-saved-headers gnus-visible-headers))
3882 ;; Ignore group parameter. See `article-hide-headers'.
3883 (gnus-summary-buffer nil))
3884 (with-current-buffer save-buffer
3885 (article-hide-headers 1 t))))
3886 (save-window-excursion
3887 (if (not gnus-default-article-saver)
3888 (error "No default saver is defined")
3889 ;; !!! Magic! The saving functions all save
3890 ;; `gnus-save-article-buffer' (or so they think), but we
3891 ;; bind that variable to our save-buffer.
3892 (set-buffer gnus-article-buffer)
3893 (let* ((gnus-save-article-buffer save-buffer)
3896 ((not gnus-prompt-before-saving) 'default)
3897 ((eq gnus-prompt-before-saving 'always) nil)
3899 (gnus-number-of-articles-to-be-saved
3900 (when (eq gnus-prompt-before-saving t)
3902 (set-buffer gnus-article-current-summary)
3903 (funcall gnus-default-article-saver filename)))))
3905 (defun gnus-read-save-file-name (prompt &optional filename
3906 function group headers variable
3909 (funcall function group headers (symbol-value variable)))
3914 ((eq filename 'default)
3920 (when (symbol-value dir-var)
3921 (setq default-name (expand-file-name
3922 (file-name-nondirectory default-name)
3923 (symbol-value dir-var))))
3924 (let* ((split-name (gnus-get-split-value gnus-split-methods))
3927 (if (and gnus-number-of-articles-to-be-saved
3928 (> gnus-number-of-articles-to-be-saved 1))
3929 (format "these %d articles"
3930 gnus-number-of-articles-to-be-saved)
3933 ;; Let the split methods have their say.
3935 ;; No split name was found.
3938 (concat prompt " (default "
3939 (file-name-nondirectory default-name) "): ")
3940 (file-name-directory default-name)
3942 ;; A single group name is returned.
3943 ((stringp split-name)
3945 (funcall function split-name headers
3946 (symbol-value variable)))
3948 (concat prompt " (default "
3949 (file-name-nondirectory default-name) "): ")
3950 (file-name-directory default-name)
3952 ;; A single split name was found
3953 ((= 1 (length split-name))
3954 (let* ((name (expand-file-name
3956 gnus-article-save-directory))
3957 (dir (cond ((file-directory-p name)
3958 (file-name-as-directory name))
3959 ((file-exists-p name) name)
3960 (t gnus-article-save-directory))))
3962 (concat prompt " (default " name "): ")
3964 ;; A list of splits was found.
3966 (setq split-name (nreverse split-name))
3968 (let ((file-name-history
3969 (nconc split-name file-name-history)))
3973 (concat prompt " (`M-p' for defaults): ")
3974 gnus-article-save-directory
3976 gnus-article-save-directory)))
3977 (car (push result file-name-history)))))))
3978 ;; Create the directory.
3979 (gnus-make-directory (file-name-directory file))
3980 ;; If we have read a directory, we append the default file name.
3981 (when (file-directory-p file)
3982 (setq file (expand-file-name (file-name-nondirectory
3984 (file-name-as-directory file))))
3985 ;; Possibly translate some characters.
3986 (nnheader-translate-file-chars file))))))
3987 (gnus-make-directory (file-name-directory result))
3989 (set variable result))
3991 (set dir-var (file-name-directory result)))
3994 (defun gnus-article-archive-name (_group)
3995 "Return the first instance of an \"Archive-name\" in the current buffer."
3996 (let ((case-fold-search t))
3997 (when (re-search-forward "archive-name: *\\([^ \n\t]+\\)[ \t]*$" nil t)
3998 (nnheader-concat gnus-article-save-directory
3999 (match-string 1)))))
4001 (defun gnus-article-nndoc-name (group)
4002 "If GROUP is an nndoc group, return the name of the parent group."
4003 (when (eq (car (gnus-find-method-for-group group)) 'nndoc)
4004 (gnus-group-get-parameter group 'save-article-group)))
4006 (defun gnus-summary-save-in-rmail (&optional filename)
4007 "Append this article to Rmail file.
4008 Optional argument FILENAME specifies file name.
4009 Directory to save to is default to `gnus-article-save-directory'."
4010 (setq filename (gnus-read-save-file-name
4011 "Save %s in rmail file" filename
4012 gnus-rmail-save-name gnus-newsgroup-name
4013 gnus-current-headers 'gnus-newsgroup-last-rmail))
4014 (with-current-buffer gnus-save-article-buffer
4018 ;; Note that unlike gnus-summary-save-in-mail, there is no
4019 ;; check to see if filename is Babyl. Rmail in Emacs 23 does
4021 (gnus-output-to-rmail filename))))
4024 (defun gnus-summary-save-in-mail (&optional filename)
4025 "Append this article to Unix mail file.
4026 Optional argument FILENAME specifies file name.
4027 Directory to save to is default to `gnus-article-save-directory'."
4028 (setq filename (gnus-read-save-file-name
4029 "Save %s in Unix mail file" filename
4030 gnus-mail-save-name gnus-newsgroup-name
4031 gnus-current-headers 'gnus-newsgroup-last-mail))
4032 (with-current-buffer gnus-save-article-buffer
4036 (if (and (file-readable-p filename)
4037 (file-regular-p filename)
4038 (mail-file-babyl-p filename))
4039 (gnus-output-to-rmail filename)
4040 (gnus-output-to-mail filename)))))
4043 (put 'gnus-summary-save-in-file :decode t)
4044 (put 'gnus-summary-save-in-file :headers 'gnus-saved-headers)
4045 (defun gnus-summary-save-in-file (&optional filename overwrite)
4046 "Append this article to file.
4047 Optional argument FILENAME specifies file name.
4048 Directory to save to is default to `gnus-article-save-directory'."
4049 (setq filename (gnus-read-save-file-name
4050 "Save %s in file" filename
4051 gnus-file-save-name gnus-newsgroup-name
4052 gnus-current-headers 'gnus-newsgroup-last-file))
4053 (with-current-buffer gnus-save-article-buffer
4057 (when (and overwrite
4058 (file-exists-p filename))
4059 (delete-file filename))
4060 (gnus-output-to-file filename))))
4063 (put 'gnus-summary-write-to-file :decode t)
4064 (put 'gnus-summary-write-to-file :function 'gnus-summary-save-in-file)
4065 (put 'gnus-summary-write-to-file :headers 'gnus-saved-headers)
4066 (defun gnus-summary-write-to-file (&optional filename)
4067 "Write this article to a file, overwriting it if the file exists.
4068 Optional argument FILENAME specifies file name.
4069 The directory to save in defaults to `gnus-article-save-directory'."
4070 (setq filename (gnus-read-save-file-name
4071 "Save %s in file" filename
4072 gnus-file-save-name gnus-newsgroup-name
4073 gnus-current-headers nil 'gnus-newsgroup-last-directory))
4074 (gnus-summary-save-in-file filename t))
4076 (put 'gnus-summary-save-body-in-file :decode t)
4077 (defun gnus-summary-save-body-in-file (&optional filename overwrite)
4078 "Append this article body to a file.
4079 Optional argument FILENAME specifies file name.
4080 The directory to save in defaults to `gnus-article-save-directory'."
4081 (setq filename (gnus-read-save-file-name
4082 "Save %s body in file" filename
4083 gnus-file-save-name gnus-newsgroup-name
4084 gnus-current-headers 'gnus-newsgroup-last-file))
4085 (with-current-buffer gnus-save-article-buffer
4089 (when (article-goto-body)
4090 (narrow-to-region (point) (point-max)))
4091 (when (and overwrite
4092 (file-exists-p filename))
4093 (delete-file filename))
4094 (gnus-output-to-file filename))))
4097 (put 'gnus-summary-write-body-to-file :decode t)
4098 (put 'gnus-summary-write-body-to-file
4099 :function 'gnus-summary-save-body-in-file)
4100 (defun gnus-summary-write-body-to-file (&optional filename)
4101 "Write this article body to a file, overwriting it if the file exists.
4102 Optional argument FILENAME specifies file name.
4103 The directory to save in defaults to `gnus-article-save-directory'."
4104 (setq filename (gnus-read-save-file-name
4105 "Save %s body in file" filename
4106 gnus-file-save-name gnus-newsgroup-name
4107 gnus-current-headers nil 'gnus-newsgroup-last-directory))
4108 (gnus-summary-save-body-in-file filename t))
4110 (put 'gnus-summary-save-in-pipe :decode t)
4111 (put 'gnus-summary-save-in-pipe :headers 'gnus-saved-headers)
4112 (defun gnus-summary-save-in-pipe (&optional command raw)
4113 "Pipe this article to subprocess COMMAND.
4114 Valid values for COMMAND include:
4116 The executable command name and possibly arguments.
4118 You will be prompted for the command in the minibuffer.
4119 the symbol `default'
4120 It will be replaced with the command which the variable
4121 `gnus-summary-pipe-output-default-command' holds or the command
4122 last used for saving.
4123 Non-nil value for RAW overrides `:decode' and `:headers' properties
4124 and the raw article including all headers will be piped."
4125 (let ((article (gnus-summary-article-number))
4127 (get 'gnus-summary-save-in-pipe :decode)))
4128 save-buffer default)
4130 (if (vectorp (gnus-summary-article-header article))
4131 (save-current-buffer
4132 (gnus-summary-select-article decode decode nil article)
4133 (insert-buffer-substring
4137 gnus-original-article-buffer)
4139 (nnheader-set-temp-buffer " *Gnus Save*"))))
4140 ;; Remove unwanted headers.
4141 (when (and (not raw)
4142 (or (get 'gnus-summary-save-in-pipe :headers)
4143 (not gnus-save-all-headers)))
4144 (let ((gnus-visible-headers
4145 (or (symbol-value (get 'gnus-summary-save-in-pipe
4147 gnus-saved-headers gnus-visible-headers))
4148 (gnus-summary-buffer nil))
4149 (article-hide-headers 1 t))))
4150 (error "%d is not a real article" article))
4151 (error "No article to pipe"))
4152 (setq default (or gnus-summary-pipe-output-default-command
4153 gnus-last-shell-command))
4154 (unless (stringp command)
4156 (if (and (eq command 'default) default)
4158 (gnus-read-shell-command "Shell command on this article: "
4160 (when (string-equal command "")
4162 (setq command default)
4163 (error "A command is required")))
4164 (with-current-buffer save-buffer
4167 (shell-command-on-region (point-min) (point-max) command nil)))
4168 (gnus-kill-buffer save-buffer))
4169 (setq gnus-summary-pipe-output-default-command command))
4171 (defun gnus-summary-pipe-to-muttprint (&optional command)
4172 "Pipe this article to muttprint."
4173 (unless (stringp command)
4174 (setq command (read-string
4175 "Print using command: " gnus-summary-muttprint-program
4176 nil gnus-summary-muttprint-program)))
4177 (let ((gnus-summary-pipe-output-default-command
4178 gnus-summary-pipe-output-default-command))
4179 (gnus-summary-save-in-pipe command))
4180 (setq gnus-summary-muttprint-program command))
4182 ;;; Article file names when saving.
4184 (defun gnus-capitalize-newsgroup (newsgroup)
4185 "Capitalize NEWSGROUP name."
4186 (when (not (zerop (length newsgroup)))
4187 (concat (char-to-string (upcase (aref newsgroup 0)))
4188 (substring newsgroup 1))))
4190 (defun gnus-Numeric-save-name (newsgroup headers &optional last-file)
4191 "Generate file name from NEWSGROUP, HEADERS, and optional LAST-FILE.
4192 If variable `gnus-use-long-file-name' is non-nil, it is ~/News/News.group/num.
4193 Otherwise, it is like ~/News/news/group/num."
4196 (concat (if (gnus-use-long-file-name 'not-save)
4197 (gnus-capitalize-newsgroup newsgroup)
4198 (gnus-newsgroup-directory-form newsgroup))
4199 "/" (int-to-string (mail-header-number headers)))
4200 gnus-article-save-directory)))
4202 (string-equal (file-name-directory default)
4203 (file-name-directory last-file))
4204 (string-match "^[0-9]+$" (file-name-nondirectory last-file)))
4206 (or last-file default))))
4208 (defun gnus-numeric-save-name (newsgroup headers &optional last-file)
4209 "Generate file name from NEWSGROUP, HEADERS, and optional LAST-FILE.
4210 If variable `gnus-use-long-file-name' is non-nil, it is
4211 ~/News/news.group/num. Otherwise, it is like ~/News/news/group/num."
4214 (concat (if (gnus-use-long-file-name 'not-save)
4216 (gnus-newsgroup-directory-form newsgroup))
4217 "/" (int-to-string (mail-header-number headers)))
4218 gnus-article-save-directory)))
4220 (string-equal (file-name-directory default)
4221 (file-name-directory last-file))
4222 (string-match "^[0-9]+$" (file-name-nondirectory last-file)))
4224 (or last-file default))))
4226 (defun gnus-plain-save-name (newsgroup _headers &optional last-file)
4227 "Generate file name from NEWSGROUP, HEADERS, and optional LAST-FILE.
4228 If variable `gnus-use-long-file-name' is non-nil, it is
4229 ~/News/news.group. Otherwise, it is like ~/News/news/group/news."
4232 (if (gnus-use-long-file-name 'not-save)
4235 (expand-file-name "news" (gnus-newsgroup-directory-form newsgroup))
4237 gnus-article-save-directory)))
4239 (defun gnus-sender-save-name (_newsgroup headers &optional _last-file)
4240 "Generate file name from sender."
4241 (let ((from (mail-header-from headers)))
4243 (if (and from (string-match "\\([^ <]+\\)@" from))
4244 (match-string 1 from)
4246 gnus-article-save-directory)))
4248 (defun article-verify-x-pgp-sig ()
4250 ;; <ftp://ftp.isc.org/pub/pgpcontrol/FORMAT>
4252 (if (gnus-buffer-live-p gnus-original-article-buffer)
4253 (let ((sig (with-current-buffer gnus-original-article-buffer
4254 (gnus-fetch-field "X-PGP-Sig")))
4258 (mml2015-clear-verify-function))
4260 (insert-buffer-substring gnus-original-article-buffer)
4261 (setq items (split-string sig))
4262 (message-narrow-to-head)
4263 (let ((inhibit-point-motion-hooks t)
4264 (case-fold-search t))
4265 ;; Don't verify multiple headers.
4266 (setq headers (mapconcat (lambda (header)
4268 (mail-fetch-field header)
4270 (split-string (nth 1 items) ",") "")))
4271 (delete-region (point-min) (point-max))
4272 (insert "-----BEGIN PGP SIGNED MESSAGE-----\n\n")
4273 (insert "X-Signed-Headers: " (nth 1 items) "\n")
4278 (if (looking-at "^-")
4281 (insert "\n-----BEGIN PGP SIGNATURE-----\n")
4282 (insert "Version: " (car items) "\n\n")
4283 (insert (mapconcat 'identity (cddr items) "\n"))
4284 (insert "\n-----END PGP SIGNATURE-----\n")
4285 (let ((mm-security-handle (list (format "multipart/signed"))))
4286 (mml2015-clean-buffer)
4287 (let ((coding-system-for-write (or gnus-newsgroup-charset
4289 (funcall (mml2015-clear-verify-function)))
4291 (or (mm-handle-multipart-ctl-parameter
4292 mm-security-handle 'gnus-details)
4293 (mm-handle-multipart-ctl-parameter
4294 mm-security-handle 'gnus-info)))))
4296 (let ((inhibit-read-only t) bface eface)
4298 (message-narrow-to-head)
4299 (goto-char (point-max))
4301 (setq bface (get-text-property (point-at-bol) 'face)
4302 eface (get-text-property (1- (point-at-eol)) 'face))
4303 (message-remove-header "X-Gnus-PGP-Verify")
4304 (if (re-search-forward "^X-PGP-Sig:" nil t)
4306 (goto-char (point-max)))
4307 (narrow-to-region (point) (point))
4308 (insert "X-Gnus-PGP-Verify: " info "\n")
4309 (goto-char (point-min))
4312 (if (not (looking-at "^[ \t]"))
4316 (goto-char (point-min))
4317 (when (looking-at "\\([^:]+\\): *")
4318 (put-text-property (match-beginning 1) (1+ (match-end 1))
4320 (put-text-property (match-end 0) (point-max)
4321 'face eface)))))))))
4323 (autoload 'canlock-verify "canlock" nil t) ;; for XEmacs.
4325 (defun article-verify-cancel-lock ()
4326 "Verify Cancel-Lock header."
4328 (if (gnus-buffer-live-p gnus-original-article-buffer)
4329 (canlock-verify gnus-original-article-buffer)))
4336 (setq afunc (car func)
4339 gfunc (intern (format "gnus-%s" func))))
4341 (when (fboundp afunc)
4342 `(lambda (&optional interactive &rest args)
4343 ,(documentation afunc t)
4344 (interactive (list t))
4345 (with-current-buffer gnus-article-buffer
4347 (call-interactively ',afunc)
4348 (apply ',afunc args))))))))
4349 '(article-hide-headers
4350 article-verify-x-pgp-sig
4351 article-verify-cancel-lock
4352 article-hide-boring-headers
4353 article-treat-overstrike
4354 article-treat-ansi-sequences
4355 article-fill-long-lines
4356 article-capitalize-sentences
4358 article-remove-leading-whitespace
4359 article-display-x-face
4360 article-display-face
4361 article-de-quoted-unreadable
4362 article-de-base64-unreadable
4365 article-unsplit-urls
4366 article-hide-list-identifiers
4367 article-strip-banner
4370 article-hide-signature
4371 article-strip-headers-in-body
4372 article-remove-trailing-blank-lines
4373 article-strip-leading-blank-lines
4374 article-strip-multiple-blank-lines
4375 article-strip-leading-space
4376 article-strip-trailing-space
4377 article-strip-blank-lines
4378 article-strip-all-blank-lines
4380 article-date-english
4381 article-date-iso8601
4382 article-date-original
4385 article-decode-mime-words
4386 article-decode-charset
4387 article-decode-encoded-words
4390 article-date-combined-lapsed
4392 article-treat-dumbquotes
4393 article-treat-non-ascii
4394 article-normalize-headers
4395 ;;(article-show-all . gnus-article-show-all-headers)
4399 ;;; Gnus article mode
4402 (put 'gnus-article-mode 'mode-class 'special)
4404 (set-keymap-parent gnus-article-mode-map widget-keymap)
4406 (gnus-define-keys gnus-article-mode-map
4407 " " gnus-article-goto-next-page
4408 [?\S-\ ] gnus-article-goto-prev-page
4409 "\177" gnus-article-goto-prev-page
4410 [delete] gnus-article-goto-prev-page
4411 "\C-c^" gnus-article-refer-article
4412 "h" gnus-article-show-summary
4413 "s" gnus-article-show-summary
4414 "\C-c\C-m" gnus-article-mail
4415 "?" gnus-article-describe-briefly
4416 "<" beginning-of-buffer
4418 "\C-c\C-i" gnus-info-find-node
4420 "R" gnus-article-reply-with-original
4421 "F" gnus-article-followup-with-original
4422 "\C-hk" gnus-article-describe-key
4423 "\C-hc" gnus-article-describe-key-briefly
4424 "\C-hb" gnus-article-describe-bindings
4426 "e" gnus-article-read-summary-keys
4427 "\C-d" gnus-article-read-summary-keys
4428 "\M-*" gnus-article-read-summary-keys
4429 "\M-#" gnus-article-read-summary-keys
4430 "\M-^" gnus-article-read-summary-keys
4431 "\M-g" gnus-article-read-summary-keys)
4433 (substitute-key-definition
4434 'undefined 'gnus-article-read-summary-keys gnus-article-mode-map)
4436 (defvar gnus-article-send-map)
4438 (gnus-define-keys (gnus-article-send-map "S" gnus-article-mode-map)
4439 "W" gnus-article-wide-reply-with-original)
4440 (if (featurep 'xemacs)
4441 (set-keymap-default-binding gnus-article-send-map
4442 'gnus-article-read-summary-send-keys)
4443 (define-key gnus-article-send-map [t] 'gnus-article-read-summary-send-keys))
4445 (defun gnus-article-make-menu-bar ()
4446 (unless (boundp 'gnus-article-commands-menu)
4447 (gnus-summary-make-menu-bar))
4448 (unless (boundp 'gnus-article-article-menu)
4450 gnus-article-article-menu gnus-article-mode-map ""
4452 ["Scroll forwards" gnus-article-goto-next-page t]
4453 ["Scroll backwards" gnus-article-goto-prev-page t]
4454 ["Show summary" gnus-article-show-summary t]
4455 ["Fetch Message-ID at point" gnus-article-refer-article t]
4456 ["Mail to address at point" gnus-article-mail t]
4457 ["Send a bug report" gnus-bug t]))
4460 gnus-article-treatment-menu gnus-article-mode-map ""
4461 ;; Fixme: this should use :active (and maybe :visible).
4463 ["Hide headers" gnus-article-hide-headers t]
4464 ["Hide signature" gnus-article-hide-signature t]
4465 ["Hide citation" gnus-article-hide-citation t]
4466 ["Treat overstrike" gnus-article-treat-overstrike t]
4467 ["Treat ANSI sequences" gnus-article-treat-ansi-sequences t]
4468 ["Remove carriage return" gnus-article-remove-cr t]
4469 ["Remove leading whitespace" gnus-article-remove-leading-whitespace t]
4470 ["Remove quoted-unreadable" gnus-article-de-quoted-unreadable t]
4471 ["Remove base64" gnus-article-de-base64-unreadable t]
4472 ["Treat html" gnus-article-wash-html t]
4473 ["Remove newlines from within URLs" gnus-article-unsplit-urls t]
4474 ["Decode HZ" gnus-article-decode-HZ t]))
4476 ;; Note "Commands" menu is defined in gnus-sum.el for consistency
4478 ;; Note "Post" menu is defined in gnus-sum.el for consistency
4480 (gnus-run-hooks 'gnus-article-menu-hook)))
4482 (defvar bookmark-make-record-function)
4483 (defvar shr-put-image-function)
4485 (define-derived-mode gnus-article-mode fundamental-mode "Article"
4486 "Major mode for displaying an article.
4488 All normal editing commands are switched off.
4490 The following commands are available in addition to all summary mode
4492 \\<gnus-article-mode-map>
4493 \\[gnus-article-next-page]\t Scroll the article one page forwards
4494 \\[gnus-article-prev-page]\t Scroll the article one page backwards
4495 \\[gnus-article-refer-article]\t Go to the article referred to by an article id near point
4496 \\[gnus-article-show-summary]\t Display the summary buffer
4497 \\[gnus-article-mail]\t Send a reply to the address near point
4498 \\[gnus-article-describe-briefly]\t Describe the current mode briefly
4499 \\[gnus-info-find-node]\t Go to the Gnus info node"
4500 (gnus-simplify-mode-line)
4501 (make-local-variable 'minor-mode-alist)
4502 (when (gnus-visual-p 'article-menu 'menu)
4503 (gnus-article-make-menu-bar)
4504 (when gnus-summary-tool-bar-map
4505 (set (make-local-variable 'tool-bar-map) gnus-summary-tool-bar-map)))
4506 (gnus-update-format-specifications nil 'article-mode)
4507 (set (make-local-variable 'page-delimiter) gnus-page-delimiter)
4508 (set (make-local-variable 'gnus-page-broken) nil)
4509 (make-local-variable 'gnus-article-current-summary)
4510 (make-local-variable 'gnus-article-mime-handles)
4511 (make-local-variable 'gnus-article-decoded-p)
4512 (make-local-variable 'gnus-article-mime-handle-alist)
4513 (make-local-variable 'gnus-article-wash-types)
4514 (make-local-variable 'gnus-article-image-alist)
4515 (make-local-variable 'gnus-article-charset)
4516 (make-local-variable 'gnus-article-ignored-charsets)
4517 (set (make-local-variable 'bookmark-make-record-function)
4518 'gnus-summary-bookmark-make-record)
4519 ;; Prevent Emacs 22 from displaying non-break space with `nobreak-space'
4521 (set (make-local-variable 'nobreak-char-display) nil)
4522 ;; Enable `gnus-article-remove-images' to delete images shr.el renders.
4523 (set (make-local-variable 'shr-put-image-function) 'gnus-shr-put-image)
4524 (setq cursor-in-non-selected-windows nil)
4525 (gnus-set-default-directory)
4526 (buffer-disable-undo)
4527 (setq buffer-read-only t
4528 show-trailing-whitespace nil)
4529 (mm-enable-multibyte))
4531 (defun gnus-article-setup-buffer ()
4532 "Initialize the article buffer."
4533 (let* ((name (if gnus-single-article-buffer "*Article*"
4535 (gnus-group-decoded-name gnus-newsgroup-name)
4538 (progn (string-match "\\*Article" name)
4539 (concat " *Original Article"
4540 (substring name (match-end 0))))))
4541 (setq gnus-article-buffer name)
4542 (setq gnus-original-article-buffer original)
4543 (setq gnus-article-mime-handle-alist nil)
4544 (with-current-buffer gnus-summary-buffer
4545 ;; This might be a variable local to the summary buffer.
4546 (unless gnus-single-article-buffer
4547 (setq gnus-article-buffer name)
4548 (setq gnus-original-article-buffer original)
4549 (gnus-set-global-variables)))
4550 (gnus-article-setup-highlight-words)
4551 ;; Init original article buffer.
4552 (with-current-buffer (gnus-get-buffer-create gnus-original-article-buffer)
4553 (mm-enable-multibyte)
4554 (setq major-mode 'gnus-original-article-mode)
4555 (make-local-variable 'gnus-original-article))
4556 (if (and (get-buffer name)
4557 (with-current-buffer name
4558 (if gnus-article-edit-mode
4559 (if (y-or-n-p "Article mode edit in progress; discard? ")
4561 (set-buffer-modified-p nil)
4562 (gnus-kill-buffer name)
4565 (error "Action aborted"))
4567 (let ((summary gnus-summary-buffer))
4568 (with-current-buffer name
4569 (set (make-local-variable 'gnus-article-edit-mode) nil)
4570 (gnus-article-stop-animations)
4571 (when gnus-article-mime-handles
4572 (mm-destroy-parts gnus-article-mime-handles)
4573 (setq gnus-article-mime-handles nil))
4574 ;; Set it to nil in article-buffer!
4575 (setq gnus-article-mime-handle-alist nil)
4576 (buffer-disable-undo)
4577 (setq buffer-read-only t)
4578 (unless (derived-mode-p 'gnus-article-mode)
4579 (gnus-article-mode))
4580 (set (make-local-variable 'gnus-summary-buffer) summary)
4581 (setq truncate-lines gnus-article-truncate-lines)
4583 (let ((summary gnus-summary-buffer))
4584 (with-current-buffer (gnus-get-buffer-create name)
4586 (setq truncate-lines gnus-article-truncate-lines)
4587 (set (make-local-variable 'gnus-summary-buffer) summary)
4588 (gnus-summary-set-local-parameters gnus-newsgroup-name)
4589 (when article-lapsed-timer
4590 (gnus-stop-date-timer))
4591 (when gnus-article-update-date-headers
4592 (gnus-start-date-timer gnus-article-update-date-headers))
4593 (current-buffer))))))
4595 (defun gnus-article-stop-animations ()
4596 (dolist (timer (and (boundp 'timer-list)
4598 (when (eq (gnus-timer--function timer) 'image-animate-timeout)
4599 (cancel-timer timer))))
4601 (defun gnus-stop-downloads ()
4602 (when (boundp 'url-queue)
4603 (set (intern "url-queue" obarray) nil)))
4605 ;; Set article window start at LINE, where LINE is the number of lines
4606 ;; from the head of the article.
4607 (defun gnus-article-set-window-start (&optional line)
4608 (let ((article-window (gnus-get-buffer-window gnus-article-buffer t)))
4609 (when article-window
4612 (with-current-buffer gnus-article-buffer
4613 (goto-char (point-min))
4616 (gnus-message 6 "Moved to bookmark")
4617 (search-forward "\n\n" nil t)
4621 (defvar gnus-tmp-internal-hook)
4623 (defun gnus-article-prepare (article &optional all-headers _header)
4624 "Prepare ARTICLE in article mode buffer.
4625 ARTICLE should either be an article number or a Message-ID.
4626 If ARTICLE is an id, HEADER should be the article headers.
4627 If ALL-HEADERS is non-nil, no headers are hidden."
4628 (save-excursion ;FIXME: Shouldn't that be save-current-buffer?
4629 ;; Make sure we start in a summary buffer.
4630 (unless (derived-mode-p 'gnus-summary-mode)
4631 (set-buffer gnus-summary-buffer))
4632 (setq gnus-summary-buffer (current-buffer))
4633 (let* ((summary-buffer (current-buffer))
4634 (gnus-tmp-internal-hook gnus-article-internal-prepare-hook)
4635 (group gnus-newsgroup-name)
4638 (gnus-article-setup-buffer)
4639 (set-buffer gnus-article-buffer)
4640 ;; Deactivate active regions.
4641 (when (and (boundp 'transient-mark-mode)
4642 transient-mark-mode)
4643 (setq mark-active nil))
4644 (if (not (setq result (let ((inhibit-read-only t))
4645 (gnus-request-article-this-buffer
4647 ;; There is no such article.
4649 (when (and (numberp article)
4650 (not (memq article gnus-newsgroup-sparse)))
4651 (setq gnus-article-current
4652 (cons gnus-newsgroup-name article))
4653 (set-buffer gnus-summary-buffer)
4654 (setq gnus-current-article article)
4655 (if (and (memq article gnus-newsgroup-undownloaded)
4656 (not (gnus-online (gnus-find-method-for-group
4657 gnus-newsgroup-name))))
4659 (gnus-summary-set-agent-mark article)
4660 (message "Message marked for downloading"))
4661 (gnus-summary-mark-article article gnus-canceled-mark)
4662 (unless (memq article gnus-newsgroup-sparse)
4663 (gnus-error 1 "No such article (may have expired or been canceled)")))))
4664 (if (or (eq result 'pseudo)
4665 (eq result 'nneething))
4667 (with-current-buffer summary-buffer
4668 (push article gnus-newsgroup-history)
4669 (setq gnus-last-article gnus-current-article
4670 gnus-current-article 0
4671 gnus-current-headers nil
4672 gnus-article-current nil)
4673 (if (eq result 'nneething)
4674 (gnus-configure-windows 'summary)
4675 (gnus-configure-windows 'article))
4676 (gnus-set-global-variables))
4677 (let ((gnus-article-mime-handle-alist-1
4678 gnus-article-mime-handle-alist))
4679 (gnus-set-mode-line 'article)))
4680 ;; The result from the `request' was an actual article -
4681 ;; or at least some text that is now displayed in the
4683 (when (and (numberp article)
4684 (not (eq article gnus-current-article)))
4685 ;; Seems like a new article has been selected.
4686 ;; `gnus-current-article' must be an article number.
4687 (with-current-buffer summary-buffer
4688 (push article gnus-newsgroup-history)
4689 (setq gnus-last-article gnus-current-article
4690 gnus-current-article article
4691 gnus-current-headers
4692 (gnus-summary-article-header gnus-current-article)
4693 gnus-article-current
4694 (cons gnus-newsgroup-name gnus-current-article))
4695 (unless (vectorp gnus-current-headers)
4696 (setq gnus-current-headers nil))
4697 (gnus-summary-goto-subject gnus-current-article)
4698 (when (gnus-summary-show-thread)
4699 ;; If the summary buffer really was folded, the
4700 ;; previous goto may not actually have gone to
4701 ;; the right article, but the thread root instead.
4703 (gnus-summary-goto-subject gnus-current-article))
4704 (gnus-run-hooks 'gnus-mark-article-hook)
4705 (gnus-set-mode-line 'summary)
4706 (when (gnus-visual-p 'article-highlight 'highlight)
4707 (gnus-run-hooks 'gnus-visual-mark-article-hook))
4708 ;; Set the global newsgroup variables here.
4709 (gnus-set-global-variables)
4710 (setq gnus-have-all-headers
4711 (or all-headers gnus-show-all-headers))))
4713 (gnus-configure-windows 'article))
4714 (when (or (numberp article)
4716 (gnus-article-prepare-display)
4718 (goto-char (point-min))
4719 (when gnus-break-pages
4720 (gnus-narrow-to-page)))
4721 (let ((gnus-article-mime-handle-alist-1
4722 gnus-article-mime-handle-alist))
4723 (gnus-set-mode-line 'article))
4727 (set-window-point (get-buffer-window (current-buffer)) (point))
4728 (gnus-configure-windows 'article)
4729 (gnus-run-hooks 'gnus-article-prepare-hook)
4732 (defvar gnus-mime-display-attachment-buttons-in-header)
4735 (defun gnus-article-prepare-display ()
4736 "Make the current buffer look like a nice article."
4737 ;; Hooks for getting information from the article.
4738 ;; This hook must be called before being narrowed.
4739 (let ((gnus-article-buffer (current-buffer))
4741 (inhibit-read-only t))
4742 (unless (derived-mode-p 'gnus-article-mode)
4743 (gnus-article-mode))
4744 (setq buffer-read-only nil
4745 gnus-article-wash-types nil
4746 gnus-article-image-alist nil)
4747 (gnus-run-hooks 'gnus-tmp-internal-hook)
4748 (when gnus-display-mime-function
4749 (funcall gnus-display-mime-function))
4750 ;; Add attachment buttons to the header.
4751 (when gnus-mime-display-attachment-buttons-in-header
4752 (gnus-mime-buttonize-attachments-in-header))))
4755 ;;; Gnus Sticky Article Mode
4758 (define-derived-mode gnus-sticky-article-mode gnus-article-mode "StickyArticle"
4759 "Mode for sticky articles."
4760 ;; Release bindings that won't work.
4761 (substitute-key-definition 'gnus-article-read-summary-keys 'undefined
4762 gnus-sticky-article-mode-map)
4763 (substitute-key-definition 'gnus-article-refer-article 'undefined
4764 gnus-sticky-article-mode-map)
4765 (dolist (k '("e" "h" "s" "F" "R"))
4766 (define-key gnus-sticky-article-mode-map k nil))
4767 (define-key gnus-sticky-article-mode-map "k" 'gnus-kill-sticky-article-buffer)
4768 (define-key gnus-sticky-article-mode-map "q" 'bury-buffer)
4769 (define-key gnus-sticky-article-mode-map "\C-hc" 'describe-key-briefly)
4770 (define-key gnus-sticky-article-mode-map "\C-hk" 'describe-key))
4772 (defun gnus-sticky-article (arg)
4773 "Make the current article sticky.
4774 If a prefix ARG is given, ask for a name for this sticky article buffer."
4776 (gnus-summary-show-thread)
4777 (gnus-summary-select-article nil nil 'pseudo)
4778 (let (new-art-buf-name)
4779 (gnus-eval-in-buffer-window gnus-article-buffer
4780 (setq new-art-buf-name
4784 (read-from-minibuffer "Sticky article buffer name: ")
4785 (gnus-with-article-headers
4786 (gnus-article-goto-header "subject")
4787 (setq new-art-buf-name
4788 (buffer-substring-no-properties
4789 (line-beginning-position) (line-end-position)))
4790 (goto-char (point-min))
4791 (gnus-article-goto-header "from")
4792 (setq new-art-buf-name
4794 new-art-buf-name ", "
4795 (buffer-substring-no-properties
4796 (line-beginning-position) (line-end-position))))
4797 (goto-char (point-min))
4798 (gnus-article-goto-header "date")
4799 (setq new-art-buf-name
4801 new-art-buf-name ", "
4802 (buffer-substring-no-properties
4803 (line-beginning-position) (line-end-position))))))
4805 (if (and (gnus-buffer-live-p new-art-buf-name)
4806 (with-current-buffer new-art-buf-name
4807 (derived-mode-p 'gnus-sticky-article-mode)))
4808 (switch-to-buffer new-art-buf-name)
4809 (setq new-art-buf-name (rename-buffer new-art-buf-name t)))
4810 (gnus-sticky-article-mode))
4811 (setq gnus-article-buffer new-art-buf-name))
4812 (gnus-summary-recenter)
4813 (gnus-summary-position-point))
4815 (defun gnus-kill-sticky-article-buffer (&optional buffer)
4816 "Kill the given sticky article BUFFER.
4817 If none is given, assume the current buffer and kill it if it has
4818 `gnus-sticky-article-mode'."
4821 (setq buffer (current-buffer)))
4822 (with-current-buffer buffer
4823 (when (derived-mode-p 'gnus-sticky-article-mode)
4824 (gnus-kill-buffer buffer))))
4826 (defun gnus-kill-sticky-article-buffers (arg)
4827 "Kill all sticky article buffers.
4828 If a prefix ARG is given, ask for confirmation."
4830 (dolist (buf (gnus-buffers))
4831 (with-current-buffer buf
4832 (when (derived-mode-p 'gnus-sticky-article-mode)
4834 (gnus-kill-buffer buf)
4835 (when (yes-or-no-p (concat "Kill buffer " (buffer-name buf) "? "))
4836 (gnus-kill-buffer buf)))))))
4839 ;;; Gnus MIME viewing functions
4842 (defvar gnus-mime-button-line-format "%{%([%p. %d%T]%)%}%e\n"
4843 "Format of the MIME buttons.
4845 Valid specifiers include:
4847 %T MIME type, along with additional info
4848 %n The `name' parameter
4849 %d The description, if any
4850 %l The length of the encoded part
4851 %p The part identifier number
4852 %e Dots if the part isn't displayed
4854 General format specifiers can also be used. See Info node
4855 `(gnus)Formatting Variables'.")
4857 (defvar gnus-tmp-type)
4858 (defvar gnus-tmp-type-long)
4859 (defvar gnus-tmp-name)
4860 (defvar gnus-tmp-description)
4861 (defvar gnus-tmp-id)
4862 (defvar gnus-tmp-length)
4863 (defvar gnus-tmp-dots)
4864 (defvar gnus-tmp-info)
4865 (defvar gnus-tmp-pressed-details)
4867 (defvar gnus-mime-button-line-format-alist
4868 '((?t gnus-tmp-type ?s)
4869 (?T gnus-tmp-type-long ?s)
4870 (?n gnus-tmp-name ?s)
4871 (?d gnus-tmp-description ?s)
4873 (?l gnus-tmp-length ?d)
4874 (?e gnus-tmp-dots ?s)))
4876 (defvar gnus-mime-button-commands
4877 '((gnus-article-press-button "\r" "Toggle Display")
4878 (gnus-mime-view-part "v" "View Interactively...")
4879 (gnus-mime-view-part-as-type "t" "View As Type...")
4880 (gnus-mime-view-part-as-charset "C" "View As charset...")
4881 (gnus-mime-save-part "o" "Save...")
4882 (gnus-mime-save-part-and-strip "\C-o" "Save and Strip")
4883 (gnus-mime-replace-part "r" "Replace part")
4884 (gnus-mime-delete-part "d" "Delete part")
4885 (gnus-mime-copy-part "c" "View As Text, In Other Buffer")
4886 (gnus-mime-inline-part "i" "View As Text, In This Buffer")
4887 (gnus-mime-view-part-internally "E" "View Internally") ;; Why `E'?
4888 (gnus-mime-view-part-externally "e" "View Externally")
4889 (gnus-mime-print-part "p" "Print")
4890 (gnus-mime-pipe-part "|" "Pipe To Command...")
4891 (gnus-mime-action-on-part "." "Take action on the part...")))
4893 (defun gnus-article-mime-part-status ()
4894 (if gnus-article-mime-handle-alist-1
4895 (if (eq 1 (length gnus-article-mime-handle-alist-1))
4897 (format " (%d parts)" (length gnus-article-mime-handle-alist-1)))
4900 (defvar gnus-mime-button-map
4901 (let ((map (make-sparse-keymap)))
4902 (define-key map gnus-mouse-2 'gnus-article-push-button)
4903 (define-key map gnus-down-mouse-3 'gnus-mime-button-menu)
4904 (dolist (c gnus-mime-button-commands)
4905 (define-key map (cadr c) (car c)))
4909 gnus-mime-button-menu gnus-mime-button-map "MIME button menu."
4911 ,@(mapcar (lambda (c)
4912 (vector (caddr c) (car c) :active t))
4913 gnus-mime-button-commands)))
4915 (defvar gnus-url-button-commands
4916 '((gnus-article-copy-string "u" "Copy URL to kill ring")))
4918 (defvar gnus-url-button-map
4919 (let ((map (make-sparse-keymap)))
4920 (dolist (c gnus-url-button-commands)
4921 (define-key map (cadr c) (car c)))
4925 gnus-url-button-menu gnus-url-button-map "URL button menu."
4927 ,@(mapcar (lambda (c)
4928 (vector (caddr c) (car c) :active t))
4929 gnus-url-button-commands)))
4931 (defmacro gnus-bind-mm-vars (&rest body)
4932 "Bind some mm-* variables and execute BODY."
4933 `(let (mm-html-inhibit-images
4934 mm-html-blocked-images
4935 (mm-w3m-safe-url-regexp mm-w3m-safe-url-regexp))
4936 (with-current-buffer
4937 (cond ((derived-mode-p 'gnus-article-mode)
4938 (if (gnus-buffer-live-p gnus-article-current-summary)
4939 gnus-article-current-summary
4940 ;; Maybe we're in a mml-preview buffer
4941 ;; and no group is selected.
4943 ((gnus-buffer-live-p gnus-summary-buffer)
4944 gnus-summary-buffer)
4945 (t (current-buffer)))
4946 (setq mm-html-inhibit-images gnus-inhibit-images
4947 mm-html-blocked-images (gnus-blocked-images))
4948 (when (or (not gnus-newsgroup-name)
4949 (and (stringp gnus-safe-html-newsgroups)
4950 (string-match gnus-safe-html-newsgroups
4951 gnus-newsgroup-name))
4952 (and (consp gnus-safe-html-newsgroups)
4953 (member gnus-newsgroup-name gnus-safe-html-newsgroups)))
4954 (setq mm-w3m-safe-url-regexp nil)))
4957 (defun gnus-mime-button-menu (event prefix)
4958 "Construct a context-sensitive menu of MIME commands."
4959 (interactive "e\nP")
4960 (save-window-excursion
4961 (let ((pos (event-start event)))
4962 (select-window (posn-window pos))
4963 (goto-char (posn-point pos))
4964 (gnus-article-check-buffer)
4965 (popup-menu gnus-mime-button-menu nil prefix))))
4967 (defun gnus-mime-view-all-parts (&optional handles)
4968 "View all the MIME parts."
4970 (with-current-buffer gnus-article-buffer
4971 (let ((handles (or handles gnus-article-mime-handles))
4972 (mail-parse-charset gnus-newsgroup-charset)
4973 (mail-parse-ignored-charsets
4974 (with-current-buffer gnus-summary-buffer
4975 gnus-newsgroup-ignored-charsets)))
4977 (mm-remove-parts handles)
4978 (goto-char (point-min))
4979 (or (search-forward "\n\n") (goto-char (point-max)))
4980 (let ((inhibit-read-only t))
4981 (delete-region (point) (point-max))
4982 (gnus-bind-mm-vars (mm-display-parts handles)))))))
4984 (defun gnus-article-jump-to-part (n)
4985 "Jump to MIME part N."
4987 (let ((parts (with-current-buffer gnus-article-buffer
4988 (length gnus-article-mime-handle-alist))))
4990 (error "No such part"))
4991 (pop-to-buffer gnus-article-buffer)
4993 (setq n (if (= parts 1)
4995 (read-number (format "Jump to part (1..%s): " parts)))))
4996 (unless (and (integerp n) (<= n parts) (>= n 1))
4999 (gnus-message 7 "Invalid part `%s', using %s instead."
5002 (gnus-message 9 "Jumping to part %s." n)
5003 (cond ((>= gnus-auto-select-part 1)
5004 (while (and (<= n parts)
5005 (not (gnus-article-goto-part n)))
5007 ((< gnus-auto-select-part 0)
5008 (while (and (>= n 1)
5009 (not (gnus-article-goto-part n)))
5012 (gnus-article-goto-part n)))))
5014 (defvar gnus-mime-buttonized-part-id nil
5015 "ID of a mime part that should be buttonized.
5016 `gnus-mime-save-part-and-strip' and `gnus-mime-delete-part' bind it.")
5019 (defsubst gnus-article-edit-part (handles &optional current-id)
5020 "Edit an article in order to delete a mime part.
5021 This function is exclusively used by `gnus-mime-save-part-and-strip'
5022 and `gnus-mime-delete-part', and not provided at run-time normally."
5023 (gnus-article-edit-article
5025 (buffer-disable-undo)
5026 (let ((mail-parse-charset (or gnus-article-charset
5027 ',gnus-newsgroup-charset))
5028 (mail-parse-ignored-charsets
5029 (or gnus-article-ignored-charsets
5030 ',gnus-newsgroup-ignored-charsets))
5031 (mbl mml-buffer-list))
5032 (setq mml-buffer-list nil)
5033 ;; A new text must be inserted before deleting existing ones
5034 ;; at the end so as not to move existing markers of which
5035 ;; the insertion type is t.
5039 (goto-char (point-max))
5040 (insert-buffer-substring gnus-original-article-buffer)))
5041 (mime-to-mml ',handles)
5042 (setq gnus-article-mime-handles nil)
5043 (let ((mbl1 mml-buffer-list))
5044 (setq mml-buffer-list mbl)
5045 (set (make-local-variable 'mml-buffer-list) mbl1))
5046 (gnus-make-local-hook 'kill-buffer-hook)
5047 (add-hook 'kill-buffer-hook 'mml-destroy-buffers t t)))
5048 `(lambda (no-highlight)
5049 (let ((mail-parse-charset (or gnus-article-charset
5050 ',gnus-newsgroup-charset))
5051 (message-options message-options)
5052 (message-options-set-recipient)
5053 (mail-parse-ignored-charsets
5054 (or gnus-article-ignored-charsets
5055 ',gnus-newsgroup-ignored-charsets)))
5057 (mml-destroy-buffers)
5058 (remove-hook 'kill-buffer-hook
5059 'mml-destroy-buffers t)
5060 (kill-local-variable 'mml-buffer-list))
5061 (gnus-summary-edit-article-done
5062 ,(or (mail-header-references gnus-current-headers) "")
5063 ,(gnus-group-read-only-p)
5064 ,gnus-summary-buffer no-highlight))
5066 ;; Force buttonizing this part.
5067 (let ((gnus-mime-buttonized-part-id current-id))
5068 (gnus-article-edit-done))
5069 (gnus-configure-windows 'article)
5071 (when (and current-id (integerp gnus-auto-select-part))
5072 (gnus-article-jump-to-part
5073 (min (max (+ current-id gnus-auto-select-part) 1)
5074 (with-current-buffer gnus-article-buffer
5075 (length gnus-article-mime-handle-alist)))))))
5077 (defun gnus-mime-replace-part (file)
5078 "Replace MIME part under point with an external body."
5079 ;; Useful if file has already been saved to disk
5082 (read-file-name "Replace MIME part with file: "
5083 (or mm-default-directory default-directory)
5085 (gnus-mime-save-part-and-strip file))
5087 (defun gnus-mime-save-part-and-strip (&optional file)
5088 "Save the MIME part under point then replace it with an external body.
5089 If FILE is given, use it for the external part."
5091 (gnus-article-check-buffer)
5092 (when (gnus-group-read-only-p)
5093 (error "The current group does not support deleting of parts"))
5094 (when (mm-complicated-handles gnus-article-mime-handles)
5096 The current article has a complicated MIME structure, giving up..."))
5097 (let* ((data (get-text-property (point) 'gnus-data))
5098 (id (get-text-property (point) 'gnus-part))
5099 (handles gnus-article-mime-handles))
5102 (and data (mm-save-part data "Delete MIME part and save to: "))))
5104 (with-current-buffer (mm-handle-buffer data)
5106 (insert "Content-Type: " (mm-handle-media-type data))
5107 (mml-insert-parameter-string (cdr (mm-handle-type data))
5109 ;; Add a filename for the sake of saving the part again.
5110 (mml-insert-parameter
5111 (mail-header-encode-parameter "name" (file-name-nondirectory file)))
5113 (insert "Content-ID: " (message-make-message-id) "\n")
5114 (insert "Content-Transfer-Encoding: binary\n")
5117 (cdr (mm-make-handle nil
5118 `("message/external-body"
5119 (access-type . "LOCAL-FILE")
5121 ;; (set-buffer gnus-summary-buffer)
5122 (gnus-article-edit-part handles id))))
5124 ;; A function like `gnus-summary-save-parts' (`X m', `<MIME> <Extract all
5125 ;; parts...>') but with stripping would be nice.
5127 (defun gnus-mime-delete-part ()
5128 "Delete the MIME part under point.
5129 Replace it with some information about the removed part."
5131 (gnus-article-check-buffer)
5132 (when (gnus-group-read-only-p)
5133 (error "The current group does not support deleting of parts"))
5134 (when (mm-complicated-handles gnus-article-mime-handles)
5136 The current article has a complicated MIME structure, giving up..."))
5137 (when (or gnus-expert-user
5138 (gnus-yes-or-no-p "\
5139 Deleting parts may malfunction or destroy the article; continue? "))
5140 (let* ((data (get-text-property (point) 'gnus-data))
5141 (id (get-text-property (point) 'gnus-part))
5142 (handles gnus-article-mime-handles)
5144 (let ((desc (mm-handle-description data)))
5146 (mail-decode-encoded-word-string desc))))
5147 (filename (or (mm-handle-filename data) "(none)"))
5148 (type (mm-handle-media-type data)))
5150 (error "No MIME part under point"))
5151 (with-current-buffer (mm-handle-buffer data)
5152 (let ((bsize (buffer-size)))
5157 "| The following attachment has been deleted:\n"
5159 "| Type: " type "\n"
5160 "| Filename: " filename "\n"
5161 "| Size (encoded): " (format "%s byte%s\n"
5162 bsize (if (= bsize 1)
5166 (concat "| Description: " description "\n"))
5169 (cdr (mm-make-handle
5170 nil `("text/plain" (charset . gnus-decoded)) nil nil
5172 (format "Deleted attachment (%s bytes)" bsize))))))
5173 ;; (set-buffer gnus-summary-buffer)
5174 (gnus-article-edit-part handles id))))
5176 (defun gnus-mime-save-part ()
5177 "Save the MIME part under point."
5179 (gnus-article-check-buffer)
5180 (let ((data (get-text-property (point) 'gnus-data)))
5182 (mm-save-part data))))
5184 (defun gnus-mime-pipe-part (&optional cmd)
5185 "Pipe the MIME part under point to a process.
5186 Use CMD as the process."
5188 (gnus-article-check-buffer)
5189 (let ((data (get-text-property (point) 'gnus-data)))
5191 (mm-pipe-part data cmd))))
5193 (defun gnus-mime-view-part ()
5194 "Interactively choose a viewing method for the MIME part under point."
5196 (gnus-article-check-buffer)
5197 (let ((data (get-text-property (point) 'gnus-data)))
5199 (setq gnus-article-mime-handles
5201 gnus-article-mime-handles (setq data (copy-sequence data))))
5202 (mm-interactively-view-part data))))
5204 (defun gnus-mime-view-part-as-type-internal ()
5205 (gnus-article-check-buffer)
5206 (let* ((handle (get-text-property (point) 'gnus-data))
5208 ;; Content-Type: foo/bar; name=...
5209 (mail-content-type-get (mm-handle-type handle) 'name)
5210 ;; Content-Disposition: attachment; filename=...
5211 (cdr (assq 'filename (cdr (mm-handle-disposition handle))))))
5212 (def-type (and name (mm-default-file-encoding name))))
5213 (or (and def-type (cons def-type 0))
5215 (equal (mm-handle-media-supertype handle) "text")
5216 '("text/plain" . 0))
5217 '("application/octet-stream" . 0))))
5219 (defun gnus-mime-view-part-as-type (&optional mime-type pred)
5220 "Choose a MIME media type, and view the part as such.
5221 If non-nil, PRED is a predicate to use during completion to limit the
5222 available media-types."
5226 (let ((default (gnus-mime-view-part-as-type-internal)))
5227 (gnus-completing-read
5230 (gnus-remove-if-not pred (mailcap-mime-types))
5231 (mailcap-mime-types))
5234 (gnus-article-check-buffer)
5235 (let ((handle (get-text-property (point) 'gnus-data)))
5237 (when (equal (mm-handle-media-type handle) "message/external-body")
5238 (unless (mm-handle-cache handle)
5239 (mm-extern-cache-contents handle))
5240 (setq handle (mm-handle-cache handle)))
5242 (mm-make-handle (mm-handle-buffer handle)
5243 (cons mime-type (cdr (mm-handle-type handle)))
5244 (mm-handle-encoding handle)
5245 (mm-handle-undisplayer handle)
5246 (mm-handle-disposition handle)
5247 (mm-handle-description handle)
5249 (mm-handle-id handle)))
5250 (setq gnus-article-mime-handles
5251 (mm-merge-handles gnus-article-mime-handles handle))
5252 (when (mm-handle-displayed-p handle)
5253 (mm-remove-part handle))
5254 (gnus-mm-display-part handle))))
5256 (defun gnus-mime-copy-part (&optional handle arg)
5257 "Put the MIME part under point into a new buffer.
5258 If `auto-compression-mode' is enabled, compressed files like .gz and .bz2
5260 (interactive (list nil current-prefix-arg))
5261 (gnus-article-check-buffer)
5263 (setq handle (get-text-property (point) 'gnus-data)))
5265 (let ((filename (mm-handle-filename handle))
5266 contents dont-decode charset coding-system)
5267 (mm-with-unibyte-buffer
5268 (mm-insert-part handle)
5269 (setq contents (or (condition-case nil
5270 (mm-decompress-buffer filename nil 'sig)
5272 (setq dont-decode t)
5275 (setq filename (cond (filename (file-name-nondirectory filename))
5276 (dont-decode "*raw data*")
5281 (unless (setq charset (mail-content-type-get
5282 (mm-handle-type handle) 'charset))
5283 (unless (setq coding-system (mm-with-unibyte-buffer
5285 (mm-find-buffer-file-coding-system)))
5286 (setq charset gnus-newsgroup-charset))))
5288 (setq charset (or (cdr (assq arg
5289 gnus-summary-show-article-charset-alist))
5290 (mm-read-coding-system "Charset: ")))))
5291 (switch-to-buffer (generate-new-buffer filename))
5292 (if (or coding-system
5294 (setq coding-system (mm-charset-to-coding-system
5296 (not (eq coding-system 'ascii))))
5298 (mm-enable-multibyte)
5299 (insert (mm-decode-coding-string contents coding-system))
5300 (setq buffer-file-coding-system
5301 (if (boundp 'last-coding-system-used)
5302 (symbol-value 'last-coding-system-used)
5304 (mm-disable-multibyte)
5306 (setq buffer-file-coding-system mm-binary-coding-system))
5307 ;; We do it this way to make `normal-mode' set the appropriate mode.
5310 (setq buffer-file-name (expand-file-name filename))
5312 (setq buffer-file-name nil))
5313 (goto-char (point-min)))))
5315 (defun gnus-mime-print-part (&optional handle filename)
5316 "Print the MIME part under point."
5317 (interactive (list nil (ps-print-preprint current-prefix-arg)))
5318 (gnus-article-check-buffer)
5319 (let* ((handle (or handle (get-text-property (point) 'gnus-data)))
5320 (contents (and handle (mm-get-part handle)))
5321 (file (mm-make-temp-file (expand-file-name "mm." mm-tmp-directory)))
5322 (printer (mailcap-mime-info (mm-handle-media-type handle) "print")))
5327 (mm-save-part-to-file handle file)
5328 (call-process shell-file-name nil
5329 (generate-new-buffer " *mm*")
5331 shell-command-switch
5333 printer file (mm-handle-type handle))))
5337 (gnus-print-buffer))
5338 (ps-despool filename)))))
5340 (defun gnus-mime-inline-part (&optional handle arg)
5341 "Insert the MIME part under point into the current buffer.
5342 Compressed files like .gz and .bz2 are decompressed."
5343 (interactive (list nil current-prefix-arg))
5344 (gnus-article-check-buffer)
5345 (let* ((inhibit-read-only t)
5347 (btn ;; position where the MIME button exists
5349 (if (eq handle (get-text-property b 'gnus-data))
5352 (or (text-property-any (point) (point-max) 'gnus-data handle)
5353 (text-property-any (point-min) (point) 'gnus-data handle)))
5354 (setq handle (get-text-property b 'gnus-data))
5360 (setq start (next-single-property-change btn 'gnus-data
5362 btn (previous-single-property-change start
5365 (if (and (not arg) (mm-handle-undisplayer handle))
5367 (setq b (copy-marker b)
5368 btn (copy-marker btn))
5369 (mm-remove-part handle))
5373 (if (mm-handle-undisplayer handle)
5374 (mm-remove-part handle)))
5375 ((mm-handle-undisplayer handle)
5376 (mm-remove-part handle)))
5379 ;; This is a header button.
5381 (mm-display-inline handle))
5382 ;; Toggle the button appearance between `[button]...' and `[button]'.
5384 (setq btn (prog1 (marker-position btn)
5385 (set-marker btn nil))))
5387 (let ((displayed-p (mm-handle-displayed-p handle)))
5388 (gnus-insert-mime-button handle (get-text-property btn 'gnus-part)
5390 (if (featurep 'emacs)
5393 (next-single-property-change (point) 'gnus-data nil (point-max)))
5394 (let* ((end (next-single-property-change (point) 'gnus-data))
5395 (annots (annotations-at (or end (point-max)))))
5396 (delete-region (point)
5398 (if annots (1+ end) end)
5400 (dolist (annot annots)
5401 (set-extent-endpoints annot (point) (point)))))
5402 (setq start (point))
5403 (if (search-backward "\n\n" nil t)
5406 (unless (or displayed-p (eolp))
5407 ;; Add extra newline.
5408 (insert (propertize (buffer-substring (1- start) start)
5409 'gnus-undeletable t))))
5410 ;; We're in the article header.
5412 (dolist (ovl (overlays-in btn (point)))
5413 (overlay-put ovl 'gnus-button-attachment-extra t)
5414 (overlay-put ovl 'face nil))
5416 (message-narrow-to-field)
5417 (let ((gnus-treatment-function-alist
5418 '((gnus-treat-highlight-headers
5419 gnus-article-highlight-headers))))
5420 (gnus-treat-article 'head)))))
5422 (setq b (prog1 (marker-position b)
5423 (set-marker b nil))))
5426 (defun gnus-mime-set-charset-parameters (handle charset)
5427 "Set CHARSET to parameters in HANDLE.
5428 CHARSET may either be a string or a symbol."
5429 (unless (stringp charset)
5430 (setq charset (symbol-name charset)))
5431 (if (stringp (car handle))
5432 (dolist (h (cdr handle))
5433 (gnus-mime-set-charset-parameters h charset))
5434 (let* ((type (mm-handle-type (if (equal (mm-handle-media-type handle)
5435 "message/external-body")
5437 (unless (mm-handle-cache handle)
5438 (mm-extern-cache-contents handle))
5439 (mm-handle-cache handle))
5441 (param (assq 'charset (cdr type))))
5443 (setcdr param charset)
5444 (setcdr type (cons (cons 'charset charset) (cdr type)))))))
5446 (defun gnus-mime-view-part-as-charset (&optional handle arg)
5447 "Insert the MIME part under point into the current buffer using the
5449 (interactive (list nil current-prefix-arg))
5450 (gnus-article-check-buffer)
5451 (let ((handle (or handle (get-text-property (point) 'gnus-data)))
5452 (fun (get-text-property (point) 'gnus-callback))
5453 (gnus-newsgroup-ignored-charsets 'gnus-all)
5454 charset form preferred parts)
5461 gnus-summary-show-article-charset-alist))
5462 (mm-read-coding-system "Charset: "))))
5463 (if (mm-handle-undisplayer handle)
5464 (mm-remove-part handle)))
5465 (gnus-mime-set-charset-parameters handle charset)
5466 (when (and (consp (setq form (cdr-safe fun)))
5467 (setq form (ignore-errors
5468 (assq 'gnus-mime-display-alternative form)))
5469 (setq preferred (caddr form))
5471 (when (eq (car preferred) 'quote)
5472 (setq preferred (cadr preferred)))
5473 (not (equal preferred
5474 (get-text-property (point) 'gnus-data))))
5475 (setq parts (get-text-property (point) 'gnus-part))
5476 (setq parts (cdr (assq parts
5477 gnus-article-mime-handle-alist)))
5478 (equal (mm-handle-media-type parts) "multipart/alternative")
5479 (setq parts (reverse (cdr parts))))
5481 (list 'quote (or (cadr (member preferred parts))
5483 (funcall fun handle)))))
5485 (defun gnus-mime-view-part-externally (&optional handle)
5486 "View the MIME part under point with an external viewer."
5488 (gnus-article-check-buffer)
5489 (let* ((handle (or handle (get-text-property (point) 'gnus-data)))
5490 (mm-inlined-types nil)
5491 (mail-parse-charset gnus-newsgroup-charset)
5492 (mail-parse-ignored-charsets
5493 (with-current-buffer gnus-summary-buffer
5494 gnus-newsgroup-ignored-charsets))
5495 (type (mm-handle-media-type handle))
5496 (method (mailcap-mime-info type))
5497 (mm-enable-external t))
5498 (if (not (stringp method))
5499 (gnus-mime-view-part-as-type
5500 nil (lambda (type) (stringp (mailcap-mime-info type))))
5502 (mm-display-part handle nil t)))))
5504 (defun gnus-mime-view-part-internally (&optional handle)
5505 "View the MIME part under point with an internal viewer.
5506 If no internal viewer is available, use an external viewer."
5508 (gnus-article-check-buffer)
5509 (let* ((handle (or handle (get-text-property (point) 'gnus-data)))
5510 (mm-inlined-types '(".*"))
5511 (mm-inline-large-images t)
5512 (mail-parse-charset gnus-newsgroup-charset)
5513 (mail-parse-ignored-charsets
5514 (with-current-buffer gnus-summary-buffer
5515 gnus-newsgroup-ignored-charsets))
5516 (inhibit-read-only t))
5517 (if (not (mm-inlinable-p handle))
5518 (gnus-mime-view-part-as-type
5519 nil (lambda (type) (mm-inlinable-p handle type)))
5521 (gnus-bind-mm-vars (mm-display-part handle nil t))))))
5523 (defun gnus-mime-action-on-part (&optional action)
5524 "Do something with the MIME attachment at (point)."
5526 (list (gnus-completing-read "Action" (mapcar 'car gnus-mime-action-alist) t)))
5527 (gnus-article-check-buffer)
5528 (let ((action-pair (assoc action gnus-mime-action-alist)))
5530 (funcall (cdr action-pair)))))
5532 (defun gnus-article-part-wrapper (n function &optional no-handle interactive)
5533 "Call FUNCTION on MIME part N.
5534 Unless NO-HANDLE, call FUNCTION with N-th MIME handle as its only argument.
5535 If INTERACTIVE, call FUNCTION interactively."
5537 ;; Check whether the article is displayed.
5538 (unless (and (gnus-buffer-live-p gnus-article-buffer)
5539 (setq window (get-buffer-window gnus-article-buffer t))
5540 (frame-visible-p (setq frame (window-frame window))))
5541 (error "No article is displayed"))
5542 (with-current-buffer gnus-article-buffer
5543 ;; Check whether the article displays the right contents.
5544 (unless (with-current-buffer gnus-summary-buffer
5545 (eq gnus-current-article (gnus-summary-article-number)))
5546 (error "You should select the right article first"))
5548 (setq n (prefix-numeric-value n))
5550 (setq n (or (get-text-property pt 'gnus-part)
5552 (get-text-property (1- pt) 'gnus-part))
5553 (get-text-property (prog2
5559 (or (and (setq pt (previous-single-property-change
5562 (next-single-property-change (point) 'gnus-part)
5566 ;; Check whether the specified part exists.
5567 (when (> n (length gnus-article-mime-handle-alist))
5568 (error "No such part")))
5571 ;; To select the window is needed so that the cursor
5572 ;; might be visible on the MIME button.
5573 (select-window (prog1
5575 (setq window (selected-window))
5576 ;; Article may be displayed in the other frame.
5577 (gnus-select-frame-set-input-focus
5580 (setq frame (selected-frame))))))
5581 (when (gnus-article-goto-part n)
5582 ;; We point the cursor and the arrow at the MIME button
5583 ;; when the `function' prompt the user for something.
5584 (unless (and (pos-visible-in-window-p)
5585 (> (count-lines (point) (window-end))
5586 (/ (1- (window-height)) 3)))
5587 (recenter (/ (1- (window-height)) 3)))
5588 (let ((cursor-in-non-selected-windows t)
5589 (overlay-arrow-string "=>")
5590 (overlay-arrow-position (point-marker)))
5593 ((and no-handle interactive)
5594 (call-interactively function))
5599 function (get-text-property (point) 'gnus-data)))
5602 (get-text-property (point) 'gnus-data))))
5603 (set-marker overlay-arrow-position nil)
5604 (unless gnus-auto-select-part
5605 (gnus-select-frame-set-input-focus frame)
5606 (select-window window))))
5608 (if gnus-inhibit-mime-unbuttonizing
5609 ;; This is the default though the program shouldn't reach here.
5610 (error "No such part")
5611 ;; The part which doesn't have the MIME button is selected.
5612 ;; So, we display all the buttons and redo it.
5613 (let ((gnus-inhibit-mime-unbuttonizing t))
5614 (gnus-summary-show-article)
5615 (gnus-article-part-wrapper n function no-handle))))))
5617 (defun gnus-article-pipe-part (n)
5618 "Pipe MIME part N, which is the numerical prefix."
5620 (gnus-article-part-wrapper n 'mm-pipe-part))
5622 (defun gnus-article-save-part (n)
5623 "Save MIME part N, which is the numerical prefix."
5625 (gnus-article-part-wrapper n 'mm-save-part))
5627 (defun gnus-article-interactively-view-part (n)
5628 "View MIME part N interactively, which is the numerical prefix."
5630 (gnus-article-part-wrapper n 'mm-interactively-view-part))
5632 (defun gnus-article-copy-part (n)
5633 "Copy MIME part N, which is the numerical prefix."
5635 (gnus-article-part-wrapper n 'gnus-mime-copy-part))
5637 (defun gnus-article-view-part-as-charset (n)
5638 "View MIME part N using a specified charset.
5639 N is the numerical prefix."
5641 (gnus-article-part-wrapper n 'gnus-mime-view-part-as-charset))
5643 (defun gnus-article-view-part-externally (n)
5644 "View MIME part N externally, which is the numerical prefix."
5646 (gnus-article-part-wrapper n 'gnus-mime-view-part-externally))
5648 (defun gnus-article-inline-part (n)
5649 "Inline MIME part N, which is the numerical prefix."
5651 (gnus-article-part-wrapper n 'gnus-mime-inline-part))
5653 (defun gnus-article-save-part-and-strip (n)
5654 "Save MIME part N and replace it with an external body.
5655 N is the numerical prefix."
5657 (gnus-article-part-wrapper n 'gnus-mime-save-part-and-strip t))
5659 (defun gnus-article-replace-part (n)
5660 "Replace MIME part N with an external body.
5661 N is the numerical prefix."
5663 (gnus-article-part-wrapper n 'gnus-mime-replace-part t t))
5665 (defun gnus-article-delete-part (n)
5666 "Delete MIME part N and add some information about the removed part.
5667 N is the numerical prefix."
5669 (gnus-article-part-wrapper n 'gnus-mime-delete-part t))
5671 (defun gnus-article-view-part-as-type (n)
5672 "Choose a MIME media type, and view part N as such.
5673 N is the numerical prefix."
5675 (gnus-article-part-wrapper n 'gnus-mime-view-part-as-type t))
5677 (defun gnus-article-mime-match-handle-first (condition)
5680 (dolist (ihandle gnus-article-mime-handle-alist)
5682 ((functionp condition)
5683 (funcall condition (cdr ihandle)))
5684 ((eq condition 'undisplayed)
5685 (not (or (mm-handle-undisplayer (cdr ihandle))
5686 (equal (mm-handle-media-type (cdr ihandle))
5687 "multipart/alternative"))))
5688 ((eq condition 'undisplayed-alternative)
5689 (not (mm-handle-undisplayer (cdr ihandle))))
5691 (gnus-article-goto-part (car ihandle))
5692 (or (not n) (< (car ihandle) n)))
5693 (setq n (car ihandle))))
5697 (defun gnus-article-view-part (&optional n)
5698 "View MIME part N, which is the numerical prefix.
5699 If the part is already shown, hide the part. If N is nil, view
5702 (with-current-buffer gnus-article-buffer
5703 (or (numberp n) (setq n (gnus-article-mime-match-handle-first
5704 gnus-article-mime-match-handle-function)))
5705 (when (> n (length gnus-article-mime-handle-alist))
5706 (error "No such part"))
5707 (let ((handle (cdr (assq n gnus-article-mime-handle-alist))))
5708 (when (gnus-article-goto-part n)
5709 (if (equal (car handle) "multipart/alternative")
5711 (beginning-of-line) ;; Make it toggle subparts
5712 (gnus-article-press-button))
5713 (when (eq (gnus-mm-display-part handle) 'internal)
5714 (gnus-set-window-start)))))))
5716 (defsubst gnus-article-mime-total-parts ()
5717 (if (bufferp (car gnus-article-mime-handles))
5719 (1- (length gnus-article-mime-handles))))
5721 (defun gnus-mm-display-part (handle)
5722 "Display HANDLE and fix MIME button."
5723 (let ((id (get-text-property (point) 'gnus-part))
5725 (inhibit-read-only t)
5726 (window (selected-window))
5727 (mail-parse-charset gnus-newsgroup-charset)
5728 (mail-parse-ignored-charsets
5729 (if (gnus-buffer-live-p gnus-summary-buffer)
5730 (with-current-buffer gnus-summary-buffer
5731 gnus-newsgroup-ignored-charsets)
5736 (let ((win (gnus-get-buffer-window (current-buffer) t)))
5740 (setq start (next-single-property-change point 'gnus-data
5742 point (previous-single-property-change start 'gnus-data))
5743 (if (mm-handle-displayed-p handle)
5744 ;; This will remove the part.
5745 (setq point (copy-marker point)
5746 retval (mm-display-part handle))
5747 (let ((part (or (and (mm-inlinable-p handle)
5748 (mm-inlined-p handle)
5752 (setq retval (mm-display-part handle)))
5753 (unless (zerop (buffer-size))
5754 (buffer-string))))))
5757 ;; This is a header button.
5759 (cond ((stringp part)
5761 (narrow-to-region (point)
5764 (unless (bolp) (insert "\n"))
5766 (gnus-treat-article nil id
5767 (gnus-article-mime-total-parts)
5768 (mm-handle-media-type handle))
5769 (mm-handle-set-undisplayer
5772 (let ((inhibit-read-only t))
5773 (delete-region ,(copy-marker (point-min) t)
5774 ,(point-max-marker)))))))
5776 (mm-display-inline handle))))))
5777 (when (markerp point)
5778 (setq point (prog1 (marker-position point)
5779 (set-marker point nil))))
5781 ;; Toggle the button appearance between `[button]...' and `[button]'.
5782 (let ((displayed-p (mm-handle-displayed-p handle)))
5783 (gnus-insert-mime-button handle id (list displayed-p))
5784 (if (featurep 'emacs)
5787 (next-single-property-change (point) 'gnus-data nil (point-max)))
5788 (let* ((end (next-single-property-change (point) 'gnus-data))
5789 (annots (annotations-at (or end (point-max)))))
5790 (delete-region (point)
5792 (if annots (1+ end) end)
5794 (dolist (annot annots)
5795 (set-extent-endpoints annot (point) (point)))))
5796 (setq start (point))
5797 (if (search-backward "\n\n" nil t)
5800 (unless (or displayed-p (eolp))
5801 ;; Add extra newline.
5802 (insert (propertize (buffer-substring (1- start) start)
5803 'gnus-undeletable t))))
5804 ;; We're in the article header.
5806 (dolist (ovl (overlays-in point (point)))
5807 (overlay-put ovl 'gnus-button-attachment-extra t)
5808 (overlay-put ovl 'face nil))
5810 (message-narrow-to-field)
5811 (let ((gnus-treatment-function-alist
5812 '((gnus-treat-highlight-headers
5813 gnus-article-highlight-headers))))
5814 (gnus-treat-article 'head)))))
5816 (if (window-live-p window)
5817 (select-window window)))
5820 (defun gnus-article-goto-part (n)
5821 "Go to MIME part N."
5822 (when gnus-break-pages
5826 (let ((start (or (text-property-any (point) (point-max) 'gnus-part n)
5827 ;; There may be header buttons.
5828 (text-property-any (point-min) (point) 'gnus-part n)))
5829 part handle end next handles)
5832 (if (setq handle (get-text-property start 'gnus-data))
5834 ;; Go to the displayed subpart, assuming this is
5835 ;; multipart/alternative.
5838 (while (and (not handle)
5841 (setq next (text-property-not-all part end
5844 handle (get-text-property part 'gnus-data))
5845 (push (cons handle part) handles)
5846 (unless (mm-handle-displayed-p handle)
5848 part (text-property-any part end 'gnus-data nil))))
5850 ;; No subpart is displayed, so we find preferred one.
5852 (cdr (assq (mm-preferred-alternative
5853 (nreverse (mapcar 'car handles)))
5856 (goto-char (1+ part))
5858 (when gnus-break-pages
5859 (gnus-narrow-to-page))))
5861 (defun gnus-insert-mime-button (handle id &optional displayed)
5862 (let ((gnus-tmp-name
5863 (or (mm-handle-filename handle)
5864 (mail-content-type-get (mm-handle-type handle) 'url)
5867 (gnus-tmp-type (mm-handle-media-type handle))
5868 (gnus-tmp-description (or (mm-handle-description handle) ""))
5870 (if (if displayed (car displayed)
5871 (mm-handle-displayed-p handle))
5873 (gnus-tmp-length (with-current-buffer (mm-handle-buffer handle)
5875 gnus-tmp-type-long b e)
5876 (when (string-match ".*/" gnus-tmp-name)
5877 (setq gnus-tmp-name (replace-match "" t t gnus-tmp-name)))
5878 (setq gnus-tmp-type-long (concat gnus-tmp-type
5879 (and (not (equal gnus-tmp-name ""))
5880 (concat "; " gnus-tmp-name))))
5881 (unless (equal gnus-tmp-description "")
5882 (setq gnus-tmp-type-long (concat " --- " gnus-tmp-type-long)))
5885 gnus-mime-button-line-format gnus-mime-button-line-format-alist
5886 `(keymap ,gnus-mime-button-map
5887 gnus-callback gnus-mm-display-part
5888 gnus-part ,gnus-tmp-id
5889 article-type annotation
5893 ;; Exclude a newline.
5896 (when gnus-article-button-face
5897 (overlay-put (make-overlay b e nil t)
5898 'face gnus-article-button-face))
5899 (widget-convert-button
5902 :action 'gnus-widget-press-button
5903 :button-keymap gnus-mime-button-map
5906 ;; Needed to properly clear the message due to a bug in
5907 ;; wid-edit (XEmacs only).
5908 (if (boundp 'help-echo-owns-message)
5909 (setq help-echo-owns-message t))
5911 "%S: %s the MIME part; %S: more options"
5912 (aref gnus-mouse-2 0)
5913 (if (mm-handle-displayed-p (widget-get widget :mime-handle))
5915 (aref gnus-down-mouse-3 0))))))
5917 (defun gnus-widget-press-button (elems _el)
5918 (goto-char (widget-get elems :from))
5919 (gnus-article-press-button))
5921 (defvar gnus-displaying-mime nil)
5923 (defun gnus-display-mime (&optional ihandles)
5924 "Display the MIME parts."
5926 (save-selected-window
5927 (let ((window (get-buffer-window gnus-article-buffer))
5930 (select-window window)
5931 ;; We have to do this since selecting the window
5932 ;; may change the point. So we set the window point.
5933 (set-window-point window point)))
5934 (let ((handles ihandles)
5935 (inhibit-read-only t))
5937 ((setq handles (mm-dissect-buffer nil gnus-article-loose-mime))
5938 (when gnus-article-emulate-mime
5939 (mm-uu-dissect-text-parts handles)))
5940 (gnus-article-emulate-mime
5941 (setq handles (mm-uu-dissect))))
5942 (when (and (not ihandles)
5943 (not gnus-displaying-mime))
5944 ;; Top-level call; we clean up.
5945 (when gnus-article-mime-handles
5946 (mm-destroy-parts gnus-article-mime-handles)
5947 (setq gnus-article-mime-handle-alist nil));; A trick.
5948 (setq gnus-article-mime-handles handles)
5949 ;; We allow users to glean info from the handles.
5950 (when gnus-article-mime-part-function
5951 (gnus-mime-part-function handles)))
5953 (or (not (stringp (car handles)))
5956 (when (and (not ihandles)
5957 (not gnus-displaying-mime))
5958 ;; Clean up for mime parts.
5960 (delete-region (point) (point-max)))
5961 (let ((gnus-displaying-mime t))
5962 (gnus-mime-display-part handles)))
5965 (narrow-to-region (point) (point-max))
5966 (gnus-treat-article nil 1 1 "text/plain")
5969 ;; Highlight the headers.
5973 (narrow-to-region (point-min) (point))
5974 (gnus-article-save-original-date
5975 (gnus-treat-article 'head)))))))
5976 ;; Cope with broken MIME messages.
5977 (goto-char (point-max))
5981 (defcustom gnus-mime-display-multipart-as-mixed nil
5982 "Display \"multipart\" parts as \"multipart/mixed\".
5984 If t, it overrides nil values of
5985 `gnus-mime-display-multipart-alternative-as-mixed' and
5986 `gnus-mime-display-multipart-related-as-mixed'."
5987 :group 'gnus-article-mime
5990 (defcustom gnus-mime-display-multipart-alternative-as-mixed nil
5991 "Display \"multipart/alternative\" parts as \"multipart/mixed\"."
5993 :group 'gnus-article-mime
5996 (defcustom gnus-mime-display-multipart-related-as-mixed nil
5997 "Display \"multipart/related\" parts as \"multipart/mixed\".
5999 If displaying \"text/html\" is discouraged \(see
6000 `mm-discouraged-alternatives') images or other material inside a
6001 \"multipart/related\" part might be overlooked when this variable is nil."
6003 :group 'gnus-article-mime
6006 (defcustom gnus-mime-display-attachment-buttons-in-header t
6007 "Add attachment buttons in the end of the header of an article.
6008 Since MIME attachments tend to be put at the end of an article, we may
6009 overlook them if there is a huge body. This option offers you a copy
6010 of all non-inlinable MIME parts as buttons shown in front of an article.
6011 If nil, don't show those extra buttons."
6013 :group 'gnus-article-mime
6016 (defun gnus-mime-display-part (handle)
6018 ;; Maybe a broken MIME message.
6021 ((not (stringp (car handle)))
6022 (gnus-mime-display-single handle))
6023 ;; User-defined multipart
6024 ((cdr (assoc (car handle) gnus-mime-multipart-functions))
6025 (funcall (cdr (assoc (car handle) gnus-mime-multipart-functions))
6027 ;; multipart/alternative
6028 ((and (equal (car handle) "multipart/alternative")
6029 (not (or gnus-mime-display-multipart-as-mixed
6030 gnus-mime-display-multipart-alternative-as-mixed)))
6031 (let ((id (1+ (length gnus-article-mime-handle-alist))))
6032 (push (cons id handle) gnus-article-mime-handle-alist)
6033 (gnus-mime-display-alternative (cdr handle) nil nil id)))
6034 ;; multipart/related
6035 ((and (equal (car handle) "multipart/related")
6036 (not (or gnus-mime-display-multipart-as-mixed
6037 gnus-mime-display-multipart-related-as-mixed)))
6038 (gnus-mime-display-part (cadr handle)))
6039 ((equal (car handle) "multipart/signed")
6040 (gnus-add-wash-type 'signed)
6041 (gnus-mime-display-security handle))
6042 ((equal (car handle) "multipart/encrypted")
6043 (gnus-add-wash-type 'encrypted)
6044 (gnus-mime-display-security handle))
6045 ;; Other multiparts are handled like multipart/mixed.
6047 (gnus-mime-display-mixed (cdr handle)))))
6049 (defun gnus-mime-part-function (handles)
6050 (if (stringp (car handles))
6051 (mapcar 'gnus-mime-part-function (cdr handles))
6052 (funcall gnus-article-mime-part-function handles)))
6054 (defun gnus-mime-display-mixed (handles)
6055 (mapcar 'gnus-mime-display-part handles))
6057 (defun gnus-mime-display-single (handle)
6058 (let ((type (mm-handle-media-type handle))
6059 (ignored gnus-ignored-mime-types)
6065 (when (string-match (pop ignored) type)
6066 (throw 'ignored nil)))
6067 (if (and (not (and (if (gnus-buffer-live-p gnus-summary-buffer)
6068 (with-current-buffer gnus-summary-buffer
6069 gnus-inhibit-images)
6070 gnus-inhibit-images)
6071 (string-match "\\`image/" type)))
6072 (setq not-attachment
6073 (and (not (mm-inline-override-p handle))
6074 (or (not (mm-handle-disposition handle))
6075 (equal (car (mm-handle-disposition handle))
6077 (mm-attachment-override-p handle))))
6078 (mm-automatic-display-p handle)
6080 (mm-inlinable-p handle)
6081 (mm-inlined-p handle))
6082 (mm-automatic-external-display-p type)))
6084 (when (equal (mm-handle-media-supertype handle) "text")
6086 (let ((id (car (rassq handle gnus-article-mime-handle-alist)))
6089 (setq id (1+ (length gnus-article-mime-handle-alist)))
6090 (push (cons id handle) gnus-article-mime-handle-alist))
6092 (equal (mm-handle-media-supertype handle) "message"))
6095 (cond ((not (bolp)) 2)
6096 ((or (bobp) (eq (char-before (1- (point))) ?\n)) 0)
6098 (when (or (not display)
6099 (not (gnus-unbuttonized-mime-type-p type))
6100 (eq id gnus-mime-buttonized-part-id))
6101 (gnus-insert-mime-button
6102 handle id (list (or display (and not-attachment text)))))
6106 (let ((mail-parse-charset gnus-newsgroup-charset)
6107 (mail-parse-ignored-charsets
6108 (save-excursion (condition-case ()
6109 (set-buffer gnus-summary-buffer)
6111 gnus-newsgroup-ignored-charsets)))
6112 (gnus-bind-mm-vars (mm-display-part handle t))))
6113 ((and text not-attachment)
6114 (mm-display-inline handle)))
6115 (goto-char (point-max))
6116 (if (string-match "\\`image/" type)
6117 (gnus-article-insert-newline)
6119 (= (skip-chars-backward "\n") -1)
6120 (unless (eobp) (forward-char 1)))
6121 (gnus-article-insert-newline)
6122 (put-text-property (point) (point-max) 'gnus-undeletable t))
6123 (goto-char (point-max)))
6127 (narrow-to-region beg (point))
6128 (if (eq handle gnus-article-mime-handles)
6129 ;; The format=flowed case.
6130 (gnus-treat-article nil 1 1 (mm-handle-media-type handle))
6131 ;; Don't count signature parts that are never displayed.
6132 ;; The part number should be re-calculated supposing this
6133 ;; might be a message/rfc822 part.
6135 (dolist (part gnus-article-mime-handles)
6136 (unless (or (stringp part)
6137 (equal (car (mm-handle-type part))
6138 "application/pgp-signature"))
6139 (push part handles)))
6141 nil (length (memq handle handles)) (length handles)
6142 (mm-handle-media-type handle)))))))))))
6144 (defun gnus-unbuttonized-mime-type-p (type)
6145 "Say whether TYPE is to be unbuttonized."
6146 (unless gnus-inhibit-mime-unbuttonizing
6148 (let ((types gnus-unbuttonized-mime-types))
6150 (when (string-match (pop types) type)
6151 (throw 'found t)))))
6153 (let ((types gnus-buttonized-mime-types))
6155 (when (string-match (pop types) type)
6156 (throw 'found t)))))))))
6158 (defun gnus-article-insert-newline ()
6159 "Insert a newline, but mark it as undeletable."
6160 (gnus-put-text-property
6161 (point) (progn (insert "\n") (point)) 'gnus-undeletable t))
6163 (defun gnus-mime-display-alternative (handles &optional preferred ibegend id)
6164 (let* ((preferred (or preferred (mm-preferred-alternative handles)))
6167 handle (inhibit-read-only t) from begend not-pref)
6168 (save-window-excursion
6171 (narrow-to-region (car ibegend)
6174 (goto-char (car ibegend))
6177 (delete-region (point-min) (point-max))
6178 (mm-remove-parts handles))
6179 (setq begend (list (point-marker)))
6181 (unless (setq not-pref (cadr (member preferred ihandles)))
6182 (setq not-pref (car ihandles)))
6185 (not (gnus-unbuttonized-mime-type-p
6186 "multipart/alternative")))
6187 (gnus-add-text-properties
6190 (insert (format "%d. " id))
6194 (unless ,(not ibegend)
6195 (setq gnus-article-mime-handle-alist
6196 ',gnus-article-mime-handle-alist))
6197 (gnus-mime-display-alternative
6198 ',ihandles ',not-pref ',begend ,id))
6199 keymap ,gnus-mime-button-map
6200 ,gnus-mouse-face-prop ,gnus-article-mouse-face
6201 face ,gnus-article-button-face
6203 article-type multipart
6205 (widget-convert-button 'link from (point)
6206 :action 'gnus-widget-press-button
6207 :button-keymap gnus-widget-button-keymap)
6209 (while (setq handle (pop handles))
6210 (gnus-add-text-properties
6213 (insert (format "(%c) %-18s"
6214 (if (equal handle preferred) ?* ? )
6215 (mm-handle-media-type handle)))
6219 (unless ,(not ibegend)
6220 (setq gnus-article-mime-handle-alist
6221 ',gnus-article-mime-handle-alist))
6222 (gnus-mime-display-alternative
6223 ',ihandles ',handle ',begend ,id))
6224 keymap ,gnus-mime-button-map
6225 ,gnus-mouse-face-prop ,gnus-article-mouse-face
6226 face ,gnus-article-button-face
6230 (widget-convert-button 'link from (point)
6231 :action 'gnus-widget-press-button
6232 :button-keymap gnus-widget-button-keymap)
6236 (if (stringp (car preferred))
6237 (gnus-display-mime preferred)
6238 (let ((mail-parse-charset gnus-newsgroup-charset)
6239 (mail-parse-ignored-charsets
6240 (with-current-buffer gnus-summary-buffer
6241 gnus-newsgroup-ignored-charsets)))
6242 (gnus-bind-mm-vars (mm-display-part preferred))
6246 (narrow-to-region (car begend) (point-max))
6248 nil (length gnus-article-mime-handle-alist)
6249 (gnus-article-mime-total-parts)
6250 (mm-handle-media-type preferred))))))
6251 (goto-char (point-max))
6252 (setcdr begend (point-marker)))))
6255 ;; Redraw attachment buttons in the header.
6256 (when gnus-mime-display-attachment-buttons-in-header
6257 (gnus-mime-buttonize-attachments-in-header)))
6259 (defconst gnus-article-wash-status-strings
6260 (let ((alist '((cite "c" "Possible hidden citation text"
6261 " " "All citation text visible")
6262 (headers "h" "Hidden headers"
6263 " " "All headers visible.")
6264 (pgp "p" "Encrypted or signed message status hidden"
6265 " " "No hidden encryption nor digital signature status")
6266 (signature "s" "Signature has been hidden"
6267 " " "Signature is visible")
6268 (overstrike "o" "Overstrike (^H) characters applied"
6269 " " "No overstrike characters applied")
6270 (emphasis "e" "/*_Emphasis_*/ characters applied"
6271 " " "No /*_emphasis_*/ characters applied")))
6273 (dolist (entry alist result)
6274 (let ((key (nth 0 entry))
6275 (on (copy-sequence (nth 1 entry)))
6276 (on-help (nth 2 entry))
6277 (off (copy-sequence (nth 3 entry)))
6278 (off-help (nth 4 entry)))
6279 (put-text-property 0 1 'help-echo on-help on)
6280 (put-text-property 0 1 'help-echo off-help off)
6281 (push (list key on off) result))))
6282 "Alist of strings describing wash status in the mode line.
6283 Each entry has the form (KEY ON OF), where the KEY is a symbol
6284 representing the particular washing function, ON is the string to use
6285 in the article mode line when the washing function is active, and OFF
6286 is the string to use when it is inactive.")
6288 (defun gnus-article-wash-status-entry (key value)
6289 (let ((entry (assoc key gnus-article-wash-status-strings)))
6290 (if value (nth 1 entry) (nth 2 entry))))
6292 (defun gnus-article-wash-status ()
6293 "Return a string which display status of article washing."
6294 (with-current-buffer gnus-article-buffer
6295 (let ((cite (memq 'cite gnus-article-wash-types))
6296 (headers (memq 'headers gnus-article-wash-types))
6297 (boring (memq 'boring-headers gnus-article-wash-types))
6298 (pgp (memq 'pgp gnus-article-wash-types))
6299 (pem (memq 'pem gnus-article-wash-types))
6300 (signed (memq 'signed gnus-article-wash-types))
6301 (encrypted (memq 'encrypted gnus-article-wash-types))
6302 (signature (memq 'signature gnus-article-wash-types))
6303 (overstrike (memq 'overstrike gnus-article-wash-types))
6304 (emphasis (memq 'emphasis gnus-article-wash-types)))
6306 (gnus-article-wash-status-entry 'cite cite)
6307 (gnus-article-wash-status-entry 'headers (or headers boring))
6308 (gnus-article-wash-status-entry 'pgp (or pgp pem signed encrypted))
6309 (gnus-article-wash-status-entry 'signature signature)
6310 (gnus-article-wash-status-entry 'overstrike overstrike)
6311 (gnus-article-wash-status-entry 'emphasis emphasis)))))
6313 (defun gnus-add-wash-type (type)
6314 "Add a washing of TYPE to the current status."
6315 (add-to-list 'gnus-article-wash-types type))
6317 (defun gnus-delete-wash-type (type)
6318 "Add a washing of TYPE to the current status."
6319 (setq gnus-article-wash-types (delq type gnus-article-wash-types)))
6321 (defun gnus-add-image (category image)
6322 "Add IMAGE of CATEGORY to the list of displayed images."
6323 (let ((entry (assq category gnus-article-image-alist)))
6325 (setq entry (list category))
6326 (push entry gnus-article-image-alist))
6327 (nconc entry (list image))))
6329 (defun gnus-delete-images (category)
6330 "Delete all images in CATEGORY."
6331 (let ((entry (assq category gnus-article-image-alist)))
6332 (dolist (image (cdr entry))
6333 (gnus-remove-image image category))
6334 (setq gnus-article-image-alist (delq entry gnus-article-image-alist))
6335 (gnus-delete-wash-type category)))
6337 (defalias 'gnus-article-hide-headers-if-wanted 'gnus-article-maybe-hide-headers)
6339 (defun gnus-article-maybe-hide-headers ()
6340 "Hide unwanted headers if `gnus-have-all-headers' is nil.
6341 Provided for backwards compatibility."
6342 (when (and (or (not (gnus-buffer-live-p gnus-summary-buffer))
6343 (not (with-current-buffer gnus-summary-buffer
6344 gnus-have-all-headers)))
6345 (not gnus-inhibit-hiding))
6346 (gnus-article-hide-headers)))
6348 (declare-function shr-put-image "shr" (data alt &optional flags))
6350 (defun gnus-shr-put-image (data alt &optional flags)
6351 "Put image DATA with a string ALT. Enable image to be deleted."
6352 (let ((image (if flags
6353 (shr-put-image data (propertize (or alt "*")
6354 'gnus-image-category 'shr)
6356 ;; Old `shr-put-image' doesn't take the optional `flags'
6358 (shr-put-image data (propertize (or alt "*")
6359 'gnus-image-category 'shr)))))
6361 (gnus-add-image 'shr image))))
6363 (defun gnus-article-mime-handles (&optional alist id all)
6365 (let ((i 1) newid flat)
6366 (dolist (handle alist flat)
6367 (setq newid (append id (list i))
6369 (if (stringp (car handle))
6370 (setq flat (nconc flat (gnus-article-mime-handles
6371 (cdr handle) newid all)))
6372 (delq (rassq handle all) all)
6373 (setq flat (nconc flat (list (cons newid handle)))))))
6374 (let ((flat (list nil)))
6375 ;; Assume that elements of `gnus-article-mime-handle-alist'
6376 ;; are in the decreasing order, but unnumbered subsidiaries
6377 ;; in each element are in the increasing order.
6378 (dolist (handle (reverse gnus-article-mime-handle-alist))
6379 (if (stringp (cadr handle))
6380 (setq flat (nconc flat (gnus-article-mime-handles
6381 (cddr handle) (list (car handle)) flat)))
6382 (delq (rassq (cdr handle) flat) flat)
6383 (setq flat (nconc flat (list (cons (list (car handle))
6385 (setq flat (cdr flat))
6386 (mapc (lambda (handle)
6388 ;; This is a hidden (i.e. unnumbered) handle.
6391 (1+ (caar gnus-article-mime-handle-alist)))
6392 (push handle gnus-article-mime-handle-alist))
6393 (setcar handle (caar handle))))
6397 (defun gnus-mime-buttonize-attachments-in-header (&optional interactive)
6398 "Show attachments as buttons in the end of the header of an article.
6399 This function toggles the display when called interactively. Note that
6400 buttons to be added to the header are only the ones that aren't inlined
6401 in the body. Use `gnus-header-face-alist' to highlight buttons."
6402 (interactive (list t))
6403 (gnus-with-article-buffer
6404 (let ((case-fold-search t) buttons handle type st)
6408 (article-narrow-to-head)
6409 ;; Header buttons exist?
6410 (while (and (not buttons)
6411 (re-search-forward "^attachments?:[\n ]+" nil t))
6412 (when (get-char-property (match-end 0)
6413 'gnus-button-attachment-extra)
6414 (setq buttons (match-beginning 0))))
6417 ;; Delete header buttons.
6418 (delete-region buttons (if (re-search-forward "^[^ ]" nil t)
6421 (unless (and interactive buttons)
6424 (dolist (button (gnus-article-mime-handles))
6425 (setq handle (cdr button)
6426 type (mm-handle-media-type handle))
6427 (when (or (and (if (gnus-buffer-live-p gnus-summary-buffer)
6428 (with-current-buffer gnus-summary-buffer
6429 gnus-inhibit-images)
6430 gnus-inhibit-images)
6431 (string-match "\\`image/" type))
6432 (mm-inline-override-p handle)
6433 (and (mm-handle-disposition handle)
6434 (not (equal (car (mm-handle-disposition handle))
6436 (not (mm-attachment-override-p handle)))
6437 (not (mm-automatic-display-p handle))
6438 (not (or (and (mm-inlinable-p handle)
6439 (mm-inlined-p handle))
6440 (mm-automatic-external-display-p type))))
6441 (push button buttons)))
6443 ;; Add header buttons.
6446 (narrow-to-region (point) (point))
6447 (insert "Attachment" (if (cdr buttons) "s" "") ":")
6448 (dolist (button (nreverse buttons))
6451 (mm-handle-set-undisplayer (setq handle (cdr button)) nil)
6452 (gnus-insert-mime-button handle (car button))
6453 (skip-chars-backward "\t\n ")
6454 (delete-region (point) (point-max))
6455 (when (> (current-column) (window-width))
6460 (dolist (ovl (overlays-in (point-min) (point)))
6461 (overlay-put ovl 'gnus-button-attachment-extra t)
6462 (overlay-put ovl 'face nil))
6463 (let ((gnus-treatment-function-alist
6464 '((gnus-treat-highlight-headers
6465 gnus-article-highlight-headers))))
6466 (gnus-treat-article 'head)))))))))
6470 (defun gnus-output-to-file (file-name)
6471 "Append the current article to a file named FILE-NAME.
6472 If `gnus-article-save-coding-system' is non-nil, it is used to encode
6473 text and used as the value of the coding cookie which is added to the
6474 top of a file. Otherwise, this function saves a raw article without
6476 (let* ((artbuf (current-buffer))
6477 (file-name-coding-system nnmail-pathname-coding-system)
6478 (coding gnus-article-save-coding-system)
6479 (coding-system-for-read (if coding
6480 nil ;; Rely on the coding cookie.
6481 mm-text-coding-system))
6482 (coding-system-for-write (or coding
6483 mm-text-coding-system-for-write
6484 mm-text-coding-system))
6485 (exists (file-exists-p file-name)))
6488 (insert-file-contents file-name)
6489 (goto-char (point-min))
6490 ;; Remove the existing coding cookie.
6491 (when (looking-at "X-Gnus-Coding-System: .+\n\n")
6492 (delete-region (match-beginning 0) (match-end 0))))
6493 (goto-char (point-max))
6494 (insert-buffer-substring artbuf)
6495 ;; Append newline at end of the buffer as separator, and then
6497 (goto-char (point-max))
6500 ;; If the coding system is not suitable to encode the text,
6501 ;; ask a user for a proper one.
6502 (when (fboundp 'select-safe-coding-system)
6503 (setq coding (coding-system-base
6504 (save-window-excursion
6505 (select-safe-coding-system (point-min) (point-max)
6507 (setq coding-system-for-write
6508 (or (cdr (assq coding '((mule-utf-8 . utf-8))))
6510 (goto-char (point-min))
6511 ;; Add the coding cookie.
6512 (insert (format "X-Gnus-Coding-System: -*- coding: %s; -*-\n\n"
6513 coding-system-for-write)))
6516 (write-region (point-min) (point-max) file-name nil 'no-message)
6517 (message "Appended to %s" file-name))
6518 (write-region (point-min) (point-max) file-name))))
6521 (defun gnus-narrow-to-page (&optional arg)
6522 "Narrow the article buffer to a page.
6523 If given a numerical ARG, move forward ARG pages."
6525 (setq arg (if arg (prefix-numeric-value arg) 0))
6526 (with-current-buffer gnus-article-buffer
6528 ;; Remove any old next/prev buttons.
6529 (when (gnus-visual-p 'page-marker)
6530 (let ((inhibit-read-only t))
6531 (gnus-remove-text-with-property 'gnus-prev)
6532 (gnus-remove-text-with-property 'gnus-next)))
6534 (when (save-excursion
6536 (if (re-search-backward page-delimiter nil 'move (abs arg))
6538 (setq nd (match-beginning 0)
6540 (when (re-search-backward page-delimiter nil t)
6541 (setq st (match-end 0))))
6542 (when (re-search-forward page-delimiter nil t)
6543 (setq nd (match-beginning 0)
6546 (if (re-search-forward page-delimiter nil 'move arg)
6548 (setq st (match-end 0)
6550 (when (re-search-forward page-delimiter nil t)
6551 (setq nd (match-beginning 0))))
6552 (when (re-search-backward page-delimiter nil t)
6553 (setq st (match-end 0)
6556 (when (re-search-backward page-delimiter nil t)
6557 (goto-char (setq st (match-end 0))))
6558 (when (re-search-forward page-delimiter nil t)
6559 (setq nd (match-beginning 0)))
6561 (setq gnus-page-broken t)
6562 (when pt (goto-char pt))
6563 (narrow-to-region (or st (point-min)) (or nd (point-max)))
6564 (when (gnus-visual-p 'page-marker)
6568 (gnus-insert-next-page-button))
6571 (gnus-insert-prev-page-button))))))))
6573 ;; Article mode commands
6575 (defun gnus-article-goto-next-page ()
6576 "Show the next page of the article."
6578 (when (gnus-article-next-page)
6579 (goto-char (point-min))
6580 (gnus-article-read-summary-keys nil (gnus-character-to-event ?n))))
6583 (defun gnus-article-goto-prev-page ()
6584 "Show the previous page of the article."
6586 (if (save-restriction (widen) (bobp)) ;; Real beginning-of-buffer?
6587 (gnus-article-read-summary-keys nil (gnus-character-to-event ?p))
6588 (gnus-article-prev-page nil)))
6590 ;; This is cleaner but currently breaks `gnus-pick-mode':
6592 ;; (defun gnus-article-goto-next-page ()
6593 ;; "Show the next page of the article."
6595 ;; (gnus-eval-in-buffer-window gnus-summary-buffer
6596 ;; (gnus-summary-next-page)))
6598 ;; (defun gnus-article-goto-prev-page ()
6599 ;; "Show the next page of the article."
6601 ;; (gnus-eval-in-buffer-window gnus-summary-buffer
6602 ;; (gnus-summary-prev-page)))
6604 (defun gnus-article-next-page (&optional lines)
6605 "Show the next page of the current article.
6606 If end of article, return non-nil. Otherwise return nil.
6607 Argument LINES specifies lines to be scrolled up."
6609 (move-to-window-line (if (featurep 'xemacs) -1 (- -1 scroll-margin)))
6610 (if (and (not (and gnus-article-over-scroll
6611 (> (count-lines (window-start) (point-max))
6612 (if (featurep 'xemacs)
6613 (or lines (1- (window-height)))
6614 (+ (or lines (1- (window-height))) scroll-margin)))))
6617 (and (pos-visible-in-window-p) ;Not continuation line.
6618 (>= (point) (point-max)))))
6619 ;; Nothing in this page.
6620 (if (or (not gnus-page-broken)
6625 (eobp)))) ;Real end-of-buffer?
6627 (when gnus-article-over-scroll
6628 (gnus-article-next-page-1 lines))
6630 (gnus-narrow-to-page 1) ;Go to next page.
6632 ;; More in this page.
6633 (gnus-article-next-page-1 lines)
6636 (defun gnus-article-beginning-of-window ()
6637 "Move point to the beginning of the window.
6638 In Emacs, the point is placed at the line number which `scroll-margin'
6640 (if (featurep 'xemacs)
6641 (move-to-window-line 0)
6642 ;; There is an obscure bug in Emacs that makes it impossible to
6643 ;; scroll past big pictures in the article buffer. Try to fix
6644 ;; this by adding a sanity check by counting the lines visible.
6645 (when (> (count-lines (window-start) (window-end)) 30)
6646 (move-to-window-line
6647 (min (max 0 scroll-margin)
6648 (max 1 (- (window-height)
6649 (if mode-line-format 1 0)
6650 (if header-line-format 1 0)
6653 (defvar scroll-in-place)
6655 (defun gnus-article-next-page-1 (lines)
6657 (let ((scroll-in-place nil)
6658 (auto-window-vscroll nil))
6661 ;; Long lines may cause an end-of-buffer error.
6662 (goto-char (point-max))))
6663 (gnus-article-beginning-of-window))
6665 (defun gnus-article-prev-page (&optional lines)
6666 "Show previous page of current article.
6667 Argument LINES specifies lines to be scrolled down."
6669 (move-to-window-line 0)
6670 (if (and gnus-page-broken
6672 (not (save-restriction (widen) (bobp)))) ;Real beginning-of-buffer?
6674 (gnus-narrow-to-page -1) ;Go to previous page.
6675 (goto-char (point-max))
6676 (recenter (if gnus-article-over-scroll
6678 (max (if (featurep 'xemacs)
6680 (+ lines scroll-margin))
6682 (- (window-height) 2))
6686 (let ((scroll-in-place nil))
6687 (scroll-down lines))
6688 (beginning-of-buffer
6689 (goto-char (point-min))))
6690 (gnus-article-beginning-of-window))))
6692 (defun gnus-article-only-boring-p ()
6693 "Decide whether there is only boring text remaining in the article.
6694 Something \"interesting\" is a word of at least two letters that does
6695 not have a face in `gnus-article-boring-faces'."
6696 (when (and gnus-article-skip-boring
6697 (boundp 'gnus-article-boring-faces)
6698 (symbol-value 'gnus-article-boring-faces))
6700 (let ((inhibit-point-motion-hooks t))
6702 (while (re-search-forward "\\b\\w\\w" nil t)
6704 (when (not (gnus-intersection
6705 (gnus-faces-at (point))
6706 (symbol-value 'gnus-article-boring-faces)))
6707 (throw 'only-boring nil)))
6708 (throw 'only-boring t))))))
6710 (defun gnus-article-refer-article ()
6711 "Read article specified by message-id around point."
6714 (re-search-backward "[ \t]\\|^" (point-at-bol) t)
6715 (re-search-forward "<?news:<?\\|<" (point-at-eol) t)
6716 (if (re-search-forward "[^@ ]+@[^ \t>]+" (point-at-eol) t)
6717 (let ((msg-id (concat "<" (match-string 0) ">")))
6718 (set-buffer gnus-summary-buffer)
6719 (gnus-summary-refer-article msg-id))
6720 (error "No references around point"))))
6722 (defun gnus-article-show-summary ()
6723 "Reconfigure windows to show summary buffer."
6725 (if (not (gnus-buffer-live-p gnus-summary-buffer))
6726 (error "There is no summary buffer for this article buffer")
6727 (gnus-article-set-globals)
6728 (gnus-configure-windows 'article)
6729 (gnus-summary-goto-subject gnus-current-article)
6730 (gnus-summary-position-point)))
6732 (defun gnus-article-describe-briefly ()
6733 "Describe article mode commands briefly."
6735 (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")))
6737 (defun gnus-article-check-buffer ()
6738 "Beep if not in an article buffer."
6739 (unless (derived-mode-p 'gnus-article-mode)
6740 (error "Command invoked outside of a Gnus article buffer")))
6742 (defvar gnus-pick-mode)
6744 (defun gnus-article-read-summary-keys (&optional _arg key not-restore-window)
6745 "Read a summary buffer key sequence and execute it from the article buffer."
6747 (gnus-article-check-buffer)
6749 '("q" "Q" "c" "r" "\C-c\C-f" "m" "a" "f"
6750 "Zc" "ZC" "ZE" "ZQ" "ZZ" "Zn" "ZR" "ZG" "ZN" "ZP"
6751 "=" "^" "\M-^" "|"))
6753 '("A " "A<" "A>" "AM" "AP" "AR" "AT" "A\C-?" "A\M-\r" "A\r" "Ab" "Ae"
6754 "An" "Ap" [?A (meta return)] [?A delete]))
6758 (with-current-buffer gnus-article-current-summary
6759 (let (gnus-pick-mode)
6760 (setq unread-command-events (nconc unread-command-events
6761 (list (or key last-command-event)))
6762 keys (if (featurep 'xemacs)
6763 (events-to-keys (read-key-sequence nil t))
6764 (read-key-sequence nil t)))))
6769 ((eq (aref keys (1- (length keys))) ?\C-h)
6770 (gnus-article-describe-bindings (substring keys 0 -1)))
6771 ((or (member keys nosaves)
6772 (member keys nosave-but-article)
6773 (member keys nosave-in-article))
6775 (save-window-excursion
6776 (pop-to-buffer gnus-article-current-summary)
6777 ;; We disable the pick minor mode commands.
6778 (let (gnus-pick-mode)
6779 (setq func (key-binding keys t))))
6783 (unless (member keys nosave-in-article)
6784 (set-buffer gnus-article-current-summary))
6785 (when (and (symbolp func)
6786 (get func 'disabled))
6787 (error "Function %s disabled" func))
6788 (call-interactively func)
6789 (setq new-sum-point (point)))
6790 (when (member keys nosave-but-article)
6791 (pop-to-buffer gnus-article-buffer))))
6793 ;; These commands should restore window configuration.
6794 (let ((obuf (current-buffer))
6795 (owin (current-window-configuration))
6796 win func in-buffer selected new-sum-start new-sum-hscroll err)
6797 (cond (not-restore-window
6798 (pop-to-buffer gnus-article-current-summary)
6799 (setq win (selected-window)))
6800 ((setq win (get-buffer-window gnus-article-current-summary))
6801 (select-window win))
6803 (let ((summary-buffer gnus-article-current-summary))
6804 (gnus-configure-windows 'article)
6805 (unless (setq win (get-buffer-window summary-buffer 'visible))
6806 (let ((gnus-buffer-configuration
6807 '((article ((vertical 1.0
6808 (summary 0.25 point)
6810 (gnus-configure-windows 'article))
6811 (setq win (get-buffer-window summary-buffer 'visible)))
6812 (gnus-select-frame-set-input-focus (window-frame win))
6813 (select-window win))))
6814 (setq in-buffer (current-buffer))
6815 ;; We disable the pick minor mode commands.
6816 (setq func (let (gnus-pick-mode)
6817 (key-binding keys t)))
6818 (when (get func 'disabled)
6819 (error "Function %s disabled" func))
6822 (condition-case code
6824 (call-interactively func)
6830 (when (eq win (selected-window))
6831 (setq new-sum-point (point)
6832 new-sum-start (window-start win)
6833 new-sum-hscroll (window-hscroll win)))
6834 (when (or (eq in-buffer (current-buffer))
6835 (when (eq obuf (current-buffer))
6836 (set-buffer in-buffer)
6838 (setq selected (ignore-errors (gnus-summary-select-article)))
6840 (unless not-restore-window
6841 (set-window-configuration owin))
6842 (when (and (eq selected 'old)
6844 (set-window-start (get-buffer-window (current-buffer))
6846 (set-window-point (get-buffer-window (current-buffer))
6847 (if (article-goto-body)
6850 (when (and (not not-restore-window)
6853 (with-current-buffer (window-buffer win)
6854 (derived-mode-p 'gnus-summary-mode)))
6855 (set-window-point win new-sum-point)
6856 (set-window-start win new-sum-start)
6857 (set-window-hscroll win new-sum-hscroll))))
6858 (set-window-configuration owin)
6860 (signal (car err) (cdr err))
6863 (defun gnus-article-read-summary-send-keys ()
6865 (let ((unread-command-events (list (gnus-character-to-event ?S))))
6866 (gnus-article-read-summary-keys)))
6868 (defun gnus-article-describe-key (key)
6869 "Display documentation of the function invoked by KEY.
6870 KEY is a string or a vector."
6871 (interactive (list (let ((cursor-in-echo-area t)) ;; better for XEmacs.
6872 (read-key-sequence "Describe key: "))))
6873 (gnus-article-check-buffer)
6874 (if (memq (key-binding key t) '(gnus-article-read-summary-keys
6875 gnus-article-read-summary-send-keys))
6876 (with-current-buffer gnus-article-current-summary
6877 (setq unread-command-events
6878 (if (featurep 'xemacs)
6879 (append key unread-command-events)
6881 (mapcar (lambda (x) (if (and (integerp x) (>= x 128))
6882 (list 'meta (- x 128))
6885 unread-command-events)))
6886 (let ((cursor-in-echo-area t)
6888 (describe-key (read-key-sequence nil t))))
6889 (describe-key key)))
6891 (defun gnus-article-describe-key-briefly (key &optional insert)
6892 "Display documentation of the function invoked by KEY.
6893 KEY is a string or a vector."
6894 (interactive (list (let ((cursor-in-echo-area t)) ;; better for XEmacs.
6895 (read-key-sequence "Describe key: "))
6896 current-prefix-arg))
6897 (gnus-article-check-buffer)
6898 (if (memq (key-binding key t) '(gnus-article-read-summary-keys
6899 gnus-article-read-summary-send-keys))
6900 (with-current-buffer gnus-article-current-summary
6901 (setq unread-command-events
6902 (if (featurep 'xemacs)
6903 (append key unread-command-events)
6905 (mapcar (lambda (x) (if (and (integerp x) (>= x 128))
6906 (list 'meta (- x 128))
6909 unread-command-events)))
6910 (let ((cursor-in-echo-area t)
6912 (describe-key-briefly (read-key-sequence nil t) insert)))
6913 (describe-key-briefly key insert)))
6915 ;;`gnus-agent-mode' in gnus-agent.el will define it.
6916 (defvar gnus-agent-summary-mode)
6917 (defvar gnus-draft-mode)
6918 (defvar help-xref-stack-item)
6919 (defvar help-xref-following)
6921 (defun gnus-article-describe-bindings (&optional prefix)
6922 "Show a list of all defined keys, and their definitions.
6923 The optional argument PREFIX, if non-nil, should be a key sequence;
6924 then we display only bindings that start with that prefix."
6926 (gnus-article-check-buffer)
6927 (let ((keymap (copy-keymap gnus-article-mode-map))
6928 (map (copy-keymap gnus-article-send-map))
6929 (sumkeys (where-is-internal 'gnus-article-read-summary-keys))
6931 (define-key keymap "S" map)
6932 (define-key map [t] nil)
6933 (with-current-buffer gnus-article-current-summary
6936 (if (setq parent (keymap-parent gnus-article-mode-map))
6938 (setq parent (copy-keymap parent))
6939 (set-keymap-parent parent (current-local-map)))
6940 (current-local-map)))
6941 (set-keymap-parent map (key-binding "S"))
6942 (let (key def gnus-pick-mode)
6944 (setq key (pop sumkeys))
6945 (cond ((and (vectorp key) (= (length key) 1)
6946 (consp (setq def (aref key 0)))
6947 (numberp (car def)) (numberp (cdr def)))
6948 (when (< (max (car def) (cdr def)) 128)
6952 (nreverse (gnus-uncompress-range def)))
6954 ((setq def (key-binding key))
6955 (unless (eq def 'undefined)
6956 (define-key keymap key def))))))
6957 (when (boundp 'gnus-agent-summary-mode)
6958 (setq agent gnus-agent-summary-mode))
6959 (when (boundp 'gnus-draft-mode)
6960 (setq draft gnus-draft-mode)))
6962 (use-local-map keymap)
6963 (set (make-local-variable 'gnus-agent-summary-mode) agent)
6964 (set (make-local-variable 'gnus-draft-mode) draft)
6965 (describe-bindings prefix))
6966 (let ((item `((lambda (prefix)
6967 (with-current-buffer ,(current-buffer)
6968 (gnus-article-describe-bindings prefix)))
6970 ;; Loading `help-mode' here is necessary if `describe-bindings'
6971 ;; is replaced with something, e.g. `helm-descbinds'.
6972 (require 'help-mode)
6973 (with-current-buffer (let (help-xref-following) (help-buffer))
6974 (setq help-xref-stack-item item)))))
6976 (defun gnus-article-reply-with-original (&optional wide)
6977 "Start composing a reply mail to the current message.
6978 The text in the region will be yanked. If the region isn't active,
6979 the entire article will be yanked."
6981 (let ((article (cdr gnus-article-current))
6983 (if (not (gnus-region-active-p))
6984 (with-current-buffer gnus-summary-buffer
6985 (gnus-summary-reply (list (list article)) wide))
6986 (setq contents (buffer-substring (point) (mark t)))
6987 ;; Deactivate active regions.
6988 (when (and (boundp 'transient-mark-mode)
6989 transient-mark-mode)
6990 (setq mark-active nil))
6991 (with-current-buffer gnus-summary-buffer
6993 (list (list article contents)) wide)))))
6995 (defun gnus-article-wide-reply-with-original ()
6996 "Start composing a wide reply mail to the current message.
6997 The text in the region will be yanked. If the region isn't active,
6998 the entire article will be yanked."
7000 (gnus-article-reply-with-original t))
7002 (defun gnus-article-followup-with-original ()
7003 "Compose a followup to the current article.
7004 The text in the region will be yanked. If the region isn't active,
7005 the entire article will be yanked."
7007 (let ((article (cdr gnus-article-current))
7009 (if (not (gnus-region-active-p))
7010 (with-current-buffer gnus-summary-buffer
7011 (gnus-summary-followup (list (list article))))
7012 (setq contents (buffer-substring (point) (mark t)))
7013 ;; Deactivate active regions.
7014 (when (and (boundp 'transient-mark-mode)
7015 transient-mark-mode)
7016 (setq mark-active nil))
7017 (with-current-buffer gnus-summary-buffer
7018 (gnus-summary-followup
7019 (list (list article contents)))))))
7021 (defun gnus-article-hide (&optional arg force)
7022 "Hide all the gruft in the current article.
7023 This means that signatures, cited text and (some) headers will be
7025 If given a prefix, show the hidden text instead."
7026 (interactive (append (gnus-article-hidden-arg) (list 'force)))
7027 (gnus-article-hide-headers arg)
7028 (gnus-article-hide-list-identifiers arg)
7029 (gnus-article-hide-citation-maybe arg force)
7030 (gnus-article-hide-signature arg))
7032 (defun gnus-check-group-server ()
7033 ;; Make sure the connection to the server is alive.
7034 (unless (gnus-server-opened
7035 (gnus-find-method-for-group gnus-newsgroup-name))
7036 (gnus-check-server (gnus-find-method-for-group gnus-newsgroup-name))
7037 (gnus-request-group gnus-newsgroup-name t)))
7039 (declare-function nneething-get-file-name "nneething" (id))
7041 (defun gnus-request-article-this-buffer (article group)
7042 "Get an article and insert it into this buffer."
7043 (let (do-update-line sparse-header)
7047 (gnus-kill-all-overlays)
7048 (setq group (or group gnus-newsgroup-name))
7050 ;; Using `gnus-request-article' directly will insert the article into
7051 ;; `nntp-server-buffer' - so we'll save some time by not having to
7052 ;; copy it from the server buffer into the article buffer.
7054 ;; We only request an article by message-id when we do not have the
7055 ;; headers for it, so we'll have to get those.
7056 (when (stringp article)
7057 (gnus-read-header article))
7059 ;; If the article number is negative, that means that this article
7060 ;; doesn't belong in this newsgroup (possibly), so we find its
7061 ;; message-id and request it by id instead of number.
7062 (when (and (numberp article)
7064 (get-buffer gnus-summary-buffer)
7065 (gnus-buffer-exists-p gnus-summary-buffer))
7066 (with-current-buffer gnus-summary-buffer
7067 (let ((header (gnus-summary-article-header article)))
7070 ((memq article gnus-newsgroup-sparse)
7071 ;; This is a sparse gap article.
7072 (setq do-update-line article)
7073 (setq article (mail-header-id header))
7074 (setq sparse-header (gnus-read-header article))
7075 (setq gnus-newsgroup-sparse
7076 (delq article gnus-newsgroup-sparse)))
7078 ;; It's a real article.
7079 (setq article (mail-header-id header)))
7081 ;; It is an extracted pseudo-article.
7082 (setq article 'pseudo)
7083 (gnus-request-pseudo-article header))))
7085 (let ((method (gnus-find-method-for-group
7086 gnus-newsgroup-name)))
7087 (when (and (eq (car method) 'nneething)
7089 (let ((dir (nneething-get-file-name
7090 (mail-header-id header))))
7091 (when (and (stringp dir)
7092 (file-directory-p dir))
7093 (setq article 'nneething)
7094 (gnus-group-enter-directory dir))))))))
7097 ;; Refuse to select canceled articles.
7098 ((and (numberp article)
7100 (get-buffer gnus-summary-buffer)
7101 (gnus-buffer-exists-p gnus-summary-buffer)
7102 (eq (cdr (with-current-buffer gnus-summary-buffer
7103 (assq article gnus-newsgroup-reads)))
7104 gnus-canceled-mark))
7106 ;; We first check `gnus-original-article-buffer'.
7107 ((and (get-buffer gnus-original-article-buffer)
7109 (with-current-buffer gnus-original-article-buffer
7110 (and (equal (car gnus-original-article) group)
7111 (eq (cdr gnus-original-article) article))))
7112 ;; `insert-buffer-substring' would incorrectly use the
7113 ;; equivalent of string-make-multibyte which amount to decoding
7114 ;; with locale-coding-system, causing failure of
7115 ;; subsequent decoding.
7116 (insert (mm-string-to-multibyte
7117 (with-current-buffer gnus-original-article-buffer
7118 (buffer-substring (point-min) (point-max)))))
7120 ;; Check the backlog.
7121 ((and gnus-keep-backlog
7122 (gnus-backlog-request-article group article (current-buffer)))
7124 ;; Check asynchronous pre-fetch.
7125 ((gnus-async-request-fetched-article group article (current-buffer))
7126 (gnus-async-prefetch-next group article gnus-summary-buffer)
7127 (when (and (numberp article) gnus-keep-backlog)
7128 (gnus-backlog-enter-article group article (current-buffer)))
7131 ((and gnus-use-cache
7133 (gnus-cache-request-article article group))
7135 ;; Check the agent cache.
7136 ((gnus-agent-request-article article group)
7138 ;; Get the article and put into the article buffer.
7139 ((or (stringp article)
7141 (let ((gnus-override-method gnus-override-method)
7142 (methods (and (stringp article)
7143 (with-current-buffer gnus-summary-buffer
7144 (gnus-refer-article-methods))))
7145 (backend (car (gnus-find-method-for-group
7146 gnus-newsgroup-name)))
7148 (inhibit-read-only t))
7149 (when (and (null gnus-override-method)
7151 (setq gnus-override-method (pop methods)))
7154 (gnus-kill-all-overlays)
7155 (let ((gnus-newsgroup-name group))
7156 (gnus-check-group-server))
7158 ((gnus-request-article article group (current-buffer))
7159 (when (numberp article)
7160 (gnus-async-prefetch-next group article
7161 gnus-summary-buffer)
7162 (when gnus-keep-backlog
7163 (gnus-backlog-enter-article
7164 group article (current-buffer)))
7165 (when (and gnus-agent
7166 (gnus-agent-group-covered-p group))
7167 (gnus-agent-store-article article group)))
7168 (setq result 'article))
7170 (setq gnus-override-method (pop methods)))
7171 ((not (string-match "^400 "
7172 (nnheader-get-report backend)))
7173 ;; If we get 400 server disconnect, reconnect and
7174 ;; retry; otherwise, assume the article has expired.
7175 (setq result 'done))))
7176 (and (eq result 'article) 'article)))
7180 ;; Associate this article with the current summary buffer.
7181 (setq gnus-article-current-summary gnus-summary-buffer)
7183 ;; Take the article from the original article buffer
7184 ;; and place it in the buffer it's supposed to be in.
7185 (when (and (get-buffer gnus-article-buffer)
7186 (equal (buffer-name (current-buffer))
7187 (buffer-name (get-buffer gnus-article-buffer))))
7189 (if (get-buffer gnus-original-article-buffer)
7190 (set-buffer gnus-original-article-buffer)
7191 (set-buffer (gnus-get-buffer-create gnus-original-article-buffer))
7192 (buffer-disable-undo)
7193 (setq major-mode 'gnus-original-article-mode)
7194 (setq buffer-read-only t))
7195 (let ((inhibit-read-only t))
7197 (insert-buffer-substring gnus-article-buffer))
7198 (setq gnus-original-article (cons group article)))
7201 (run-hooks 'gnus-article-decode-hook)
7202 ;; Mark article as decoded or not.
7203 (setq gnus-article-decoded-p gnus-article-decode-hook))
7205 ;; Update sparse articles.
7206 (when (and do-update-line
7207 (or (numberp article)
7209 (let ((buf (current-buffer)))
7210 (set-buffer gnus-summary-buffer)
7211 (gnus-summary-update-article do-update-line sparse-header)
7212 (gnus-summary-goto-subject do-update-line nil t)
7213 (set-window-point (gnus-get-buffer-window (current-buffer) t)
7215 (set-buffer buf))))))
7217 (defun gnus-block-private-groups (group)
7218 "Allows images in newsgroups to be shown, blocks images in all
7220 (if (or (gnus-news-group-p group)
7221 (gnus-member-of-valid 'global group))
7222 ;; Block nothing in news groups.
7224 ;; Block everything anywhere else.
7227 (defun gnus-blocked-images ()
7228 (if (functionp gnus-blocked-images)
7229 (funcall gnus-blocked-images gnus-newsgroup-name)
7230 gnus-blocked-images))
7236 (defcustom gnus-article-edit-mode-hook nil
7237 "Hook run in article edit mode buffers."
7238 :group 'gnus-article-various
7241 (defvar gnus-article-edit-done-function nil)
7243 (defvar gnus-article-edit-mode-map nil)
7245 ;; Should we be using derived.el for this?
7246 (unless gnus-article-edit-mode-map
7247 (setq gnus-article-edit-mode-map (make-keymap))
7248 (set-keymap-parent gnus-article-edit-mode-map text-mode-map)
7250 (gnus-define-keys gnus-article-edit-mode-map
7251 "\C-c?" describe-mode
7252 "\C-c\C-c" gnus-article-edit-done
7253 "\C-c\C-k" gnus-article-edit-exit
7254 "\C-c\C-f\C-t" message-goto-to
7255 "\C-c\C-f\C-o" message-goto-from
7256 "\C-c\C-f\C-b" message-goto-bcc
7257 ;;"\C-c\C-f\C-w" message-goto-fcc
7258 "\C-c\C-f\C-c" message-goto-cc
7259 "\C-c\C-f\C-s" message-goto-subject
7260 "\C-c\C-f\C-r" message-goto-reply-to
7261 "\C-c\C-f\C-n" message-goto-newsgroups
7262 "\C-c\C-f\C-d" message-goto-distribution
7263 "\C-c\C-f\C-f" message-goto-followup-to
7264 "\C-c\C-f\C-m" message-goto-mail-followup-to
7265 "\C-c\C-f\C-k" message-goto-keywords
7266 "\C-c\C-f\C-u" message-goto-summary
7267 "\C-c\C-f\C-i" message-insert-or-toggle-importance
7268 "\C-c\C-f\C-a" message-generate-unsubscribed-mail-followup-to
7269 "\C-c\C-b" message-goto-body
7270 "\C-c\C-i" message-goto-signature
7272 "\C-c\C-t" message-insert-to
7273 "\C-c\C-n" message-insert-newsgroups
7274 "\C-c\C-o" message-sort-headers
7275 "\C-c\C-e" message-elide-region
7276 "\C-c\C-v" message-delete-not-region
7277 "\C-c\C-z" message-kill-to-signature
7278 "\M-\r" message-newline-and-reformat
7279 "\C-c\C-a" mml-attach-file
7280 "\C-a" message-beginning-of-line
7282 "\M-;" comment-region)
7284 (gnus-define-keys (gnus-article-edit-wash-map
7285 "\C-c\C-w" gnus-article-edit-mode-map)
7286 "f" gnus-article-edit-full-stops))
7289 gnus-article-edit-mode-field-menu gnus-article-edit-mode-map ""
7291 ["Fetch To" message-insert-to t]
7292 ["Fetch Newsgroups" message-insert-newsgroups t]
7294 ["To" message-goto-to t]
7295 ["From" message-goto-from t]
7296 ["Subject" message-goto-subject t]
7297 ["Cc" message-goto-cc t]
7298 ["Reply-To" message-goto-reply-to t]
7299 ["Summary" message-goto-summary t]
7300 ["Keywords" message-goto-keywords t]
7301 ["Newsgroups" message-goto-newsgroups t]
7302 ["Followup-To" message-goto-followup-to t]
7303 ["Mail-Followup-To" message-goto-mail-followup-to t]
7304 ["Distribution" message-goto-distribution t]
7305 ["Body" message-goto-body t]
7306 ["Signature" message-goto-signature t]))
7308 (define-derived-mode gnus-article-edit-mode message-mode "Article Edit"
7309 "Major mode for editing articles.
7310 This is an extended text-mode.
7312 \\{gnus-article-edit-mode-map}"
7313 (make-local-variable 'gnus-article-edit-done-function)
7314 (make-local-variable 'gnus-prev-winconf)
7315 (set (make-local-variable 'font-lock-defaults)
7316 '(message-font-lock-keywords t))
7317 (set (make-local-variable 'mail-header-separator) "")
7318 (set (make-local-variable 'gnus-article-edit-mode) t)
7319 (easy-menu-add message-mode-field-menu message-mode-map)
7321 (setq buffer-read-only nil)
7322 (buffer-enable-undo)
7325 (defun gnus-article-edit (&optional force)
7326 "Edit the current article.
7327 This will have permanent effect only in mail groups.
7328 If FORCE is non-nil, allow editing of articles even in read-only
7331 (when (and (not force)
7332 (gnus-group-read-only-p))
7333 (error "The current newsgroup does not support article editing"))
7334 (gnus-article-date-original)
7335 (gnus-article-edit-article
7337 `(lambda (no-highlight)
7339 (gnus-summary-edit-article-done
7340 ,(or (mail-header-references gnus-current-headers) "")
7341 ,(gnus-group-read-only-p) ,gnus-summary-buffer no-highlight))))
7343 (defun gnus-article-edit-article (start-func exit-func &optional quiet)
7344 "Start editing the contents of the current article buffer."
7345 (let ((winconf (current-window-configuration)))
7346 (set-buffer gnus-article-buffer)
7347 (let ((message-auto-save-directory
7348 ;; Don't associate the article buffer with a draft file.
7350 (gnus-article-edit-mode))
7351 (funcall start-func)
7352 (set-buffer-modified-p nil)
7353 (gnus-configure-windows 'edit-article)
7354 (setq gnus-article-edit-done-function exit-func)
7355 (setq gnus-prev-winconf winconf)
7357 (gnus-message 6 "C-c C-c to end edits"))))
7359 (defun gnus-article-edit-done (&optional arg)
7360 "Update the article edits and exit."
7362 (let ((func gnus-article-edit-done-function)
7363 (buf (current-buffer))
7364 (start (window-start))
7365 (winconf gnus-prev-winconf))
7366 (widen) ;; Widen it in case that users narrowed the buffer.
7369 ;; The cache and backlog have to be flushed somewhat.
7370 (when gnus-keep-backlog
7371 (gnus-backlog-remove-article
7372 (car gnus-article-current) (cdr gnus-article-current)))
7373 ;; Flush original article as well.
7374 (gnus-flush-original-article-buffer)
7375 (when gnus-use-cache
7376 (gnus-cache-update-article
7377 (car gnus-article-current) (cdr gnus-article-current)))
7378 ;; We remove all text props from the article buffer.
7379 (kill-all-local-variables)
7380 (set-text-properties (point-min) (point-max) nil)
7382 (set-window-configuration winconf)
7384 (set-window-start (get-buffer-window buf) start)
7385 (set-window-point (get-buffer-window buf) (point)))
7386 (gnus-summary-show-article))
7388 (defun gnus-flush-original-article-buffer ()
7389 (when (get-buffer gnus-original-article-buffer)
7390 (with-current-buffer gnus-original-article-buffer
7391 (setq gnus-original-article nil))))
7393 (defun gnus-article-edit-exit ()
7394 "Exit the article editing without updating."
7396 (when (or (not (buffer-modified-p))
7397 (yes-or-no-p "Article modified; kill anyway? "))
7398 (let ((curbuf (current-buffer))
7400 (window-start (window-start)))
7402 (if (gnus-buffer-live-p gnus-original-article-buffer)
7403 (insert-buffer-substring gnus-original-article-buffer))
7404 (let ((winconf gnus-prev-winconf))
7405 (kill-all-local-variables)
7407 (set-window-configuration winconf)
7408 ;; Tippy-toe some to make sure that point remains where it was.
7409 (save-current-buffer
7411 (set-window-start (get-buffer-window (current-buffer)) window-start)
7413 (gnus-summary-show-article)))
7415 (defun gnus-article-edit-full-stops ()
7416 "Interactively repair spacing at end of sentences."
7419 (goto-char (point-min))
7420 (search-forward-regexp "^$" nil t)
7421 (let ((case-fold-search nil))
7422 (query-replace-regexp "\\([.!?][])}]* \\)\\([[({A-Z]\\)" "\\1 \\2"))))
7425 ;;; Article highlights
7428 ;; Written by Per Abrahamsen <abraham@iesd.auc.dk>.
7430 ;;; Internal Variables:
7432 (defcustom gnus-button-url-regexp
7434 "\\b\\(\\(www\\.\\|\\(s?https?\\|ftp\\|file\\|gopher\\|"
7435 "nntp\\|news\\|telnet\\|wais\\|mailto\\|info\\):\\)"
7436 "\\(//[-a-z0-9_.]+:[0-9]*\\)?"
7437 (if (string-match "[[:digit:]]" "1") ;; Support POSIX?
7438 (let ((chars "-a-z0-9_=#$@~%&*+\\/[:word:]")
7442 ;; Match paired parentheses, e.g. in Wikipedia URLs:
7443 ;; http://thread.gmane.org/47B4E3B2.3050402@gmail.com
7444 "[" chars punct "]+" "(" "[" chars punct "]+" "[" chars "]*)"
7445 "\\(?:" "[" chars punct "]+" "[" chars "]" "\\)?"
7447 "[" chars punct "]+" "[" chars "]"
7449 (concat ;; XEmacs 21.4 doesn't support POSIX.
7450 "\\([-a-z0-9_=!?#$@~%&*+\\/:;.,]\\|\\w\\)+"
7451 "\\([-a-z0-9_=#$@~%&*+\\/]\\|\\w\\)"))
7453 "Regular expression that matches URLs."
7455 :group 'gnus-article-buttons
7458 (defcustom gnus-button-valid-fqdn-regexp
7459 message-valid-fqdn-regexp
7460 "Regular expression that matches a valid FQDN."
7462 :group 'gnus-article-buttons
7465 ;; Regexp suggested by Felix Wiemann in <87oeuomcz9.fsf@news2.ososo.de>
7466 (defcustom gnus-button-valid-localpart-regexp
7467 "[a-z0-9$%(*-=?[_][^<>\")!;:,{}\n\t @]*"
7468 "Regular expression that matches a localpart of mail addresses or MIDs."
7470 :group 'gnus-article-buttons
7473 (defcustom gnus-button-man-handler 'manual-entry
7474 "Function to use for displaying man pages.
7475 The function must take at least one argument with a string naming the
7478 :type '(choice (function-item :tag "Man" manual-entry)
7479 (function-item :tag "Woman" woman)
7480 (function :tag "Other"))
7481 :group 'gnus-article-buttons)
7483 (defcustom gnus-button-mid-or-mail-regexp
7484 (concat "\\b\\(<?" gnus-button-valid-localpart-regexp "@"
7485 gnus-button-valid-fqdn-regexp
7487 "Regular expression that matches a message ID or a mail address."
7489 :group 'gnus-article-buttons
7492 (defcustom gnus-button-prefer-mid-or-mail 'gnus-button-mid-or-mail-heuristic
7493 "What to do when the button on a string as \"foo123@bar.invalid\" is pushed.
7494 Strings like this can be either a message ID or a mail address. If it is one
7495 of the symbols `mid' or `mail', Gnus will always assume that the string is a
7496 message ID or a mail address, respectively. If this variable is set to the
7497 symbol `ask', always query the user what do do. If it is a function, this
7498 function will be called with the string as its only argument. The function
7499 must return `mid', `mail', `invalid' or `ask'."
7501 :group 'gnus-article-buttons
7502 :type '(choice (function-item :tag "Heuristic function"
7503 gnus-button-mid-or-mail-heuristic)
7508 (defcustom gnus-button-mid-or-mail-heuristic-alist
7509 '((-10.0 . ".+\\$.+@")
7512 (-5.0 . "\\+[^+]*\\+.*@") ;; # two plus signs
7513 (-5.0 . "@[Nn][Ee][Ww][Ss]") ;; /\@news/i
7514 (-5.0 . "@.*[Dd][Ii][Aa][Ll][Uu][Pp]") ;; /\@.*dialup/i;
7515 (-1.0 . "^[^a-z]+@")
7517 (-5.0 . "\\.[0-9][0-9]+.*@") ;; "\.[0-9]{2,}.*\@"
7518 (-5.0 . "[a-z].*[A-Z].*[a-z].*[A-Z].*@") ;; "([a-z].*[A-Z].*){2,}\@"
7519 (-3.0 . "[A-Z][A-Z][a-z][a-z].*@")
7520 (-5.0 . "\\...?.?@") ;; (-5.0 . "\..{1,3}\@")
7523 (-1.0 . "^[0-9][0-9]")
7525 ;; -3.0 /^[0-9][0-9a-fA-F]{2,2}/;
7526 (-3.0 . "^[0-9][0-9a-fA-F][0-9a-fA-F][^0-9a-fA-F]")
7527 ;; -5.0 /^[0-9][0-9a-fA-F]{3,3}/;
7528 (-5.0 . "^[0-9][0-9a-fA-F][0-9a-fA-F][0-9a-fA-F][^0-9a-fA-F]")
7530 (-3.0 . "[0-9][0-9][0-9][0-9][0-9][^0-9].*@") ;; "[0-9]{5,}.*\@"
7531 (-3.0 . "[0-9][0-9][0-9][0-9][0-9][0-9][0-9][0-9][^0-9].*@")
7534 . "[0-9][0-9][0-9][0-9][0-9][0-9][0-9][0-9][0-9][0-9][0-9][0-9].*@")
7536 ;; compensation for TDMA dated mail addresses:
7537 (25.0 . "-dated-[0-9][0-9][0-9][0-9][0-9][0-9][0-9][0-9]+.*@")
7539 (-20.0 . "\\.fsf@") ;; Gnus
7542 (-20.0 . "^alpine\\.")
7543 (-20.0 . "_-_") ;; Subject change in thread
7545 (-20.0 . "\\.ln@") ;; leafnode
7546 (-30.0 . "@ID-[0-9]+\\.[a-zA-Z]+\\.dfncis\\.de")
7547 (-30.0 . "@4[Aa][Xx]\\.com") ;; Forte Agent
7549 ;; (5.0 . "") ;; $local_part_len <= 7
7550 (10.0 . "^[^0-9]+@")
7551 (3.0 . "^[^0-9]+[0-9][0-9]?[0-9]?@")
7552 ;; ^[^0-9]+[0-9]{1,3}\@ digits only at end of local part
7555 (2.0 . "[a-z][a-z][._-][A-Z][a-z].*@")
7557 (0.5 . "^[A-Z][a-z]")
7558 (0.5 . "^[A-Z][a-z][a-z]")
7559 (1.5 . "^[A-Z][a-z][A-Z][a-z][^a-z]") ;; ^[A-Z][a-z]{3,3}
7560 (2.0 . "^[A-Z][a-z][A-Z][a-z][a-z][^a-z]")) ;; ^[A-Z][a-z]{4,4}
7561 "An alist of (RATE . REGEXP) pairs for `gnus-button-mid-or-mail-heuristic'.
7563 A negative RATE indicates a message IDs, whereas a positive indicates a mail
7564 address. The REGEXP is processed with `case-fold-search' set to nil."
7566 :group 'gnus-article-buttons
7567 :type '(repeat (cons (number :tag "Rate")
7568 (regexp :tag "Regexp"))))
7570 (defun gnus-button-mid-or-mail-heuristic (mid-or-mail)
7571 "Guess whether MID-OR-MAIL is a message ID or a mail address.
7572 Returns `mid' if MID-OR-MAIL is a message IDs, `mail' if it's a mail
7573 address, `ask' if unsure and `invalid' if the string is invalid."
7574 (let ((case-fold-search nil)
7575 (list gnus-button-mid-or-mail-heuristic-alist)
7576 (result 0) rate regexp lpartlen elem)
7578 (length (gnus-replace-in-string mid-or-mail "^\\(.*\\)@.*$" "\\1")))
7579 (gnus-message 8 "`%s', length of local part=`%s'." mid-or-mail lpartlen)
7580 ;; Certain special cases...
7583 "^0[0-9]+-[0-9][0-9][0-9][0-9]@t-online\\.de$\\|"
7584 "^[0-9]+\\.[0-9]+@compuserve\\|"
7585 "@public\\.gmane\\.org")
7587 (gnus-message 8 "`%s' is a known mail address." mid-or-mail)
7588 (setq result 'mail))
7589 (when (string-match "@.*@\\| " mid-or-mail)
7590 (gnus-message 8 "`%s' is invalid." mid-or-mail)
7591 (setq result 'invalid))
7592 ;; Nothing more to do, if result is not a number here...
7593 (when (numberp result)
7595 (setq elem (car list)
7599 (when (string-match regexp mid-or-mail)
7600 (setq result (+ result rate))
7602 9 "`%s' matched `%s', rate `%s', result `%s'."
7603 mid-or-mail regexp rate result)))
7604 (when (<= lpartlen 7)
7605 (setq result (+ result 5.0))
7606 (gnus-message 9 "`%s' matched (<= lpartlen 7), result `%s'."
7607 mid-or-mail result))
7608 (when (>= lpartlen 12)
7609 (gnus-message 9 "`%s' matched (>= lpartlen 12)" mid-or-mail)
7611 ((string-match "[0-9][^0-9]+[0-9].*@" mid-or-mail)
7612 ;; Long local part should contain realname if e-mail address,
7613 ;; too many digits: message-id.
7614 ;; $score -= 5.0 + 0.1 * $local_part_len;
7615 (setq rate (* -1.0 (+ 5.0 (* 0.1 lpartlen))))
7616 (setq result (+ result rate))
7618 9 "Many digits in `%s', rate `%s', result `%s'."
7619 mid-or-mail rate result))
7620 ((string-match "[^aeiouy][^aeiouy][^aeiouy][^aeiouy]+.*@"
7622 ;; Too few vowels [^aeiouy]{4,}.*@
7623 (setq result (+ result -5.0))
7625 9 "Few vowels in `%s', rate `%s', result `%s'."
7626 mid-or-mail -5.0 result))
7628 (setq result (+ result 5.0))
7630 9 "`%s', rate `%s', result `%s'." mid-or-mail 5.0 result)))))
7631 (gnus-message 8 "`%s': Final rate is `%s'." mid-or-mail result)
7632 ;; Maybe we should make this a customizable alist: (condition . 'result)
7634 ((symbolp result) result)
7635 ;; Now convert number into proper results:
7636 ((< result -10.0) 'mid)
7637 ((> result 10.0) 'mail)
7640 (defun gnus-button-handle-mid-or-mail (mid-or-mail)
7641 (let* ((pref gnus-button-prefer-mid-or-mail) guessed
7642 (url-mid (concat "news" ":" mid-or-mail))
7643 (url-mailto (concat "mailto" ":" mid-or-mail)))
7644 (gnus-message 9 "mid-or-mail=%s" mid-or-mail)
7645 (when (fboundp pref)
7647 ;; get rid of surrounding angles...
7649 (gnus-replace-in-string mid-or-mail "^<\\|>$" "")))
7650 (if (or (eq 'mid guessed) (eq 'mail guessed))
7654 (save-window-excursion
7655 (if (y-or-n-p (concat "Is <" mid-or-mail "> a mail address? "))
7658 (cond ((eq pref 'mid)
7659 (gnus-message 8 "calling `gnus-button-handle-news' %s" url-mid)
7660 (gnus-button-handle-news url-mid))
7662 (gnus-message 8 "calling `gnus-url-mailto' %s" url-mailto)
7663 (gnus-url-mailto url-mailto))
7664 (t (gnus-message 3 "Invalid string.")))))
7666 (defun gnus-button-handle-custom (fun arg)
7667 "Call function FUN on argument ARG.
7668 Both FUN and ARG are supposed to be strings. ARG will be passed
7669 as a symbol to FUN."
7670 (funcall (intern fun)
7671 (if (string-match "^customize-apropos" fun)
7675 (defvar gnus-button-handle-describe-prefix "^\\(C-h\\|<?[Ff]1>?\\)")
7677 (defun gnus-button-handle-describe-function (url)
7678 "Call `describe-function' when pushing the corresponding URL button."
7681 (gnus-replace-in-string url gnus-button-handle-describe-prefix ""))))
7683 (defun gnus-button-handle-describe-variable (url)
7684 "Call `describe-variable' when pushing the corresponding URL button."
7687 (gnus-replace-in-string url gnus-button-handle-describe-prefix ""))))
7689 (defun gnus-button-handle-symbol (url)
7690 "Display help on variable or function.
7691 Calls `describe-variable' or `describe-function'."
7692 (let ((sym (intern url)))
7694 ((fboundp sym) (describe-function sym))
7695 ((boundp sym) (describe-variable sym))
7696 (t (gnus-message 3 "`%s' is not a known function of variable." url)))))
7698 (defun gnus-button-handle-describe-key (url)
7699 "Call `describe-key' when pushing the corresponding URL button."
7701 (gnus-replace-in-string url gnus-button-handle-describe-prefix ""))
7702 (keys (ignore-errors (eval `(kbd ,key-string)))))
7705 (gnus-message 3 "Invalid key sequence in button: %s" key-string))))
7707 (defun gnus-button-handle-apropos (url)
7708 "Call `apropos' when pushing the corresponding URL button."
7709 (apropos (gnus-replace-in-string url gnus-button-handle-describe-prefix "")))
7711 (defun gnus-button-handle-apropos-command (url)
7712 "Call `apropos' when pushing the corresponding URL button."
7714 (gnus-replace-in-string url gnus-button-handle-describe-prefix "")))
7716 (defun gnus-button-handle-apropos-variable (url)
7717 "Call `apropos' when pushing the corresponding URL button."
7719 (if (fboundp 'apropos-variable) 'apropos-variable 'apropos)
7720 (gnus-replace-in-string url gnus-button-handle-describe-prefix "")))
7722 (defun gnus-button-handle-apropos-documentation (url)
7723 "Call `apropos' when pushing the corresponding URL button."
7725 (if (fboundp 'apropos-documentation) 'apropos-documentation 'apropos)
7726 (gnus-replace-in-string url gnus-button-handle-describe-prefix "")))
7728 (defun gnus-button-handle-library (url)
7729 "Call `locate-library' when pushing the corresponding URL button."
7730 (gnus-message 9 "url=`%s'" url)
7731 (let* ((lib (locate-library url))
7732 (file (gnus-replace-in-string (or lib "") "\\.elc" ".el")))
7734 (gnus-message 1 "Cannot locale library `%s'." url)
7735 (find-file-read-only file))))
7737 (defcustom gnus-button-man-level 5
7738 "*Integer that says how many man-related buttons Gnus will show.
7739 The higher the number, the more buttons will appear and the more false
7740 positives are possible. Note that you can set this variable local to
7741 specific groups. Setting it higher in Unix groups is probably a good idea.
7742 See Info node `(gnus)Group Parameters' and the variable `gnus-parameters' on
7743 how to set variables in specific groups."
7745 :group 'gnus-article-buttons
7746 :link '(custom-manual "(gnus)Group Parameters")
7749 (defcustom gnus-button-emacs-level 5
7750 "*Integer that says how many emacs-related buttons Gnus will show.
7751 The higher the number, the more buttons will appear and the more false
7752 positives are possible. Note that you can set this variable local to
7753 specific groups. Setting it higher in Emacs or Gnus related groups is
7754 probably a good idea. See Info node `(gnus)Group Parameters' and the variable
7755 `gnus-parameters' on how to set variables in specific groups."
7757 :group 'gnus-article-buttons
7758 :link '(custom-manual "(gnus)Group Parameters")
7761 (defcustom gnus-button-message-level 5
7762 "*Integer that says how many buttons for news or mail messages will appear.
7763 The higher the number, the more buttons will appear and the more false
7764 positives are possible."
7765 ;; mail addresses, MIDs, URLs for news, ...
7767 :group 'gnus-article-buttons
7770 (defcustom gnus-button-browse-level 5
7771 "*Integer that says how many buttons for browsing will appear.
7772 The higher the number, the more buttons will appear and the more false
7773 positives are possible."
7774 ;; stuff handled by `browse-url' or `gnus-button-embedded-url'
7776 :group 'gnus-article-buttons
7779 (defcustom gnus-button-alist
7780 '(("<\\(url:[>\n\t ]*?\\)?\\(nntp\\|news\\):[>\n\t ]*\\([^>\n\t ]*@[^>\n\t ]*\\)>"
7781 0 (>= gnus-button-message-level 0) gnus-button-handle-news 3)
7782 ((concat "\\b\\(nntp\\|news\\):\\("
7783 gnus-button-valid-localpart-regexp "@[a-z0-9.-]+[a-z]\\)")
7784 0 t gnus-button-handle-news 2)
7785 ("\\(\\b<\\(url:[>\n\t ]*\\)?\\(nntp\\|news\\):[>\n\t ]*\\(//\\)?\\([^>\n\t ]*\\)>\\)"
7786 1 (>= gnus-button-message-level 0) gnus-button-fetch-group 5)
7787 ("\\b\\(nntp\\|news\\):\\(//\\)?\\([^'\">\n\t ]+\\)"
7788 0 (>= gnus-button-message-level 0) gnus-button-fetch-group 3)
7789 ;; RFC 2392 (Don't allow `/' in domain part --> CID)
7790 ("\\bmid:\\(//\\)?\\([^'\">\n\t ]+@[^'\">\n\t /]+\\)"
7791 0 (>= gnus-button-message-level 0) gnus-button-message-id 2)
7792 ("\\bin\\( +article\\| +message\\)? +\\(<\\([^\n @<>]+@[^\n @<>]+\\)>\\)"
7793 2 (>= gnus-button-message-level 0) gnus-button-message-id 3)
7794 ("\\b\\(mid\\|message-id\\):? +\\(<\\([^\n @<>]+@[^\n @<>]+\\)>\\)"
7795 2 (>= gnus-button-message-level 0) gnus-button-message-id 3)
7796 ("\\(<URL: *\\)mailto: *\\([^> \n\t]+\\)>"
7797 0 (>= gnus-button-message-level 0) gnus-url-mailto 2)
7798 ;; RFC 2368 (The mailto URL scheme)
7799 ("\\bmailto:\\([-a-z.@_+0-9%=?&/]+\\)"
7800 0 (>= gnus-button-message-level 0) gnus-url-mailto 1)
7801 ("\\bmailto:\\([^ \n\t]+\\)"
7802 0 (>= gnus-button-message-level 0) gnus-url-mailto 1)
7803 ;; Info Konqueror style <info:/foo/bar baz>.
7804 ;; Must come before " Gnus home-grown style".
7805 ("\\binfo://?\\([^'\">\n\t]+\\)"
7806 0 (>= gnus-button-emacs-level 1) gnus-button-handle-info-url 1)
7807 ;; Info, Gnus home-grown style (deprecated) <info://foo/bar+baz>
7808 ("\\binfo://\\([^'\">\n\t ]+\\)"
7809 0 (>= gnus-button-emacs-level 1) gnus-button-handle-info-url 1)
7810 ;; Info GNOME style <info:foo#bar_baz>
7811 ("\\binfo:\\([^('\n\t\r \"><][^'\n\t\r \"><]*\\)"
7812 0 (>= gnus-button-emacs-level 1) gnus-button-handle-info-url-gnome 1)
7813 ;; Info KDE style <info:(foo)bar baz>
7814 ("<\\(info:\\(([^)]+)[^>\n\r]*\\)\\)>"
7815 1 (>= gnus-button-emacs-level 1) gnus-button-handle-info-url-kde 2)
7816 ("\\((Info-goto-node\\|(info\\)[ \t\n]*\\(\"[^\"]*\"\\))" 0
7817 (>= gnus-button-emacs-level 1) gnus-button-handle-info-url 2)
7818 ("\\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,]*\\)\\)?"
7819 ;; Info links like `C-h i d m Gnus RET' or `C-h i d m Gnus RET i partial RET'
7820 0 (>= gnus-button-emacs-level 1) gnus-button-handle-info-keystrokes 0)
7822 ("M-x[ \t\n]\\(customize-[^ ]+\\)[ \t\n]RET[ \t\n]\\([^ ]+\\)[ \t\n]RET\\>" 0
7823 (>= gnus-button-emacs-level 1) gnus-button-handle-custom 1 2)
7824 ;; Emacs help commands
7825 ("M-x[ \t\n]+apropos[ \t\n]+RET[ \t\n]+\\([^ \t\n]+\\)[ \t\n]+RET\\>"
7826 ;; regexp doesn't match arguments containing ` '.
7827 0 (>= gnus-button-emacs-level 1) gnus-button-handle-apropos 1)
7828 ("M-x[ \t\n]+apropos-command[ \t\n]+RET[ \t\n]+\\([^ \t\n]+\\)[ \t\n]+RET\\>"
7829 0 (>= gnus-button-emacs-level 1) gnus-button-handle-apropos-command 1)
7830 ("M-x[ \t\n]+apropos-variable[ \t\n]+RET[ \t\n]+\\([^ \t\n]+\\)[ \t\n]+RET\\>"
7831 0 (>= gnus-button-emacs-level 1) gnus-button-handle-apropos-variable 1)
7832 ("M-x[ \t\n]+apropos-documentation[ \t\n]+RET[ \t\n]+\\([^ \t\n]+\\)[ \t\n]+RET\\>"
7833 0 (>= gnus-button-emacs-level 1) gnus-button-handle-apropos-documentation 1)
7834 ;; The following entries may lead to many false positives so don't enable
7835 ;; them by default (use a high button level).
7836 ("/\\([a-z][-a-z0-9]+\\.el\\)\\>[^.?]"
7837 ;; Exclude [.?] for URLs in gmane.emacs.cvs
7838 1 (>= gnus-button-emacs-level 8) gnus-button-handle-library 1)
7839 ("['`‘]\\([a-z][-a-z0-9]+\\.el\\)['’]"
7840 1 (>= gnus-button-emacs-level 8) gnus-button-handle-library 1)
7841 ("['`‘]\\([a-z][a-z0-9]+-[a-z0-9]+-[-a-z0-9]*[a-z]\\|\\(gnus\\|message\\)-[-a-z]+\\)['’]"
7842 0 (>= gnus-button-emacs-level 8) gnus-button-handle-symbol 1)
7843 ("['`‘]\\([a-z][a-z0-9]+-[a-z]+\\)['’]"
7844 0 (>= gnus-button-emacs-level 9) gnus-button-handle-symbol 1)
7845 ("(setq[ \t\n]+\\([a-z][a-z0-9]+-[-a-z0-9]+\\)[ \t\n]+.+)"
7846 1 (>= gnus-button-emacs-level 7) gnus-button-handle-describe-variable 1)
7847 ("\\bM-x[ \t\n]+\\([^ \t\n]+\\)[ \t\n]+RET\\>"
7848 1 (>= gnus-button-emacs-level 7) gnus-button-handle-describe-function 1)
7849 ("\\b\\(C-h\\|<?[Ff]1>?\\)[ \t\n]+f[ \t\n]+\\([^ \t\n]+\\)[ \t\n]+RET\\>"
7850 0 (>= gnus-button-emacs-level 1) gnus-button-handle-describe-function 2)
7851 ("\\b\\(C-h\\|<?[Ff]1>?\\)[ \t\n]+v[ \t\n]+\\([^ \t\n]+\\)[ \t\n]+RET\\>"
7852 0 (>= gnus-button-emacs-level 1) gnus-button-handle-describe-variable 2)
7853 ("['`‘]\\(\\(C-h\\|<?[Ff]1>?\\)[ \t\n]+k[ \t\n]+\\([^'’]+\\)\\)['’]"
7854 ;; Unlike the other regexps we really have to require quoting
7855 ;; here to determine where it ends.
7856 1 (>= gnus-button-emacs-level 1) gnus-button-handle-describe-key 3)
7857 ;; This is how URLs _should_ be embedded in text (RFC 1738, RFC 2396)...
7858 ("<URL: *\\([^\n<>]*\\)>"
7859 1 (>= gnus-button-browse-level 0) gnus-button-embedded-url 1)
7860 ;; RFC 2396 (2.4.3., delims) ...
7861 ("\"URL: *\\([^\n\"]*\\)\""
7862 1 (>= gnus-button-browse-level 0) gnus-button-embedded-url 1)
7864 (gnus-button-url-regexp
7865 0 (>= gnus-button-browse-level 0) browse-url 0)
7867 ("\\b\\([a-z][a-z]+([1-9])\\)\\W"
7868 0 (and (>= gnus-button-man-level 1) (< gnus-button-man-level 3))
7869 gnus-button-handle-man 1)
7870 ;; more man pages: resolv.conf(5), iso_8859-1(7), xterm(1x)
7871 ("\\b\\([a-z][-_.a-z0-9]+([1-9])\\)\\W"
7872 0 (and (>= gnus-button-man-level 3) (< gnus-button-man-level 5))
7873 gnus-button-handle-man 1)
7874 ;; even more: Apache::PerlRun(3pm), PDL::IO::FastRaw(3pm),
7875 ;; SoWWWAnchor(3iv), XSelectInput(3X11), X(1), X(7)
7876 ("\\b\\(\\(?:[a-z][-+_.:a-z0-9]+([1-9][X1a-z]*)\\)\\|\\b\\(?:X([1-9])\\)\\)\\W"
7877 0 (>= gnus-button-man-level 5) gnus-button-handle-man 1)
7878 ;; Recognizing patches to .el files. This is somewhat obscure,
7879 ;; but considering the percentage of Gnus users who hack Emacs
7881 ("^--- \\([^ .]+\\.el\\).*\n.*\n@@ -?\\([0-9]+\\)" 1
7882 (>= gnus-button-message-level 4) gnus-button-patch 1 2)
7883 ("^\\*\\*\\* \\([^ .]+\\.el\\).*\n.*\n\\*+\n\\*\\*\\* \\([0-9]+\\)" 1
7884 (>= gnus-button-message-level 4) gnus-button-patch 1 2)
7885 ;; MID or mail: To avoid too many false positives we don't try to catch
7886 ;; all kind of allowed MIDs or mail addresses. Domain part must contain
7887 ;; at least one dot. TLD must contain two or three chars or be a know TLD
7888 ;; (info|name|...). Put this entry near the _end_ of `gnus-button-alist'
7889 ;; so that non-ambiguous entries (see above) match first.
7890 (gnus-button-mid-or-mail-regexp
7891 0 (>= gnus-button-message-level 5) gnus-button-handle-mid-or-mail 1))
7892 "*Alist of regexps matching buttons in article bodies.
7894 Each entry has the form (REGEXP BUTTON FORM CALLBACK PAR...), where
7895 REGEXP: is the string (case insensitive) matching text around the button (can
7896 also be Lisp expression evaluating to a string),
7897 BUTTON: is the number of the regexp grouping actually matching the button,
7898 FORM: is a Lisp expression which must eval to true for the button to
7900 CALLBACK: is the function to call when the user push this button, and each
7901 PAR: is a number of a regexp grouping whose text will be passed to CALLBACK.
7903 CALLBACK can also be a variable, in that case the value of that
7904 variable it the real callback function."
7905 :group 'gnus-article-buttons
7906 :type '(repeat (list (choice regexp variable sexp)
7907 (integer :tag "Button")
7909 (function :tag "Callback")
7912 (integer :tag "Regexp group")))))
7913 (put 'gnus-button-alist 'risky-local-variable t)
7915 (defcustom gnus-header-button-alist
7916 '(("^\\(References\\|Message-I[Dd]\\|^In-Reply-To\\):" "<[^<>]+>"
7917 0 (>= gnus-button-message-level 0) gnus-button-message-id 0)
7918 ("^\\(From\\|Reply-To\\):" ": *\\(.+\\)$"
7919 1 (>= gnus-button-message-level 0) gnus-button-reply 1)
7920 ("^\\(Cc\\|To\\):" "[^ \t\n<>,()\"]+@[^ \t\n<>,()\"]+"
7921 0 (>= gnus-button-message-level 0) gnus-msg-mail 0)
7922 ("^X-[Uu][Rr][Ll]:" gnus-button-url-regexp
7923 0 (>= gnus-button-browse-level 0) browse-url 0)
7924 ("^Subject:" gnus-button-url-regexp
7925 0 (>= gnus-button-browse-level 0) browse-url 0)
7926 ("^[^:]+:" gnus-button-url-regexp
7927 0 (>= gnus-button-browse-level 0) browse-url 0)
7928 ("^OpenPGP:.*url=" gnus-button-url-regexp
7929 0 (>= gnus-button-browse-level 0) gnus-button-openpgp 0)
7930 ("^[^:]+:" "\\bmailto:\\([-a-z.@_+0-9%=?&/]+\\)"
7931 0 (>= gnus-button-message-level 0) gnus-url-mailto 1)
7932 ("^[^:]+:" "\\(<\\(url: \\)?\\(nntp\\|news\\):\\([^>\n ]*\\)>\\)"
7933 1 (>= gnus-button-message-level 0) gnus-button-message-id 4))
7934 "*Alist of headers and regexps to match buttons in article heads.
7936 This alist is very similar to `gnus-button-alist', except that each
7937 alist has an additional HEADER element first in each entry:
7939 \(HEADER REGEXP BUTTON FORM CALLBACK PAR)
7941 HEADER is a regexp to match a header. For a fuller explanation, see
7942 `gnus-button-alist'."
7943 :group 'gnus-article-buttons
7944 :group 'gnus-article-headers
7945 :type '(repeat (list (regexp :tag "Header")
7946 (choice regexp variable)
7947 (integer :tag "Button")
7949 (function :tag "Callback")
7952 (integer :tag "Regexp group")))))
7953 (put 'gnus-header-button-alist 'risky-local-variable t)
7957 (defun gnus-article-push-button (event)
7958 "Check text under the mouse pointer for a callback function.
7959 If the text under the mouse pointer has a `gnus-callback' property,
7960 call it with the value of the `gnus-data' text property."
7962 (set-buffer (window-buffer (posn-window (event-start event))))
7963 (let* ((pos (posn-point (event-start event)))
7964 (data (get-text-property pos 'gnus-data))
7965 (fun (get-text-property pos 'gnus-callback)))
7968 (funcall fun data))))
7970 (defun gnus-article-press-button ()
7971 "Check text at point for a callback function.
7972 If the text at point has a `gnus-callback' property,
7973 call it with the value of the `gnus-data' text property."
7975 (let ((data (get-text-property (point) 'gnus-data))
7976 (fun (get-text-property (point) 'gnus-callback)))
7978 (funcall fun data))))
7980 (defun gnus-article-highlight (&optional force)
7981 "Highlight current article.
7982 This function calls `gnus-article-highlight-headers',
7983 `gnus-article-highlight-citation',
7984 `gnus-article-highlight-signature', and `gnus-article-add-buttons' to
7985 do the highlighting. See the documentation for those functions."
7986 (interactive (list 'force))
7987 (gnus-article-highlight-headers)
7988 (gnus-article-highlight-citation force)
7989 (gnus-article-highlight-signature)
7990 (gnus-article-add-buttons)
7991 (gnus-article-add-buttons-to-head))
7993 (defun gnus-article-highlight-some (&optional _force)
7994 "Highlight current article.
7995 This function calls `gnus-article-highlight-headers',
7996 `gnus-article-highlight-signature', and `gnus-article-add-buttons' to
7997 do the highlighting. See the documentation for those functions."
7998 (interactive (list 'force))
7999 (gnus-article-highlight-headers)
8000 (gnus-article-highlight-signature)
8001 (gnus-article-add-buttons))
8003 (defun gnus-article-highlight-headers ()
8004 "Highlight article headers as specified by `gnus-header-face-alist'."
8006 (gnus-with-article-headers
8007 (let (regexp header-face field-face from hpoints fpoints)
8008 (dolist (entry gnus-header-face-alist)
8009 (goto-char (point-min))
8010 (setq regexp (concat "^\\("
8011 (if (string-equal "" (nth 0 entry))
8015 header-face (nth 1 entry)
8016 field-face (nth 2 entry))
8017 (while (and (re-search-forward regexp nil t)
8021 (unless (search-forward ":" nil t)
8023 (when (and header-face
8024 (not (memq (point) hpoints)))
8025 (push (point) hpoints)
8026 (gnus-put-text-property from (point) 'face header-face))
8027 (when (and field-face
8028 (not (memq (setq from (point)) fpoints)))
8030 (if (re-search-forward "^[^ \t]" nil t)
8032 (goto-char (point-max)))
8033 (gnus-put-text-property from (point) 'face field-face)))))))
8035 (defun gnus-article-highlight-signature ()
8036 "Highlight the signature in an article.
8037 It does this by highlighting everything after
8038 `gnus-signature-separator' using the face `gnus-signature'."
8040 (gnus-with-article-buffer
8041 (let ((inhibit-point-motion-hooks t))
8043 (when (and gnus-signature-face
8044 (gnus-article-narrow-to-signature))
8045 (overlay-put (make-overlay (point-min) (point-max) nil t)
8046 'face gnus-signature-face)
8048 (gnus-article-search-signature)
8049 (let ((start (match-beginning 0))
8050 (end (set-marker (make-marker) (1+ (match-end 0)))))
8051 (gnus-article-add-button start (1- end) 'gnus-signature-toggle
8054 (defun gnus-button-in-region-p (b e prop)
8055 "Say whether PROP exists in the region."
8056 (text-property-not-all b e prop nil))
8058 (defun gnus-article-add-buttons ()
8059 "Find external references in the article and make buttons of them.
8060 \"External references\" are things like Message-IDs and URLs, as
8061 specified by `gnus-button-alist'."
8063 (gnus-with-article-buffer
8064 (let ((inhibit-point-motion-hooks t)
8065 (case-fold-search t)
8066 (alist gnus-button-alist)
8068 ;; We skip the headers.
8071 (while (setq entry (pop alist))
8072 (setq regexp (eval (car entry)))
8074 (while (re-search-forward regexp nil t)
8075 (let ((start (match-beginning (nth 1 entry)))
8076 (end (match-end (nth 1 entry)))
8077 (from (match-beginning 0)))
8078 (when (and (eval (nth 2 entry))
8079 (not (gnus-button-in-region-p
8080 start end 'gnus-callback)))
8081 ;; That optional form returned non-nil, so we add the
8083 (setq from (set-marker (make-marker) from))
8084 (unless (and (eq (car entry) 'gnus-button-url-regexp)
8085 (gnus-article-extend-url-button from start end))
8086 (gnus-article-add-button start end
8087 'gnus-button-push (list from entry))
8088 (gnus-put-text-property
8090 'gnus-string (buffer-substring-no-properties
8093 (defun gnus-article-extend-url-button (beg start end)
8094 "Extend url button if url is folded into two or more lines.
8095 Return non-nil if button is extended. BEG is a marker that points to
8096 the beginning position of a text containing url. START and END are
8097 the endpoints of a url button before it is extended. The concatenated
8098 url is put as the `gnus-button-url' overlay property on the button."
8099 (let ((opoint (point))
8100 (points (list start end))
8105 (not (looking-at "[\t ]*[\">]")))
8109 "\\(?:\"\\|\\(<\\)\\)[\t ]*\\(?:url[\t ]*:[\t ]*\\)?\\'"
8110 (buffer-substring (point-at-bol) start)))
8112 (setq url (list (buffer-substring start end))
8113 delim (if (match-beginning 1) ">" "\""))
8115 (setq regexp (concat
8116 (when (and (looking-at
8117 message-cite-prefix-regexp)
8118 (< (match-end 0) start))
8119 (regexp-quote (match-string 0)))
8121 [\t ]*\\(?:\\([^\t\n \">]+\\)[\t ]*$\\|\\([^\t\n \">]*\\)[\t ]*"
8125 (and (looking-at regexp)
8128 (push (or (match-string 2)
8131 (push (setq end (or (match-end 2)
8134 (push (or (match-beginning 2)
8135 (match-beginning 1))
8137 (match-beginning 2)))
8138 (let (gnus-article-mouse-face widget-mouse-face)
8140 (gnus-article-add-button (pop points) (pop points)
8142 (list beg (assq 'gnus-button-url-regexp
8143 gnus-button-alist)))))
8144 (let ((overlay (make-overlay start end)))
8145 (overlay-put overlay 'evaporate t)
8146 (overlay-put overlay 'gnus-button-url
8147 (list (mapconcat 'identity (nreverse url) "")))
8148 (when gnus-article-mouse-face
8149 (overlay-put overlay 'mouse-face gnus-article-mouse-face)))
8151 (goto-char opoint))))
8153 ;; Add buttons to the head of an article.
8154 (defun gnus-article-add-buttons-to-head ()
8155 "Add buttons to the head of the article."
8157 (gnus-with-article-headers
8159 (dolist (entry gnus-header-button-alist)
8160 ;; Each alist entry.
8161 (goto-char (point-min))
8162 (while (re-search-forward (car entry) nil t)
8163 ;; Each header matching the entry.
8164 (setq beg (match-beginning 0))
8165 (setq end (or (and (re-search-forward "^[^ \t]" nil t)
8166 (match-beginning 0))
8169 (while (re-search-forward (eval (nth 1 entry)) end t)
8170 ;; Each match within a header.
8171 (let* ((entry (cdr entry))
8172 (start (match-beginning (nth 1 entry)))
8173 (end (match-end (nth 1 entry)))
8174 (form (nth 2 entry)))
8175 (goto-char (match-end 0))
8177 (gnus-article-add-button
8178 start end (nth 3 entry)
8179 (buffer-substring (match-beginning (nth 4 entry))
8180 (match-end (nth 4 entry)))))))
8181 (goto-char end))))))
8183 ;;; External functions:
8185 (defun gnus-article-add-button (from to fun &optional data text)
8186 "Create a button between FROM and TO with callback FUN and data DATA."
8187 (when gnus-article-button-face
8188 (overlay-put (make-overlay from to nil t)
8189 'face gnus-article-button-face))
8190 (gnus-add-text-properties
8192 (nconc (and gnus-article-mouse-face
8193 (list gnus-mouse-face-prop gnus-article-mouse-face))
8194 (list 'gnus-callback fun)
8195 (and data (list 'gnus-data data))))
8196 (widget-convert-button 'link from to :action 'gnus-widget-press-button
8197 :help-echo (or text "Follow the link")
8198 :keymap gnus-url-button-map
8199 :button-keymap gnus-widget-button-keymap))
8201 (defun gnus-article-copy-string ()
8202 "Copy the string in the button to the kill ring."
8204 (gnus-article-check-buffer)
8205 (let ((data (get-text-property (point) 'gnus-string)))
8209 (copy-region-as-kill (point-min) (point-max))
8210 (message "Copied %s" data)))))
8212 ;;; Internal functions:
8214 (defun gnus-article-set-globals ()
8215 (with-current-buffer gnus-summary-buffer
8216 (gnus-set-global-variables)))
8218 (defun gnus-signature-toggle (end)
8219 (gnus-with-article-buffer
8220 (let ((inhibit-point-motion-hooks t))
8221 (if (text-property-any end (point-max) 'article-type 'signature)
8223 (gnus-delete-wash-type 'signature)
8224 (gnus-remove-text-properties-when
8225 'article-type 'signature end (point-max)
8226 (cons 'article-type (cons 'signature
8227 gnus-hidden-properties))))
8228 (gnus-add-wash-type 'signature)
8229 (gnus-add-text-properties-when
8230 'article-type nil end (point-max)
8231 (cons 'article-type (cons 'signature
8232 gnus-hidden-properties)))))
8233 (let ((gnus-article-mime-handle-alist-1 gnus-article-mime-handle-alist))
8234 (gnus-set-mode-line 'article))))
8236 (defun gnus-button-push (marker-and-entry)
8237 ;; Push button starting at MARKER.
8239 (let* ((marker (car marker-and-entry))
8240 (entry (cadr marker-and-entry))
8241 (regexp (car entry))
8242 (inhibit-point-motion-hooks t))
8244 ;; This is obviously true, or something bad is happening :)
8245 ;; But we need it to have the match-data
8246 (when (looking-at (or (if (symbolp regexp)
8247 (symbol-value regexp)
8249 (let ((fun (nth 3 entry))
8250 (args (or (and (eq (car entry) 'gnus-button-url-regexp)
8251 (get-char-property marker 'gnus-button-url))
8252 (mapcar (lambda (group)
8253 (let ((string (match-string group)))
8254 (set-text-properties
8255 0 (length string) nil string)
8257 (nthcdr 4 entry)))))
8263 (fboundp (symbol-value fun)))
8264 (apply (symbol-value fun) args))
8266 (gnus-message 1 "You must define `%S' to use this button"
8267 (cons fun args)))))))))
8269 (defun gnus-parse-news-url (url)
8270 (let (scheme server port group message-id articles)
8273 (goto-char (point-min))
8274 (when (looking-at "\\([A-Za-z]+\\):")
8275 (setq scheme (match-string 1))
8276 (goto-char (match-end 0)))
8277 (when (looking-at "//\\([^:/]+\\)\\(:?\\)\\([0-9]+\\)?/")
8278 (setq server (match-string 1))
8279 (setq port (if (stringp (match-string 3))
8280 (string-to-number (match-string 3))
8282 (goto-char (match-end 0)))
8285 ((looking-at "\\(.*@.*\\)")
8286 (setq message-id (match-string 1)))
8287 ((looking-at "\\([^/]+\\)/\\([-0-9]+\\)")
8288 (setq group (match-string 1)
8289 articles (split-string (match-string 2) "-")))
8290 ((looking-at "\\([^/]+\\)/?")
8291 (setq group (match-string 1)))
8293 (error "Unknown news URL syntax"))))
8294 (list scheme server port group message-id articles)))
8296 (defvar nntp-port-number)
8298 (defun gnus-button-handle-news (url)
8300 (destructuring-bind (_scheme server port group message-id _articles)
8301 (gnus-parse-news-url url)
8304 (with-current-buffer gnus-summary-buffer
8306 (let ((gnus-refer-article-method
8307 (nconc (list (list 'nntp server))
8308 gnus-refer-article-method))
8309 (nntp-port-number (or port "nntp")))
8310 (gnus-message 7 "Fetching %s with %s"
8311 message-id gnus-refer-article-method)
8312 (gnus-summary-refer-article message-id))
8313 (gnus-summary-refer-article message-id))))
8315 (gnus-button-fetch-group url)))))
8317 (defun gnus-button-patch (library line)
8318 "Visit an Emacs Lisp library LIBRARY on line LINE."
8320 (let ((file (locate-library (file-name-nondirectory library))))
8322 (error "Couldn't find library %s" library))
8324 (goto-char (point-min))
8325 (forward-line (1- (string-to-number line)))))
8327 (defun gnus-button-handle-man (url)
8329 (gnus-message 9 "`%s' `%s'" gnus-button-man-handler url)
8330 (when (eq gnus-button-man-handler 'woman)
8331 (setq url (gnus-replace-in-string url "([1-9][X1a-z]*).*\\'" "")))
8332 (gnus-message 9 "`%s' `%s'" gnus-button-man-handler url)
8333 (funcall gnus-button-man-handler url))
8335 (defun gnus-button-handle-info-url (url)
8336 "Fetch an info URL."
8337 (setq url (mm-subst-char-in-string ?+ ?\ url))
8339 ((string-match "^\\([^:/]+\\)?/\\(.*\\)" url)
8340 (gnus-info-find-node
8341 (concat "(" (or (gnus-url-unhex-string (match-string 1 url))
8343 ")" (gnus-url-unhex-string (match-string 2 url)))))
8344 ((string-match "([^)\"]+)[^\"]+" url)
8346 (gnus-replace-in-string
8347 (gnus-replace-in-string url "[\n\t ]+" " ") "\"" ""))
8348 (gnus-info-find-node url))
8349 (t (error "Can't parse %s" url))))
8351 (defun gnus-button-handle-info-url-gnome (url)
8352 "Fetch GNOME style info URL."
8353 (setq url (mm-subst-char-in-string ?_ ?\ url))
8354 (if (string-match "\\([^#]+\\)#?\\(.*\\)" url)
8355 (gnus-info-find-node
8357 (gnus-url-unhex-string
8358 (match-string 1 url))
8360 (or (gnus-url-unhex-string
8361 (match-string 2 url))
8363 (error "Can't parse %s" url)))
8365 (defun gnus-button-handle-info-url-kde (url)
8366 "Fetch KDE style info URL."
8367 (gnus-info-find-node (gnus-url-unhex-string url)))
8369 ;; (info) will autoload info.el
8370 (declare-function Info-menu "info" (menu-item &optional fork))
8371 (declare-function Info-index-next "info" (num))
8373 (defun gnus-button-handle-info-keystrokes (url)
8374 "Call `info' when pushing the corresponding URL button."
8375 ;; For links like `C-h i d m gnus RET part RET , ,', `C-h i d m CC Mode RET'.
8376 (let (node indx comma)
8378 (concat "\\b\\(C-h\\|<?[Ff]1>?\\)[ \t\n]+i[ \t\n]+d?[ \t\n]?m[ \t\n]+"
8379 "\\([^ ]+ ?[^ ]+\\)[ \t\n]+RET"
8380 "\\([ \t\n]+i[ \t\n]+[^ ]+ ?[^ ]+[ \t\n]+RET\\>"
8381 "\\(?:[ \t\n,]*\\)\\)?")
8383 (setq node (match-string 2 url)
8384 indx (match-string 3 url))
8385 (error "Can't parse %s" url))
8389 (when (> (length indx) 0)
8390 (string-match (concat "[ \t\n]+i[ \t\n]+\\([^ ]+ ?[^ ]+\\)[ \t\n]+RET\\>"
8393 (setq comma (match-string 2 indx))
8394 (setq indx (match-string 1 indx))
8397 (dotimes (i (with-temp-buffer
8399 ;; Note: the XEmacs version of `how-many' takes
8400 ;; no optional argument.
8401 (goto-char (point-min))
8403 (Info-index-next 1)))
8406 (autoload 'pgg-snarf-keys-region "pgg")
8407 ;; Called after pgg-snarf-keys-region, which autoloads pgg.el.
8408 (declare-function pgg-display-output-buffer "pgg" (start end status))
8410 (defun gnus-button-openpgp (url)
8411 "Retrieve and add an OpenPGP key given URL from an OpenPGP header."
8413 (mm-url-insert-file-contents-external url)
8414 (pgg-snarf-keys-region (point-min) (point-max))
8415 (pgg-display-output-buffer nil nil nil)))
8417 (defun gnus-button-message-id (message-id)
8419 (with-current-buffer gnus-summary-buffer
8420 (gnus-summary-refer-article message-id)))
8422 (defun gnus-button-fetch-group (address &rest _ignore)
8423 "Fetch GROUP specified by ADDRESS."
8424 (when (string-match "\\`\\(nntp\\|news\\):\\(//\\)?\\(.*\\)\\'"
8426 ;; Allow to use `gnus-button-fetch-group' in `browse-url-browser-function'
8427 ;; for nntp:// and news://
8428 (setq address (match-string 3 address)))
8429 (if (not (string-match "[:/]" address))
8430 ;; This is just a simple group url.
8431 (gnus-group-read-ephemeral-group address gnus-select-method)
8434 "^\\([^:/]+\\)\\(:\\([^/]+\\)\\)?/\\([^/]+\\)\\(/\\([0-9]+\\)\\)?"
8436 (error "Can't parse %s" address)
8437 (gnus-group-read-ephemeral-group
8438 (match-string 4 address)
8439 `(nntp ,(match-string 1 address)
8440 (nntp-address ,(match-string 1 address))
8441 (nntp-port-number ,(if (match-end 3)
8442 (match-string 3 address)
8445 (and (match-end 6) (list (string-to-number (match-string 6 address))))))))
8447 (defun gnus-url-parse-query-string (query &optional downcase)
8448 (let (retval pairs cur key val)
8449 (setq pairs (split-string query "&"))
8451 (setq cur (car pairs)
8453 (if (not (string-match "=" cur))
8455 (setq key (gnus-url-unhex-string (substring cur 0 (match-beginning 0)))
8456 val (gnus-url-unhex-string (substring cur (match-end 0) nil) t))
8458 (setq key (downcase key)))
8459 (setq cur (assoc key retval))
8461 (setcdr cur (cons val (cdr cur)))
8462 (setq retval (cons (list key val) retval)))))
8465 (defun gnus-url-mailto (url)
8466 ;; Send mail to someone
8467 (setq url (replace-regexp-in-string "\n" " " url))
8468 (when (string-match "mailto:/*\\(.*\\)" url)
8469 (setq url (substring url (match-beginning 1) nil)))
8470 (let* ((args (gnus-url-parse-query-string
8471 (if (string-match "^\\?" url)
8473 (if (string-match "^\\([^?]+\\)\\?\\(.*\\)" url)
8474 (concat "to=" (match-string 1 url) "&"
8475 (match-string 2 url))
8476 (concat "to=" url)))))
8477 (subject (cdr-safe (assoc "subject" args)))
8481 (setq func (intern-soft (concat "message-goto-" (downcase (caar args)))))
8484 (message-position-on-field (caar args)))
8485 (insert (gnus-replace-in-string
8486 (mapconcat 'identity (reverse (cdar args)) ", ")
8488 (setq args (cdr args)))
8491 (message-goto-subject))))
8493 (defun gnus-button-embedded-url (address)
8494 "Activate ADDRESS with `browse-url'."
8495 (browse-url (gnus-strip-whitespace address)))
8497 ;;; Next/prev buttons in the article buffer.
8499 (defvar gnus-next-page-line-format "%{%(Next page...%)%}\n")
8500 (defvar gnus-prev-page-line-format "%{%(Previous page...%)%}\n")
8502 (defvar gnus-prev-page-map
8503 (let ((map (make-sparse-keymap)))
8504 (define-key map gnus-mouse-2 'gnus-button-prev-page)
8505 (define-key map "\r" 'gnus-button-prev-page)
8508 (defvar gnus-next-page-map
8509 (let ((map (make-sparse-keymap)))
8510 (define-key map gnus-mouse-2 'gnus-button-next-page)
8511 (define-key map "\r" 'gnus-button-next-page)
8514 (defun gnus-insert-prev-page-button ()
8516 (inhibit-read-only t))
8518 gnus-prev-page-line-format nil
8519 `(keymap ,gnus-prev-page-map
8521 gnus-callback gnus-article-button-prev-page
8522 article-type annotation))
8524 ;; Exclude a newline.
8527 (when gnus-article-button-face
8528 (overlay-put (make-overlay b e nil t)
8529 'face gnus-article-button-face))
8530 (widget-convert-button
8532 :action 'gnus-button-prev-page
8533 :button-keymap gnus-prev-page-map)))
8535 (defun gnus-button-next-page (&optional _args _more-args)
8536 "Go to the next page."
8538 (let ((win (selected-window)))
8539 (select-window (gnus-get-buffer-window gnus-article-buffer t))
8540 (gnus-article-next-page)
8541 (select-window win)))
8543 (defun gnus-button-prev-page (&optional _args _more-args)
8544 "Go to the prev page."
8546 (let ((win (selected-window)))
8547 (select-window (gnus-get-buffer-window gnus-article-buffer t))
8548 (gnus-article-prev-page)
8549 (select-window win)))
8551 (defun gnus-insert-next-page-button ()
8553 (inhibit-read-only t))
8554 (gnus-eval-format gnus-next-page-line-format nil
8555 `(keymap ,gnus-next-page-map
8557 gnus-callback gnus-article-button-next-page
8558 article-type annotation))
8560 ;; Exclude a newline.
8563 (when gnus-article-button-face
8564 (overlay-put (make-overlay b e nil t)
8565 'face gnus-article-button-face))
8566 (widget-convert-button
8568 :action 'gnus-button-next-page
8569 :button-keymap gnus-next-page-map)))
8571 (defun gnus-article-button-next-page (_arg)
8572 "Go to the next page."
8574 (let ((win (selected-window)))
8575 (select-window (gnus-get-buffer-window gnus-article-buffer t))
8576 (gnus-article-next-page)
8577 (select-window win)))
8579 (defun gnus-article-button-prev-page (_arg)
8580 "Go to the prev page."
8582 (let ((win (selected-window)))
8583 (select-window (gnus-get-buffer-window gnus-article-buffer t))
8584 (gnus-article-prev-page)
8585 (select-window win)))
8587 (defvar gnus-decode-header-methods
8588 '(mail-decode-encoded-word-region)
8589 "List of methods used to decode headers.
8591 This variable is a list of FUNCTION or (REGEXP . FUNCTION). If item
8592 is FUNCTION, FUNCTION will be applied to all newsgroups. If item is a
8593 \(REGEXP . FUNCTION), FUNCTION will be only apply to the newsgroups
8594 whose names match REGEXP.
8597 \((\"chinese\" . gnus-decode-encoded-word-region-by-guess)
8598 mail-decode-encoded-word-region
8599 (\"chinese\" . rfc1843-decode-region))
8602 (defvar gnus-decode-header-methods-cache nil)
8604 (defun gnus-multi-decode-header (start end)
8605 "Apply the functions from `gnus-encoded-word-methods' that match."
8606 (unless (and gnus-decode-header-methods-cache
8607 (eq gnus-newsgroup-name
8608 (car gnus-decode-header-methods-cache)))
8609 (setq gnus-decode-header-methods-cache (list gnus-newsgroup-name))
8610 (dolist (x gnus-decode-header-methods)
8612 (nconc gnus-decode-header-methods-cache (list x))
8613 (if (and gnus-newsgroup-name
8614 (string-match (car x) gnus-newsgroup-name))
8615 (nconc gnus-decode-header-methods-cache
8617 (let ((xlist gnus-decode-header-methods-cache))
8620 (narrow-to-region start end)
8622 (funcall (pop xlist) (point-min) (point-max))))))
8625 ;;; Treatment top-level handling.
8628 (defvar gnus-inhibit-article-treatments nil)
8630 ;; Dynamic variables.
8631 (defvar part-number) ;FIXME: Lacks a "gnus-" prefix.
8632 (defvar total-parts) ;FIXME: Lacks a "gnus-" prefix.
8633 (defvar gnus-treat-type)
8634 (defvar gnus-treat-condition)
8635 (defvar gnus-treat-length)
8637 (defun gnus-treat-article (condition
8638 &optional part-num total type)
8639 (let ((gnus-treat-condition condition)
8640 (part-number part-num)
8642 (gnus-treat-type type)
8643 (gnus-treat-length (- (point-max) (point-min)))
8644 (alist gnus-treatment-function-alist)
8645 (article-goto-body-goes-to-point-min-p t)
8649 (let ((list gnus-article-treat-types))
8651 (when (string-match (pop list) type)
8652 (throw 'found t)))))))
8653 (highlightp (gnus-visual-p 'article-highlight 'highlight))
8655 (gnus-run-hooks 'gnus-part-display-hook)
8656 (dolist (elem alist)
8659 (when (gnus-buffer-live-p gnus-summary-buffer)
8660 (set-buffer gnus-summary-buffer))
8661 (symbol-value (car elem))))
8662 (when (and (or (consp val)
8664 (or (not gnus-inhibit-article-treatments)
8665 (eq gnus-treat-condition 'head))
8666 (gnus-treat-predicate val)
8667 (or (not (get (car elem) 'highlight))
8670 (funcall (cadr elem)))))))
8672 (defun gnus-treat-predicate (val)
8676 (gnus-treat-condition
8677 (eq gnus-treat-condition val))
8679 (stringp (car val)))
8680 (apply 'gnus-or (mapcar `(lambda (s)
8681 (string-match s ,(or gnus-newsgroup-name "")))
8684 (let ((pred (pop val)))
8687 (apply 'gnus-or (mapcar 'gnus-treat-predicate val)))
8689 (apply 'gnus-and (mapcar 'gnus-treat-predicate val)))
8691 (not (gnus-treat-predicate (car val))))
8693 (equal (car val) gnus-treat-type))
8697 (error "%S is not a valid predicate" pred)))))
8705 (eq part-number total-parts))
8707 (< gnus-treat-length val))
8709 (error "%S is not a valid value" val))))
8711 (defun gnus-article-encrypt-body (protocol &optional n)
8712 "Encrypt the article body."
8715 (or gnus-article-encrypt-protocol
8716 (gnus-completing-read "Encrypt protocol"
8717 (mapcar 'car gnus-article-encrypt-protocol-alist)
8719 current-prefix-arg))
8720 ;; User might hit `K E' instead of `K e', so prompt once.
8721 (when (and gnus-article-encrypt-protocol
8723 (unless (gnus-y-or-n-p "Really encrypt article(s)? ")
8724 (error "Encrypt aborted")))
8725 (let ((func (cdr (assoc protocol gnus-article-encrypt-protocol-alist))))
8727 (error "Can't find the encrypt protocol %s" protocol))
8728 (if (member gnus-newsgroup-name '("nndraft:delayed"
8731 (error "Can't encrypt the article in group %s"
8732 gnus-newsgroup-name))
8733 (gnus-summary-iterate n
8734 (with-current-buffer gnus-summary-buffer
8735 (let ((mail-parse-charset gnus-newsgroup-charset)
8736 (mail-parse-ignored-charsets gnus-newsgroup-ignored-charsets)
8737 (summary-buffer gnus-summary-buffer)
8739 (gnus-set-global-variables)
8740 (when (gnus-group-read-only-p)
8741 (error "The current newsgroup does not support article encrypt"))
8742 (gnus-summary-show-article t)
8744 (or (mail-header-references gnus-current-headers) ""))
8745 (set-buffer gnus-article-buffer)
8746 (let* ((inhibit-read-only t)
8748 (mapcar (lambda (field)
8749 (and (save-restriction
8750 (message-narrow-to-head)
8751 (goto-char (point-min))
8752 (search-forward field nil t))
8754 (message-narrow-to-field)
8756 (delete-region (point-min) (point-max))
8758 '("Content-Type:" "Content-Transfer-Encoding:"
8759 "Content-Disposition:"))))
8760 (message-narrow-to-head)
8761 (message-remove-header "MIME-Version")
8762 (goto-char (point-max))
8763 (setq point (point))
8764 (insert (apply 'concat headers))
8766 (narrow-to-region point (point-max))
8767 (let ((message-options message-options))
8768 (message-options-set 'message-sender user-mail-address)
8769 (message-options-set 'message-recipients user-mail-address)
8770 (message-options-set 'message-sign-encrypt 'not)
8772 (goto-char (point-min))
8773 (insert "MIME-Version: 1.0\n")
8775 (gnus-summary-edit-article-done
8776 references nil summary-buffer t))
8777 (when gnus-keep-backlog
8778 (gnus-backlog-remove-article
8779 (car gnus-article-current) (cdr gnus-article-current)))
8780 (gnus-flush-original-article-buffer)
8781 (when gnus-use-cache
8782 (gnus-cache-update-article
8783 (car gnus-article-current) (cdr gnus-article-current))))))))
8785 (defvar gnus-mime-security-button-line-format "%{%([[%t:%i]%D]%)%}\n"
8786 "The following specs can be used:
8787 %t The security MIME type
8790 %D Details if button is pressed")
8792 (defvar gnus-mime-security-button-end-line-format "%{%([[End of %t]%D]%)%}\n"
8793 "The following specs can be used:
8794 %t The security MIME type
8797 %D Details if button is pressed")
8799 (defvar gnus-mime-security-button-line-format-alist
8800 '((?t gnus-tmp-type ?s)
8801 (?i gnus-tmp-info ?s)
8802 (?d gnus-tmp-details ?s)
8803 (?D gnus-tmp-pressed-details ?s)))
8805 (defvar gnus-mime-security-button-commands
8806 '((gnus-article-press-button "\r" "Show Detail")
8810 (gnus-mime-security-save-part "o" "Save...")
8819 (gnus-mime-security-pipe-part "|" "Pipe To Command...")
8822 (defvar gnus-mime-security-button-map
8823 (let ((map (make-sparse-keymap)))
8824 (define-key map gnus-mouse-2 'gnus-article-push-button)
8825 (define-key map gnus-down-mouse-3 'gnus-mime-security-button-menu)
8826 (dolist (c gnus-mime-security-button-commands)
8827 (define-key map (cadr c) (car c)))
8831 gnus-mime-security-button-menu gnus-mime-security-button-map
8832 "Security button menu."
8836 (unless (eq (car c) 'undefined)
8837 (vector (caddr c) (car c) :active t)))
8838 gnus-mime-security-button-commands))))
8840 (defun gnus-mime-security-button-menu (event prefix)
8841 "Construct a context-sensitive menu of security commands."
8842 (interactive "e\nP")
8843 (save-window-excursion
8844 (let ((pos (event-start event)))
8845 (select-window (posn-window pos))
8846 (goto-char (posn-point pos))
8847 (gnus-article-check-buffer)
8848 (popup-menu gnus-mime-security-button-menu nil prefix))))
8850 (defvar gnus-mime-security-details-buffer nil)
8852 (defvar gnus-mime-security-button-pressed nil)
8854 (defvar gnus-mime-security-show-details-inline t
8855 "If non-nil, show details in the article buffer.")
8857 (defun gnus-mime-security-verify-or-decrypt (handle)
8858 (mm-remove-parts (cdr handle))
8859 (let ((region (mm-handle-multipart-ctl-parameter handle 'gnus-region))
8860 point (inhibit-read-only t))
8862 (goto-char (car region)))
8863 (setq point (point))
8864 (with-current-buffer (mm-handle-multipart-original-buffer handle)
8865 (let* ((mm-verify-option 'known)
8866 (mm-decrypt-option 'known)
8867 (nparts (mm-possibly-verify-or-decrypt (cdr handle) handle)))
8868 (unless (eq nparts (cdr handle))
8869 (mm-destroy-parts (cdr handle))
8870 (setcdr handle nparts))))
8871 (gnus-mime-display-security handle)
8873 (delete-region (point) (cdr region))
8874 (set-marker (car region) nil)
8875 (set-marker (cdr region) nil))
8878 (defun gnus-mime-security-show-details (handle)
8879 (let ((details (mm-handle-multipart-ctl-parameter handle 'gnus-details)))
8881 (gnus-message 5 "No details.")
8882 (if gnus-mime-security-show-details-inline
8883 (let ((gnus-mime-security-button-pressed
8884 (not (get-text-property (point) 'gnus-mime-details)))
8885 (gnus-mime-security-button-line-format
8886 (get-text-property (point) 'gnus-line-format))
8887 (inhibit-read-only t))
8889 (while (eq (get-text-property (point) 'gnus-line-format)
8890 gnus-mime-security-button-line-format)
8894 (narrow-to-region (point) (point))
8895 (gnus-insert-mime-security-button handle))
8896 (delete-region (point)
8897 (or (text-property-not-all
8900 gnus-mime-security-button-line-format)
8903 (if (gnus-buffer-live-p gnus-mime-security-details-buffer)
8904 (with-current-buffer gnus-mime-security-details-buffer
8907 (setq gnus-mime-security-details-buffer
8908 (gnus-get-buffer-create "*MIME Security Details*")))
8909 (with-current-buffer gnus-mime-security-details-buffer
8911 (goto-char (point-min)))
8912 (pop-to-buffer gnus-mime-security-details-buffer)))))
8914 (defun gnus-mime-security-press-button (handle)
8916 (if (mm-handle-multipart-ctl-parameter handle 'gnus-info)
8917 (gnus-mime-security-show-details handle)
8918 (gnus-mime-security-verify-or-decrypt handle))))
8920 (defun gnus-insert-mime-security-button (handle &optional _displayed)
8921 (let* ((protocol (mm-handle-multipart-ctl-parameter handle 'protocol))
8924 (or (nth 2 (assoc protocol mm-verify-function-alist))
8925 (nth 2 (assoc protocol mm-decrypt-function-alist))
8927 (if (equal (car handle) "multipart/signed")
8928 " Signed" " Encrypted")
8931 (or (mm-handle-multipart-ctl-parameter handle 'gnus-info)
8934 (mm-handle-multipart-ctl-parameter handle 'gnus-details))
8935 gnus-tmp-pressed-details
8937 (setq gnus-tmp-details
8938 (if gnus-tmp-details
8939 (concat "\n" gnus-tmp-details)
8941 (setq gnus-tmp-pressed-details
8942 (if gnus-mime-security-button-pressed gnus-tmp-details ""))
8947 gnus-mime-security-button-line-format
8948 gnus-mime-security-button-line-format-alist
8949 `(keymap ,gnus-mime-security-button-map
8950 gnus-callback gnus-mime-security-press-button
8951 gnus-line-format ,gnus-mime-security-button-line-format
8952 gnus-mime-details ,gnus-mime-security-button-pressed
8953 article-type annotation
8956 ;; Exclude a newline.
8959 (when gnus-article-button-face
8960 (overlay-put (make-overlay b e nil t)
8961 'face gnus-article-button-face))
8962 (widget-convert-button
8965 :action 'gnus-widget-press-button
8966 :button-keymap gnus-mime-security-button-map
8969 ;; Needed to properly clear the message due to a bug in
8970 ;; wid-edit (XEmacs only).
8971 (when (boundp 'help-echo-owns-message)
8972 (setq help-echo-owns-message t))
8974 "%S: show detail; %S: more options"
8975 (aref gnus-mouse-2 0)
8976 (aref gnus-down-mouse-3 0))))))
8978 (defun gnus-mime-display-security (handle)
8980 (narrow-to-region (point) (point))
8981 (unless (gnus-unbuttonized-mime-type-p (car handle))
8982 (gnus-insert-mime-security-button handle))
8983 (gnus-mime-display-part (cadr handle))
8986 (unless (gnus-unbuttonized-mime-type-p (car handle))
8987 (let ((gnus-mime-security-button-line-format
8988 gnus-mime-security-button-end-line-format))
8989 (gnus-insert-mime-security-button handle)))
8990 (mm-set-handle-multipart-parameter
8991 handle 'gnus-region (cons (point-min-marker) (point-max-marker)))
8992 (goto-char (point-max))))
8994 (defun gnus-mime-security-run-function (function)
8995 "Run FUNCTION with the security part under point."
8996 (gnus-article-check-buffer)
8997 (let ((data (get-text-property (point) 'gnus-data))
8999 (when (and (stringp (car-safe data))
9000 (setq buffer (mm-handle-multipart-original-buffer data))
9001 (setq handle (cadr data)))
9002 (if (bufferp (mm-handle-buffer handle))
9004 (setq handle (cons buffer (copy-sequence (cdr handle))))
9005 (mm-handle-set-undisplayer handle nil))
9006 (setq handle (mm-make-handle
9008 (mm-handle-multipart-ctl-parameter handle 'protocol)
9009 nil nil nil nil nil nil)))
9010 (funcall function handle))))
9012 (defun gnus-mime-security-save-part ()
9013 "Save the security part under point."
9015 (gnus-mime-security-run-function 'mm-save-part))
9017 (defun gnus-mime-security-pipe-part ()
9018 "Pipe the security part under point to a process."
9020 (gnus-mime-security-run-function 'mm-pipe-part))
9026 (run-hooks 'gnus-art-load-hook)
9028 ;;; gnus-art.el ends here