1 ;;; gnus-art.el --- article mode commands for Gnus
3 ;; Copyright (C) 1996-2014 Free Software Foundation, Inc.
5 ;; Author: Lars Magne Ingebrigtsen <larsi@gnus.org>
8 ;; This file is part of GNU Emacs.
10 ;; GNU Emacs is free software: you can redistribute it and/or modify
11 ;; it under the terms of the GNU General Public License as published by
12 ;; the Free Software Foundation, either version 3 of the License, or
13 ;; (at your option) any later version.
15 ;; GNU Emacs is distributed in the hope that it will be useful,
16 ;; but WITHOUT ANY WARRANTY; without even the implied warranty of
17 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 ;; GNU General Public License for more details.
20 ;; You should have received a copy of the GNU General Public License
21 ;; along with GNU Emacs. If not, see <http://www.gnu.org/licenses/>.
30 (defvar w3m-minor-mode-map)
47 (autoload 'gnus-msg-mail "gnus-msg" nil t)
48 (autoload 'gnus-button-mailto "gnus-msg")
49 (autoload 'gnus-button-reply "gnus-msg" nil t)
50 (autoload 'parse-time-string "parse-time" nil nil)
51 (autoload 'ansi-color-apply-on-region "ansi-color")
52 (autoload 'mm-url-insert-file-contents-external "mm-url")
53 (autoload 'mm-extern-cache-contents "mm-extern")
55 (defgroup gnus-article nil
57 :link '(custom-manual "(gnus)Article Buffer")
60 (defgroup gnus-article-treat nil
61 "Treating article parts."
62 :link '(custom-manual "(gnus)Article Hiding")
65 (defgroup gnus-article-hiding nil
66 "Hiding article parts."
67 :link '(custom-manual "(gnus)Article Hiding")
70 (defgroup gnus-article-highlight nil
71 "Article highlighting."
72 :link '(custom-manual "(gnus)Article Highlighting")
76 (defgroup gnus-article-signature nil
78 :link '(custom-manual "(gnus)Article Signature")
81 (defgroup gnus-article-headers nil
83 :link '(custom-manual "(gnus)Hiding Headers")
86 (defgroup gnus-article-washing nil
87 "Special commands on articles."
88 :link '(custom-manual "(gnus)Article Washing")
91 (defgroup gnus-article-emphasis nil
92 "Fontisizing articles."
93 :link '(custom-manual "(gnus)Article Fontisizing")
96 (defgroup gnus-article-saving nil
98 :link '(custom-manual "(gnus)Saving Articles")
101 (defgroup gnus-article-mime nil
102 "Worshiping the MIME wonder."
103 :link '(custom-manual "(gnus)Using MIME")
104 :group 'gnus-article)
106 (defgroup gnus-article-buttons nil
107 "Pushable buttons in the article buffer."
108 :link '(custom-manual "(gnus)Article Buttons")
109 :group 'gnus-article)
111 (defgroup gnus-article-various nil
112 "Other article options."
113 :link '(custom-manual "(gnus)Misc Article")
114 :group 'gnus-article)
116 (defcustom gnus-ignored-headers
119 (concat "^" header ":"))
120 '("Path" "Expires" "Date-Received" "References" "Xref" "Lines"
121 "Relay-Version" "Message-ID" "Approved" "Sender" "Received"
122 "X-UIDL" "MIME-Version" "Return-Path" "In-Reply-To"
123 "Content-Type" "Content-Transfer-Encoding" "X-WebTV-Signature"
124 "X-MimeOLE" "X-MSMail-Priority" "X-Priority" "X-Loop"
125 "X-Authentication-Warning" "X-MIME-Autoconverted" "X-Face"
126 "X-Attribution" "X-Originating-IP" "Delivered-To"
127 "NNTP-[-A-Za-z]+" "Distribution" "X-no-archive" "X-Trace"
128 "X-Complaints-To" "X-NNTP-Posting-Host" "X-Orig.*"
129 "Abuse-Reports-To" "Cache-Post-Path" "X-Article-Creation-Date"
130 "X-Poster" "X-Mail2News-Path" "X-Server-Date" "X-Cache"
131 "Originator" "X-Problems-To" "X-Auth-User" "X-Post-Time"
132 "X-Admin" "X-UID" "Resent-[-A-Za-z]+" "X-Mailing-List"
133 "Precedence" "Original-[-A-Za-z]+" "X-filename" "X-Orcpt"
134 "Old-Received" "X-Pgp" "X-Auth" "X-From-Line"
135 "X-Gnus-Article-Number" "X-Majordomo" "X-Url" "X-Sender"
136 "MBOX-Line" "Priority" "X400-[-A-Za-z]+"
137 "Status" "X-Gnus-Mail-Source" "Cancel-Lock"
138 "X-FTN" "X-EXP32-SerialNo" "Encoding" "Importance"
139 "Autoforwarded" "Original-Encoded-Information-Types" "X-Ya-Pop3"
140 "X-Face-Version" "X-Vms-To" "X-ML-NAME" "X-ML-COUNT"
141 "Mailing-List" "X-finfo" "X-md5sum" "X-md5sum-Origin"
142 "X-Sun-Charset" "X-Accept-Language" "X-Envelope-Sender"
143 "List-[A-Za-z]+" "X-Listprocessor-Version"
144 "X-Received" "X-Distribute" "X-Sequence" "X-Juno-Line-Breaks"
145 "X-Notes-Item" "X-MS-TNEF-Correlator" "x-uunet-gateway"
146 "X-Received" "Content-length" "X-precedence"
147 "X-Authenticated-User" "X-Comment" "X-Report" "X-Abuse-Info"
148 "X-HTTP-Proxy" "X-Mydeja-Info" "X-Copyright" "X-No-Markup"
149 "X-Abuse-Info" "X-From_" "X-Accept-Language" "Errors-To"
150 "X-BeenThere" "X-Mailman-Version" "List-Help" "List-Post"
151 "List-Subscribe" "List-Id" "List-Unsubscribe" "List-Archive"
152 "X-Content-length" "X-Posting-Agent" "Original-Received"
153 "X-Request-PGP" "X-Fingerprint" "X-WRIEnvto" "X-WRIEnvfrom"
154 "X-Virus-Scanned" "X-Delivery-Agent" "Posted-Date" "X-Gateway"
155 "X-Local-Origin" "X-Local-Destination" "X-UserInfo1"
156 "X-Received-Date" "X-Hashcash" "Face" "X-DMCA-Notifications"
157 "X-Abuse-and-DMCA-Info" "X-Postfilter" "X-Gpg-.*" "X-Disclaimer"
158 "Envelope-To" "X-Spam-Score" "System-Type" "X-Injected-Via-Gmane"
159 "X-Gmane-NNTP-Posting-Host" "Jabber-ID" "Archived-At"
160 "Envelope-Sender" "Envelope-Recipients"))
161 "*All headers that start with this regexp will be hidden.
162 This variable can also be a list of regexps of headers to be ignored.
163 If `gnus-visible-headers' is non-nil, this variable will be ignored."
164 :type '(choice regexp
166 :group 'gnus-article-hiding)
168 (defcustom gnus-visible-headers
169 "^From:\\|^Newsgroups:\\|^Subject:\\|^Date:\\|^Followup-To:\\|^Reply-To:\\|^Organization:\\|^Summary:\\|^Keywords:\\|^To:\\|^[BGF]?Cc:\\|^Posted-To:\\|^Mail-Copies-To:\\|^Mail-Followup-To:\\|^Apparently-To:\\|^Gnus-Warning:\\|^Resent-From:"
170 "*All headers that do not match this regexp will be hidden.
171 This variable can also be a list of regexp of headers to remain visible.
172 If this variable is non-nil, `gnus-ignored-headers' will be ignored."
174 (repeat :value-to-internal (lambda (widget value)
175 (custom-split-regexp-maybe value))
176 :match (lambda (widget value)
178 (widget-editable-list-match widget value)))
180 (const :tag "Use gnus-ignored-headers" nil)
182 :group 'gnus-article-hiding)
184 (defcustom gnus-sorted-header-list
185 '("^From:" "^Subject:" "^Summary:" "^Keywords:" "^Newsgroups:"
186 "^Followup-To:" "^To:" "^Cc:" "^Date:" "^Organization:")
187 "*This variable is a list of regular expressions.
188 If it is non-nil, headers that match the regular expressions will
189 be placed first in the article buffer in the sequence specified by
191 :type '(repeat regexp)
192 :group 'gnus-article-hiding)
194 (defcustom gnus-boring-article-headers '(empty followup-to reply-to)
195 "Headers that are only to be displayed if they have interesting data.
196 Possible values in this list are:
198 'empty Headers with no content.
199 'newsgroups Newsgroup identical to Gnus group.
200 'to-address To identical to To-address.
201 'to-list To identical to To-list.
202 'cc-list CC identical to To-list.
203 'followup-to Followup-to identical to Newsgroups.
204 'reply-to Reply-to identical to From.
205 'date Date less than four days old.
206 'long-to To and/or Cc longer than 1024 characters.
207 'many-to Multiple To and/or Cc."
208 :type '(set (const :tag "Headers with no content." empty)
209 (const :tag "Newsgroups identical to Gnus group." newsgroups)
210 (const :tag "To identical to To-address." to-address)
211 (const :tag "To identical to To-list." to-list)
212 (const :tag "CC identical to To-list." cc-list)
213 (const :tag "Followup-to identical to Newsgroups." followup-to)
214 (const :tag "Reply-to identical to From." reply-to)
215 (const :tag "Date less than four days old." date)
216 (const :tag "To and/or Cc longer than 1024 characters." long-to)
217 (const :tag "Multiple To and/or Cc headers." many-to))
218 :group 'gnus-article-hiding)
220 (defcustom gnus-article-skip-boring nil
221 "Skip over text that is not worth reading.
222 By default, if you set this t, then Gnus will display citations and
223 signatures, but will never scroll down to show you a page consisting
224 only of boring text. Boring text is controlled by
225 `gnus-article-boring-faces'."
228 :group 'gnus-article-hiding)
230 (defcustom gnus-signature-separator '("^-- $" "^-- *$")
231 "Regexp matching signature separator.
232 This can also be a list of regexps. In that case, it will be checked
233 from head to tail looking for a separator. Searches will be done from
234 the end of the buffer."
235 :type '(choice :format "%{%t%}: %[Value Menu%]\n%v"
237 (repeat :tag "List of regexp" regexp))
238 :group 'gnus-article-signature)
240 (defcustom gnus-signature-limit nil
241 "Provide a limit to what is considered a signature.
242 If it is a number, no signature may not be longer (in characters) than
243 that number. If it is a floating point number, no signature may be
244 longer (in lines) than that number. If it is a function, the function
245 will be called without any parameters, and if it returns nil, there is
246 no signature in the buffer. If it is a string, it will be used as a
247 regexp. If it matches, the text in question is not a signature.
249 This can also be a list of the above values."
250 :type '(choice (const nil)
254 (regexp :value ".*"))
255 :group 'gnus-article-signature)
257 (defcustom gnus-hidden-properties
258 (if (featurep 'xemacs)
259 ;; `intangible' is evil, but I keep it here in case it's useful.
260 '(invisible t intangible t)
261 ;; Emacs's command loop moves point out of invisible text anyway, so
262 ;; `intangible' is clearly not needed there.
264 "Property list to use for hiding text."
266 :group 'gnus-article-hiding)
268 ;; Fixme: This isn't the right thing for mixed graphical and non-graphical
269 ;; frames in a session.
270 (defcustom gnus-article-x-face-command
271 (if (featurep 'xemacs)
272 (if (or (gnus-image-type-available-p 'xface)
273 (gnus-image-type-available-p 'pbm))
274 'gnus-display-x-face-in-from
276 '/* Format_version=1, Width=48, Height=48, Depth=1, Valid_bits_per_item=16 */'\
277 ; uncompface; } | icontopbm | ee -")
278 (if (gnus-image-type-available-p 'pbm)
279 'gnus-display-x-face-in-from
281 '/* Format_version=1, Width=48, Height=48, Depth=1, Valid_bits_per_item=16 */'\
282 ; uncompface; } | icontopbm | display -"))
283 "*String or function to be executed to display an X-Face header.
284 If it is a string, the command will be executed in a sub-shell
285 asynchronously. The compressed face will be piped to this command."
286 :type `(choice string
287 (function-item gnus-display-x-face-in-from)
291 :group 'gnus-article-washing)
293 (defcustom gnus-article-x-face-too-ugly nil
294 "Regexp matching posters whose face shouldn't be shown automatically."
295 :type '(choice regexp (const nil))
296 :group 'gnus-article-washing)
298 (defcustom gnus-article-banner-alist nil
299 "Banner alist for stripping.
301 ((egroups . \"^[ \\t\\n]*-------------------+\\\\( \\\\(e\\\\|Yahoo! \\\\)Groups Sponsor -+\\\\)?....\\n\\\\(.+\\n\\\\)+\"))"
303 :type '(repeat (cons symbol regexp))
304 :group 'gnus-article-washing)
306 (gnus-define-group-parameter
309 "Alist of regexps (to match group names) and banner."
310 :variable-group gnus-article-washing
312 '(choice :tag "Banner"
314 (const :tag "Remove signature" signature)
315 (symbol :tag "Item in `gnus-article-banner-alist'" none)
317 (const :tag "None" nil))
319 "If non-nil, specify how to remove `banners' from articles.
321 Symbol `signature' means to remove signatures delimited by
322 `gnus-signature-separator'. Any other symbol is used to look up a
323 regular expression to match the banner in `gnus-article-banner-alist'.
324 A string is used as a regular expression to match the banner
327 (defcustom gnus-article-address-banner-alist nil
328 "Alist of mail addresses and banners.
329 Each element has the form (ADDRESS . BANNER), where ADDRESS is a regexp
330 to match a mail address in the From: header, BANNER is one of a symbol
331 `signature', an item in `gnus-article-banner-alist', a regexp and nil.
332 If ADDRESS matches author's mail address, it will remove things like
333 advertisements. For example:
335 \((\"@yoo-hoo\\\\.co\\\\.jp\\\\'\" . \"\\n_+\\nDo You Yoo-hoo!\\\\?\\n.*\\n.*\\n\"))
339 (regexp :tag "Address")
340 (choice :tag "Banner" :value nil
341 (const :tag "Remove signature" signature)
342 (symbol :tag "Item in `gnus-article-banner-alist'" none)
344 (const :tag "None" nil))))
346 :group 'gnus-article-washing)
348 (defmacro gnus-emphasis-custom-with-format (&rest body)
350 \\(\\s-\\|^\\|\\=\\|[-\"]\\|\\s(\\)\\(%s\\(\\w+\\(\\s-+\\w+\\)*[.,]?\\)%s\\)\
351 \\(\\([-,.;:!?\"]\\|\\s)\\)+\\s-\\|[?!.]\\s-\\|\\s)\\|\\s-\\)"))
354 (defun gnus-emphasis-custom-value-to-external (value)
355 (gnus-emphasis-custom-with-format
356 (if (consp (car value))
357 (list (format format (car (car value)) (cdr (car value)))
359 (if (nth 1 value) 2 3)
363 (defun gnus-emphasis-custom-value-to-internal (value)
364 (gnus-emphasis-custom-with-format
365 (let ((regexp (concat "\\`"
366 (format (regexp-quote format)
367 "\\([^()]+\\)" "\\([^()]+\\)")
370 (if (string-match regexp (setq pattern (car value)))
371 (list (cons (match-string 1 pattern) (match-string 2 pattern))
376 (defcustom gnus-emphasis-alist
378 '(("\\*" "\\*" bold nil 2)
381 ("_/" "/_" underline-italic)
382 ("_\\*" "\\*_" underline-bold)
383 ("\\*/" "/\\*" bold-italic)
384 ("_\\*/" "/\\*_" underline-bold-italic))))
386 (gnus-emphasis-custom-with-format
387 (mapcar (lambda (spec)
388 (list (format format (car spec) (cadr spec))
391 (intern (format "gnus-emphasis-%s" (nth 2 spec)))))
393 '(;; I've never seen anyone use this strikethru convention whereas I've
394 ;; several times seen it triggered by normal text. --Stef
395 ;; Miles suggests that this form is sometimes used but for italics,
396 ;; so maybe we should map it to `italic'.
397 ;; ("\\(\\s-\\|^\\)\\(-\\(\\(\\w\\|-[^-]\\)+\\)-\\)\\(\\s-\\|[?!.,;]\\)"
398 ;; 2 3 gnus-emphasis-strikethru)
399 ("\\(\\s-\\|^\\)\\(_\\(\\(\\w\\|_[^_]\\)+\\)_\\)\\(\\s-\\|[?!.,;]\\)"
400 2 3 gnus-emphasis-underline))))
401 "*Alist that says how to fontify certain phrases.
402 Each item looks like this:
404 (\"_\\\\(\\\\w+\\\\)_\" 0 1 'underline)
406 The first element is a regular expression to be matched. The second
407 is a number that says what regular expression grouping used to find
408 the entire emphasized word. The third is a number that says what
409 regexp grouping should be displayed and highlighted. The fourth
410 is the face used for highlighting."
414 :format "%[Customizing Style%]\n%v"
416 (group :tag "Default"
417 :value ("" 0 0 default)
420 (let ((value (widget-get
421 (cadr (widget-get (widget-get widget :parent)
424 (if (not (eq (nth 2 value) 'default))
428 (gnus-emphasis-custom-value-to-external value))))
429 (widget-group-value-create widget))
431 (integer :format "Match group: %v")
432 (integer :format "Emphasize group: %v")
435 :value (("_" . "_") nil default)
437 (regexp :format "Start regexp: %v")
438 (regexp :format "End regexp: %v"))
439 (boolean :format "Show start and end patterns: %[%v%]\n"
440 :on " On " :off " Off ")
442 :get (lambda (symbol)
443 (mapcar 'gnus-emphasis-custom-value-to-internal
444 (default-value symbol)))
445 :set (lambda (symbol value)
446 (set-default symbol (mapcar 'gnus-emphasis-custom-value-to-external
448 :group 'gnus-article-emphasis)
450 (defcustom gnus-emphasize-whitespace-regexp "^[ \t]+\\|[ \t]*\n"
451 "A regexp to describe whitespace which should not be emphasized.
452 Typical values are \"^[ \\t]+\\\\|[ \\t]*\\n\" and \"[ \\t]+\\\\|[ \\t]*\\n\".
453 The former avoids underlining of leading and trailing whitespace,
454 and the latter avoids underlining any whitespace at all."
456 :group 'gnus-article-emphasis
459 (defface gnus-emphasis-bold '((t (:bold t)))
460 "Face used for displaying strong emphasized text (*word*)."
461 :group 'gnus-article-emphasis)
463 (defface gnus-emphasis-italic '((t (:italic t)))
464 "Face used for displaying italic emphasized text (/word/)."
465 :group 'gnus-article-emphasis)
467 (defface gnus-emphasis-underline '((t (:underline t)))
468 "Face used for displaying underlined emphasized text (_word_)."
469 :group 'gnus-article-emphasis)
471 (defface gnus-emphasis-underline-bold '((t (:bold t :underline t)))
472 "Face used for displaying underlined bold emphasized text (_*word*_)."
473 :group 'gnus-article-emphasis)
475 (defface gnus-emphasis-underline-italic '((t (:italic t :underline t)))
476 "Face used for displaying underlined italic emphasized text (_/word/_)."
477 :group 'gnus-article-emphasis)
479 (defface gnus-emphasis-bold-italic '((t (:bold t :italic t)))
480 "Face used for displaying bold italic emphasized text (/*word*/)."
481 :group 'gnus-article-emphasis)
483 (defface gnus-emphasis-underline-bold-italic
484 '((t (:bold t :italic t :underline t)))
485 "Face used for displaying underlined bold italic emphasized text.
486 Example: (_/*word*/_)."
487 :group 'gnus-article-emphasis)
489 (defface gnus-emphasis-strikethru (if (featurep 'xemacs)
490 '((t (:strikethru t)))
491 '((t (:strike-through t))))
492 "Face used for displaying strike-through text (-word-)."
493 :group 'gnus-article-emphasis)
495 (defface gnus-emphasis-highlight-words
496 '((t (:background "black" :foreground "yellow")))
497 "Face used for displaying highlighted words."
498 :group 'gnus-article-emphasis)
500 (defcustom gnus-article-time-format "%a, %d %b %Y %T %Z"
501 "Format for display of Date headers in article bodies.
502 See `format-time-string' for the possible values.
504 The variable can also be function, which should return a complete Date
505 header. The function is called with one argument, the time, which can
506 be fed to `format-time-string'."
507 :type '(choice string function)
508 :link '(custom-manual "(gnus)Article Date")
509 :group 'gnus-article-washing)
511 (defcustom gnus-save-all-headers t
512 "*If non-nil, don't remove any headers before saving.
513 This will be overridden by the `:headers' property that the symbol of
514 the saver function, which is specified by `gnus-default-article-saver',
516 :group 'gnus-article-saving
519 (defcustom gnus-prompt-before-saving 'always
520 "*This variable says how much prompting is to be done when saving articles.
521 If it is nil, no prompting will be done, and the articles will be
522 saved to the default files. If this variable is `always', each and
523 every article that is saved will be preceded by a prompt, even when
524 saving large batches of articles. If this variable is neither nil not
525 `always', there the user will be prompted once for a file name for
526 each invocation of the saving commands."
527 :group 'gnus-article-saving
528 :type '(choice (item always)
529 (item :tag "never" nil)
530 (sexp :tag "once" :format "%t\n" :value t)))
532 (defcustom gnus-saved-headers gnus-visible-headers
533 "Headers to keep if `gnus-save-all-headers' is nil.
534 If `gnus-save-all-headers' is non-nil, this variable will be ignored.
535 If that variable is nil, however, all headers that match this regexp
536 will be kept while the rest will be deleted before saving. This and
537 `gnus-save-all-headers' will be overridden by the `:headers' property
538 that the symbol of the saver function, which is specified by
539 `gnus-default-article-saver', might have."
540 :group 'gnus-article-saving
543 ;; Note that "Rmail format" is mbox since Emacs 23, but Babyl before.
544 (defcustom gnus-default-article-saver 'gnus-summary-save-in-rmail
545 "A function to save articles in your favorite format.
546 The function will be called by way of the `gnus-summary-save-article'
547 command, and friends such as `gnus-summary-save-article-rmail'.
549 Gnus provides the following functions:
551 * gnus-summary-save-in-rmail (Rmail format)
552 * gnus-summary-save-in-mail (Unix mail format)
553 * gnus-summary-save-in-folder (MH folder)
554 * gnus-summary-save-in-file (article format)
555 * gnus-summary-save-body-in-file (article body)
556 * gnus-summary-save-in-vm (use VM's folder format)
557 * gnus-summary-write-to-file (article format -- overwrite)
558 * gnus-summary-write-body-to-file (article body -- overwrite)
559 * gnus-summary-save-in-pipe (article format)
561 The symbol of each function may have the following properties:
564 The value non-nil means save decoded articles. This is meaningful
565 only with `gnus-summary-save-in-file', `gnus-summary-save-body-in-file',
566 `gnus-summary-write-to-file', `gnus-summary-write-body-to-file', and
567 `gnus-summary-save-in-pipe'.
570 The value specifies an alternative function which appends, not
571 overwrites, articles to a file. This implies that when saving many
572 articles at a time, `gnus-prompt-before-saving' is bound to t and all
573 articles are saved in a single file. This is meaningful only with
574 `gnus-summary-write-to-file' and `gnus-summary-write-body-to-file'.
577 The value specifies the symbol of a variable of which the value
578 specifies headers to be saved. If it is omitted,
579 `gnus-save-all-headers' and `gnus-saved-headers' control what
580 headers should be saved."
581 :group 'gnus-article-saving
582 :type '(radio (function-item gnus-summary-save-in-rmail)
583 (function-item gnus-summary-save-in-mail)
584 (function-item gnus-summary-save-in-folder)
585 (function-item gnus-summary-save-in-file)
586 (function-item gnus-summary-save-body-in-file)
587 (function-item gnus-summary-save-in-vm)
588 (function-item gnus-summary-write-to-file)
589 (function-item gnus-summary-write-body-to-file)
590 (function-item gnus-summary-save-in-pipe)
593 (defcustom gnus-article-save-coding-system
594 (or (and (mm-coding-system-p 'utf-8) 'utf-8)
595 (and (mm-coding-system-p 'iso-2022-7bit) 'iso-2022-7bit)
596 (and (mm-coding-system-p 'emacs-mule) 'emacs-mule)
597 (and (mm-coding-system-p 'escape-quoted) 'escape-quoted))
598 "Coding system used to save decoded articles to a file.
600 The recommended coding systems are `utf-8', `iso-2022-7bit' and so on,
601 which can safely encode any characters in text. This is used by the
604 * gnus-summary-save-article-file
605 * gnus-summary-save-article-body-file
606 * gnus-summary-write-article-file
607 * gnus-summary-write-article-body-file
609 and the functions to which you may set `gnus-default-article-saver':
611 * gnus-summary-save-in-file
612 * gnus-summary-save-body-in-file
613 * gnus-summary-write-to-file
614 * gnus-summary-write-body-to-file
616 Those commands and functions save just text displayed in the article
617 buffer to a file if the value of this variable is non-nil. Note that
618 buttonized MIME parts will be lost in a saved file in that case.
619 Otherwise, raw articles will be saved."
620 :group 'gnus-article-saving
622 :format "%{%t%}:\n %[Value Menu%] %v"
623 (const :tag "Save raw articles" nil)
626 (lambda (arg) (if (mm-coding-system-p (nth 3 arg)) arg))
627 '((const :tag "UTF-8" utf-8)
628 (const :tag "iso-2022-7bit" iso-2022-7bit)
629 (const :tag "Emacs internal" emacs-mule)
630 (const :tag "escape-quoted" escape-quoted))))
631 (symbol :tag "Coding system")))
633 (defcustom gnus-rmail-save-name 'gnus-plain-save-name
634 "A function generating a file name to save articles in Rmail format.
635 The function is called with NEWSGROUP, HEADERS, and optional LAST-FILE."
636 :group 'gnus-article-saving
639 (defcustom gnus-mail-save-name 'gnus-plain-save-name
640 "A function generating a file name to save articles in Unix mail format.
641 The function is called with NEWSGROUP, HEADERS, and optional LAST-FILE."
642 :group 'gnus-article-saving
645 (defcustom gnus-folder-save-name 'gnus-folder-save-name
646 "A function generating a file name to save articles in MH folder.
647 The function is called with NEWSGROUP, HEADERS, and optional LAST-FOLDER."
648 :group 'gnus-article-saving
651 (defcustom gnus-file-save-name 'gnus-numeric-save-name
652 "A function generating a file name to save articles in article format.
653 The function is called with NEWSGROUP, HEADERS, and optional
655 :group 'gnus-article-saving
658 (defcustom gnus-split-methods
659 '((gnus-article-archive-name)
660 (gnus-article-nndoc-name))
661 "*Variable used to suggest where articles are to be saved.
662 For instance, if you would like to save articles related to Gnus in
663 the file \"gnus-stuff\", and articles related to VM in \"vm-stuff\",
664 you could set this variable to something like:
666 '((\"^Subject:.*gnus\\|^Newsgroups:.*gnus\" \"gnus-stuff\")
667 (\"^Subject:.*vm\\|^Xref:.*vm\" \"vm-stuff\"))
669 This variable is an alist where the key is the match and the
670 value is a list of possible files to save in if the match is
673 If the match is a string, it is used as a regexp match on the
674 article. If the match is a symbol, that symbol will be funcalled
675 from the buffer of the article to be saved with the newsgroup as the
676 parameter. If it is a list, it will be evalled in the same buffer.
678 If this form or function returns a string, this string will be used as a
679 possible file name; and if it returns a non-nil list, that list will be
680 used as possible file names."
681 :group 'gnus-article-saving
682 :type '(repeat (choice (list :value (fun) function)
683 (cons :value ("" "") regexp (repeat string))
686 (defcustom gnus-page-delimiter "^\^L"
687 "*Regexp describing what to use as article page delimiters.
688 The default value is \"^\^L\", which is a form linefeed at the
689 beginning of a line."
691 :group 'gnus-article-various)
693 (defcustom gnus-article-mode-line-format "Gnus: %g %S%m"
694 "*The format specification for the article mode line.
695 See `gnus-summary-mode-line-format' for a closer description.
697 The following additional specs are available:
699 %w The article washing status.
700 %m The number of MIME parts in the article."
703 :group 'gnus-article-various)
705 (defcustom gnus-article-mode-hook nil
706 "*A hook for Gnus article mode."
708 :group 'gnus-article-various)
710 (when (featurep 'xemacs)
711 ;; Extracted from gnus-xmas-define in order to preserve user settings
712 (when (fboundp 'turn-off-scroll-in-place)
713 (add-hook 'gnus-article-mode-hook 'turn-off-scroll-in-place))
714 ;; Extracted from gnus-xmas-redefine in order to preserve user settings
715 (add-hook 'gnus-article-mode-hook 'gnus-xmas-article-menu-add))
717 (defcustom gnus-article-menu-hook nil
718 "*Hook run after the creation of the article mode menu."
720 :group 'gnus-article-various)
722 (defcustom gnus-article-prepare-hook nil
723 "*A hook called after an article has been prepared in the article buffer."
725 :group 'gnus-article-various)
727 (defcustom gnus-copy-article-ignored-headers nil
728 "List of headers to be removed when copying an article.
729 Each element is a regular expression."
730 :version "23.1" ;; No Gnus
731 :type '(repeat regexp)
732 :group 'gnus-article-various)
734 (make-obsolete-variable 'gnus-article-hide-pgp-hook nil
735 "Gnus 5.10 (Emacs 22.1)")
738 '((t (:weight bold)))
739 "Face used for highlighting a button in the article buffer."
740 :group 'gnus-article-buttons)
742 (defcustom gnus-article-button-face 'gnus-button
743 "Face used for highlighting buttons in the article buffer.
745 An article button is a piece of text that you can activate by pressing
746 `RET' or `mouse-2' above it."
748 :group 'gnus-article-buttons)
750 (defcustom gnus-article-mouse-face 'highlight
751 "Face used for mouse highlighting in the article buffer.
753 Article buttons will be displayed in this face when the cursor is
756 :group 'gnus-article-buttons)
758 (defcustom gnus-signature-face 'gnus-signature
759 "Face used for highlighting a signature in the article buffer.
760 Obsolete; use the face `gnus-signature' for customizations instead."
762 :group 'gnus-article-highlight
763 :group 'gnus-article-signature)
765 (defface gnus-signature
768 "Face used for highlighting a signature in the article buffer."
769 :group 'gnus-article-highlight
770 :group 'gnus-article-signature)
771 ;; backward-compatibility alias
772 (put 'gnus-signature-face 'face-alias 'gnus-signature)
773 (put 'gnus-signature-face 'obsolete-face "22.1")
775 (defface gnus-header-from
778 (:foreground "PaleGreen1"))
781 (:foreground "red3"))
784 "Face used for displaying from headers."
785 :group 'gnus-article-headers
786 :group 'gnus-article-highlight)
787 ;; backward-compatibility alias
788 (put 'gnus-header-from-face 'face-alias 'gnus-header-from)
789 (put 'gnus-header-from-face 'obsolete-face "22.1")
791 (defface gnus-header-subject
794 (:foreground "SeaGreen1"))
797 (:foreground "red4"))
799 (:bold t :italic t)))
800 "Face used for displaying subject headers."
801 :group 'gnus-article-headers
802 :group 'gnus-article-highlight)
803 ;; backward-compatibility alias
804 (put 'gnus-header-subject-face 'face-alias 'gnus-header-subject)
805 (put 'gnus-header-subject-face 'obsolete-face "22.1")
807 (defface gnus-header-newsgroups
810 (:foreground "yellow" :italic t))
813 (:foreground "MidnightBlue" :italic t))
816 "Face used for displaying newsgroups headers.
817 In the default setup this face is only used for crossposted
819 :group 'gnus-article-headers
820 :group 'gnus-article-highlight)
821 ;; backward-compatibility alias
822 (put 'gnus-header-newsgroups-face 'face-alias 'gnus-header-newsgroups)
823 (put 'gnus-header-newsgroups-face 'obsolete-face "22.1")
825 (defface gnus-header-name
828 (:foreground "SpringGreen2"))
831 (:foreground "maroon"))
834 "Face used for displaying header names."
835 :group 'gnus-article-headers
836 :group 'gnus-article-highlight)
837 ;; backward-compatibility alias
838 (put 'gnus-header-name-face 'face-alias 'gnus-header-name)
839 (put 'gnus-header-name-face 'obsolete-face "22.1")
841 (defface gnus-header-content
844 (:foreground "SpringGreen1" :italic t))
847 (:foreground "indianred4" :italic t))
849 (:italic t))) "Face used for displaying header content."
850 :group 'gnus-article-headers
851 :group 'gnus-article-highlight)
852 ;; backward-compatibility alias
853 (put 'gnus-header-content-face 'face-alias 'gnus-header-content)
854 (put 'gnus-header-content-face 'obsolete-face "22.1")
856 (defcustom gnus-header-face-alist
857 '(("From" nil gnus-header-from)
858 ("Subject" nil gnus-header-subject)
859 ("Newsgroups:.*," nil gnus-header-newsgroups)
860 ("" gnus-header-name gnus-header-content))
861 "*Controls highlighting of article headers.
863 An alist of the form (HEADER NAME CONTENT).
865 HEADER is a regular expression which should match the name of a
866 header and NAME and CONTENT are either face names or nil.
868 The name of each header field will be displayed using the face
869 specified by the first element in the list where HEADER matches
870 the header name and NAME is non-nil. Similarly, the content will
871 be displayed by the first non-nil matching CONTENT face."
872 :group 'gnus-article-headers
873 :group 'gnus-article-highlight
874 :type '(repeat (list (regexp :tag "Header")
876 (item :tag "skip" nil)
877 (face :value default))
878 (choice :tag "Content"
879 (item :tag "skip" nil)
880 (face :value default)))))
882 (defcustom gnus-face-properties-alist (if (featurep 'xemacs)
883 '((xface . (:face gnus-x-face)))
884 '((pbm . (:face gnus-x-face))
886 "Alist of image types and properties applied to Face and X-Face images.
889 ;; Specify the altitude of Face images in the From header.
890 \(setq gnus-face-properties-alist
891 '((pbm . (:face gnus-x-face :ascent 80))
892 (png . (:ascent 80))))
894 ;; Show Face images as pressed buttons.
895 \(setq gnus-face-properties-alist
896 '((pbm . (:face gnus-x-face :relief -2))
897 (png . (:relief -2))))
899 See the manual for the valid properties for various image types.
900 Currently, `pbm' is used for X-Face images and `png' is used for Face
901 images in Emacs. Only the `:face' property is effective on the `xface'
902 image type in XEmacs if it is built with the libcompface library."
903 :version "23.1" ;; No Gnus
904 :group 'gnus-article-headers
905 :type '(repeat (cons :format "%v" (symbol :tag "Image type") plist)))
907 (defcustom gnus-article-decode-hook
908 '(article-decode-charset article-decode-encoded-words
909 article-decode-group-name article-decode-idna-rhs)
910 "*Hook run to decode charsets in articles."
911 :group 'gnus-article-headers
914 (defcustom gnus-display-mime-function 'gnus-display-mime
915 "Function to display MIME articles."
916 :group 'gnus-article-mime
919 (defvar gnus-decode-header-function 'mail-decode-encoded-word-region
920 "Function used to decode headers.")
922 (defvar gnus-decode-address-function 'mail-decode-encoded-address-region
923 "Function used to decode addresses.")
925 (defvar gnus-article-dumbquotes-map
945 "Table for MS-to-Latin1 translation.")
947 (defcustom gnus-ignored-mime-types nil
948 "List of MIME types that should be ignored by Gnus."
950 :group 'gnus-article-mime
951 :type '(repeat regexp))
953 (defcustom gnus-unbuttonized-mime-types '(".*/.*")
954 "List of MIME types that should not be given buttons when rendered inline.
955 See also `gnus-buttonized-mime-types' which may override this variable.
956 This variable is only used when `gnus-inhibit-mime-unbuttonizing' is nil."
958 :group 'gnus-article-mime
959 :type '(repeat regexp))
961 (defcustom gnus-buttonized-mime-types nil
962 "List of MIME types that should be given buttons when rendered inline.
963 If set, this variable overrides `gnus-unbuttonized-mime-types'.
964 To see e.g. security buttons you could set this to
965 `(\"multipart/signed\")'. You could also add \"multipart/alternative\" to
966 this list to display radio buttons that allow you to choose one of two
967 media types those mails include. See also `mm-discouraged-alternatives'.
968 This variable is only used when `gnus-inhibit-mime-unbuttonizing' is nil."
970 :group 'gnus-article-mime
971 :type '(repeat regexp))
973 (defcustom gnus-inhibit-mime-unbuttonizing nil
974 "If non-nil, all MIME parts get buttons.
975 When nil (the default value), then some MIME parts do not get buttons,
976 as described by the variables `gnus-buttonized-mime-types' and
977 `gnus-unbuttonized-mime-types'."
979 :group 'gnus-article-mime
982 (defcustom gnus-body-boundary-delimiter "_"
983 "String used to delimit header and body.
984 This variable is used by `gnus-article-treat-body-boundary' which can
985 be controlled by `gnus-treat-body-boundary'."
987 :group 'gnus-article-various
988 :type '(choice (item :tag "None" :value nil)
991 (defcustom gnus-picon-databases '("/usr/lib/picon" "/usr/local/faces"
993 "Defines the location of the faces database.
994 For information on obtaining this database of pretty pictures, please
995 see http://www.cs.indiana.edu/picons/ftp/index.html"
997 :type '(repeat directory)
998 :link '(url-link :tag "download"
999 "http://www.cs.indiana.edu/picons/ftp/index.html")
1000 :link '(custom-manual "(gnus)Picons")
1003 (defun gnus-picons-installed-p ()
1004 "Say whether picons are installed on your machine."
1005 (let ((installed nil))
1006 (dolist (database gnus-picon-databases)
1007 (when (file-exists-p database)
1008 (setq installed t)))
1011 (defcustom gnus-article-mime-part-function nil
1012 "Function called with a MIME handle as the argument.
1013 This is meant for people who want to do something automatic based
1014 on parts -- for instance, adding Vcard info to a database."
1015 :group 'gnus-article-mime
1016 :type '(choice (const nil)
1019 (defcustom gnus-mime-multipart-functions nil
1020 "An alist of MIME types to functions to display them."
1022 :group 'gnus-article-mime
1023 :type '(repeat (cons :format "%v" (string :tag "MIME type") function)))
1025 (defcustom gnus-article-date-headers '(combined-lapsed)
1026 "A list of Date header formats to display.
1027 Valid formats are `ut' (universal time), `local' (local time
1028 zone), `english' (readable English), `lapsed' (elapsed time),
1029 `combined-lapsed' (both the original date and the elapsed time),
1030 `original' (the original date header), `iso8601' (ISO8601
1031 format), and `user-defined' (a user-defined format defined by the
1032 `gnus-article-time-format' variable).
1034 You have as many date headers as you want in the article buffer.
1035 Some of these headers are updated automatically. See
1036 `gnus-article-update-date-headers' for details."
1038 :group 'gnus-article-headers
1040 (const :tag "Universal time (UT)" ut)
1041 (const :tag "Local time zone" local)
1042 (const :tag "Readable English" english)
1043 (const :tag "Elapsed time" lapsed)
1044 (const :tag "Original and elapsed time" combined-lapsed)
1045 (const :tag "Original date header" original)
1046 (const :tag "ISO8601 format" iso8601)
1047 (const :tag "User-defined" user-defined)))
1049 (defcustom gnus-article-update-date-headers nil
1050 "A number that says how often to update the date header (in seconds).
1051 If nil, don't update it at all."
1053 :group 'gnus-article-headers
1055 (item :tag "Don't update" :value nil)
1058 (defcustom gnus-article-mime-match-handle-function 'undisplayed-alternative
1059 "Function called with a MIME handle as the argument.
1060 This is meant for people who want to view first matched part.
1061 For `undisplayed-alternative' (default), the first undisplayed
1062 part or alternative part is used. For `undisplayed', the first
1063 undisplayed part is used. For a function, the first part which
1064 the function return t is used. For nil, the first part is
1067 :group 'gnus-article-mime
1069 (item :tag "first" :value nil)
1070 (item :tag "undisplayed" :value undisplayed)
1071 (item :tag "undisplayed or alternative"
1072 :value undisplayed-alternative)
1075 (defcustom gnus-mime-action-alist
1076 '(("save to file" . gnus-mime-save-part)
1077 ("save and strip" . gnus-mime-save-part-and-strip)
1078 ("replace with file" . gnus-mime-replace-part)
1079 ("delete part" . gnus-mime-delete-part)
1080 ("display as text" . gnus-mime-inline-part)
1081 ("view the part" . gnus-mime-view-part)
1082 ("pipe to command" . gnus-mime-pipe-part)
1083 ("toggle display" . gnus-article-press-button)
1084 ("toggle display" . gnus-article-view-part-as-charset)
1085 ("view as type" . gnus-mime-view-part-as-type)
1086 ("view internally" . gnus-mime-view-part-internally)
1087 ("view externally" . gnus-mime-view-part-externally))
1088 "An alist of actions that run on the MIME attachment."
1089 :group 'gnus-article-mime
1090 :type '(repeat (cons (string :tag "name")
1093 (defcustom gnus-auto-select-part 1
1094 "Advance to next MIME part when deleting or stripping parts.
1096 When 0, point will be placed on the same part as before. When
1097 positive (negative), move point forward (backwards) this many
1098 parts. When nil, redisplay article."
1099 :version "23.1" ;; No Gnus
1100 :group 'gnus-article-mime
1101 :type '(choice (const nil :tag "Redisplay article.")
1102 (const 1 :tag "Next part.")
1103 (const 0 :tag "Current part.")
1107 ;;; The treatment variables
1110 (defvar gnus-part-display-hook nil
1111 "Hook called on parts that are to receive treatment.")
1113 (defvar gnus-article-treat-custom
1114 '(choice (const :tag "Off" nil)
1116 (const :tag "Header" head)
1117 (const :tag "First" first)
1118 (const :tag "Last" last)
1119 (integer :tag "Less")
1120 (repeat :tag "Groups" regexp)
1121 (sexp :tag "Predicate")))
1123 (defvar gnus-article-treat-head-custom
1124 '(choice (const :tag "Off" nil)
1125 (const :tag "Header" head)))
1127 (defvar gnus-article-treat-types '("text/plain" "text/x-verbatim"
1128 "text/x-patch" "text/html")
1129 "Part types eligible for treatment.")
1131 (defvar gnus-inhibit-treatment nil
1132 "Whether to inhibit treatment.")
1134 (defcustom gnus-treat-highlight-signature '(or t (typep "text/x-vcard"))
1135 "Highlight the signature.
1136 Valid values are nil, t, `head', `first', `last', an integer or a
1137 predicate. See Info node `(gnus)Customizing Articles'."
1138 :group 'gnus-article-treat
1139 :link '(custom-manual "(gnus)Customizing Articles")
1140 :type gnus-article-treat-custom)
1141 (put 'gnus-treat-highlight-signature 'highlight t)
1143 (defcustom gnus-treat-buttonize 100000
1145 Valid values are nil, t, `head', `first', `last', an integer or a
1146 predicate. See Info node `(gnus)Customizing Articles'."
1147 :group 'gnus-article-treat
1148 :link '(custom-manual "(gnus)Customizing Articles")
1149 :type gnus-article-treat-custom)
1150 (put 'gnus-treat-buttonize 'highlight t)
1152 (defcustom gnus-treat-buttonize-head 'head
1153 "Add buttons to the head.
1154 Valid values are nil, t, `head', `first', `last', an integer or a
1155 predicate. See Info node `(gnus)Customizing Articles'."
1156 :group 'gnus-article-treat
1157 :link '(custom-manual "(gnus)Customizing Articles")
1158 :type gnus-article-treat-head-custom)
1159 (put 'gnus-treat-buttonize-head 'highlight t)
1161 (defcustom gnus-treat-date 'head
1162 "Display dates according to the `gnus-article-date-headers' variable.
1163 Valid values are nil, t, `head', `first', `last', an integer or a
1164 predicate. See Info node `(gnus)Customizing Articles'."
1166 :group 'gnus-article-treat
1167 :link '(custom-manual "(gnus)Customizing Articles")
1168 :type gnus-article-treat-head-custom)
1170 (defcustom gnus-treat-emphasize 50000
1172 Valid values are nil, t, `head', `first', `last', an integer or a
1173 predicate. See Info node `(gnus)Customizing Articles'."
1174 :group 'gnus-article-treat
1175 :link '(custom-manual "(gnus)Customizing Articles")
1176 :type gnus-article-treat-custom)
1177 (put 'gnus-treat-emphasize 'highlight t)
1179 (defcustom gnus-treat-strip-cr nil
1180 "Remove carriage returns.
1181 Valid values are nil, t, `head', `first', `last', an integer or a
1182 predicate. See Info node `(gnus)Customizing Articles'."
1184 :group 'gnus-article-treat
1185 :link '(custom-manual "(gnus)Customizing Articles")
1186 :type gnus-article-treat-custom)
1188 (defcustom gnus-treat-unsplit-urls nil
1189 "Remove newlines from within URLs.
1190 Valid values are nil, t, `head', `first', `last', an integer or a
1191 predicate. See Info node `(gnus)Customizing Articles'."
1193 :group 'gnus-article-treat
1194 :link '(custom-manual "(gnus)Customizing Articles")
1195 :type gnus-article-treat-custom)
1197 (defcustom gnus-treat-leading-whitespace nil
1198 "Remove leading whitespace in headers.
1199 Valid values are nil, t, `head', `first', `last', an integer or a
1200 predicate. See Info node `(gnus)Customizing Articles'."
1202 :group 'gnus-article-treat
1203 :link '(custom-manual "(gnus)Customizing Articles")
1204 :type gnus-article-treat-custom)
1206 (defcustom gnus-treat-hide-headers 'head
1208 Valid values are nil, t, `head', `first', `last', an integer or a
1209 predicate. See Info node `(gnus)Customizing Articles'."
1210 :group 'gnus-article-treat
1211 :link '(custom-manual "(gnus)Customizing Articles")
1212 :type gnus-article-treat-head-custom)
1214 (defcustom gnus-treat-hide-boring-headers nil
1215 "Hide boring headers.
1216 Valid values are nil, t, `head', `first', `last', an integer or a
1217 predicate. See Info node `(gnus)Customizing Articles'."
1218 :group 'gnus-article-treat
1219 :link '(custom-manual "(gnus)Customizing Articles")
1220 :type gnus-article-treat-head-custom)
1222 (defcustom gnus-treat-hide-signature nil
1223 "Hide the signature.
1224 Valid values are nil, t, `head', `first', `last', an integer or a
1225 predicate. See Info node `(gnus)Customizing Articles'."
1226 :group 'gnus-article-treat
1227 :link '(custom-manual "(gnus)Customizing Articles")
1228 :type gnus-article-treat-custom)
1230 (defcustom gnus-treat-fill-article nil
1232 Valid values are nil, t, `head', `first', `last', an integer or a
1233 predicate. See Info node `(gnus)Customizing Articles'."
1234 :group 'gnus-article-treat
1235 :link '(custom-manual "(gnus)Customizing Articles")
1236 :type gnus-article-treat-custom)
1238 (defcustom gnus-treat-hide-citation nil
1240 Valid values are nil, t, `head', `first', `last', an integer or a
1241 predicate. See Info node `(gnus)Customizing Articles'.
1243 See `gnus-article-highlight-citation' for variables used to
1244 control what it hides."
1245 :group 'gnus-article-treat
1246 :link '(custom-manual "(gnus)Customizing Articles")
1247 :type gnus-article-treat-custom)
1249 (defcustom gnus-treat-hide-citation-maybe nil
1250 "Hide cited text according to certain conditions.
1251 Valid values are nil, t, `head', `first', `last', an integer or a
1252 predicate. See Info node `(gnus)Customizing Articles'.
1254 See `gnus-cite-hide-percentage' and `gnus-cite-hide-absolute' for
1255 how to control what it hides."
1256 :group 'gnus-article-treat
1257 :link '(custom-manual "(gnus)Customizing Articles")
1258 :type gnus-article-treat-custom)
1260 (defcustom gnus-treat-strip-list-identifiers 'head
1261 "Strip list identifiers from `gnus-list-identifiers`.
1262 Valid values are nil, t, `head', `first', `last', an integer or a
1263 predicate. See Info node `(gnus)Customizing Articles'."
1265 :group 'gnus-article-treat
1266 :link '(custom-manual "(gnus)Customizing Articles")
1267 :type gnus-article-treat-custom)
1269 (gnus-define-group-parameter
1272 "Alist of regexps and correspondent identifiers."
1273 :variable-group gnus-article-washing
1275 '(choice :tag "Identifier"
1277 (symbol :tag "Item in `gnus-list-identifiers'" none)
1279 (const :tag "None" nil))
1281 "If non-nil, specify how to remove `identifiers' from articles' subject.
1283 Any symbol is used to look up a regular expression to match the
1284 banner in `gnus-list-identifiers'. A string is used as a regular
1285 expression to match the identifier directly.")
1287 (make-obsolete-variable 'gnus-treat-strip-pgp nil
1288 "Gnus 5.10 (Emacs 22.1)")
1290 (defcustom gnus-treat-strip-pem nil
1291 "Strip PEM signatures.
1292 Valid values are nil, t, `head', `first', `last', an integer or a
1293 predicate. See Info node `(gnus)Customizing Articles'."
1294 :group 'gnus-article-treat
1295 :link '(custom-manual "(gnus)Customizing Articles")
1296 :type gnus-article-treat-custom)
1298 (defcustom gnus-treat-strip-banner t
1299 "Strip banners from articles.
1300 The banner to be stripped is specified in the `banner' group parameter.
1301 Valid values are nil, t, `head', `first', `last', an integer or a
1302 predicate. See Info node `(gnus)Customizing Articles'."
1303 :group 'gnus-article-treat
1304 :link '(custom-manual "(gnus)Customizing Articles")
1305 :type gnus-article-treat-custom)
1307 (defcustom gnus-treat-highlight-headers 'head
1308 "Highlight the headers.
1309 Valid values are nil, t, `head', `first', `last', an integer or a
1310 predicate. See Info node `(gnus)Customizing Articles'."
1311 :group 'gnus-article-treat
1312 :link '(custom-manual "(gnus)Customizing Articles")
1313 :type gnus-article-treat-head-custom)
1314 (put 'gnus-treat-highlight-headers 'highlight t)
1316 (defcustom gnus-treat-highlight-citation t
1317 "Highlight cited text.
1318 Valid values are nil, t, `head', `first', `last', an integer or a
1319 predicate. See Info node `(gnus)Customizing Articles'."
1320 :group 'gnus-article-treat
1321 :link '(custom-manual "(gnus)Customizing Articles")
1322 :type gnus-article-treat-custom)
1323 (put 'gnus-treat-highlight-citation 'highlight t)
1325 (defcustom gnus-treat-strip-headers-in-body t
1326 "Strip the X-No-Archive header line from the beginning of the body.
1327 Valid values are nil, t, `head', `first', `last', an integer or a
1328 predicate. See Info node `(gnus)Customizing Articles'."
1330 :group 'gnus-article-treat
1331 :link '(custom-manual "(gnus)Customizing Articles")
1332 :type gnus-article-treat-custom)
1334 (defcustom gnus-treat-strip-trailing-blank-lines nil
1335 "Strip trailing blank lines.
1336 Valid values are nil, t, `head', `first', `last', an integer or a
1337 predicate. See Info node `(gnus)Customizing Articles'.
1339 When set to t, it also strips trailing blanks in all MIME parts.
1340 Consider to use `last' instead."
1341 :group 'gnus-article-treat
1342 :link '(custom-manual "(gnus)Customizing Articles")
1343 :type gnus-article-treat-custom)
1345 (defcustom gnus-treat-strip-leading-blank-lines nil
1346 "Strip leading blank lines.
1347 Valid values are nil, t, `head', `first', `last', an integer or a
1348 predicate. See Info node `(gnus)Customizing Articles'.
1350 When set to t, it also strips trailing blanks in all MIME parts."
1351 :group 'gnus-article-treat
1352 :link '(custom-manual "(gnus)Customizing Articles")
1353 :type gnus-article-treat-custom)
1355 (defcustom gnus-treat-strip-multiple-blank-lines nil
1356 "Strip multiple blank lines.
1357 Valid values are nil, t, `head', `first', `last', an integer or a
1358 predicate. See Info node `(gnus)Customizing Articles'."
1359 :group 'gnus-article-treat
1360 :link '(custom-manual "(gnus)Customizing Articles")
1361 :type gnus-article-treat-custom)
1363 (defcustom gnus-treat-unfold-headers 'head
1364 "Unfold folded header lines.
1365 Valid values are nil, t, `head', `first', `last', an integer or a
1366 predicate. See Info node `(gnus)Customizing Articles'."
1368 :group 'gnus-article-treat
1369 :link '(custom-manual "(gnus)Customizing Articles")
1370 :type gnus-article-treat-custom)
1372 (defcustom gnus-article-unfold-long-headers nil
1373 "If non-nil, allow unfolding headers even if the header is long.
1374 If it is a regexp, only long headers matching this regexp are unfolded.
1375 If it is t, all long headers are unfolded.
1377 This variable has no effect if `gnus-treat-unfold-headers' is nil."
1378 :version "23.1" ;; No Gnus
1379 :group 'gnus-article-treat
1380 :type '(choice (const nil)
1381 (const :tag "all" t)
1384 (defcustom gnus-treat-fold-headers nil
1386 Valid values are nil, t, `head', `first', `last', an integer or a
1387 predicate. See Info node `(gnus)Customizing Articles'."
1389 :group 'gnus-article-treat
1390 :link '(custom-manual "(gnus)Customizing Articles")
1391 :type gnus-article-treat-custom)
1393 (defcustom gnus-treat-fold-newsgroups 'head
1394 "Fold the Newsgroups and Followup-To headers.
1395 Valid values are nil, t, `head', `first', `last', an integer or a
1396 predicate. See Info node `(gnus)Customizing Articles'."
1398 :group 'gnus-article-treat
1399 :link '(custom-manual "(gnus)Customizing Articles")
1400 :type gnus-article-treat-custom)
1402 (defcustom gnus-treat-overstrike t
1403 "Treat overstrike highlighting.
1404 Valid values are nil, t, `head', `first', `last', an integer or a
1405 predicate. See Info node `(gnus)Customizing Articles'."
1406 :group 'gnus-article-treat
1407 :link '(custom-manual "(gnus)Customizing Articles")
1408 :type gnus-article-treat-custom)
1409 (put 'gnus-treat-overstrike 'highlight t)
1411 (defcustom gnus-treat-ansi-sequences (if (locate-library "ansi-color") t)
1412 "Treat ANSI SGR control sequences.
1413 Valid values are nil, t, `head', `first', `last', an integer or a
1414 predicate. See Info node `(gnus)Customizing Articles'."
1415 :group 'gnus-article-treat
1416 :link '(custom-manual "(gnus)Customizing Articles")
1417 :type gnus-article-treat-custom)
1419 (make-obsolete-variable 'gnus-treat-display-xface
1420 'gnus-treat-display-x-face "Emacs 22.1")
1422 (defcustom gnus-treat-display-x-face
1423 (and (not noninteractive)
1424 (gnus-image-type-available-p 'xbm)
1425 (if (featurep 'xemacs)
1428 (and (string-match "^0x" (shell-command-to-string "uncompface"))
1429 (executable-find "icontopbm"))
1430 ;; shell-command-to-string may signal an error, e.g. if
1431 ;; shell-file-name is not found.
1434 "Display X-Face headers.
1435 Valid values are nil and `head'.
1436 See Info node `(gnus)Customizing Articles' and Info node
1437 `(gnus)X-Face' for details."
1438 :group 'gnus-article-treat
1440 :link '(custom-manual "(gnus)Customizing Articles")
1441 :link '(custom-manual "(gnus)X-Face")
1442 :type gnus-article-treat-head-custom
1443 :set (lambda (symbol value)
1446 (cond ((or (boundp symbol) (get symbol 'saved-value))
1448 ((boundp 'gnus-treat-display-xface)
1450 ** gnus-treat-display-xface is an obsolete variable;\
1451 use gnus-treat-display-x-face instead")
1452 (default-value 'gnus-treat-display-xface))
1453 ((get 'gnus-treat-display-xface 'saved-value)
1455 ** gnus-treat-display-xface is an obsolete variable;\
1456 use gnus-treat-display-x-face instead")
1457 (eval (car (get 'gnus-treat-display-xface 'saved-value))))
1460 (put 'gnus-treat-display-x-face 'highlight t)
1462 (defcustom gnus-treat-display-face
1463 (and (not noninteractive)
1464 (gnus-image-type-available-p 'png)
1466 "Display Face headers.
1467 Valid values are nil, t, `head', `first', `last', an integer or a
1468 predicate. See Info node `(gnus)Customizing Articles' and Info
1469 node `(gnus)Face' for details."
1470 :group 'gnus-article-treat
1472 :link '(custom-manual "(gnus)Customizing Articles")
1473 :link '(custom-manual "(gnus)X-Face")
1474 :type gnus-article-treat-head-custom)
1475 (put 'gnus-treat-display-face 'highlight t)
1477 (defcustom gnus-treat-display-smileys (gnus-image-type-available-p 'xpm)
1479 Valid values are nil, t, `head', `first', `last', an integer or a
1480 predicate. See Info node `(gnus)Customizing Articles' and Info
1481 node `(gnus)Smileys' for details."
1482 :group 'gnus-article-treat
1484 :link '(custom-manual "(gnus)Customizing Articles")
1485 :link '(custom-manual "(gnus)Smileys")
1486 :type gnus-article-treat-custom)
1487 (put 'gnus-treat-display-smileys 'highlight t)
1489 (defcustom gnus-treat-from-picon
1490 (if (and (gnus-image-type-available-p 'xpm)
1491 (gnus-picons-installed-p))
1493 "Display picons in the From header.
1494 Valid values are nil, t, `head', `first', `last', an integer or a
1495 predicate. See Info node `(gnus)Customizing Articles' and Info
1496 node `(gnus)Picons' for details."
1498 :group 'gnus-article-treat
1500 :link '(custom-manual "(gnus)Customizing Articles")
1501 :link '(custom-manual "(gnus)Picons")
1502 :type gnus-article-treat-head-custom)
1503 (put 'gnus-treat-from-picon 'highlight t)
1505 (defcustom gnus-treat-mail-picon
1506 (if (and (gnus-image-type-available-p 'xpm)
1507 (gnus-picons-installed-p))
1509 "Display picons in To and Cc headers.
1510 Valid values are nil, t, `head', `first', `last', an integer or a
1511 predicate. See Info node `(gnus)Customizing Articles' and Info
1512 node `(gnus)Picons' for details."
1514 :group 'gnus-article-treat
1516 :link '(custom-manual "(gnus)Customizing Articles")
1517 :link '(custom-manual "(gnus)Picons")
1518 :type gnus-article-treat-head-custom)
1519 (put 'gnus-treat-mail-picon 'highlight t)
1521 (defcustom gnus-treat-newsgroups-picon
1522 (if (and (gnus-image-type-available-p 'xpm)
1523 (gnus-picons-installed-p))
1525 "Display picons in the Newsgroups and Followup-To headers.
1526 Valid values are nil, t, `head', `first', `last', an integer or a
1527 predicate. See Info node `(gnus)Customizing Articles' and Info
1528 node `(gnus)Picons' for details."
1530 :group 'gnus-article-treat
1532 :link '(custom-manual "(gnus)Customizing Articles")
1533 :link '(custom-manual "(gnus)Picons")
1534 :type gnus-article-treat-head-custom)
1535 (put 'gnus-treat-newsgroups-picon 'highlight t)
1537 (defcustom gnus-treat-from-gravatar nil
1538 "Display gravatars in the From header.
1539 Valid values are nil, t, `head', `first', `last', an integer or a
1540 predicate. See Info node `(gnus)Customizing Articles' and Info
1541 node `(gnus)Gravatars' for details."
1543 :group 'gnus-article-treat
1544 :group 'gnus-gravatar
1545 :link '(custom-manual "(gnus)Customizing Articles")
1546 :link '(custom-manual "(gnus)Gravatars")
1547 :type gnus-article-treat-head-custom)
1548 (put 'gnus-treat-from-gravatar 'highlight t)
1550 (defcustom gnus-treat-mail-gravatar nil
1551 "Display gravatars in To and Cc headers.
1552 Valid values are nil, t, `head', `first', `last', an integer or a
1553 predicate. See Info node `(gnus)Customizing Articles' and Info
1554 node `(gnus)Gravatars' for details."
1556 :group 'gnus-article-treat
1557 :group 'gnus-gravatar
1558 :link '(custom-manual "(gnus)Customizing Articles")
1559 :link '(custom-manual "(gnus)Gravatars")
1560 :type gnus-article-treat-head-custom)
1561 (put 'gnus-treat-mail-gravatar 'highlight t)
1563 (defcustom gnus-treat-body-boundary
1564 (if (or gnus-treat-newsgroups-picon
1565 gnus-treat-mail-picon
1566 gnus-treat-from-picon
1567 gnus-treat-from-gravatar
1568 gnus-treat-mail-gravatar)
1569 ;; If there's much decoration, the user might prefer a boundary.
1572 "Draw a boundary at the end of the headers.
1573 Valid values are nil and `head'.
1574 See Info node `(gnus)Customizing Articles' for details."
1576 :group 'gnus-article-treat
1577 :link '(custom-manual "(gnus)Customizing Articles")
1578 :type gnus-article-treat-head-custom)
1580 (defcustom gnus-treat-capitalize-sentences nil
1581 "Capitalize sentence-starting words.
1582 Valid values are nil, t, `head', `first', `last', an integer or a
1583 predicate. See Info node `(gnus)Customizing Articles'."
1585 :group 'gnus-article-treat
1586 :link '(custom-manual "(gnus)Customizing Articles")
1587 :type gnus-article-treat-custom)
1589 (defcustom gnus-treat-wash-html nil
1591 Valid values are nil, t, `head', `first', `last', an integer or a
1592 predicate. See Info node `(gnus)Customizing Articles'."
1594 :group 'gnus-article-treat
1595 :link '(custom-manual "(gnus)Customizing Articles")
1596 :type gnus-article-treat-custom)
1598 (defcustom gnus-treat-fill-long-lines '(typep "text/plain")
1600 Valid values are nil, t, `head', `first', `last', an integer or a
1601 predicate. See Info node `(gnus)Customizing Articles'."
1603 :group 'gnus-article-treat
1604 :link '(custom-manual "(gnus)Customizing Articles")
1605 :type gnus-article-treat-custom)
1607 (defcustom gnus-treat-x-pgp-sig nil
1609 To automatically treat X-PGP-Sig, set it to head.
1610 Valid values are nil, t, `head', `first', `last', an integer or a
1611 predicate. See Info node `(gnus)Customizing Articles'."
1613 :group 'gnus-article-treat
1614 :group 'mime-security
1615 :link '(custom-manual "(gnus)Customizing Articles")
1616 :type gnus-article-treat-custom)
1618 (defvar gnus-article-encrypt-protocol-alist
1619 '(("PGP" . mml2015-self-encrypt)))
1621 ;; Set to nil if more than one protocol added to
1622 ;; gnus-article-encrypt-protocol-alist.
1623 (defcustom gnus-article-encrypt-protocol "PGP"
1624 "The protocol used for encrypt articles.
1625 It is a string, such as \"PGP\". If nil, ask user."
1628 :group 'mime-security)
1630 (defcustom gnus-use-idna (and (condition-case nil (require 'idna) (file-error))
1631 (mm-coding-system-p 'utf-8)
1632 (executable-find idna-program))
1633 "Whether IDNA decoding of headers is used when viewing messages.
1634 This requires GNU Libidn, and by default only enabled if it is found."
1636 :group 'gnus-article-headers
1639 (defcustom gnus-article-over-scroll nil
1640 "If non-nil, allow scrolling the article buffer even when there no more text."
1642 :group 'gnus-article
1645 (defcustom gnus-inhibit-images nil
1646 "Non-nil means inhibit displaying of images inline in the article body."
1648 :group 'gnus-article
1651 (defcustom gnus-blocked-images 'gnus-block-private-groups
1652 "Images that have URLs matching this regexp will be blocked.
1653 This can also be a function to be evaluated. If so, it will be
1654 called with the group name as the parameter, and should return a
1658 :type '(choice regexp function))
1660 ;;; Internal variables
1662 (defvar gnus-english-month-names
1663 '("January" "February" "March" "April" "May" "June" "July" "August"
1664 "September" "October" "November" "December"))
1666 (defvar article-goto-body-goes-to-point-min-p nil)
1667 (defvar gnus-article-wash-types nil)
1668 (defvar gnus-article-emphasis-alist nil)
1669 (defvar gnus-article-image-alist nil)
1671 (defvar gnus-article-mime-handle-alist-1 nil)
1672 (defvar gnus-treatment-function-alist
1673 '((gnus-treat-strip-cr gnus-article-remove-cr)
1674 (gnus-treat-x-pgp-sig gnus-article-verify-x-pgp-sig)
1675 (gnus-treat-strip-banner gnus-article-strip-banner)
1676 (gnus-treat-strip-headers-in-body gnus-article-strip-headers-in-body)
1677 (gnus-treat-highlight-signature gnus-article-highlight-signature)
1678 (gnus-treat-buttonize gnus-article-add-buttons)
1679 (gnus-treat-fill-article gnus-article-fill-cited-article)
1680 (gnus-treat-fill-long-lines gnus-article-fill-cited-long-lines)
1681 (gnus-treat-unsplit-urls gnus-article-unsplit-urls)
1682 (gnus-treat-display-x-face gnus-article-display-x-face)
1683 (gnus-treat-display-face gnus-article-display-face)
1684 (gnus-treat-hide-headers gnus-article-maybe-hide-headers)
1685 (gnus-treat-hide-boring-headers gnus-article-hide-boring-headers)
1686 (gnus-treat-hide-signature gnus-article-hide-signature)
1687 (gnus-treat-strip-list-identifiers gnus-article-hide-list-identifiers)
1688 (gnus-treat-leading-whitespace gnus-article-remove-leading-whitespace)
1689 (gnus-treat-from-picon gnus-treat-from-picon)
1690 (gnus-treat-mail-picon gnus-treat-mail-picon)
1691 (gnus-treat-newsgroups-picon gnus-treat-newsgroups-picon)
1692 (gnus-treat-strip-pem gnus-article-hide-pem)
1693 (gnus-treat-date gnus-article-treat-date)
1694 (gnus-treat-from-gravatar gnus-treat-from-gravatar)
1695 (gnus-treat-mail-gravatar gnus-treat-mail-gravatar)
1696 (gnus-treat-highlight-headers gnus-article-highlight-headers)
1697 (gnus-treat-highlight-signature gnus-article-highlight-signature)
1698 (gnus-treat-strip-trailing-blank-lines
1699 gnus-article-remove-trailing-blank-lines)
1700 (gnus-treat-strip-leading-blank-lines
1701 gnus-article-strip-leading-blank-lines)
1702 (gnus-treat-strip-multiple-blank-lines
1703 gnus-article-strip-multiple-blank-lines)
1704 (gnus-treat-overstrike gnus-article-treat-overstrike)
1705 (gnus-treat-ansi-sequences gnus-article-treat-ansi-sequences)
1706 (gnus-treat-unfold-headers gnus-article-treat-unfold-headers)
1707 (gnus-treat-fold-newsgroups gnus-article-treat-fold-newsgroups)
1708 (gnus-treat-fold-headers gnus-article-treat-fold-headers)
1709 (gnus-treat-buttonize-head gnus-article-add-buttons-to-head)
1710 (gnus-treat-display-smileys gnus-treat-smiley)
1711 (gnus-treat-capitalize-sentences gnus-article-capitalize-sentences)
1712 (gnus-treat-wash-html gnus-article-wash-html)
1713 (gnus-treat-emphasize gnus-article-emphasize)
1714 (gnus-treat-hide-citation gnus-article-hide-citation)
1715 (gnus-treat-hide-citation-maybe gnus-article-hide-citation-maybe)
1716 (gnus-treat-highlight-citation gnus-article-highlight-citation)
1717 (gnus-treat-body-boundary gnus-article-treat-body-boundary)))
1719 (defvar gnus-article-mime-handle-alist nil)
1720 (defvar article-lapsed-timer nil)
1721 (defvar gnus-article-current-summary nil)
1723 (defvar gnus-article-mode-syntax-table
1724 (let ((table (copy-syntax-table text-mode-syntax-table)))
1725 ;; This causes the citation match run O(2^n).
1726 ;; (modify-syntax-entry ?- "w" table)
1727 (modify-syntax-entry ?> ")<" table)
1728 (modify-syntax-entry ?< "(>" table)
1729 ;; make M-. in article buffers work for `foo' strings
1730 (modify-syntax-entry ?' " " table)
1731 (modify-syntax-entry ?` " " table)
1733 "Syntax table used in article mode buffers.
1734 Initialized from `text-mode-syntax-table.")
1736 (defvar gnus-save-article-buffer nil)
1738 (defvar gnus-number-of-articles-to-be-saved nil)
1740 (defvar gnus-inhibit-hiding nil)
1742 (defvar gnus-article-edit-mode nil)
1744 ;;; Macros for dealing with the article buffer.
1746 (defmacro gnus-with-article-headers (&rest forms)
1747 `(with-current-buffer gnus-article-buffer
1749 (let ((inhibit-read-only t)
1750 (inhibit-point-motion-hooks t)
1751 (case-fold-search t))
1752 (article-narrow-to-head)
1755 (put 'gnus-with-article-headers 'lisp-indent-function 0)
1756 (put 'gnus-with-article-headers 'edebug-form-spec '(body))
1758 (defmacro gnus-with-article-buffer (&rest forms)
1759 `(when (buffer-live-p (get-buffer gnus-article-buffer))
1760 (with-current-buffer gnus-article-buffer
1761 (let ((inhibit-read-only t))
1764 (put 'gnus-with-article-buffer 'lisp-indent-function 0)
1765 (put 'gnus-with-article-buffer 'edebug-form-spec '(body))
1767 (defun gnus-article-goto-header (header)
1768 "Go to HEADER, which is a regular expression."
1769 (re-search-forward (concat "^\\(" header "\\):") nil t))
1771 (defsubst gnus-article-hide-text (b e props)
1772 "Set text PROPS on the B to E region, extending `intangible' 1 past B."
1773 (gnus-add-text-properties-when 'article-type nil b e props)
1774 (when (memq 'intangible props)
1776 (max (1- b) (point-min))
1777 b 'intangible (cddr (memq 'intangible props)))))
1779 (defsubst gnus-article-unhide-text (b e)
1780 "Remove hidden text properties from region between B and E."
1781 (remove-text-properties b e gnus-hidden-properties)
1782 (when (memq 'intangible gnus-hidden-properties)
1783 (put-text-property (max (1- b) (point-min))
1784 b 'intangible nil)))
1786 (defun gnus-article-hide-text-type (b e type)
1787 "Hide text of TYPE between B and E."
1788 (gnus-add-wash-type type)
1789 (gnus-article-hide-text
1790 b e (cons 'article-type (cons type gnus-hidden-properties))))
1792 (defun gnus-article-unhide-text-type (b e type)
1793 "Unhide text of TYPE between B and E."
1794 (gnus-delete-wash-type type)
1795 (remove-text-properties
1796 b e (cons 'article-type (cons type gnus-hidden-properties)))
1797 (when (memq 'intangible gnus-hidden-properties)
1798 (put-text-property (max (1- b) (point-min))
1799 b 'intangible nil)))
1801 (defun gnus-article-delete-text-of-type (type)
1802 "Delete text of TYPE in the current buffer."
1804 (let ((b (point-min)))
1805 (if (eq type 'multipart)
1806 ;; Remove MIME buttons associated with multipart/alternative parts.
1809 (while (if (get-text-property (point) 'gnus-part)
1811 (when (setq b (next-single-property-change (point)
1816 (skip-chars-forward "\n")
1817 (when (eq (get-text-property b 'article-type) 'multipart)
1818 (delete-region b (point)))))
1819 (while (setq b (text-property-any b (point-max) 'article-type type))
1821 b (or (text-property-not-all b (point-max) 'article-type type)
1824 (defun gnus-article-delete-invisible-text ()
1825 "Delete all invisible text in the current buffer."
1827 (let ((b (point-min)))
1828 (while (setq b (text-property-any b (point-max) 'invisible t))
1830 b (or (text-property-not-all b (point-max) 'invisible t)
1833 (defsubst gnus-article-header-rank ()
1834 "Give the rank of the string HEADER as given by `gnus-sorted-header-list'."
1835 (let ((list gnus-sorted-header-list)
1838 (if (looking-at (car list))
1840 (setq list (cdr list))
1844 (defun article-hide-headers (&optional arg delete)
1845 "Hide unwanted headers and possibly sort them as well."
1847 ;; This function might be inhibited.
1848 (unless gnus-inhibit-hiding
1849 (let ((inhibit-read-only t)
1850 (case-fold-search t)
1851 (max (1+ (length gnus-sorted-header-list)))
1852 (inhibit-point-motion-hooks t)
1853 (cur (current-buffer))
1854 ignored visible beg)
1856 ;; `gnus-ignored-headers' and `gnus-visible-headers' may be
1857 ;; group parameters, so we should go to the summary buffer.
1860 (progn (set-buffer gnus-summary-buffer) t)
1862 (setq ignored (when (not gnus-visible-headers)
1863 (cond ((stringp gnus-ignored-headers)
1864 gnus-ignored-headers)
1865 ((listp gnus-ignored-headers)
1866 (mapconcat 'identity
1867 gnus-ignored-headers
1869 visible (cond ((stringp gnus-visible-headers)
1870 gnus-visible-headers)
1871 ((and gnus-visible-headers
1872 (listp gnus-visible-headers))
1873 (mapconcat 'identity
1874 gnus-visible-headers
1878 ;; First we narrow to just the headers.
1879 (article-narrow-to-head)
1880 ;; Hide any "From " lines at the beginning of (mail) articles.
1881 (while (looking-at "From ")
1884 (delete-region (point-min) (point)))
1885 ;; Then treat the rest of the header lines.
1886 ;; Then we use the two regular expressions
1887 ;; `gnus-ignored-headers' and `gnus-visible-headers' to
1888 ;; select which header lines is to remain visible in the
1890 (while (re-search-forward "^[^ \t:]*:" nil t)
1892 ;; Mark the rank of the header.
1894 (point) (1+ (point)) 'message-rank
1895 (if (or (and visible (looking-at visible))
1897 (not (looking-at ignored))))
1898 (gnus-article-header-rank)
1901 (message-sort-headers-1)
1902 (when (setq beg (text-property-any
1903 (point-min) (point-max) 'message-rank (+ 2 max)))
1904 ;; We delete the unwanted headers.
1905 (gnus-add-wash-type 'headers)
1906 (add-text-properties (point-min) (+ 5 (point-min))
1907 '(article-type headers dummy-invisible t))
1908 (delete-region beg (point-max))))))))
1910 (defun article-hide-boring-headers (&optional arg)
1911 "Toggle hiding of headers that aren't very interesting.
1912 If given a negative prefix, always show; if given a positive prefix,
1914 (interactive (gnus-article-hidden-arg))
1915 (when (and (not (gnus-article-check-hidden-text 'boring-headers arg))
1916 (not gnus-show-all-headers))
1919 (let ((inhibit-read-only t)
1920 (inhibit-point-motion-hooks t))
1921 (article-narrow-to-head)
1922 (dolist (elem gnus-boring-article-headers)
1923 (goto-char (point-min))
1925 ;; Hide empty headers.
1927 (while (re-search-forward "^[^: \t]+:[ \t]*\n[^ \t]" nil t)
1929 (gnus-article-hide-text-type
1933 (if (re-search-forward "^[^ \t]" nil t)
1937 ;; Hide boring Newsgroups header.
1938 ((eq elem 'newsgroups)
1939 (when (gnus-string-equal
1940 (gnus-fetch-field "newsgroups")
1941 (gnus-group-real-name
1942 (if (boundp 'gnus-newsgroup-name)
1945 (gnus-article-hide-header "newsgroups")))
1946 ((eq elem 'to-address)
1947 (let ((to (message-fetch-field "to"))
1949 (gnus-parameter-to-address
1950 (if (boundp 'gnus-newsgroup-name)
1951 gnus-newsgroup-name ""))))
1952 (when (and to to-address
1955 ;; only one address in To
1956 (nth 1 (mail-extract-address-components to))
1958 (gnus-article-hide-header "to"))))
1960 (let ((to (message-fetch-field "to"))
1962 (gnus-parameter-to-list
1963 (if (boundp 'gnus-newsgroup-name)
1964 gnus-newsgroup-name ""))))
1965 (when (and to to-list
1968 ;; only one address in To
1969 (nth 1 (mail-extract-address-components to))
1971 (gnus-article-hide-header "to"))))
1973 (let ((cc (message-fetch-field "cc"))
1975 (gnus-parameter-to-list
1976 (if (boundp 'gnus-newsgroup-name)
1977 gnus-newsgroup-name ""))))
1978 (when (and cc to-list
1981 ;; only one address in CC
1982 (nth 1 (mail-extract-address-components cc))
1984 (gnus-article-hide-header "cc"))))
1985 ((eq elem 'followup-to)
1986 (when (gnus-string-equal
1987 (message-fetch-field "followup-to")
1988 (message-fetch-field "newsgroups"))
1989 (gnus-article-hide-header "followup-to")))
1990 ((eq elem 'reply-to)
1991 (if (gnus-group-find-parameter
1992 gnus-newsgroup-name 'broken-reply-to)
1993 (gnus-article-hide-header "reply-to")
1994 (let ((from (message-fetch-field "from"))
1995 (reply-to (message-fetch-field "reply-to")))
2002 (lambda (x) (downcase (cadr x)))
2003 (mail-extract-address-components from t))
2006 (lambda (x) (downcase (cadr x)))
2007 (mail-extract-address-components reply-to t))
2009 (gnus-article-hide-header "reply-to")))))
2011 (let ((date (with-current-buffer gnus-original-article-buffer
2012 ;; If date in `gnus-article-buffer' is localized
2013 ;; (`gnus-treat-date-user-defined'),
2014 ;; `days-between' might fail.
2015 (message-fetch-field "date"))))
2017 (< (days-between (current-time-string) date)
2019 (gnus-article-hide-header "date"))))
2021 (let ((to (message-fetch-field "to"))
2022 (cc (message-fetch-field "cc")))
2023 (when (> (length to) 1024)
2024 (gnus-article-hide-header "to"))
2025 (when (> (length cc) 1024)
2026 (gnus-article-hide-header "cc"))))
2030 (goto-char (point-min))
2031 (while (re-search-forward "^to:" nil t)
2032 (setq to-count (1+ to-count)))
2033 (when (> to-count 1)
2034 (while (> to-count 0)
2035 (goto-char (point-min))
2037 (re-search-forward "^to:" nil nil to-count)
2039 (narrow-to-region (point) (point-max))
2040 (gnus-article-hide-header "to"))
2041 (setq to-count (1- to-count))))
2042 (goto-char (point-min))
2043 (while (re-search-forward "^cc:" nil t)
2044 (setq cc-count (1+ cc-count)))
2045 (when (> cc-count 1)
2046 (while (> cc-count 0)
2047 (goto-char (point-min))
2049 (re-search-forward "^cc:" nil nil cc-count)
2051 (narrow-to-region (point) (point-max))
2052 (gnus-article-hide-header "cc"))
2053 (setq cc-count (1- cc-count)))))))))))))
2055 (defun gnus-article-hide-header (header)
2057 (goto-char (point-min))
2058 (when (re-search-forward (concat "^" header ":") nil t)
2059 (gnus-article-hide-text-type
2063 (if (re-search-forward "^[^ \t]" nil t)
2068 (defvar gnus-article-normalized-header-length 40
2069 "Length of normalized headers.")
2071 (defun article-normalize-headers ()
2072 "Make all header lines 40 characters long."
2074 (let ((inhibit-read-only t)
2078 (article-narrow-to-head)
2081 ((< (setq column (- (point-at-eol) (point)))
2082 gnus-article-normalized-header-length)
2084 (insert (make-string
2085 (- gnus-article-normalized-header-length column)
2087 ((> column gnus-article-normalized-header-length)
2088 (gnus-put-text-property
2090 (forward-char gnus-article-normalized-header-length)
2097 (forward-line 1))))))
2099 (defun article-treat-dumbquotes ()
2100 "Translate M****s*** sm*rtq**t*s and other symbols into proper text.
2101 Note that this function guesses whether a character is a sm*rtq**t* or
2102 not, so it should only be used interactively.
2104 Sm*rtq**t*s are M****s***'s unilateral extension to the
2105 iso-8859-1 character map in an attempt to provide more quoting
2106 characters. If you see something like \\222 or \\264 where
2107 you're expecting some kind of apostrophe or quotation mark, then
2110 (article-translate-strings gnus-article-dumbquotes-map))
2112 (defvar org-entities)
2114 (defun article-treat-non-ascii ()
2115 "Translate many Unicode characters into their ASCII equivalents."
2117 (require 'org-entities)
2118 (let ((table (make-char-table (if (featurep 'xemacs) 'generic))))
2119 (dolist (elem org-entities)
2120 (when (and (listp elem)
2121 (= (length (nth 6 elem)) 1))
2122 (if (featurep 'xemacs)
2123 (put-char-table (aref (nth 6 elem) 0) (nth 4 elem) table)
2124 (set-char-table-range table (aref (nth 6 elem) 0) (nth 4 elem)))))
2126 (when (article-goto-body)
2127 (let ((inhibit-read-only t)
2130 (if (not (setq replace (if (featurep 'xemacs)
2131 (get-char-table (following-char) table)
2132 (aref table (following-char)))))
2135 (setq props (text-properties-at (point)))
2137 (add-text-properties (point) (progn (insert replace) (point))
2139 (insert replace)))))))))
2141 (defun article-translate-strings (map)
2142 "Translate all string in the body of the article according to MAP.
2143 MAP is an alist where the elements are on the form (\"from\" \"to\")."
2145 (when (article-goto-body)
2146 (let ((inhibit-read-only t))
2148 (let ((from (car elem))
2152 (while (search-forward from nil t)
2155 (if (eq (following-char) from)
2159 (forward-char 1)))))))))))
2161 (defun article-treat-overstrike ()
2162 "Translate overstrikes into bold text."
2165 (when (article-goto-body)
2166 (let ((inhibit-read-only t))
2167 (while (search-forward "\b" nil t)
2168 (let ((next (char-after))
2169 (previous (char-after (- (point) 2))))
2170 ;; We do the boldification/underlining by hiding the
2171 ;; overstrikes and putting the proper text property
2175 (gnus-article-hide-text-type (- (point) 2) (point) 'overstrike)
2176 (put-text-property (point) (1+ (point)) 'face 'bold))
2178 (gnus-article-hide-text-type
2179 (1- (point)) (1+ (point)) 'overstrike)
2181 (- (point) 2) (1- (point)) 'face 'underline))
2183 (gnus-article-hide-text-type (- (point) 2) (point) 'overstrike)
2185 (point) (1+ (point)) 'face 'underline)))))))))
2187 (defun article-treat-ansi-sequences ()
2188 "Translate ANSI SGR control sequences into overlays or extents."
2191 (when (article-goto-body)
2192 (let ((inhibit-read-only t))
2193 (ansi-color-apply-on-region (point) (point-max))))))
2195 (defun gnus-article-treat-unfold-headers ()
2196 "Unfold folded message headers.
2197 Only the headers that fit into the current window width will be
2200 (gnus-with-article-headers
2204 (mail-header-narrow-to-field)
2205 (let* ((header (buffer-string))
2207 (or (equal gnus-article-unfold-long-headers t)
2208 (and (stringp gnus-article-unfold-long-headers)
2209 (string-match gnus-article-unfold-long-headers
2213 (goto-char (point-min))
2214 (while (re-search-forward "\n[\t ]" nil t)
2215 (replace-match " " t t)))
2216 (setq length (- (point-max) (point-min) 1))
2217 (when (or unfoldable
2218 (< length (window-width)))
2219 (while (re-search-forward "\n[\t ]" nil t)
2220 (replace-match " " t t))))
2221 (goto-char (point-max)))))))
2223 (defun gnus-article-treat-fold-headers ()
2224 "Fold message headers."
2226 (gnus-with-article-headers
2229 (mail-header-narrow-to-field)
2230 (mail-header-fold-field)
2231 (goto-char (point-max))))))
2233 (defun gnus-treat-smiley ()
2234 "Toggle display of textual emoticons (\"smileys\") as small graphical icons."
2236 (gnus-with-article-buffer
2237 (if (memq 'smiley gnus-article-wash-types)
2238 (gnus-delete-images 'smiley)
2240 (let ((images (smiley-region (point) (point-max))))
2242 (gnus-add-wash-type 'smiley)
2243 (dolist (image images)
2244 (gnus-add-image 'smiley image)))))))
2246 (defun gnus-article-remove-images ()
2247 "Remove all images from the article buffer."
2249 (gnus-with-article-buffer
2252 (dolist (elem gnus-article-image-alist)
2253 (gnus-delete-images (car elem))))))
2255 (autoload 'w3m-toggle-inline-images "w3m")
2257 (defun gnus-article-show-images ()
2258 "Show any images that are in the HTML-rendered article buffer.
2259 This only works if the article in question is HTML."
2261 (gnus-with-article-buffer
2264 (if (eq mm-text-html-renderer 'w3m)
2265 (let ((mm-inline-text-html-with-images nil))
2266 (w3m-toggle-inline-images))
2267 (dolist (region (gnus-find-text-property-region (point-min) (point-max)
2269 (destructuring-bind (start end function) region
2270 (funcall function (get-text-property start 'image-url)
2273 (defun gnus-article-treat-fold-newsgroups ()
2274 "Unfold folded message headers.
2275 Only the headers that fit into the current window width will be
2278 (gnus-with-article-headers
2279 (while (gnus-article-goto-header "newsgroups\\|followup-to")
2281 (mail-header-narrow-to-field)
2282 (while (re-search-forward ", *" nil t)
2283 (replace-match ", " t t))
2284 (mail-header-fold-field)
2285 (goto-char (point-max))))))
2287 (defcustom gnus-article-truncate-lines (default-value 'truncate-lines)
2288 "Value of `truncate-lines' in Gnus Article buffer.
2289 Valid values are nil, t, `head', `first', `last', an integer or a
2290 predicate. See Info node `(gnus)Customizing Articles'."
2291 :version "23.1" ;; No Gnus
2292 :group 'gnus-article
2293 ;; :link '(custom-manual "(gnus)Customizing Articles")
2296 (defun gnus-article-toggle-truncate-lines (&optional arg)
2297 "Toggle whether to fold or truncate long lines in article the buffer.
2298 If ARG is non-nil and not a number, toggle
2299 `gnus-article-truncate-lines' too. If ARG is a number, truncate
2300 long lines if and only if arg is positive."
2303 ((and (numberp arg) (> arg 0))
2304 (setq gnus-article-truncate-lines t))
2306 (setq gnus-article-truncate-lines nil))
2308 (setq gnus-article-truncate-lines
2309 (not gnus-article-truncate-lines))))
2310 (gnus-with-article-buffer
2312 ((and (numberp arg) (> arg 0))
2313 (setq truncate-lines nil))
2315 (setq truncate-lines t)))
2316 ;; In versions of Emacs 22 (CVS) before 2006-05-26,
2317 ;; `toggle-truncate-lines' needs an argument.
2318 (toggle-truncate-lines)))
2320 (defun gnus-article-treat-body-boundary ()
2321 "Place a boundary line at the end of the headers."
2323 (when (and gnus-body-boundary-delimiter
2324 (> (length gnus-body-boundary-delimiter) 0))
2325 (gnus-with-article-headers
2326 (goto-char (point-max))
2327 (let ((start (point)))
2328 (insert "X-Boundary: ")
2329 (gnus-add-text-properties start (point) '(invisible t intangible t))
2330 (insert (let (str (max (window-width)))
2331 (if (featurep 'xemacs)
2332 (setq max (1- max)))
2333 (while (>= max (length str))
2334 (setq str (concat str gnus-body-boundary-delimiter)))
2335 (substring str 0 max))
2337 (gnus-put-text-property start (point) 'gnus-decoration 'header)))))
2339 (defun article-fill-long-lines ()
2340 "Fill lines that are wider than the window width."
2343 (let ((inhibit-read-only t)
2344 (width (window-width (get-buffer-window (current-buffer)))))
2347 (let ((adaptive-fill-mode nil)) ;Why? -sm
2350 (when (>= (current-column) (min fill-column width))
2351 (narrow-to-region (min (1+ (point)) (point-max))
2353 (let ((goback (point-marker)))
2354 (fill-paragraph nil)
2355 (goto-char (marker-position goback)))
2357 (forward-line 1)))))))
2359 (defun article-capitalize-sentences ()
2360 "Capitalize the first word in each sentence."
2363 (let ((inhibit-read-only t)
2364 (paragraph-start "^[\n\^L]"))
2368 (forward-sentence)))))
2370 (defun article-remove-cr ()
2371 "Remove trailing CRs and then translate remaining CRs into LFs."
2374 (let ((inhibit-read-only t))
2375 (goto-char (point-min))
2376 (while (re-search-forward "\r+$" nil t)
2377 (replace-match "" t t))
2378 (goto-char (point-min))
2379 (while (search-forward "\r" nil t)
2380 (replace-match "\n" t t)))))
2382 (defun article-remove-trailing-blank-lines ()
2383 "Remove all trailing blank lines from the article."
2386 (let ((inhibit-read-only t))
2387 (goto-char (point-max))
2391 (while (and (not (bobp))
2392 (looking-at "^[ \t]*$")
2393 (not (gnus-annotation-in-region-p
2394 (point) (point-at-eol))))
2399 (defvar gnus-face-properties-alist)
2401 (defun article-display-face (&optional force)
2402 "Display any Face headers in the header."
2403 (interactive (list 'force))
2404 (let ((wash-face-p buffer-read-only))
2405 (gnus-with-article-headers
2406 ;; When displaying parts, this function can be called several times on
2407 ;; the same article, without any intended toggle semantic (as typing `W
2408 ;; D d' would have). So face deletion must occur only when we come from
2409 ;; an interactive command, that is when the *Article* buffer is
2411 (if (and wash-face-p (memq 'face gnus-article-wash-types))
2412 (gnus-delete-images 'face)
2413 (let ((from (message-fetch-field "from"))
2415 (save-current-buffer
2416 (when (and wash-face-p
2417 (gnus-buffer-live-p gnus-original-article-buffer)
2418 (not (re-search-forward "^Face:[\t ]*" nil t)))
2419 (set-buffer gnus-original-article-buffer))
2421 (mail-narrow-to-head)
2423 ;; Check whether this face is censored.
2424 (not (and gnus-article-x-face-too-ugly
2426 (setq from (message-fetch-field "from")))
2427 (string-match gnus-article-x-face-too-ugly
2429 (while (gnus-article-goto-header "Face")
2430 (push (mail-header-field-value) faces)))))
2432 (goto-char (point-min))
2434 (unless (setq from (gnus-article-goto-header "from"))
2437 (insert " [no `from' set]\n"))
2439 (when (setq png (gnus-convert-face-to-png (pop faces)))
2441 (apply 'gnus-create-image png 'png t
2442 (cdr (assq 'png gnus-face-properties-alist))))
2445 (gnus-add-wash-type 'face)
2446 (gnus-add-image 'face image)
2447 (gnus-put-image image nil 'face)))))))))))
2449 (defun article-display-x-face (&optional force)
2450 "Look for an X-Face header and display it if present."
2451 (interactive (list 'force))
2452 (let ((wash-face-p buffer-read-only)) ;; When type `W f'
2453 (gnus-with-article-headers
2454 ;; Delete the old process, if any.
2455 (when (process-status "article-x-face")
2456 (delete-process "article-x-face"))
2457 ;; See the comment in `article-display-face'.
2458 (if (and wash-face-p (memq 'xface gnus-article-wash-types))
2459 ;; We have already displayed X-Faces, so we remove them
2461 (gnus-delete-images 'xface)
2463 (let ((from (message-fetch-field "from"))
2465 (save-current-buffer
2466 (when (and wash-face-p
2467 (gnus-buffer-live-p gnus-original-article-buffer)
2468 (not (re-search-forward "^X-Face:[\t ]*" nil t)))
2469 ;; If type `W f', use gnus-original-article-buffer,
2470 ;; otherwise use the current buffer because displaying
2471 ;; RFC822 parts calls this function too.
2472 (set-buffer gnus-original-article-buffer))
2474 (mail-narrow-to-head)
2475 (and gnus-article-x-face-command
2477 ;; Check whether this face is censored.
2478 (not (and gnus-article-x-face-too-ugly
2480 (setq from (message-fetch-field "from")))
2481 (string-match gnus-article-x-face-too-ugly
2483 (while (gnus-article-goto-header "X-Face")
2484 (push (mail-header-field-value) x-faces)))))
2486 ;; We display the face.
2487 (cond ((functionp gnus-article-x-face-command)
2488 ;; The command is a lisp function, so we call it.
2489 (mapc gnus-article-x-face-command x-faces))
2490 ((stringp gnus-article-x-face-command)
2491 ;; The command is a string, so we interpret the command
2492 ;; as a, well, command, and fork it off.
2493 (let ((process-connection-type nil))
2494 (gnus-set-process-query-on-exit-flag
2496 "article-x-face" nil shell-file-name
2497 shell-command-switch gnus-article-x-face-command)
2499 ;; Sending multiple EOFs to xv doesn't work,
2500 ;; so we only do a single external face.
2502 (insert (car x-faces))
2503 (process-send-region "article-x-face"
2504 (point-min) (point-max)))
2505 (process-send-eof "article-x-face")))
2507 (error "`%s' set to `%s' is not a function"
2508 gnus-article-x-face-command
2509 'gnus-article-x-face-command)))))))))
2511 (defun article-decode-mime-words ()
2512 "Decode all MIME-encoded words in the article."
2514 (gnus-with-article-buffer
2515 (let ((inhibit-point-motion-hooks t)
2516 (mail-parse-charset gnus-newsgroup-charset)
2517 (mail-parse-ignored-charsets
2518 (with-current-buffer gnus-summary-buffer
2519 gnus-newsgroup-ignored-charsets)))
2520 (mail-decode-encoded-word-region (point-min) (point-max)))))
2522 (defun article-decode-charset (&optional prompt)
2523 "Decode charset-encoded text in the article.
2524 If PROMPT (the prefix), prompt for a coding system to use."
2526 (let ((inhibit-point-motion-hooks t) (case-fold-search t)
2527 (inhibit-read-only t)
2528 (mail-parse-charset gnus-newsgroup-charset)
2529 (mail-parse-ignored-charsets
2530 (save-excursion (condition-case nil
2531 (set-buffer gnus-summary-buffer)
2533 gnus-newsgroup-ignored-charsets))
2534 ct cte ctl charset format)
2537 (article-narrow-to-head)
2538 (setq ct (message-fetch-field "Content-Type" t)
2539 cte (message-fetch-field "Content-Transfer-Encoding" t)
2540 ctl (and ct (mail-header-parse-content-type ct))
2543 (mm-read-coding-system "Charset to decode: "))
2545 (mail-content-type-get ctl 'charset)))
2546 format (and ctl (mail-content-type-get ctl 'format)))
2548 (setq cte (mail-header-strip cte)))
2549 (if (and ctl (not (string-match "/" (car ctl))))
2551 (goto-char (point-max)))
2554 (narrow-to-region (point) (point-max))
2555 (when (and (eq mail-parse-charset 'gnus-decoded)
2556 (eq (mm-body-7-or-8) '8bit))
2557 ;; The text code could have been decoded.
2558 (setq charset mail-parse-charset))
2559 (when (and (or (not ctl)
2560 (equal (car ctl) "text/plain"))
2561 (not format)) ;; article with format will decode later.
2563 charset (and cte (intern (downcase
2564 (gnus-strip-whitespace cte))))
2567 (defun article-decode-encoded-words ()
2568 "Remove encoded-word encoding from headers."
2569 (let ((inhibit-point-motion-hooks t)
2570 (mail-parse-charset gnus-newsgroup-charset)
2571 (mail-parse-ignored-charsets
2572 (save-excursion (condition-case nil
2573 (set-buffer gnus-summary-buffer)
2575 gnus-newsgroup-ignored-charsets))
2576 (inhibit-read-only t)
2578 (goto-char (point-min))
2579 (when (search-forward "\n\n" nil 'move)
2586 (memq (char-after) '(?\t ? )))))
2587 (setq start (point))
2589 \\(?:Resent-\\)?\\(?:From\\|Cc\\|To\\|Bcc\\|\\(?:In-\\)?Reply-To\\|Sender\
2590 \\|Mail-Followup-To\\|Mail-Copies-To\\|Approved\\):")
2591 (funcall gnus-decode-address-function start end)
2592 (funcall gnus-decode-header-function start end))
2593 (goto-char (setq end start)))))
2595 (defun article-decode-group-name ()
2596 "Decode group names in Newsgroups, Followup-To and Xref headers."
2597 (let ((inhibit-point-motion-hooks t)
2598 (inhibit-read-only t)
2599 (method (gnus-find-method-for-group gnus-newsgroup-name))
2601 (when (and (or gnus-group-name-charset-method-alist
2602 gnus-group-name-charset-group-alist)
2603 (gnus-buffer-live-p gnus-original-article-buffer))
2605 (article-narrow-to-head)
2606 (dolist (header '("Newsgroups" "Followup-To" "Xref"))
2607 (with-current-buffer gnus-original-article-buffer
2608 (goto-char (point-min)))
2609 (setq regexp (concat "^" header
2610 ":\\([^\n]*\\(?:\n[\t ]+[^\n]+\\)*\\)\n"))
2611 (while (re-search-forward regexp nil t)
2612 (replace-match (save-match-data
2613 (gnus-decode-newsgroups
2614 ;; XXX how to use data in article buffer?
2615 (with-current-buffer gnus-original-article-buffer
2616 (re-search-forward regexp nil t)
2618 gnus-newsgroup-name method))
2620 (goto-char (point-min)))))))
2622 (autoload 'idna-to-unicode "idna")
2624 (defun article-decode-idna-rhs ()
2625 "Decode IDNA strings in RHS in various headers in current buffer.
2626 The following headers are decoded: From:, To:, Cc:, Reply-To:,
2627 Mail-Reply-To: and Mail-Followup-To:."
2630 (let ((inhibit-point-motion-hooks t)
2631 (inhibit-read-only t))
2632 (article-narrow-to-head)
2633 (goto-char (point-min))
2634 (while (re-search-forward "@[^ \t\n\r,>]*\\(xn--[-A-Za-z0-9.]*\\)[ \t\n\r,>]" nil t)
2636 (when (save-match-data
2637 (and (setq ace (match-string 1))
2639 (and (re-search-backward "^[^ \t]" nil t)
2640 (looking-at "From\\|To\\|Cc\\|Reply-To\\|Mail-Reply-To\\|Mail-Followup-To")))
2641 (setq unicode (idna-to-unicode ace))))
2642 (unless (string= ace unicode)
2643 (replace-match unicode nil nil nil 1)))))))))
2645 (defun article-de-quoted-unreadable (&optional force read-charset)
2646 "Translate a quoted-printable-encoded article.
2647 If FORCE, decode the article whether it is marked as quoted-printable
2649 If READ-CHARSET, ask for a coding system."
2650 (interactive (list 'force current-prefix-arg))
2652 (let ((inhibit-read-only t) type charset)
2653 (if (gnus-buffer-live-p gnus-original-article-buffer)
2654 (with-current-buffer gnus-original-article-buffer
2656 (gnus-fetch-field "content-transfer-encoding"))
2657 (let* ((ct (gnus-fetch-field "content-type"))
2658 (ctl (and ct (mail-header-parse-content-type ct))))
2659 (setq charset (and ctl
2660 (mail-content-type-get ctl 'charset)))
2661 (if (stringp charset)
2662 (setq charset (intern (downcase charset)))))))
2664 (setq charset (mm-read-coding-system "Charset: " charset)))
2666 (setq charset gnus-newsgroup-charset))
2668 (and type (let ((case-fold-search t))
2669 (string-match "quoted-printable" type))))
2671 (quoted-printable-decode-region
2672 (point) (point-max) (mm-charset-to-coding-system charset nil t))))))
2674 (defun article-de-base64-unreadable (&optional force read-charset)
2675 "Translate a base64 article.
2676 If FORCE, decode the article whether it is marked as base64 not.
2677 If READ-CHARSET, ask for a coding system."
2678 (interactive (list 'force current-prefix-arg))
2680 (let ((inhibit-read-only t) type charset)
2681 (if (gnus-buffer-live-p gnus-original-article-buffer)
2682 (with-current-buffer gnus-original-article-buffer
2684 (gnus-fetch-field "content-transfer-encoding"))
2685 (let* ((ct (gnus-fetch-field "content-type"))
2686 (ctl (and ct (mail-header-parse-content-type ct))))
2687 (setq charset (and ctl
2688 (mail-content-type-get ctl 'charset)))
2689 (if (stringp charset)
2690 (setq charset (intern (downcase charset)))))))
2692 (setq charset (mm-read-coding-system "Charset: " charset)))
2694 (setq charset gnus-newsgroup-charset))
2696 (and type (let ((case-fold-search t))
2697 (string-match "base64" type))))
2700 (narrow-to-region (point) (point-max))
2701 (base64-decode-region (point-min) (point-max))
2702 (mm-decode-coding-region
2703 (point-min) (point-max)
2704 (mm-charset-to-coding-system charset nil t)))))))
2709 (defun article-decode-HZ ()
2710 "Translate a HZ-encoded article."
2714 (let ((inhibit-read-only t))
2715 (rfc1843-decode-region (point-min) (point-max)))))
2717 (defun article-unsplit-urls ()
2718 "Remove the newlines that some other mailers insert into URLs."
2721 (let ((inhibit-read-only t))
2722 (goto-char (point-min))
2723 (while (re-search-forward
2724 "\\(\\(https?\\|ftp\\)://\\S-+\\) *\n\\(\\S-+\\)" nil t)
2725 (replace-match "\\1\\3" t)))
2726 (when (gmm-called-interactively-p 'any)
2727 (gnus-treat-article nil))))
2729 (defun article-wash-html ()
2730 "Format an HTML article."
2733 (buffer-read-only nil))
2734 (when (gnus-buffer-live-p gnus-original-article-buffer)
2735 (with-current-buffer gnus-original-article-buffer
2736 (setq handles (mm-dissect-buffer t t))))
2738 (delete-region (point) (point-max))
2739 (mm-enable-multibyte)
2740 (mm-inline-text-html handles)))
2742 (defvar gnus-article-browse-html-temp-list nil
2743 "List of temporary files created by `gnus-article-browse-html-parts'.
2744 Internal variable.")
2746 (defcustom gnus-article-browse-delete-temp 'ask
2747 "What to do with temporary files from `gnus-article-browse-html-parts'.
2748 If nil, don't delete temporary files. If it is t, delete them on
2749 exit from the summary buffer. If it is the symbol `file', query
2750 on each file, if it is `ask' ask once when exiting from the
2752 :group 'gnus-article
2753 :version "23.1" ;; No Gnus
2754 :type '(choice (const :tag "Don't delete" nil)
2755 (const :tag "Don't ask" t)
2756 (const :tag "Ask" ask)
2757 (const :tag "Ask for each file" file)))
2759 ;; Cf. mm-postponed-undisplay-list / mm-destroy-postponed-undisplay-list.
2761 (defun gnus-article-browse-delete-temp-files (&optional how)
2762 "Delete temp-files created by `gnus-article-browse-html-parts'."
2763 (when (and gnus-article-browse-html-temp-list
2765 (or how (setq how gnus-article-browse-delete-temp))
2767 (let ((files (length gnus-article-browse-html-temp-list)))
2770 "Delete the temporary HTML file? "
2771 (format "Delete all %s temporary HTML files? "
2773 (setq gnus-article-browse-html-temp-list nil)))
2775 (dolist (file gnus-article-browse-html-temp-list)
2776 (cond ((file-directory-p file)
2777 (when (or (not (eq how 'file))
2780 "Delete temporary HTML file(s) in directory `%s'? "
2781 (file-name-as-directory file))))
2782 (gnus-delete-directory file)))
2783 ((file-exists-p file)
2784 (when (or (not (eq how 'file))
2786 (format "Delete temporary HTML file `%s'? " file)))
2787 (delete-file file)))))
2788 ;; Also remove file from the list when not deleted or if file doesn't
2790 (setq gnus-article-browse-html-temp-list nil))
2791 gnus-article-browse-html-temp-list)
2793 (defun gnus-article-browse-html-save-cid-content (cid handles directory)
2794 "Find CID content in HANDLES and save it in a file in DIRECTORY.
2799 (dolist (handle handles)
2801 ((not (listp handle)))
2802 ;; Exclude broken handles that `gnus-summary-enter-digest-group'
2804 ((not (or (bufferp (car handle)) (stringp (car handle)))))
2805 ((equal (mm-handle-media-supertype handle) "multipart")
2806 (when (setq file (gnus-article-browse-html-save-cid-content
2807 cid handle directory))
2808 (throw 'found file)))
2809 ((equal (concat "<" cid ">") (mm-handle-id handle))
2810 (setq file (or (mm-handle-filename handle)
2812 (make-temp-name "cid")
2813 (car (rassoc (car (mm-handle-type handle))
2814 mailcap-mime-extensions)))))
2815 (mm-save-part-to-file handle (expand-file-name file directory))
2816 (throw 'found (concat (file-name-nondirectory
2817 (directory-file-name directory))
2820 (defun gnus-article-browse-html-parts (list &optional header)
2821 "View all \"text/html\" parts from LIST.
2822 Recurse into multiparts. The optional HEADER that should be a decoded
2823 message header will be added to the bodies of the \"text/html\" parts."
2824 ;; Internal function used by `gnus-article-browse-html-article'.
2825 (let (type file charset content cid-dir tmp-file showed)
2826 ;; Find and show the html-parts.
2827 (dolist (handle list)
2828 ;; If HTML, show it:
2829 (cond ((not (listp handle)))
2830 ((or (equal (car (setq type (mm-handle-type handle))) "text/html")
2831 (and (equal (car type) "message/external-body")
2833 (setq file (mm-handle-filename handle)))
2834 (or (mm-handle-cache handle)
2835 (condition-case code
2836 (progn (mm-extern-cache-contents handle) t)
2838 (gnus-message 3 "%s" (error-message-string code))
2839 (when (>= gnus-verbose 3) (sit-for 2))
2842 (setq handle (mm-handle-cache handle)
2843 type (mm-handle-type handle))
2844 (equal (car type) "text/html"))))
2845 (setq charset (mail-content-type-get type 'charset)
2846 content (mm-get-part handle))
2848 (if (eq charset 'gnus-decoded)
2849 (mm-enable-multibyte)
2850 (mm-disable-multibyte))
2853 (let ((case-fold-search t))
2854 (goto-char (point-min))
2855 (when (and (search-forward "<head>" nil t)
2860 (or (search-forward "</head>" nil t) (point)))
2861 (goto-char (point-min)))
2863 "[\t\n ]*<base[\t\n ]+[^>]+>[\t\n ]*" nil t)))
2864 (replace-match "\n")))
2865 ;; resolve cid contents
2866 (let ((case-fold-search t)
2868 (goto-char (point-min))
2869 (while (re-search-forward "\
2870 <img[\t\n ]+\\(?:[^\t\n >]+[\t\n ]+\\)*src=\"\\(cid:\\([^\"]+\\)\\)\""
2873 (setq cid-dir (mm-make-temp-file "cid" t))
2874 (add-to-list 'gnus-article-browse-html-temp-list cid-dir))
2877 (when (setq cid-file
2878 (gnus-article-browse-html-save-cid-content
2880 (with-current-buffer gnus-article-buffer
2881 gnus-article-mime-handles)
2883 (replace-match cid-file nil nil nil 1))))
2884 (unless content (setq content (buffer-string))))
2885 (when (or charset header (not file))
2886 (setq tmp-file (mm-make-temp-file
2887 ;; Do we need to care for 8.3 filenames?
2888 "mm-" nil ".html")))
2889 ;; Add a meta html tag to specify charset and a header.
2892 (let (title eheader body hcharset coding)
2894 (mm-enable-multibyte)
2895 (setq case-fold-search t)
2896 (insert header "\n")
2897 (setq title (message-fetch-field "subject"))
2898 (goto-char (point-min))
2899 (while (re-search-forward "\\(<\\)\\|\\(>\\)\\|\\(&\\)\\|\n"
2901 (replace-match (cond ((match-beginning 1) "<")
2902 ((match-beginning 2) ">")
2903 ((match-beginning 3) "&")
2905 (goto-char (point-min))
2906 (while (re-search-forward "^[\t ]+" nil t)
2909 (delete-region (match-beginning 0)
2912 (goto-char (point-min))
2913 (insert "<div align=\"left\">\n")
2914 (goto-char (point-max))
2915 (insert "</div>\n<hr>\n")
2916 ;; We have to examine charset one by one since
2917 ;; charset specified in parts might be different.
2918 (if (eq charset 'gnus-decoded)
2919 (setq charset 'utf-8
2920 eheader (mm-encode-coding-string (buffer-string)
2923 (mm-encode-coding-string title charset))
2924 body (mm-encode-coding-string content charset))
2925 (setq hcharset (mm-find-mime-charset-region (point-min)
2927 (cond ((= (length hcharset) 1)
2928 (setq hcharset (car hcharset)
2929 coding (mm-charset-to-coding-system
2931 ((> (length hcharset) 1)
2932 (setq hcharset 'utf-8
2938 (mm-charset-to-coding-system charset
2940 (if (eq coding body)
2941 (setq eheader (mm-encode-coding-string
2942 (buffer-string) coding)
2944 (mm-encode-coding-string
2947 (setq charset 'utf-8
2948 eheader (mm-encode-coding-string
2949 (buffer-string) charset)
2951 (mm-encode-coding-string
2953 body (mm-encode-coding-string
2954 (mm-decode-coding-string
2957 (setq charset hcharset
2958 eheader (mm-encode-coding-string
2959 (buffer-string) coding)
2961 (mm-encode-coding-string
2964 (setq eheader (mm-string-as-unibyte (buffer-string))
2967 (mm-disable-multibyte)
2970 (mm-add-meta-html-tag handle charset t))
2972 (goto-char (point-min))
2973 (unless (search-forward "<title>" nil t)
2974 (re-search-forward "<head>\\s-*" nil t)
2975 (insert "<title>" title "</title>\n")))
2976 (goto-char (point-min))
2977 (or (re-search-forward
2978 "<body\\(?:\\s-+[^>]+\\|\\s-*\\)>\\s-*" nil t)
2980 "</head\\(?:\\s-+[^>]+\\|\\s-*\\)>\\s-*" nil t))
2982 (mm-write-region (point-min) (point-max)
2983 tmp-file nil nil nil 'binary t))))
2985 (mm-with-unibyte-buffer
2986 (insert (if (eq charset 'gnus-decoded)
2987 (mm-encode-coding-string content
2988 (setq charset 'utf-8))
2990 (if (or (mm-add-meta-html-tag handle charset)
2992 (mm-write-region (point-min) (point-max)
2993 tmp-file nil nil nil 'binary t)
2994 (setq tmp-file nil))))
2996 (mm-save-part-to-file handle tmp-file)))
2998 (add-to-list 'gnus-article-browse-html-temp-list tmp-file))
2999 (add-hook 'gnus-summary-prepare-exit-hook
3000 'gnus-article-browse-delete-temp-files)
3001 (add-hook 'gnus-exit-gnus-hook
3003 (gnus-article-browse-delete-temp-files t)))
3004 ;; FIXME: Warn if there's an <img> tag?
3005 (browse-url-of-file (or tmp-file (expand-file-name file)))
3007 ;; If multipart, recurse
3008 ((equal (mm-handle-media-supertype handle) "multipart")
3009 (when (gnus-article-browse-html-parts handle header)
3011 ((equal (mm-handle-media-type handle) "message/rfc822")
3012 (mm-with-multibyte-buffer
3013 (mm-insert-part handle)
3014 (setq handle (mm-dissect-buffer t t))
3015 (when (and (bufferp (car handle))
3016 (stringp (car (mm-handle-type handle))))
3017 (setq handle (list handle)))
3019 (article-decode-encoded-words)
3020 (let ((gnus-visible-headers
3021 (or (get 'gnus-visible-headers 'standard-value)
3022 gnus-visible-headers)))
3023 (article-hide-headers))
3024 (goto-char (point-min))
3025 (search-forward "\n\n" nil 'move)
3026 (skip-chars-backward "\t\n ")
3027 (setq header (buffer-substring (point-min) (point)))))
3029 (gnus-article-browse-html-parts handle header)
3030 (mm-destroy-parts handle))
3034 (defun gnus-article-browse-html-article (&optional arg)
3035 "View \"text/html\" parts of the current article with a WWW browser.
3036 Inline images embedded in a message using the cid scheme, as they are
3037 generally considered to be safe, will be processed properly.
3038 The message header is added to the beginning of every html part unless
3039 the prefix argument ARG is given.
3041 Warning: Spammers use links to images (using the http scheme) in HTML
3042 articles to verify whether you have read the message. As
3043 `gnus-article-browse-html-article' passes the HTML content to the
3044 browser without eliminating these \"web bugs\" you should only
3045 use it for mails from trusted senders.
3047 If you always want to display HTML parts in the browser, set
3048 `mm-text-html-renderer' to nil.
3050 This command creates temporary files to pass HTML contents including
3051 images if any to the browser, and deletes them when exiting the group
3053 ;; Cf. `mm-w3m-safe-url-regexp'
3056 (gnus-summary-show-article)
3057 (let ((gnus-visible-headers (or (get 'gnus-visible-headers 'standard-value)
3058 gnus-visible-headers))
3059 ;; As we insert a <hr>, there's no need for the body boundary.
3060 (gnus-treat-body-boundary nil))
3061 (gnus-summary-show-article)))
3062 (with-current-buffer gnus-article-buffer
3063 (let ((header (unless arg
3066 (buffer-substring-no-properties
3067 (goto-char (point-min))
3068 (if (search-forward "\n\n" nil t)
3070 (goto-char (point-max))
3071 (skip-chars-backward "\t\n ")
3074 (set-buffer gnus-original-article-buffer)
3075 (setq parts (mm-dissect-buffer t t))
3076 ;; If singlepart, enforce a list.
3077 (when (and (bufferp (car parts))
3078 (stringp (car (mm-handle-type parts))))
3079 (setq parts (list parts)))
3081 (unless (gnus-article-browse-html-parts parts header)
3082 (gnus-error 3 "Mail doesn't contain a \"text/html\" part!"))
3083 (mm-destroy-parts parts)
3085 (gnus-summary-show-article)))))
3087 (defun article-hide-list-identifiers ()
3088 "Remove list identifies from the Subject header.
3089 The `gnus-list-identifiers' variable specifies what to do."
3091 (let ((inhibit-point-motion-hooks t)
3092 (regexp (gnus-group-get-list-identifiers gnus-newsgroup-name))
3093 (inhibit-read-only t))
3097 (article-narrow-to-head)
3098 (goto-char (point-min))
3099 (while (re-search-forward
3100 (concat "^Subject: +\\(R[Ee]: +\\)*\\(" regexp " *\\)")
3102 (delete-region (match-beginning 2) (match-end 0))
3103 (beginning-of-line))
3104 (when (re-search-forward
3105 "^Subject: +\\(\\(R[Ee]: +\\)+\\)R[Ee]: +" nil t)
3106 (delete-region (match-beginning 1) (match-end 1))))))))
3108 (defun article-hide-pem (&optional arg)
3109 "Toggle hiding of any PEM headers and signatures in the current article.
3110 If given a negative prefix, always show; if given a positive prefix,
3112 (interactive (gnus-article-hidden-arg))
3113 (unless (gnus-article-check-hidden-text 'pem arg)
3115 (let ((inhibit-read-only t) end)
3116 (goto-char (point-min))
3117 ;; Hide the horrendously ugly "header".
3118 (when (and (search-forward
3119 "\n-----BEGIN PRIVACY-ENHANCED MESSAGE-----\n"
3121 (setq end (1+ (match-beginning 0))))
3122 (gnus-add-wash-type 'pem)
3123 (gnus-article-hide-text-type
3125 (if (search-forward "\n\n" nil t)
3129 ;; Hide the trailer as well
3130 (when (search-forward "\n-----END PRIVACY-ENHANCED MESSAGE-----\n"
3132 (gnus-article-hide-text-type
3133 (match-beginning 0) (match-end 0) 'pem)))))))
3135 (defun article-strip-banner ()
3136 "Strip the banners specified by the `banner' group parameter and by
3137 `gnus-article-address-banner-alist'."
3141 (let ((inhibit-point-motion-hooks t))
3142 (when (gnus-parameter-banner gnus-newsgroup-name)
3143 (article-really-strip-banner
3144 (gnus-parameter-banner gnus-newsgroup-name)))
3145 (when gnus-article-address-banner-alist
3146 ;; Note that the From header is decoded here, so it is
3147 ;; required that the *-extract-address-components function
3148 ;; supports non-ASCII text.
3149 (let ((from (save-restriction
3151 (article-narrow-to-head)
3152 (mail-fetch-field "from"))))
3155 (cadr (funcall gnus-extract-address-components
3158 (dolist (pair gnus-article-address-banner-alist)
3159 (when (string-match (car pair) from)
3161 (article-really-strip-banner (cdr pair)))))))))))))
3163 (defun article-really-strip-banner (banner)
3164 "Strip the banner specified by the argument."
3167 (let ((inhibit-point-motion-hooks t)
3168 (gnus-signature-limit nil)
3169 (inhibit-read-only t))
3172 ((eq banner 'signature)
3173 (when (gnus-article-narrow-to-signature)
3176 (delete-region (point) (point-max))))
3178 (if (setq banner (cdr (assq banner gnus-article-banner-alist)))
3179 (while (re-search-forward banner nil t)
3180 (delete-region (match-beginning 0) (match-end 0)))))
3182 (while (re-search-forward banner nil t)
3183 (delete-region (match-beginning 0) (match-end 0)))))))))
3185 (defun article-babel ()
3186 "Translate article using an online translation service."
3189 (gnus-with-article-buffer
3190 (when (article-goto-body)
3191 (let* ((start (point))
3193 (orig (buffer-substring start end))
3194 (trans (babel-as-string orig)))
3196 (narrow-to-region start end)
3197 (delete-region start end)
3200 (defun article-hide-signature (&optional arg)
3201 "Hide the signature in the current article.
3202 If given a negative prefix, always show; if given a positive prefix,
3204 (interactive (gnus-article-hidden-arg))
3205 (unless (gnus-article-check-hidden-text 'signature arg)
3208 (let ((inhibit-read-only t))
3209 (when (gnus-article-narrow-to-signature)
3210 (gnus-article-hide-text-type
3211 (point-min) (point-max) 'signature))))))
3212 (gnus-set-mode-line 'article))
3214 (defun article-strip-headers-in-body ()
3215 "Strip offensive headers from bodies."
3219 (let ((case-fold-search t))
3220 (when (looking-at "x-no-archive:")
3221 (gnus-delete-line)))))
3223 (defun article-strip-leading-blank-lines ()
3224 "Remove all blank lines from the beginning of the article."
3227 (let ((inhibit-point-motion-hooks t)
3228 (inhibit-read-only t))
3229 (when (article-goto-body)
3230 (while (and (not (eobp))
3231 (looking-at "[ \t]*$"))
3232 (gnus-delete-line))))))
3234 (defun article-narrow-to-head ()
3235 "Narrow the buffer to the head of the message.
3236 Point is left at the beginning of the narrowed-to region."
3238 (goto-char (point-min))
3240 ;; Absolutely no headers displayed.
3244 ((search-forward "\n\n" nil 1)
3246 ;; Nothing but headers.
3249 (goto-char (point-min)))
3251 (defun article-goto-body ()
3252 "Place point at the start of the body."
3253 (goto-char (point-min))
3255 ;; This variable is only bound when dealing with separate
3257 (article-goto-body-goes-to-point-min-p
3259 ((search-forward "\n\n" nil t)
3262 (goto-char (point-max))
3265 (defun article-strip-multiple-blank-lines ()
3266 "Replace consecutive blank lines with one empty line."
3269 (let ((inhibit-point-motion-hooks t)
3270 (inhibit-read-only t))
3271 ;; First make all blank lines empty.
3273 (while (re-search-forward "^[ \t]+$" nil t)
3274 (unless (gnus-annotation-in-region-p
3275 (match-beginning 0) (match-end 0))
3276 (replace-match "" nil t)))
3277 ;; Then replace multiple empty lines with a single empty line.
3279 (while (re-search-forward "\n\n\\(\n+\\)" nil t)
3280 (unless (gnus-annotation-in-region-p
3281 (match-beginning 0) (match-end 0))
3282 (delete-region (match-beginning 1) (match-end 1)))))))
3284 (defun article-strip-leading-space ()
3285 "Remove all white space from the beginning of the lines in the article."
3288 (let ((inhibit-point-motion-hooks t)
3289 (inhibit-read-only t))
3291 (while (re-search-forward "^[ \t]+" nil t)
3292 (replace-match "" t t)))))
3294 (defun article-strip-trailing-space ()
3295 "Remove all white space from the end of the lines in the article."
3298 (let ((inhibit-point-motion-hooks t)
3299 (inhibit-read-only t))
3301 (while (re-search-forward "[ \t]+$" nil t)
3302 (replace-match "" t t)))))
3304 (defun article-strip-blank-lines ()
3305 "Strip leading, trailing and multiple blank lines."
3307 (article-strip-leading-blank-lines)
3308 (article-remove-trailing-blank-lines)
3309 (article-strip-multiple-blank-lines))
3311 (defun article-strip-all-blank-lines ()
3312 "Strip all blank lines."
3315 (let ((inhibit-point-motion-hooks t)
3316 (inhibit-read-only t))
3318 (while (re-search-forward "^[ \t]*\n" nil t)
3319 (replace-match "" t t)))))
3321 (defun gnus-article-narrow-to-signature ()
3322 "Narrow to the signature; return t if a signature is found, else nil."
3323 (let ((inhibit-point-motion-hooks t))
3324 (when (gnus-article-search-signature)
3326 ;; Check whether we have some limits to what we consider
3327 ;; to be a signature.
3328 (let ((limits (if (listp gnus-signature-limit) gnus-signature-limit
3329 (list gnus-signature-limit)))
3331 (while (setq limit (pop limits))
3332 (if (or (and (integerp limit)
3333 (< (- (point-max) (point)) limit))
3335 (< (count-lines (point) (point-max)) limit))
3336 (and (functionp limit)
3338 (and (stringp limit)
3339 (not (re-search-forward limit nil t))))
3340 () ; This limit did not succeed.
3344 (narrow-to-region (point) (point-max))
3347 (defun gnus-article-search-signature ()
3348 "Search the current buffer for the signature separator.
3349 Put point at the beginning of the signature separator."
3350 (let ((cur (point)))
3351 (goto-char (point-max))
3352 (if (if (stringp gnus-signature-separator)
3353 (re-search-backward gnus-signature-separator nil t)
3354 (let ((seps gnus-signature-separator))
3356 (not (re-search-backward (car seps) nil t)))
3363 (defun gnus-article-hidden-arg ()
3364 "Return the current prefix arg as a number, or 0 if no prefix."
3365 (list (if current-prefix-arg
3366 (prefix-numeric-value current-prefix-arg)
3369 (defun gnus-article-check-hidden-text (type arg)
3370 "Return nil if hiding is necessary.
3371 Arg can be nil or a number. nil and positive means hide, negative
3372 means show, 0 means toggle."
3375 (let ((hide (gnus-article-hidden-text-p type)))
3381 (gnus-article-show-hidden-text type)
3384 (if (eq hide 'hidden)
3386 (gnus-article-show-hidden-text type)
3390 (defun gnus-article-hidden-text-p (type)
3391 "Say whether the current buffer contains hidden text of type TYPE."
3392 (let ((pos (text-property-any (point-min) (point-max) 'article-type type)))
3394 (not (get-text-property pos 'invisible))
3395 (not (get-text-property pos 'dummy-invisible)))
3397 (text-property-any (1+ pos) (point-max) 'article-type type)))
3402 (defun gnus-article-show-hidden-text (type &optional dummy)
3403 "Show all hidden text of type TYPE.
3404 Originally it is hide instead of DUMMY."
3405 (let ((inhibit-read-only t)
3406 (inhibit-point-motion-hooks t))
3407 (gnus-remove-text-properties-when
3409 (point-min) (point-max)
3410 (cons 'article-type (cons type
3411 gnus-hidden-properties)))
3412 (gnus-delete-wash-type type)))
3414 (defconst article-time-units
3415 `((year . ,(* 365.25 24 60 60))
3416 (week . ,(* 7 24 60 60))
3417 (day . ,(* 24 60 60))
3421 "Mapping from time units to seconds.")
3423 (defun gnus-article-forward-header ()
3424 "Move point to the start of the next header.
3425 If the current header is a continuation header, this can be several
3430 (if (looking-at "[ \t]+[^ \t]")
3434 (defun article-treat-date ()
3435 (article-date-ut (if (gnus-buffer-live-p gnus-summary-buffer)
3436 (with-current-buffer gnus-summary-buffer
3437 gnus-article-date-headers)
3438 gnus-article-date-headers)
3441 (defun article-date-ut (&optional type highlight date-position)
3442 "Convert DATE date to TYPE in the current article.
3443 The default type is `ut'. See `gnus-article-date-headers' for
3445 (interactive (list 'ut t))
3446 (let* ((case-fold-search t)
3447 (inhibit-read-only t)
3448 (inhibit-point-motion-hooks t)
3450 (visible-date (mail-fetch-field "Date"))
3451 pos date bface eface)
3455 (goto-char date-position)
3456 (setq date (get-text-property (point) 'original-date))
3457 (when (looking-at "[^:]+:[\t ]*")
3458 (setq bface (get-text-property (match-beginning 0) 'face)
3459 eface (get-text-property (match-end 0) 'face)))
3460 (delete-region (point)
3462 (gnus-article-forward-header)
3464 (article-transform-date date type bface eface))
3467 (goto-char (point-min))
3468 (while (or (get-text-property (setq pos (point)) 'original-date)
3469 (and (setq pos (next-single-property-change
3470 (point) 'original-date))
3472 (narrow-to-region pos (if (search-forward "\n\n" nil t)
3473 (1+ (match-beginning 0))
3475 (while (setq pos (text-property-not-all pos (point-max)
3476 'gnus-date-type nil))
3477 (setq date (get-text-property pos 'original-date))
3479 (when (looking-at "[^:]+:[\t ]*")
3480 (setq bface (get-text-property (match-beginning 0) 'face)
3481 eface (get-text-property (match-end 0) 'face)))
3482 (delete-region pos (or (text-property-any pos (point-max)
3483 'gnus-date-type nil)
3485 (unless date ;; the 1st time
3486 (goto-char (point-min))
3487 (while (re-search-forward "^Date:[\t ]*" nil t)
3488 (setq date (get-text-property (match-beginning 0)
3490 bface (get-text-property (match-beginning 0) 'face)
3491 eface (get-text-property (match-end 0) 'face))
3492 (delete-region (point-at-bol) (progn
3493 (gnus-article-forward-header)
3495 (when (and (not date)
3497 (setq date visible-date))
3499 (article-transform-date date type bface eface))
3500 (goto-char (point-max))
3503 (defun article-transform-date (date type bface eface)
3504 (dolist (this-type (cond
3514 (add-text-properties
3517 (insert (article-make-date-line date (or this-type 'ut)) "\n")
3519 (list 'original-date date 'gnus-date-type this-type))))
3522 "\\([^:]+:\\)[\t ]*\\(\\(?:[^\t\n ]+[\t ]+\\)*[^\t\n ]+\\)?")
3523 (put-text-property (match-beginning 1) (match-end 1) 'face bface)
3524 (when (match-beginning 2)
3525 (put-text-property (match-beginning 2) (match-end 2) 'face eface))
3526 (while (and (zerop (forward-line 1))
3527 (looking-at "[\t ]+\\(\\(?:[^\t\n ]+[\t ]+\\)*[^\t\n ]+\\)?"))
3528 (when (match-beginning 1)
3529 (put-text-property (match-beginning 1) (match-end 1) 'face eface))))))
3531 (defun article-make-date-line (date type)
3532 "Return a DATE line of TYPE."
3533 (unless (memq type '(local ut original user-defined iso8601 lapsed english
3535 (error "Unknown conversion type: %s" type))
3537 (let ((time (ignore-errors (date-to-time date))))
3539 ;; Convert to the local timezone.
3541 (concat "Date: " (message-make-date time)))
3542 ;; Convert to Universal Time.
3547 (let* ((e (parse-time-string date))
3548 (tm (apply 'encode-time e))
3550 (ls (- (cadr tm) (car (current-time-zone time)))))
3551 (cond ((< ls 0) (list (1- ms) (+ ls 65536)))
3552 ((> ls 65535) (list (1+ ms) (- ls 65536)))
3556 ;; Get the original date from the article.
3557 ((eq type 'original)
3558 (concat "Date: " (if (string-match "\n+$" date)
3559 (substring date 0 (match-beginning 0))
3561 ;; Let the user define the format.
3562 ((eq type 'user-defined)
3563 (let ((format (or (condition-case nil
3564 (with-current-buffer gnus-summary-buffer
3565 gnus-article-time-format)
3567 gnus-article-time-format)))
3568 (if (functionp format)
3569 (funcall format time)
3570 (concat "Date: " (format-time-string format time)))))
3573 (let ((tz (car (current-time-zone time))))
3576 (format-time-string "%Y%m%dT%H%M%S" time)
3577 (format "%s%02d%02d"
3578 (if (> tz 0) "+" "-") (/ (abs tz) 3600)
3579 (/ (% (abs tz) 3600) 60)))))
3580 ;; Do a lapsed format.
3582 (concat "Date: " (article-lapsed-string time)))
3583 ;; A combined date/lapsed format.
3584 ((eq type 'combined-lapsed)
3585 (let ((date-string (article-make-date-line date 'original))
3591 (concat " (" (article-lapsed-string time segments) ")"))
3592 (> (+ (length date-string)
3593 (length lapsed-string))
3596 (setq segments (1- segments)))
3598 (concat date-string lapsed-string)
3600 ;; Display the date in proper English
3602 (let ((dtime (decode-time time)))
3605 (number-to-string (nth 3 dtime))
3606 (let ((digit (% (nth 3 dtime) 10)))
3608 ((memq (nth 3 dtime) '(11 12 13)) "th")
3614 (nth (1- (nth 4 dtime)) gnus-english-month-names)
3616 (number-to-string (nth 5 dtime))
3618 (format "%02d" (nth 2 dtime))
3620 (format "%02d" (nth 1 dtime)))))))
3622 (format "Date: %s (from Gnus)" date))))
3624 (defun article-lapsed-string (time &optional max-segments)
3625 ;; If the date is seriously mangled, the timezone functions are
3626 ;; liable to bug out, so we ignore all errors.
3627 (let* ((now (current-time))
3628 (real-time (subtract-time now time))
3629 (real-sec (and real-time
3630 (+ (* (float (car real-time)) 65536)
3632 (sec (and real-time (abs real-sec)))
3635 (unless max-segments
3636 (setq max-segments (length article-time-units)))
3644 ;; This is a bit convoluted, but basically we go
3645 ;; through the time units for years, weeks, etc,
3646 ;; and divide things to see whether that results
3647 ;; in positive answers.
3650 (if (or (zerop (setq num (ffloor (/ sec (cdr unit)))))
3651 (>= segments max-segments))
3652 ;; The (remaining) seconds are too few to
3653 ;; be divided into this time unit.
3655 ;; It's big enough, so we output it.
3656 (setq sec (- sec (* num (cdr unit))))
3658 (concat (if prev ", " "") (int-to-string
3660 " " (symbol-name (car unit))
3661 (if (> num 1) "s" ""))
3663 segments (1+ segments)))))
3664 article-time-units "")
3665 ;; If dates are odd, then it might appear like the
3666 ;; article was sent in the future.
3669 " in the future"))))))
3671 (defun article-date-local (&optional highlight)
3672 "Convert the current article date to the local timezone."
3673 (interactive (list t))
3674 (article-date-ut 'local highlight))
3676 (defun article-date-english (&optional highlight)
3677 "Convert the current article date to something that is proper English."
3678 (interactive (list t))
3679 (article-date-ut 'english highlight))
3681 (defun article-date-original (&optional highlight)
3682 "Convert the current article date to what it was originally.
3683 This is only useful if you have used some other date conversion
3684 function and want to see what the date was before converting."
3685 (interactive (list t))
3686 (article-date-ut 'original highlight))
3688 (defun article-date-lapsed (&optional highlight)
3689 "Convert the current article date to time lapsed since it was sent."
3690 (interactive (list t))
3691 (article-date-ut 'lapsed highlight))
3693 (defun article-date-combined-lapsed (&optional highlight)
3694 "Convert the current article date to time lapsed since it was sent."
3695 (interactive (list t))
3696 (article-date-ut 'combined-lapsed highlight))
3698 (defun article-update-date-lapsed ()
3699 "Function to be run from a timer to update the lapsed time line."
3701 (let ((buffer (current-buffer)))
3705 (set-buffer (window-buffer w))
3706 (when (derived-mode-p 'gnus-article-mode)
3707 (let ((old-line (count-lines (point-min) (point)))
3708 (old-column (- (point) (line-beginning-position)))
3709 (window-start (window-start w))
3712 (while (setq pos (text-property-not-all pos (point-max)
3713 'gnus-date-type nil))
3714 (setq next (or (next-single-property-change pos
3717 (setq type (get-text-property pos 'gnus-date-type))
3718 (when (memq type '(lapsed combined-lapsed user-defined))
3719 (article-date-ut type t pos)
3720 (setq end (or (next-single-property-change pos
3724 (if (/= window-start next)
3725 (setq window-start nil)
3726 (set-window-start w end)))
3729 (goto-char (point-min))
3730 (when (> old-column 0)
3731 (setq old-line (1- old-line)))
3732 (forward-line old-line)
3734 (when (> (current-column) old-column)
3736 (forward-char old-column)))))
3738 (set-buffer buffer))))
3740 (defun gnus-start-date-timer (&optional n)
3741 "Start a timer to update the Date headers in the article buffers.
3742 The numerical prefix says how frequently (in seconds) the function
3747 (gnus-stop-date-timer)
3748 (setq article-lapsed-timer
3749 (run-at-time 1 n 'article-update-date-lapsed)))
3751 (defun gnus-stop-date-timer ()
3752 "Stop the Date timer."
3754 (when article-lapsed-timer
3755 (nnheader-cancel-timer article-lapsed-timer)
3756 (setq article-lapsed-timer nil)))
3758 (defun article-date-user (&optional highlight)
3759 "Convert the current article date to the user-defined format.
3760 This format is defined by the `gnus-article-time-format' variable."
3761 (interactive (list t))
3762 (article-date-ut 'user highlight))
3764 (defun article-date-iso8601 (&optional highlight)
3765 "Convert the current article date to ISO8601."
3766 (interactive (list t))
3767 (article-date-ut 'iso8601 highlight))
3769 (defmacro gnus-article-save-original-date (&rest forms)
3770 "Save the original date as a text property and evaluate FORMS."
3771 `(let* ((case-fold-search t)
3773 (goto-char (point-min))
3774 (when (and (re-search-forward "^date:[\t\n ]+" nil t)
3777 (date (when (and start
3778 (re-search-forward "[\t ]*\n\\(?:[^\t ]\\|\\'\\)"
3780 (buffer-substring-no-properties start
3781 (match-beginning 0)))))
3782 (goto-char (point-max))
3783 (skip-chars-backward "\n")
3784 (put-text-property (point-min) (point) 'original-date date)
3786 (goto-char (point-max))
3787 (skip-chars-backward "\n")
3788 (put-text-property (point-min) (point) 'original-date date)))
3790 ;; (defun article-show-all ()
3791 ;; "Show all hidden text in the article buffer."
3794 ;; (let ((inhibit-read-only t))
3795 ;; (gnus-article-unhide-text (point-min) (point-max)))))
3797 (defun article-remove-leading-whitespace ()
3798 "Remove excessive whitespace from all headers."
3802 (let ((inhibit-read-only t))
3803 (article-narrow-to-head)
3804 (goto-char (point-min))
3805 (while (re-search-forward "^[^ :]+: \\([ \t]+\\)" nil t)
3806 (delete-region (match-beginning 1) (match-end 1)))))))
3808 (defun article-emphasize (&optional arg)
3809 "Emphasize text according to `gnus-emphasis-alist'."
3810 (interactive (gnus-article-hidden-arg))
3811 (unless (gnus-article-check-hidden-text 'emphasis arg)
3815 (with-current-buffer gnus-summary-buffer
3816 gnus-article-emphasis-alist)
3818 gnus-emphasis-alist))
3819 (inhibit-read-only t)
3820 (props (append '(article-type emphasis)
3821 gnus-hidden-properties))
3822 regexp elem beg invisible visible face)
3825 (while (setq elem (pop alist))
3827 (setq regexp (car elem)
3828 invisible (nth 1 elem)
3829 visible (nth 2 elem)
3831 (while (re-search-forward regexp nil t)
3832 (when (and (match-beginning visible) (match-beginning invisible))
3833 (gnus-article-hide-text
3834 (match-beginning invisible) (match-end invisible) props)
3835 (gnus-article-unhide-text-type
3836 (match-beginning visible) (match-end visible) 'emphasis)
3837 (gnus-put-overlay-excluding-newlines
3838 (match-beginning visible) (match-end visible) 'face face)
3839 (gnus-add-wash-type 'emphasis)
3840 (goto-char (match-end invisible)))))))))
3842 (defun gnus-article-setup-highlight-words (&optional highlight-words)
3843 "Setup newsgroup emphasis alist."
3844 (unless gnus-article-emphasis-alist
3845 (let ((name (and gnus-newsgroup-name
3846 (gnus-group-real-name gnus-newsgroup-name))))
3847 (make-local-variable 'gnus-article-emphasis-alist)
3848 (setq gnus-article-emphasis-alist
3850 (let ((alist gnus-group-highlight-words-alist) elem highlight)
3851 (while (setq elem (pop alist))
3852 (when (and name (string-match (car elem) name))
3854 highlight (copy-sequence (cdr elem)))))
3856 (copy-sequence highlight-words)
3857 (if gnus-newsgroup-name
3858 (copy-sequence (gnus-group-find-parameter
3859 gnus-newsgroup-name 'highlight-words t)))
3860 gnus-emphasis-alist)))))
3862 (defvar gnus-summary-article-menu)
3863 (defvar gnus-summary-post-menu)
3865 ;;; Saving functions.
3867 (defun gnus-article-save (save-buffer file &optional num)
3868 "Save the currently selected article."
3869 (when (or (get gnus-default-article-saver :headers)
3870 (not gnus-save-all-headers))
3871 ;; Remove headers according to `gnus-saved-headers' or the value
3872 ;; of the `:headers' property that the saver function might have.
3873 (let ((gnus-visible-headers
3874 (or (symbol-value (get gnus-default-article-saver :headers))
3875 gnus-saved-headers gnus-visible-headers))
3876 ;; Ignore group parameter. See `article-hide-headers'.
3877 (gnus-summary-buffer nil))
3878 (with-current-buffer save-buffer
3879 (article-hide-headers 1 t))))
3880 (save-window-excursion
3881 (if (not gnus-default-article-saver)
3882 (error "No default saver is defined")
3883 ;; !!! Magic! The saving functions all save
3884 ;; `gnus-save-article-buffer' (or so they think), but we
3885 ;; bind that variable to our save-buffer.
3886 (set-buffer gnus-article-buffer)
3887 (let* ((gnus-save-article-buffer save-buffer)
3890 ((not gnus-prompt-before-saving) 'default)
3891 ((eq gnus-prompt-before-saving 'always) nil)
3893 (gnus-number-of-articles-to-be-saved
3894 (when (eq gnus-prompt-before-saving t)
3896 (set-buffer gnus-article-current-summary)
3897 (funcall gnus-default-article-saver filename)))))
3899 (defun gnus-read-save-file-name (prompt &optional filename
3900 function group headers variable
3903 (funcall function group headers (symbol-value variable)))
3908 ((eq filename 'default)
3914 (when (symbol-value dir-var)
3915 (setq default-name (expand-file-name
3916 (file-name-nondirectory default-name)
3917 (symbol-value dir-var))))
3918 (let* ((split-name (gnus-get-split-value gnus-split-methods))
3921 (if (and gnus-number-of-articles-to-be-saved
3922 (> gnus-number-of-articles-to-be-saved 1))
3923 (format "these %d articles"
3924 gnus-number-of-articles-to-be-saved)
3927 ;; Let the split methods have their say.
3929 ;; No split name was found.
3932 (concat prompt " (default "
3933 (file-name-nondirectory default-name) "): ")
3934 (file-name-directory default-name)
3936 ;; A single group name is returned.
3937 ((stringp split-name)
3939 (funcall function split-name headers
3940 (symbol-value variable)))
3942 (concat prompt " (default "
3943 (file-name-nondirectory default-name) "): ")
3944 (file-name-directory default-name)
3946 ;; A single split name was found
3947 ((= 1 (length split-name))
3948 (let* ((name (expand-file-name
3950 gnus-article-save-directory))
3951 (dir (cond ((file-directory-p name)
3952 (file-name-as-directory name))
3953 ((file-exists-p name) name)
3954 (t gnus-article-save-directory))))
3956 (concat prompt " (default " name "): ")
3958 ;; A list of splits was found.
3960 (setq split-name (nreverse split-name))
3962 (let ((file-name-history
3963 (nconc split-name file-name-history)))
3967 (concat prompt " (`M-p' for defaults): ")
3968 gnus-article-save-directory
3970 gnus-article-save-directory)))
3971 (car (push result file-name-history)))))))
3972 ;; Create the directory.
3973 (gnus-make-directory (file-name-directory file))
3974 ;; If we have read a directory, we append the default file name.
3975 (when (file-directory-p file)
3976 (setq file (expand-file-name (file-name-nondirectory
3978 (file-name-as-directory file))))
3979 ;; Possibly translate some characters.
3980 (nnheader-translate-file-chars file))))))
3981 (gnus-make-directory (file-name-directory result))
3983 (set variable result))
3985 (set dir-var (file-name-directory result)))
3988 (defun gnus-article-archive-name (group)
3989 "Return the first instance of an \"Archive-name\" in the current buffer."
3990 (let ((case-fold-search t))
3991 (when (re-search-forward "archive-name: *\\([^ \n\t]+\\)[ \t]*$" nil t)
3992 (nnheader-concat gnus-article-save-directory
3993 (match-string 1)))))
3995 (defun gnus-article-nndoc-name (group)
3996 "If GROUP is an nndoc group, return the name of the parent group."
3997 (when (eq (car (gnus-find-method-for-group group)) 'nndoc)
3998 (gnus-group-get-parameter group 'save-article-group)))
4000 (defun gnus-summary-save-in-rmail (&optional filename)
4001 "Append this article to Rmail file.
4002 Optional argument FILENAME specifies file name.
4003 Directory to save to is default to `gnus-article-save-directory'."
4004 (setq filename (gnus-read-save-file-name
4005 "Save %s in rmail file" filename
4006 gnus-rmail-save-name gnus-newsgroup-name
4007 gnus-current-headers 'gnus-newsgroup-last-rmail))
4008 (with-current-buffer gnus-save-article-buffer
4012 ;; Note that unlike gnus-summary-save-in-mail, there is no
4013 ;; check to see if filename is Babyl. Rmail in Emacs 23 does
4015 (gnus-output-to-rmail filename))))
4018 (defun gnus-summary-save-in-mail (&optional filename)
4019 "Append this article to Unix mail file.
4020 Optional argument FILENAME specifies file name.
4021 Directory to save to is default to `gnus-article-save-directory'."
4022 (setq filename (gnus-read-save-file-name
4023 "Save %s in Unix mail file" filename
4024 gnus-mail-save-name gnus-newsgroup-name
4025 gnus-current-headers 'gnus-newsgroup-last-mail))
4026 (with-current-buffer gnus-save-article-buffer
4030 (if (and (file-readable-p filename)
4031 (file-regular-p filename)
4032 (mail-file-babyl-p filename))
4033 (gnus-output-to-rmail filename)
4034 (gnus-output-to-mail filename)))))
4037 (put 'gnus-summary-save-in-file :decode t)
4038 (put 'gnus-summary-save-in-file :headers 'gnus-saved-headers)
4039 (defun gnus-summary-save-in-file (&optional filename overwrite)
4040 "Append this article to file.
4041 Optional argument FILENAME specifies file name.
4042 Directory to save to is default to `gnus-article-save-directory'."
4043 (setq filename (gnus-read-save-file-name
4044 "Save %s in file" filename
4045 gnus-file-save-name gnus-newsgroup-name
4046 gnus-current-headers 'gnus-newsgroup-last-file))
4047 (with-current-buffer gnus-save-article-buffer
4051 (when (and overwrite
4052 (file-exists-p filename))
4053 (delete-file filename))
4054 (gnus-output-to-file filename))))
4057 (put 'gnus-summary-write-to-file :decode t)
4058 (put 'gnus-summary-write-to-file :function 'gnus-summary-save-in-file)
4059 (put 'gnus-summary-write-to-file :headers 'gnus-saved-headers)
4060 (defun gnus-summary-write-to-file (&optional filename)
4061 "Write this article to a file, overwriting it if the file exists.
4062 Optional argument FILENAME specifies file name.
4063 The directory to save in defaults to `gnus-article-save-directory'."
4064 (setq filename (gnus-read-save-file-name
4065 "Save %s in file" filename
4066 gnus-file-save-name gnus-newsgroup-name
4067 gnus-current-headers nil 'gnus-newsgroup-last-directory))
4068 (gnus-summary-save-in-file filename t))
4070 (put 'gnus-summary-save-body-in-file :decode t)
4071 (defun gnus-summary-save-body-in-file (&optional filename overwrite)
4072 "Append this article body to a file.
4073 Optional argument FILENAME specifies file name.
4074 The directory to save in defaults to `gnus-article-save-directory'."
4075 (setq filename (gnus-read-save-file-name
4076 "Save %s body in file" filename
4077 gnus-file-save-name gnus-newsgroup-name
4078 gnus-current-headers 'gnus-newsgroup-last-file))
4079 (with-current-buffer gnus-save-article-buffer
4083 (when (article-goto-body)
4084 (narrow-to-region (point) (point-max)))
4085 (when (and overwrite
4086 (file-exists-p filename))
4087 (delete-file filename))
4088 (gnus-output-to-file filename))))
4091 (put 'gnus-summary-write-body-to-file :decode t)
4092 (put 'gnus-summary-write-body-to-file
4093 :function 'gnus-summary-save-body-in-file)
4094 (defun gnus-summary-write-body-to-file (&optional filename)
4095 "Write this article body to a file, overwriting it if the file exists.
4096 Optional argument FILENAME specifies file name.
4097 The directory to save in defaults to `gnus-article-save-directory'."
4098 (setq filename (gnus-read-save-file-name
4099 "Save %s body in file" filename
4100 gnus-file-save-name gnus-newsgroup-name
4101 gnus-current-headers nil 'gnus-newsgroup-last-directory))
4102 (gnus-summary-save-body-in-file filename t))
4104 (put 'gnus-summary-save-in-pipe :decode t)
4105 (put 'gnus-summary-save-in-pipe :headers 'gnus-saved-headers)
4106 (defun gnus-summary-save-in-pipe (&optional command raw)
4107 "Pipe this article to subprocess COMMAND.
4108 Valid values for COMMAND include:
4110 The executable command name and possibly arguments.
4112 You will be prompted for the command in the minibuffer.
4113 the symbol `default'
4114 It will be replaced with the command which the variable
4115 `gnus-summary-pipe-output-default-command' holds or the command
4116 last used for saving.
4117 Non-nil value for RAW overrides `:decode' and `:headers' properties
4118 and the raw article including all headers will be piped."
4119 (let ((article (gnus-summary-article-number))
4121 (get 'gnus-summary-save-in-pipe :decode)))
4122 save-buffer default)
4124 (if (vectorp (gnus-summary-article-header article))
4125 (save-current-buffer
4126 (gnus-summary-select-article decode decode nil article)
4127 (insert-buffer-substring
4131 gnus-original-article-buffer)
4133 (nnheader-set-temp-buffer " *Gnus Save*"))))
4134 ;; Remove unwanted headers.
4135 (when (and (not raw)
4136 (or (get 'gnus-summary-save-in-pipe :headers)
4137 (not gnus-save-all-headers)))
4138 (let ((gnus-visible-headers
4139 (or (symbol-value (get 'gnus-summary-save-in-pipe
4141 gnus-saved-headers gnus-visible-headers))
4142 (gnus-summary-buffer nil))
4143 (article-hide-headers 1 t))))
4144 (error "%d is not a real article" article))
4145 (error "No article to pipe"))
4146 (setq default (or gnus-summary-pipe-output-default-command
4147 gnus-last-shell-command))
4148 (unless (stringp command)
4150 (if (and (eq command 'default) default)
4152 (gnus-read-shell-command "Shell command on this article: "
4154 (when (string-equal command "")
4156 (setq command default)
4157 (error "A command is required")))
4158 (with-current-buffer save-buffer
4161 (shell-command-on-region (point-min) (point-max) command nil)))
4162 (gnus-kill-buffer save-buffer))
4163 (setq gnus-summary-pipe-output-default-command command))
4165 (defun gnus-summary-pipe-to-muttprint (&optional command)
4166 "Pipe this article to muttprint."
4167 (unless (stringp command)
4168 (setq command (read-string
4169 "Print using command: " gnus-summary-muttprint-program
4170 nil gnus-summary-muttprint-program)))
4171 (let ((gnus-summary-pipe-output-default-command
4172 gnus-summary-pipe-output-default-command))
4173 (gnus-summary-save-in-pipe command))
4174 (setq gnus-summary-muttprint-program command))
4176 ;;; Article file names when saving.
4178 (defun gnus-capitalize-newsgroup (newsgroup)
4179 "Capitalize NEWSGROUP name."
4180 (when (not (zerop (length newsgroup)))
4181 (concat (char-to-string (upcase (aref newsgroup 0)))
4182 (substring newsgroup 1))))
4184 (defun gnus-Numeric-save-name (newsgroup headers &optional last-file)
4185 "Generate file name from NEWSGROUP, HEADERS, and optional LAST-FILE.
4186 If variable `gnus-use-long-file-name' is non-nil, it is ~/News/News.group/num.
4187 Otherwise, it is like ~/News/news/group/num."
4190 (concat (if (gnus-use-long-file-name 'not-save)
4191 (gnus-capitalize-newsgroup newsgroup)
4192 (gnus-newsgroup-directory-form newsgroup))
4193 "/" (int-to-string (mail-header-number headers)))
4194 gnus-article-save-directory)))
4196 (string-equal (file-name-directory default)
4197 (file-name-directory last-file))
4198 (string-match "^[0-9]+$" (file-name-nondirectory last-file)))
4200 (or last-file default))))
4202 (defun gnus-numeric-save-name (newsgroup headers &optional last-file)
4203 "Generate file name from NEWSGROUP, HEADERS, and optional LAST-FILE.
4204 If variable `gnus-use-long-file-name' is non-nil, it is
4205 ~/News/news.group/num. Otherwise, it is like ~/News/news/group/num."
4208 (concat (if (gnus-use-long-file-name 'not-save)
4210 (gnus-newsgroup-directory-form newsgroup))
4211 "/" (int-to-string (mail-header-number headers)))
4212 gnus-article-save-directory)))
4214 (string-equal (file-name-directory default)
4215 (file-name-directory last-file))
4216 (string-match "^[0-9]+$" (file-name-nondirectory last-file)))
4218 (or last-file default))))
4220 (defun gnus-plain-save-name (newsgroup headers &optional last-file)
4221 "Generate file name from NEWSGROUP, HEADERS, and optional LAST-FILE.
4222 If variable `gnus-use-long-file-name' is non-nil, it is
4223 ~/News/news.group. Otherwise, it is like ~/News/news/group/news."
4226 (if (gnus-use-long-file-name 'not-save)
4229 (expand-file-name "news" (gnus-newsgroup-directory-form newsgroup))
4231 gnus-article-save-directory)))
4233 (defun gnus-sender-save-name (newsgroup headers &optional last-file)
4234 "Generate file name from sender."
4235 (let ((from (mail-header-from headers)))
4237 (if (and from (string-match "\\([^ <]+\\)@" from))
4238 (match-string 1 from)
4240 gnus-article-save-directory)))
4242 (defun article-verify-x-pgp-sig ()
4244 ;; <ftp://ftp.isc.org/pub/pgpcontrol/FORMAT>
4246 (if (gnus-buffer-live-p gnus-original-article-buffer)
4247 (let ((sig (with-current-buffer gnus-original-article-buffer
4248 (gnus-fetch-field "X-PGP-Sig")))
4252 (mml2015-clear-verify-function))
4254 (insert-buffer-substring gnus-original-article-buffer)
4255 (setq items (split-string sig))
4256 (message-narrow-to-head)
4257 (let ((inhibit-point-motion-hooks t)
4258 (case-fold-search t))
4259 ;; Don't verify multiple headers.
4260 (setq headers (mapconcat (lambda (header)
4262 (mail-fetch-field header)
4264 (split-string (nth 1 items) ",") "")))
4265 (delete-region (point-min) (point-max))
4266 (insert "-----BEGIN PGP SIGNED MESSAGE-----\n\n")
4267 (insert "X-Signed-Headers: " (nth 1 items) "\n")
4272 (if (looking-at "^-")
4275 (insert "\n-----BEGIN PGP SIGNATURE-----\n")
4276 (insert "Version: " (car items) "\n\n")
4277 (insert (mapconcat 'identity (cddr items) "\n"))
4278 (insert "\n-----END PGP SIGNATURE-----\n")
4279 (let ((mm-security-handle (list (format "multipart/signed"))))
4280 (mml2015-clean-buffer)
4281 (let ((coding-system-for-write (or gnus-newsgroup-charset
4283 (funcall (mml2015-clear-verify-function)))
4285 (or (mm-handle-multipart-ctl-parameter
4286 mm-security-handle 'gnus-details)
4287 (mm-handle-multipart-ctl-parameter
4288 mm-security-handle 'gnus-info)))))
4290 (let ((inhibit-read-only t) bface eface)
4292 (message-narrow-to-head)
4293 (goto-char (point-max))
4295 (setq bface (get-text-property (point-at-bol) 'face)
4296 eface (get-text-property (1- (point-at-eol)) 'face))
4297 (message-remove-header "X-Gnus-PGP-Verify")
4298 (if (re-search-forward "^X-PGP-Sig:" nil t)
4300 (goto-char (point-max)))
4301 (narrow-to-region (point) (point))
4302 (insert "X-Gnus-PGP-Verify: " info "\n")
4303 (goto-char (point-min))
4306 (if (not (looking-at "^[ \t]"))
4310 (goto-char (point-min))
4311 (when (looking-at "\\([^:]+\\): *")
4312 (put-text-property (match-beginning 1) (1+ (match-end 1))
4314 (put-text-property (match-end 0) (point-max)
4315 'face eface)))))))))
4317 (autoload 'canlock-verify "canlock" nil t) ;; for XEmacs.
4319 (defun article-verify-cancel-lock ()
4320 "Verify Cancel-Lock header."
4322 (if (gnus-buffer-live-p gnus-original-article-buffer)
4323 (canlock-verify gnus-original-article-buffer)))
4330 (setq afunc (car func)
4333 gfunc (intern (format "gnus-%s" func))))
4335 (when (fboundp afunc)
4336 `(lambda (&optional interactive &rest args)
4337 ,(documentation afunc t)
4338 (interactive (list t))
4339 (with-current-buffer gnus-article-buffer
4341 (call-interactively ',afunc)
4342 (apply ',afunc args))))))))
4343 '(article-hide-headers
4344 article-verify-x-pgp-sig
4345 article-verify-cancel-lock
4346 article-hide-boring-headers
4347 article-treat-overstrike
4348 article-treat-ansi-sequences
4349 article-fill-long-lines
4350 article-capitalize-sentences
4352 article-remove-leading-whitespace
4353 article-display-x-face
4354 article-display-face
4355 article-de-quoted-unreadable
4356 article-de-base64-unreadable
4359 article-unsplit-urls
4360 article-hide-list-identifiers
4361 article-strip-banner
4364 article-hide-signature
4365 article-strip-headers-in-body
4366 article-remove-trailing-blank-lines
4367 article-strip-leading-blank-lines
4368 article-strip-multiple-blank-lines
4369 article-strip-leading-space
4370 article-strip-trailing-space
4371 article-strip-blank-lines
4372 article-strip-all-blank-lines
4374 article-date-english
4375 article-date-iso8601
4376 article-date-original
4379 article-decode-mime-words
4380 article-decode-charset
4381 article-decode-encoded-words
4384 article-date-combined-lapsed
4386 article-treat-dumbquotes
4387 article-treat-non-ascii
4388 article-normalize-headers
4389 ;;(article-show-all . gnus-article-show-all-headers)
4393 ;;; Gnus article mode
4396 (put 'gnus-article-mode 'mode-class 'special)
4398 (set-keymap-parent gnus-article-mode-map widget-keymap)
4400 (gnus-define-keys gnus-article-mode-map
4401 " " gnus-article-goto-next-page
4402 [?\S-\ ] gnus-article-goto-prev-page
4403 "\177" gnus-article-goto-prev-page
4404 [delete] gnus-article-goto-prev-page
4405 "\C-c^" gnus-article-refer-article
4406 "h" gnus-article-show-summary
4407 "s" gnus-article-show-summary
4408 "\C-c\C-m" gnus-article-mail
4409 "?" gnus-article-describe-briefly
4410 "<" beginning-of-buffer
4412 "\C-c\C-i" gnus-info-find-node
4414 "R" gnus-article-reply-with-original
4415 "F" gnus-article-followup-with-original
4416 "\C-hk" gnus-article-describe-key
4417 "\C-hc" gnus-article-describe-key-briefly
4418 "\C-hb" gnus-article-describe-bindings
4420 "e" gnus-article-read-summary-keys
4421 "\C-d" gnus-article-read-summary-keys
4422 "\M-*" gnus-article-read-summary-keys
4423 "\M-#" gnus-article-read-summary-keys
4424 "\M-^" gnus-article-read-summary-keys
4425 "\M-g" gnus-article-read-summary-keys)
4427 (substitute-key-definition
4428 'undefined 'gnus-article-read-summary-keys gnus-article-mode-map)
4430 (gnus-define-keys (gnus-article-send-map "S" gnus-article-mode-map)
4431 "W" gnus-article-wide-reply-with-original)
4432 (if (featurep 'xemacs)
4433 (set-keymap-default-binding gnus-article-send-map
4434 'gnus-article-read-summary-send-keys)
4435 (define-key gnus-article-send-map [t] 'gnus-article-read-summary-send-keys))
4437 (defun gnus-article-make-menu-bar ()
4438 (unless (boundp 'gnus-article-commands-menu)
4439 (gnus-summary-make-menu-bar))
4440 (unless (boundp 'gnus-article-article-menu)
4442 gnus-article-article-menu gnus-article-mode-map ""
4444 ["Scroll forwards" gnus-article-goto-next-page t]
4445 ["Scroll backwards" gnus-article-goto-prev-page t]
4446 ["Show summary" gnus-article-show-summary t]
4447 ["Fetch Message-ID at point" gnus-article-refer-article t]
4448 ["Mail to address at point" gnus-article-mail t]
4449 ["Send a bug report" gnus-bug t]))
4452 gnus-article-treatment-menu gnus-article-mode-map ""
4453 ;; Fixme: this should use :active (and maybe :visible).
4455 ["Hide headers" gnus-article-hide-headers t]
4456 ["Hide signature" gnus-article-hide-signature t]
4457 ["Hide citation" gnus-article-hide-citation t]
4458 ["Treat overstrike" gnus-article-treat-overstrike t]
4459 ["Treat ANSI sequences" gnus-article-treat-ansi-sequences t]
4460 ["Remove carriage return" gnus-article-remove-cr t]
4461 ["Remove leading whitespace" gnus-article-remove-leading-whitespace t]
4462 ["Remove quoted-unreadable" gnus-article-de-quoted-unreadable t]
4463 ["Remove base64" gnus-article-de-base64-unreadable t]
4464 ["Treat html" gnus-article-wash-html t]
4465 ["Remove newlines from within URLs" gnus-article-unsplit-urls t]
4466 ["Decode HZ" gnus-article-decode-HZ t]))
4468 ;; Note "Commands" menu is defined in gnus-sum.el for consistency
4470 ;; Note "Post" menu is defined in gnus-sum.el for consistency
4472 (gnus-run-hooks 'gnus-article-menu-hook)))
4474 (defvar bookmark-make-record-function)
4475 (defvar shr-put-image-function)
4477 (define-derived-mode gnus-article-mode fundamental-mode "Article"
4478 "Major mode for displaying an article.
4480 All normal editing commands are switched off.
4482 The following commands are available in addition to all summary mode
4484 \\<gnus-article-mode-map>
4485 \\[gnus-article-next-page]\t Scroll the article one page forwards
4486 \\[gnus-article-prev-page]\t Scroll the article one page backwards
4487 \\[gnus-article-refer-article]\t Go to the article referred to by an article id near point
4488 \\[gnus-article-show-summary]\t Display the summary buffer
4489 \\[gnus-article-mail]\t Send a reply to the address near point
4490 \\[gnus-article-describe-briefly]\t Describe the current mode briefly
4491 \\[gnus-info-find-node]\t Go to the Gnus info node"
4492 (gnus-simplify-mode-line)
4493 (make-local-variable 'minor-mode-alist)
4494 (when (gnus-visual-p 'article-menu 'menu)
4495 (gnus-article-make-menu-bar)
4496 (when gnus-summary-tool-bar-map
4497 (set (make-local-variable 'tool-bar-map) gnus-summary-tool-bar-map)))
4498 (gnus-update-format-specifications nil 'article-mode)
4499 (set (make-local-variable 'page-delimiter) gnus-page-delimiter)
4500 (set (make-local-variable 'gnus-page-broken) nil)
4501 (make-local-variable 'gnus-article-current-summary)
4502 (make-local-variable 'gnus-article-mime-handles)
4503 (make-local-variable 'gnus-article-decoded-p)
4504 (make-local-variable 'gnus-article-mime-handle-alist)
4505 (make-local-variable 'gnus-article-wash-types)
4506 (make-local-variable 'gnus-article-image-alist)
4507 (make-local-variable 'gnus-article-charset)
4508 (make-local-variable 'gnus-article-ignored-charsets)
4509 (set (make-local-variable 'bookmark-make-record-function)
4510 'gnus-summary-bookmark-make-record)
4511 ;; Prevent Emacs 22 from displaying non-break space with `nobreak-space'
4513 (set (make-local-variable 'nobreak-char-display) nil)
4514 ;; Enable `gnus-article-remove-images' to delete images shr.el renders.
4515 (set (make-local-variable 'shr-put-image-function) 'gnus-shr-put-image)
4516 (setq cursor-in-non-selected-windows nil)
4517 (gnus-set-default-directory)
4518 (buffer-disable-undo)
4519 (setq buffer-read-only t
4520 show-trailing-whitespace nil)
4521 (mm-enable-multibyte))
4523 (defun gnus-article-setup-buffer ()
4524 "Initialize the article buffer."
4525 (let* ((name (if gnus-single-article-buffer "*Article*"
4527 (gnus-group-decoded-name gnus-newsgroup-name)
4530 (progn (string-match "\\*Article" name)
4531 (concat " *Original Article"
4532 (substring name (match-end 0))))))
4533 (setq gnus-article-buffer name)
4534 (setq gnus-original-article-buffer original)
4535 (setq gnus-article-mime-handle-alist nil)
4536 (with-current-buffer gnus-summary-buffer
4537 ;; This might be a variable local to the summary buffer.
4538 (unless gnus-single-article-buffer
4539 (setq gnus-article-buffer name)
4540 (setq gnus-original-article-buffer original)
4541 (gnus-set-global-variables)))
4542 (gnus-article-setup-highlight-words)
4543 ;; Init original article buffer.
4544 (with-current-buffer (gnus-get-buffer-create gnus-original-article-buffer)
4545 (mm-enable-multibyte)
4546 (setq major-mode 'gnus-original-article-mode)
4547 (make-local-variable 'gnus-original-article))
4548 (if (and (get-buffer name)
4549 (with-current-buffer name
4550 (if gnus-article-edit-mode
4551 (if (y-or-n-p "Article mode edit in progress; discard? ")
4553 (set-buffer-modified-p nil)
4554 (gnus-kill-buffer name)
4557 (error "Action aborted"))
4559 (let ((summary gnus-summary-buffer))
4560 (with-current-buffer name
4561 (set (make-local-variable 'gnus-article-edit-mode) nil)
4562 (gnus-article-stop-animations)
4563 (when gnus-article-mime-handles
4564 (mm-destroy-parts gnus-article-mime-handles)
4565 (setq gnus-article-mime-handles nil))
4566 ;; Set it to nil in article-buffer!
4567 (setq gnus-article-mime-handle-alist nil)
4568 (buffer-disable-undo)
4569 (setq buffer-read-only t)
4570 (unless (derived-mode-p 'gnus-article-mode)
4571 (gnus-article-mode))
4572 (set (make-local-variable 'gnus-summary-buffer) summary)
4573 (setq truncate-lines gnus-article-truncate-lines)
4575 (let ((summary gnus-summary-buffer))
4576 (with-current-buffer (gnus-get-buffer-create name)
4578 (setq truncate-lines gnus-article-truncate-lines)
4579 (set (make-local-variable 'gnus-summary-buffer) summary)
4580 (gnus-summary-set-local-parameters gnus-newsgroup-name)
4581 (when article-lapsed-timer
4582 (gnus-stop-date-timer))
4583 (when gnus-article-update-date-headers
4584 (gnus-start-date-timer gnus-article-update-date-headers))
4585 (current-buffer))))))
4587 (defun gnus-article-stop-animations ()
4588 (dolist (timer (and (boundp 'timer-list)
4590 (when (eq (gnus-timer--function timer) 'image-animate-timeout)
4591 (cancel-timer timer))))
4593 (defun gnus-stop-downloads ()
4594 (when (boundp 'url-queue)
4595 (set (intern "url-queue" obarray) nil)))
4597 ;; Set article window start at LINE, where LINE is the number of lines
4598 ;; from the head of the article.
4599 (defun gnus-article-set-window-start (&optional line)
4600 (let ((article-window (gnus-get-buffer-window gnus-article-buffer t)))
4601 (when article-window
4604 (with-current-buffer gnus-article-buffer
4605 (goto-char (point-min))
4608 (gnus-message 6 "Moved to bookmark")
4609 (search-forward "\n\n" nil t)
4613 (defun gnus-article-prepare (article &optional all-headers header)
4614 "Prepare ARTICLE in article mode buffer.
4615 ARTICLE should either be an article number or a Message-ID.
4616 If ARTICLE is an id, HEADER should be the article headers.
4617 If ALL-HEADERS is non-nil, no headers are hidden."
4619 ;; Make sure we start in a summary buffer.
4620 (unless (derived-mode-p 'gnus-summary-mode)
4621 (set-buffer gnus-summary-buffer))
4622 (setq gnus-summary-buffer (current-buffer))
4623 (let* ((gnus-article (if header (mail-header-number header) article))
4624 (summary-buffer (current-buffer))
4625 (gnus-tmp-internal-hook gnus-article-internal-prepare-hook)
4626 (group gnus-newsgroup-name)
4629 (gnus-article-setup-buffer)
4630 (set-buffer gnus-article-buffer)
4631 ;; Deactivate active regions.
4632 (when (and (boundp 'transient-mark-mode)
4633 transient-mark-mode)
4634 (setq mark-active nil))
4635 (if (not (setq result (let ((inhibit-read-only t))
4636 (gnus-request-article-this-buffer
4638 ;; There is no such article.
4640 (when (and (numberp article)
4641 (not (memq article gnus-newsgroup-sparse)))
4642 (setq gnus-article-current
4643 (cons gnus-newsgroup-name article))
4644 (set-buffer gnus-summary-buffer)
4645 (setq gnus-current-article article)
4646 (if (and (memq article gnus-newsgroup-undownloaded)
4647 (not (gnus-online (gnus-find-method-for-group
4648 gnus-newsgroup-name))))
4650 (gnus-summary-set-agent-mark article)
4651 (message "Message marked for downloading"))
4652 (gnus-summary-mark-article article gnus-canceled-mark)
4653 (unless (memq article gnus-newsgroup-sparse)
4654 (gnus-error 1 "No such article (may have expired or been canceled)")))))
4655 (if (or (eq result 'pseudo)
4656 (eq result 'nneething))
4658 (with-current-buffer summary-buffer
4659 (push article gnus-newsgroup-history)
4660 (setq gnus-last-article gnus-current-article
4661 gnus-current-article 0
4662 gnus-current-headers nil
4663 gnus-article-current nil)
4664 (if (eq result 'nneething)
4665 (gnus-configure-windows 'summary)
4666 (gnus-configure-windows 'article))
4667 (gnus-set-global-variables))
4668 (let ((gnus-article-mime-handle-alist-1
4669 gnus-article-mime-handle-alist))
4670 (gnus-set-mode-line 'article)))
4671 ;; The result from the `request' was an actual article -
4672 ;; or at least some text that is now displayed in the
4674 (when (and (numberp article)
4675 (not (eq article gnus-current-article)))
4676 ;; Seems like a new article has been selected.
4677 ;; `gnus-current-article' must be an article number.
4678 (with-current-buffer summary-buffer
4679 (push article gnus-newsgroup-history)
4680 (setq gnus-last-article gnus-current-article
4681 gnus-current-article article
4682 gnus-current-headers
4683 (gnus-summary-article-header gnus-current-article)
4684 gnus-article-current
4685 (cons gnus-newsgroup-name gnus-current-article))
4686 (unless (vectorp gnus-current-headers)
4687 (setq gnus-current-headers nil))
4688 (gnus-summary-goto-subject gnus-current-article)
4689 (when (gnus-summary-show-thread)
4690 ;; If the summary buffer really was folded, the
4691 ;; previous goto may not actually have gone to
4692 ;; the right article, but the thread root instead.
4694 (gnus-summary-goto-subject gnus-current-article))
4695 (gnus-run-hooks 'gnus-mark-article-hook)
4696 (gnus-set-mode-line 'summary)
4697 (when (gnus-visual-p 'article-highlight 'highlight)
4698 (gnus-run-hooks 'gnus-visual-mark-article-hook))
4699 ;; Set the global newsgroup variables here.
4700 (gnus-set-global-variables)
4701 (setq gnus-have-all-headers
4702 (or all-headers gnus-show-all-headers))))
4704 (gnus-configure-windows 'article))
4705 (when (or (numberp article)
4707 (gnus-article-prepare-display)
4709 (goto-char (point-min))
4710 (when gnus-break-pages
4711 (gnus-narrow-to-page)))
4712 (let ((gnus-article-mime-handle-alist-1
4713 gnus-article-mime-handle-alist))
4714 (gnus-set-mode-line 'article))
4718 (set-window-point (get-buffer-window (current-buffer)) (point))
4719 (gnus-configure-windows 'article)
4720 (gnus-run-hooks 'gnus-article-prepare-hook)
4724 (defun gnus-article-prepare-display ()
4725 "Make the current buffer look like a nice article."
4726 ;; Hooks for getting information from the article.
4727 ;; This hook must be called before being narrowed.
4728 (let ((gnus-article-buffer (current-buffer))
4730 (inhibit-read-only t))
4731 (unless (derived-mode-p 'gnus-article-mode)
4732 (gnus-article-mode))
4733 (setq buffer-read-only nil
4734 gnus-article-wash-types nil
4735 gnus-article-image-alist nil)
4736 (gnus-run-hooks 'gnus-tmp-internal-hook)
4737 (when gnus-display-mime-function
4738 (funcall gnus-display-mime-function))
4739 ;; Add attachment buttons to the header.
4740 (when gnus-mime-display-attachment-buttons-in-header
4741 (gnus-mime-buttonize-attachments-in-header))))
4744 ;;; Gnus Sticky Article Mode
4747 (define-derived-mode gnus-sticky-article-mode gnus-article-mode "StickyArticle"
4748 "Mode for sticky articles."
4749 ;; Release bindings that won't work.
4750 (substitute-key-definition 'gnus-article-read-summary-keys 'undefined
4751 gnus-sticky-article-mode-map)
4752 (substitute-key-definition 'gnus-article-refer-article 'undefined
4753 gnus-sticky-article-mode-map)
4754 (dolist (k '("e" "h" "s" "F" "R"))
4755 (define-key gnus-sticky-article-mode-map k nil))
4756 (define-key gnus-sticky-article-mode-map "k" 'gnus-kill-sticky-article-buffer)
4757 (define-key gnus-sticky-article-mode-map "q" 'bury-buffer)
4758 (define-key gnus-sticky-article-mode-map "\C-hc" 'describe-key-briefly)
4759 (define-key gnus-sticky-article-mode-map "\C-hk" 'describe-key))
4761 (defun gnus-sticky-article (arg)
4762 "Make the current article sticky.
4763 If a prefix ARG is given, ask for a name for this sticky article buffer."
4765 (gnus-summary-show-thread)
4766 (gnus-summary-select-article nil nil 'pseudo)
4767 (let (new-art-buf-name)
4768 (gnus-eval-in-buffer-window gnus-article-buffer
4769 (setq new-art-buf-name
4773 (read-from-minibuffer "Sticky article buffer name: ")
4774 (gnus-with-article-headers
4775 (gnus-article-goto-header "subject")
4776 (setq new-art-buf-name
4777 (buffer-substring-no-properties
4778 (line-beginning-position) (line-end-position)))
4779 (goto-char (point-min))
4780 (gnus-article-goto-header "from")
4781 (setq new-art-buf-name
4783 new-art-buf-name ", "
4784 (buffer-substring-no-properties
4785 (line-beginning-position) (line-end-position))))
4786 (goto-char (point-min))
4787 (gnus-article-goto-header "date")
4788 (setq new-art-buf-name
4790 new-art-buf-name ", "
4791 (buffer-substring-no-properties
4792 (line-beginning-position) (line-end-position))))))
4794 (if (and (gnus-buffer-live-p new-art-buf-name)
4795 (with-current-buffer new-art-buf-name
4796 (derived-mode-p 'gnus-sticky-article-mode)))
4797 (switch-to-buffer new-art-buf-name)
4798 (setq new-art-buf-name (rename-buffer new-art-buf-name t)))
4799 (gnus-sticky-article-mode))
4800 (setq gnus-article-buffer new-art-buf-name))
4801 (gnus-summary-recenter)
4802 (gnus-summary-position-point))
4804 (defun gnus-kill-sticky-article-buffer (&optional buffer)
4805 "Kill the given sticky article BUFFER.
4806 If none is given, assume the current buffer and kill it if it has
4807 `gnus-sticky-article-mode'."
4810 (setq buffer (current-buffer)))
4811 (with-current-buffer buffer
4812 (when (derived-mode-p 'gnus-sticky-article-mode)
4813 (gnus-kill-buffer buffer))))
4815 (defun gnus-kill-sticky-article-buffers (arg)
4816 "Kill all sticky article buffers.
4817 If a prefix ARG is given, ask for confirmation."
4819 (dolist (buf (gnus-buffers))
4820 (with-current-buffer buf
4821 (when (derived-mode-p 'gnus-sticky-article-mode)
4823 (gnus-kill-buffer buf)
4824 (when (yes-or-no-p (concat "Kill buffer " (buffer-name buf) "? "))
4825 (gnus-kill-buffer buf)))))))
4828 ;;; Gnus MIME viewing functions
4831 (defvar gnus-mime-button-line-format "%{%([%p. %d%T]%)%}%e\n"
4832 "Format of the MIME buttons.
4834 Valid specifiers include:
4836 %T MIME type, along with additional info
4837 %n The `name' parameter
4838 %d The description, if any
4839 %l The length of the encoded part
4840 %p The part identifier number
4841 %e Dots if the part isn't displayed
4843 General format specifiers can also be used. See Info node
4844 `(gnus)Formatting Variables'.")
4846 (defvar gnus-mime-button-line-format-alist
4847 '((?t gnus-tmp-type ?s)
4848 (?T gnus-tmp-type-long ?s)
4849 (?n gnus-tmp-name ?s)
4850 (?d gnus-tmp-description ?s)
4852 (?l gnus-tmp-length ?d)
4853 (?e gnus-tmp-dots ?s)))
4855 (defvar gnus-mime-button-commands
4856 '((gnus-article-press-button "\r" "Toggle Display")
4857 (gnus-mime-view-part "v" "View Interactively...")
4858 (gnus-mime-view-part-as-type "t" "View As Type...")
4859 (gnus-mime-view-part-as-charset "C" "View As charset...")
4860 (gnus-mime-save-part "o" "Save...")
4861 (gnus-mime-save-part-and-strip "\C-o" "Save and Strip")
4862 (gnus-mime-replace-part "r" "Replace part")
4863 (gnus-mime-delete-part "d" "Delete part")
4864 (gnus-mime-copy-part "c" "View As Text, In Other Buffer")
4865 (gnus-mime-inline-part "i" "View As Text, In This Buffer")
4866 (gnus-mime-view-part-internally "E" "View Internally") ;; Why `E'?
4867 (gnus-mime-view-part-externally "e" "View Externally")
4868 (gnus-mime-print-part "p" "Print")
4869 (gnus-mime-pipe-part "|" "Pipe To Command...")
4870 (gnus-mime-action-on-part "." "Take action on the part...")))
4872 (defun gnus-article-mime-part-status ()
4873 (if gnus-article-mime-handle-alist-1
4874 (if (eq 1 (length gnus-article-mime-handle-alist-1))
4876 (format " (%d parts)" (length gnus-article-mime-handle-alist-1)))
4879 (defvar gnus-mime-button-map
4880 (let ((map (make-sparse-keymap)))
4881 (define-key map gnus-mouse-2 'gnus-article-push-button)
4882 (define-key map gnus-down-mouse-3 'gnus-mime-button-menu)
4883 (dolist (c gnus-mime-button-commands)
4884 (define-key map (cadr c) (car c)))
4888 gnus-mime-button-menu gnus-mime-button-map "MIME button menu."
4890 ,@(mapcar (lambda (c)
4891 (vector (caddr c) (car c) :active t))
4892 gnus-mime-button-commands)))
4894 (defvar gnus-url-button-commands
4895 '((gnus-article-copy-string "u" "Copy URL to kill ring")))
4897 (defvar gnus-url-button-map
4898 (let ((map (make-sparse-keymap)))
4899 (dolist (c gnus-url-button-commands)
4900 (define-key map (cadr c) (car c)))
4904 gnus-url-button-menu gnus-url-button-map "URL button menu."
4906 ,@(mapcar (lambda (c)
4907 (vector (caddr c) (car c) :active t))
4908 gnus-url-button-commands)))
4910 (defmacro gnus-bind-safe-url-regexp (&rest body)
4911 "Bind `mm-w3m-safe-url-regexp' according to `gnus-safe-html-newsgroups'."
4912 `(let ((mm-w3m-safe-url-regexp
4913 (let ((group (if (and (derived-mode-p 'gnus-article-mode)
4915 gnus-article-current-summary))
4916 (with-current-buffer gnus-article-current-summary
4917 gnus-newsgroup-name)
4918 gnus-newsgroup-name)))
4919 (if (cond ((not group)
4920 ;; Maybe we're in a mml-preview buffer
4921 ;; and no group is selected.
4923 ((stringp gnus-safe-html-newsgroups)
4924 (string-match gnus-safe-html-newsgroups group))
4925 ((consp gnus-safe-html-newsgroups)
4926 (member group gnus-safe-html-newsgroups)))
4928 mm-w3m-safe-url-regexp))))
4931 (defun gnus-mime-button-menu (event prefix)
4932 "Construct a context-sensitive menu of MIME commands."
4933 (interactive "e\nP")
4934 (save-window-excursion
4935 (let ((pos (event-start event)))
4936 (select-window (posn-window pos))
4937 (goto-char (posn-point pos))
4938 (gnus-article-check-buffer)
4939 (popup-menu gnus-mime-button-menu nil prefix))))
4941 (defun gnus-mime-view-all-parts (&optional handles)
4942 "View all the MIME parts."
4944 (with-current-buffer gnus-article-buffer
4945 (let ((handles (or handles gnus-article-mime-handles))
4946 (mail-parse-charset gnus-newsgroup-charset)
4947 (mail-parse-ignored-charsets
4948 (with-current-buffer gnus-summary-buffer
4949 gnus-newsgroup-ignored-charsets)))
4951 (mm-remove-parts handles)
4952 (goto-char (point-min))
4953 (or (search-forward "\n\n") (goto-char (point-max)))
4954 (let ((inhibit-read-only t))
4955 (delete-region (point) (point-max))
4956 (gnus-bind-safe-url-regexp (mm-display-parts handles)))))))
4958 (defun gnus-article-jump-to-part (n)
4959 "Jump to MIME part N."
4961 (let ((parts (with-current-buffer gnus-article-buffer
4962 (length gnus-article-mime-handle-alist))))
4964 (error "No such part"))
4965 (pop-to-buffer gnus-article-buffer)
4967 (setq n (if (= parts 1)
4969 (read-number (format "Jump to part (1..%s): " parts)))))
4970 (unless (and (integerp n) (<= n parts) (>= n 1))
4973 (gnus-message 7 "Invalid part `%s', using %s instead."
4976 (gnus-message 9 "Jumping to part %s." n)
4977 (cond ((>= gnus-auto-select-part 1)
4978 (while (and (<= n parts)
4979 (not (gnus-article-goto-part n)))
4981 ((< gnus-auto-select-part 0)
4982 (while (and (>= n 1)
4983 (not (gnus-article-goto-part n)))
4986 (gnus-article-goto-part n)))))
4988 (defvar gnus-mime-buttonized-part-id nil
4989 "ID of a mime part that should be buttonized.
4990 `gnus-mime-save-part-and-strip' and `gnus-mime-delete-part' bind it.")
4993 (defsubst gnus-article-edit-part (handles &optional current-id)
4994 "Edit an article in order to delete a mime part.
4995 This function is exclusively used by `gnus-mime-save-part-and-strip'
4996 and `gnus-mime-delete-part', and not provided at run-time normally."
4997 (gnus-article-edit-article
4999 (buffer-disable-undo)
5000 (let ((mail-parse-charset (or gnus-article-charset
5001 ',gnus-newsgroup-charset))
5002 (mail-parse-ignored-charsets
5003 (or gnus-article-ignored-charsets
5004 ',gnus-newsgroup-ignored-charsets))
5005 (mbl mml-buffer-list))
5006 (setq mml-buffer-list nil)
5007 ;; A new text must be inserted before deleting existing ones
5008 ;; at the end so as not to move existing markers of which
5009 ;; the insertion type is t.
5013 (goto-char (point-max))
5014 (insert-buffer-substring gnus-original-article-buffer)))
5015 (mime-to-mml ',handles)
5016 (setq gnus-article-mime-handles nil)
5017 (let ((mbl1 mml-buffer-list))
5018 (setq mml-buffer-list mbl)
5019 (set (make-local-variable 'mml-buffer-list) mbl1))
5020 (gnus-make-local-hook 'kill-buffer-hook)
5021 (add-hook 'kill-buffer-hook 'mml-destroy-buffers t t)))
5022 `(lambda (no-highlight)
5023 (let ((mail-parse-charset (or gnus-article-charset
5024 ',gnus-newsgroup-charset))
5025 (message-options message-options)
5026 (message-options-set-recipient)
5027 (mail-parse-ignored-charsets
5028 (or gnus-article-ignored-charsets
5029 ',gnus-newsgroup-ignored-charsets)))
5031 (mml-destroy-buffers)
5032 (remove-hook 'kill-buffer-hook
5033 'mml-destroy-buffers t)
5034 (kill-local-variable 'mml-buffer-list))
5035 (gnus-summary-edit-article-done
5036 ,(or (mail-header-references gnus-current-headers) "")
5037 ,(gnus-group-read-only-p)
5038 ,gnus-summary-buffer no-highlight))
5040 ;; Force buttonizing this part.
5041 (let ((gnus-mime-buttonized-part-id current-id))
5042 (gnus-article-edit-done))
5043 (gnus-configure-windows 'article)
5044 (when (and current-id (integerp gnus-auto-select-part))
5045 (gnus-article-jump-to-part
5046 (min (max (+ current-id gnus-auto-select-part) 1)
5047 (with-current-buffer gnus-article-buffer
5048 (length gnus-article-mime-handle-alist)))))))
5050 (defun gnus-mime-replace-part (file)
5051 "Replace MIME part under point with an external body."
5052 ;; Useful if file has already been saved to disk
5055 (read-file-name "Replace MIME part with file: "
5056 (or mm-default-directory default-directory)
5058 (gnus-mime-save-part-and-strip file))
5060 (defun gnus-mime-save-part-and-strip (&optional file)
5061 "Save the MIME part under point then replace it with an external body.
5062 If FILE is given, use it for the external part."
5064 (gnus-article-check-buffer)
5065 (when (gnus-group-read-only-p)
5066 (error "The current group does not support deleting of parts"))
5067 (when (mm-complicated-handles gnus-article-mime-handles)
5069 The current article has a complicated MIME structure, giving up..."))
5070 (let* ((data (get-text-property (point) 'gnus-data))
5071 (id (get-text-property (point) 'gnus-part))
5073 (handles gnus-article-mime-handles))
5076 (and data (mm-save-part data "Delete MIME part and save to: "))))
5078 (with-current-buffer (mm-handle-buffer data)
5080 (insert "Content-Type: " (mm-handle-media-type data))
5081 (mml-insert-parameter-string (cdr (mm-handle-type data))
5083 ;; Add a filename for the sake of saving the part again.
5084 (mml-insert-parameter
5085 (mail-header-encode-parameter "name" (file-name-nondirectory file)))
5087 (insert "Content-ID: " (message-make-message-id) "\n")
5088 (insert "Content-Transfer-Encoding: binary\n")
5091 (cdr (mm-make-handle nil
5092 `("message/external-body"
5093 (access-type . "LOCAL-FILE")
5095 ;; (set-buffer gnus-summary-buffer)
5096 (gnus-article-edit-part handles id))))
5098 ;; A function like `gnus-summary-save-parts' (`X m', `<MIME> <Extract all
5099 ;; parts...>') but with stripping would be nice.
5101 (defun gnus-mime-delete-part ()
5102 "Delete the MIME part under point.
5103 Replace it with some information about the removed part."
5105 (gnus-article-check-buffer)
5106 (when (gnus-group-read-only-p)
5107 (error "The current group does not support deleting of parts"))
5108 (when (mm-complicated-handles gnus-article-mime-handles)
5110 The current article has a complicated MIME structure, giving up..."))
5111 (when (or gnus-expert-user
5112 (gnus-yes-or-no-p "\
5113 Deleting parts may malfunction or destroy the article; continue? "))
5114 (let* ((data (get-text-property (point) 'gnus-data))
5115 (id (get-text-property (point) 'gnus-part))
5116 (handles gnus-article-mime-handles)
5118 (let ((desc (mm-handle-description data)))
5120 (mail-decode-encoded-word-string desc))))
5121 (filename (or (mm-handle-filename data) "(none)"))
5122 (type (mm-handle-media-type data)))
5124 (error "No MIME part under point"))
5125 (with-current-buffer (mm-handle-buffer data)
5126 (let ((bsize (buffer-size)))
5131 "| The following attachment has been deleted:\n"
5133 "| Type: " type "\n"
5134 "| Filename: " filename "\n"
5135 "| Size (encoded): " (format "%s byte%s\n"
5136 bsize (if (= bsize 1)
5140 (concat "| Description: " description "\n"))
5143 (cdr (mm-make-handle
5144 nil `("text/plain" (charset . gnus-decoded)) nil nil
5146 (format "Deleted attachment (%s bytes)" bsize))))))
5147 ;; (set-buffer gnus-summary-buffer)
5148 (gnus-article-edit-part handles id))))
5150 (defun gnus-mime-save-part ()
5151 "Save the MIME part under point."
5153 (gnus-article-check-buffer)
5154 (let ((data (get-text-property (point) 'gnus-data)))
5156 (mm-save-part data))))
5158 (defun gnus-mime-pipe-part (&optional cmd)
5159 "Pipe the MIME part under point to a process.
5160 Use CMD as the process."
5162 (gnus-article-check-buffer)
5163 (let ((data (get-text-property (point) 'gnus-data)))
5165 (mm-pipe-part data cmd))))
5167 (defun gnus-mime-view-part ()
5168 "Interactively choose a viewing method for the MIME part under point."
5170 (gnus-article-check-buffer)
5171 (let ((data (get-text-property (point) 'gnus-data)))
5173 (setq gnus-article-mime-handles
5175 gnus-article-mime-handles (setq data (copy-sequence data))))
5176 (mm-interactively-view-part data))))
5178 (defun gnus-mime-view-part-as-type-internal ()
5179 (gnus-article-check-buffer)
5180 (let* ((handle (get-text-property (point) 'gnus-data))
5182 ;; Content-Type: foo/bar; name=...
5183 (mail-content-type-get (mm-handle-type handle) 'name)
5184 ;; Content-Disposition: attachment; filename=...
5185 (cdr (assq 'filename (cdr (mm-handle-disposition handle))))))
5186 (def-type (and name (mm-default-file-encoding name))))
5187 (or (and def-type (cons def-type 0))
5189 (equal (mm-handle-media-supertype handle) "text")
5190 '("text/plain" . 0))
5191 '("application/octet-stream" . 0))))
5193 (defun gnus-mime-view-part-as-type (&optional mime-type pred)
5194 "Choose a MIME media type, and view the part as such.
5195 If non-nil, PRED is a predicate to use during completion to limit the
5196 available media-types."
5200 (let ((default (gnus-mime-view-part-as-type-internal)))
5201 (gnus-completing-read
5204 (gnus-remove-if-not pred (mailcap-mime-types))
5205 (mailcap-mime-types))
5208 (gnus-article-check-buffer)
5209 (let ((handle (get-text-property (point) 'gnus-data)))
5211 (when (equal (mm-handle-media-type handle) "message/external-body")
5212 (unless (mm-handle-cache handle)
5213 (mm-extern-cache-contents handle))
5214 (setq handle (mm-handle-cache handle)))
5216 (mm-make-handle (mm-handle-buffer handle)
5217 (cons mime-type (cdr (mm-handle-type handle)))
5218 (mm-handle-encoding handle)
5219 (mm-handle-undisplayer handle)
5220 (mm-handle-disposition handle)
5221 (mm-handle-description handle)
5223 (mm-handle-id handle)))
5224 (setq gnus-article-mime-handles
5225 (mm-merge-handles gnus-article-mime-handles handle))
5226 (when (mm-handle-displayed-p handle)
5227 (mm-remove-part handle))
5228 (gnus-mm-display-part handle))))
5230 (defun gnus-mime-copy-part (&optional handle arg)
5231 "Put the MIME part under point into a new buffer.
5232 If `auto-compression-mode' is enabled, compressed files like .gz and .bz2
5234 (interactive (list nil current-prefix-arg))
5235 (gnus-article-check-buffer)
5237 (setq handle (get-text-property (point) 'gnus-data)))
5239 (let ((filename (mm-handle-filename handle))
5240 contents dont-decode charset coding-system)
5241 (mm-with-unibyte-buffer
5242 (mm-insert-part handle)
5243 (setq contents (or (condition-case nil
5244 (mm-decompress-buffer filename nil 'sig)
5246 (setq dont-decode t)
5249 (setq filename (cond (filename (file-name-nondirectory filename))
5250 (dont-decode "*raw data*")
5255 (unless (setq charset (mail-content-type-get
5256 (mm-handle-type handle) 'charset))
5257 (unless (setq coding-system (mm-with-unibyte-buffer
5259 (mm-find-buffer-file-coding-system)))
5260 (setq charset gnus-newsgroup-charset))))
5262 (setq charset (or (cdr (assq arg
5263 gnus-summary-show-article-charset-alist))
5264 (mm-read-coding-system "Charset: ")))))
5265 (switch-to-buffer (generate-new-buffer filename))
5266 (if (or coding-system
5268 (setq coding-system (mm-charset-to-coding-system
5270 (not (eq coding-system 'ascii))))
5272 (mm-enable-multibyte)
5273 (insert (mm-decode-coding-string contents coding-system))
5274 (setq buffer-file-coding-system
5275 (if (boundp 'last-coding-system-used)
5276 (symbol-value 'last-coding-system-used)
5278 (mm-disable-multibyte)
5280 (setq buffer-file-coding-system mm-binary-coding-system))
5281 ;; We do it this way to make `normal-mode' set the appropriate mode.
5284 (setq buffer-file-name (expand-file-name filename))
5286 (setq buffer-file-name nil))
5287 (goto-char (point-min)))))
5289 (defun gnus-mime-print-part (&optional handle filename)
5290 "Print the MIME part under point."
5291 (interactive (list nil (ps-print-preprint current-prefix-arg)))
5292 (gnus-article-check-buffer)
5293 (let* ((handle (or handle (get-text-property (point) 'gnus-data)))
5294 (contents (and handle (mm-get-part handle)))
5295 (file (mm-make-temp-file (expand-file-name "mm." mm-tmp-directory)))
5296 (printer (mailcap-mime-info (mm-handle-media-type handle) "print")))
5301 (mm-save-part-to-file handle file)
5302 (call-process shell-file-name nil
5303 (generate-new-buffer " *mm*")
5305 shell-command-switch
5307 printer file (mm-handle-type handle))))
5311 (gnus-print-buffer))
5312 (ps-despool filename)))))
5314 (defun gnus-mime-inline-part (&optional handle arg)
5315 "Insert the MIME part under point into the current buffer.
5316 Compressed files like .gz and .bz2 are decompressed."
5317 (interactive (list nil current-prefix-arg))
5318 (gnus-article-check-buffer)
5319 (let* ((inhibit-read-only t)
5321 (btn ;; position where the MIME button exists
5323 (if (eq handle (get-text-property b 'gnus-data))
5326 (or (text-property-any (point) (point-max) 'gnus-data handle)
5327 (text-property-any (point-min) (point) 'gnus-data handle)))
5328 (setq handle (get-text-property b 'gnus-data))
5330 start contents charset coding-system)
5334 (setq start (next-single-property-change btn 'gnus-data
5336 btn (previous-single-property-change start
5339 (if (and (not arg) (mm-handle-undisplayer handle))
5340 (mm-remove-part handle)
5341 (mm-with-unibyte-buffer
5342 (mm-insert-part handle)
5344 (or (mm-decompress-buffer (mm-handle-filename handle) nil t)
5348 (unless (setq charset (mail-content-type-get
5349 (mm-handle-type handle) 'charset))
5350 (unless (setq coding-system
5351 (mm-with-unibyte-buffer
5353 (mm-find-buffer-file-coding-system)))
5354 (setq charset gnus-newsgroup-charset))))
5356 (if (mm-handle-undisplayer handle)
5357 (mm-remove-part handle))
5360 gnus-summary-show-article-charset-alist))
5361 (mm-read-coding-system "Charset: "))))
5362 ((mm-handle-undisplayer handle)
5363 (mm-remove-part handle)))
5366 ;; This is a header button.
5368 (mm-display-inline handle))
5369 ;; Toggle the button appearance between `[button]...' and `[button]'.
5371 (let ((displayed-p (mm-handle-displayed-p handle)))
5372 (gnus-insert-mime-button handle (get-text-property btn 'gnus-part)
5374 (if (featurep 'emacs)
5377 (next-single-property-change (point) 'gnus-data nil (point-max)))
5378 (let* ((end (next-single-property-change (point) 'gnus-data))
5379 (annots (annotations-at (or end (point-max)))))
5380 (delete-region (point)
5382 (if annots (1+ end) end)
5384 (dolist (annot annots)
5385 (set-extent-endpoints annot (point) (point)))))
5386 (setq start (point))
5387 (if (search-backward "\n\n" nil t)
5390 (unless (or displayed-p (eolp))
5391 ;; Add extra newline.
5392 (insert (propertize (buffer-substring (1- start) start)
5393 'gnus-undeletable t))))
5394 ;; We're in the article header.
5396 (dolist (ovl (gnus-overlays-in btn (point)))
5397 (gnus-overlay-put ovl 'gnus-button-attachment-extra t)
5398 (gnus-overlay-put ovl 'face nil))
5400 (message-narrow-to-field)
5401 (let ((gnus-treatment-function-alist
5402 '((gnus-treat-highlight-headers
5403 gnus-article-highlight-headers))))
5404 (gnus-treat-article 'head)))))
5407 (defun gnus-mime-set-charset-parameters (handle charset)
5408 "Set CHARSET to parameters in HANDLE.
5409 CHARSET may either be a string or a symbol."
5410 (unless (stringp charset)
5411 (setq charset (symbol-name charset)))
5412 (if (stringp (car handle))
5413 (dolist (h (cdr handle))
5414 (gnus-mime-set-charset-parameters h charset))
5415 (let* ((type (mm-handle-type (if (equal (mm-handle-media-type handle)
5416 "message/external-body")
5418 (unless (mm-handle-cache handle)
5419 (mm-extern-cache-contents handle))
5420 (mm-handle-cache handle))
5422 (param (assq 'charset (cdr type))))
5424 (setcdr param charset)
5425 (setcdr type (cons (cons 'charset charset) (cdr type)))))))
5427 (defun gnus-mime-view-part-as-charset (&optional handle arg)
5428 "Insert the MIME part under point into the current buffer using the
5430 (interactive (list nil current-prefix-arg))
5431 (gnus-article-check-buffer)
5432 (let ((handle (or handle (get-text-property (point) 'gnus-data)))
5433 (fun (get-text-property (point) 'gnus-callback))
5434 (gnus-newsgroup-ignored-charsets 'gnus-all)
5435 charset form preferred parts)
5442 gnus-summary-show-article-charset-alist))
5443 (mm-read-coding-system "Charset: "))))
5444 (if (mm-handle-undisplayer handle)
5445 (mm-remove-part handle)))
5446 (gnus-mime-set-charset-parameters handle charset)
5447 (when (and (consp (setq form (cdr-safe fun)))
5448 (setq form (ignore-errors
5449 (assq 'gnus-mime-display-alternative form)))
5450 (setq preferred (caddr form))
5452 (when (eq (car preferred) 'quote)
5453 (setq preferred (cadr preferred)))
5454 (not (equal preferred
5455 (get-text-property (point) 'gnus-data))))
5456 (setq parts (get-text-property (point) 'gnus-part))
5457 (setq parts (cdr (assq parts
5458 gnus-article-mime-handle-alist)))
5459 (equal (mm-handle-media-type parts) "multipart/alternative")
5460 (setq parts (reverse (cdr parts))))
5462 (list 'quote (or (cadr (member preferred parts))
5464 (funcall fun handle)))))
5466 (defun gnus-mime-view-part-externally (&optional handle)
5467 "View the MIME part under point with an external viewer."
5469 (gnus-article-check-buffer)
5470 (let* ((handle (or handle (get-text-property (point) 'gnus-data)))
5471 (mm-user-display-methods nil)
5472 (mm-inlined-types nil)
5473 (mail-parse-charset gnus-newsgroup-charset)
5474 (mail-parse-ignored-charsets
5475 (with-current-buffer gnus-summary-buffer
5476 gnus-newsgroup-ignored-charsets))
5477 (type (mm-handle-media-type handle))
5478 (method (mailcap-mime-info type))
5479 (mm-enable-external t))
5480 (if (not (stringp method))
5481 (gnus-mime-view-part-as-type
5482 nil (lambda (type) (stringp (mailcap-mime-info type))))
5484 (mm-display-part handle nil t)))))
5486 (defun gnus-mime-view-part-internally (&optional handle)
5487 "View the MIME part under point with an internal viewer.
5488 If no internal viewer is available, use an external viewer."
5490 (gnus-article-check-buffer)
5491 (let* ((handle (or handle (get-text-property (point) 'gnus-data)))
5492 (mm-inlined-types '(".*"))
5493 (mm-inline-large-images t)
5494 (mail-parse-charset gnus-newsgroup-charset)
5495 (mail-parse-ignored-charsets
5496 (with-current-buffer gnus-summary-buffer
5497 gnus-newsgroup-ignored-charsets))
5498 (inhibit-read-only t))
5499 (if (not (mm-inlinable-p handle))
5500 (gnus-mime-view-part-as-type
5501 nil (lambda (type) (mm-inlinable-p handle type)))
5503 (gnus-bind-safe-url-regexp (mm-display-part handle))))))
5505 (defun gnus-mime-action-on-part (&optional action)
5506 "Do something with the MIME attachment at \(point\)."
5508 (list (gnus-completing-read "Action" (mapcar 'car gnus-mime-action-alist) t)))
5509 (gnus-article-check-buffer)
5510 (let ((action-pair (assoc action gnus-mime-action-alist)))
5512 (funcall (cdr action-pair)))))
5514 (defun gnus-article-part-wrapper (n function &optional no-handle interactive)
5515 "Call FUNCTION on MIME part N.
5516 Unless NO-HANDLE, call FUNCTION with N-th MIME handle as its only argument.
5517 If INTERACTIVE, call FUNCTION interactively."
5519 ;; Check whether the article is displayed.
5520 (unless (and (gnus-buffer-live-p gnus-article-buffer)
5521 (setq window (get-buffer-window gnus-article-buffer t))
5522 (frame-visible-p (setq frame (window-frame window))))
5523 (error "No article is displayed"))
5524 (with-current-buffer gnus-article-buffer
5525 ;; Check whether the article displays the right contents.
5526 (unless (with-current-buffer gnus-summary-buffer
5527 (eq gnus-current-article (gnus-summary-article-number)))
5528 (error "You should select the right article first"))
5530 (setq n (prefix-numeric-value n))
5532 (setq n (or (get-text-property pt 'gnus-part)
5534 (get-text-property (1- pt) 'gnus-part))
5535 (get-text-property (prog2
5541 (or (and (setq pt (previous-single-property-change
5544 (next-single-property-change (point) 'gnus-part)
5548 ;; Check whether the specified part exists.
5549 (when (> n (length gnus-article-mime-handle-alist))
5550 (error "No such part")))
5553 ;; To select the window is needed so that the cursor
5554 ;; might be visible on the MIME button.
5555 (select-window (prog1
5557 (setq window (selected-window))
5558 ;; Article may be displayed in the other frame.
5559 (gnus-select-frame-set-input-focus
5562 (setq frame (selected-frame))))))
5563 (when (gnus-article-goto-part n)
5564 ;; We point the cursor and the arrow at the MIME button
5565 ;; when the `function' prompt the user for something.
5566 (unless (and (pos-visible-in-window-p)
5567 (> (count-lines (point) (window-end))
5568 (/ (1- (window-height)) 3)))
5569 (recenter (/ (1- (window-height)) 3)))
5570 (let ((cursor-in-non-selected-windows t)
5571 (overlay-arrow-string "=>")
5572 (overlay-arrow-position (point-marker)))
5575 ((and no-handle interactive)
5576 (call-interactively function))
5581 function (get-text-property (point) 'gnus-data)))
5584 (get-text-property (point) 'gnus-data))))
5585 (set-marker overlay-arrow-position nil)
5586 (unless gnus-auto-select-part
5587 (gnus-select-frame-set-input-focus frame)
5588 (select-window window))))
5590 (if gnus-inhibit-mime-unbuttonizing
5591 ;; This is the default though the program shouldn't reach here.
5592 (error "No such part")
5593 ;; The part which doesn't have the MIME button is selected.
5594 ;; So, we display all the buttons and redo it.
5595 (let ((gnus-inhibit-mime-unbuttonizing t))
5596 (gnus-summary-show-article)
5597 (gnus-article-part-wrapper n function no-handle))))))
5599 (defun gnus-article-pipe-part (n)
5600 "Pipe MIME part N, which is the numerical prefix."
5602 (gnus-article-part-wrapper n 'mm-pipe-part))
5604 (defun gnus-article-save-part (n)
5605 "Save MIME part N, which is the numerical prefix."
5607 (gnus-article-part-wrapper n 'mm-save-part))
5609 (defun gnus-article-interactively-view-part (n)
5610 "View MIME part N interactively, which is the numerical prefix."
5612 (gnus-article-part-wrapper n 'mm-interactively-view-part))
5614 (defun gnus-article-copy-part (n)
5615 "Copy MIME part N, which is the numerical prefix."
5617 (gnus-article-part-wrapper n 'gnus-mime-copy-part))
5619 (defun gnus-article-view-part-as-charset (n)
5620 "View MIME part N using a specified charset.
5621 N is the numerical prefix."
5623 (gnus-article-part-wrapper n 'gnus-mime-view-part-as-charset))
5625 (defun gnus-article-view-part-externally (n)
5626 "View MIME part N externally, which is the numerical prefix."
5628 (gnus-article-part-wrapper n 'gnus-mime-view-part-externally))
5630 (defun gnus-article-inline-part (n)
5631 "Inline MIME part N, which is the numerical prefix."
5633 (gnus-article-part-wrapper n 'gnus-mime-inline-part))
5635 (defun gnus-article-save-part-and-strip (n)
5636 "Save MIME part N and replace it with an external body.
5637 N is the numerical prefix."
5639 (gnus-article-part-wrapper n 'gnus-mime-save-part-and-strip t))
5641 (defun gnus-article-replace-part (n)
5642 "Replace MIME part N with an external body.
5643 N is the numerical prefix."
5645 (gnus-article-part-wrapper n 'gnus-mime-replace-part t t))
5647 (defun gnus-article-delete-part (n)
5648 "Delete MIME part N and add some information about the removed part.
5649 N is the numerical prefix."
5651 (gnus-article-part-wrapper n 'gnus-mime-delete-part t))
5653 (defun gnus-article-view-part-as-type (n)
5654 "Choose a MIME media type, and view part N as such.
5655 N is the numerical prefix."
5657 (gnus-article-part-wrapper n 'gnus-mime-view-part-as-type t))
5659 (defun gnus-article-mime-match-handle-first (condition)
5662 (dolist (ihandle gnus-article-mime-handle-alist)
5664 ((functionp condition)
5665 (funcall condition (cdr ihandle)))
5666 ((eq condition 'undisplayed)
5667 (not (or (mm-handle-undisplayer (cdr ihandle))
5668 (equal (mm-handle-media-type (cdr ihandle))
5669 "multipart/alternative"))))
5670 ((eq condition 'undisplayed-alternative)
5671 (not (mm-handle-undisplayer (cdr ihandle))))
5673 (gnus-article-goto-part (car ihandle))
5674 (or (not n) (< (car ihandle) n)))
5675 (setq n (car ihandle))))
5679 (defun gnus-article-view-part (&optional n)
5680 "View MIME part N, which is the numerical prefix.
5681 If the part is already shown, hide the part. If N is nil, view
5684 (with-current-buffer gnus-article-buffer
5685 (or (numberp n) (setq n (gnus-article-mime-match-handle-first
5686 gnus-article-mime-match-handle-function)))
5687 (when (> n (length gnus-article-mime-handle-alist))
5688 (error "No such part"))
5689 (let ((handle (cdr (assq n gnus-article-mime-handle-alist))))
5690 (when (gnus-article-goto-part n)
5691 (if (equal (car handle) "multipart/alternative")
5693 (beginning-of-line) ;; Make it toggle subparts
5694 (gnus-article-press-button))
5695 (when (eq (gnus-mm-display-part handle) 'internal)
5696 (gnus-set-window-start)))))))
5698 (defsubst gnus-article-mime-total-parts ()
5699 (if (bufferp (car gnus-article-mime-handles))
5701 (1- (length gnus-article-mime-handles))))
5703 (defun gnus-mm-display-part (handle)
5704 "Display HANDLE and fix MIME button."
5705 (let ((id (get-text-property (point) 'gnus-part))
5707 (inhibit-read-only t)
5708 (window (selected-window))
5709 (mail-parse-charset gnus-newsgroup-charset)
5710 (mail-parse-ignored-charsets
5711 (if (gnus-buffer-live-p gnus-summary-buffer)
5712 (with-current-buffer gnus-summary-buffer
5713 gnus-newsgroup-ignored-charsets)
5718 (let ((win (gnus-get-buffer-window (current-buffer) t)))
5722 (setq start (next-single-property-change point 'gnus-data
5724 point (previous-single-property-change start 'gnus-data))
5725 (if (mm-handle-displayed-p handle)
5726 ;; This will remove the part.
5727 (setq retval (mm-display-part handle))
5728 (let ((part (or (and (mm-inlinable-p handle)
5729 (mm-inlined-p handle)
5732 (gnus-bind-safe-url-regexp
5733 (setq retval (mm-display-part handle)))
5734 (unless (zerop (buffer-size))
5735 (buffer-string))))))
5738 ;; This is a header button.
5740 (cond ((stringp part)
5742 (narrow-to-region (point)
5745 (unless (bolp) (insert "\n"))
5747 (gnus-treat-article nil id
5748 (gnus-article-mime-total-parts)
5749 (mm-handle-media-type handle))
5750 (mm-handle-set-undisplayer
5753 (let ((inhibit-read-only t))
5754 (delete-region ,(copy-marker (point-min) t)
5755 ,(point-max-marker)))))))
5757 (mm-display-inline handle))))))
5759 ;; Toggle the button appearance between `[button]...' and `[button]'.
5760 (let ((displayed-p (mm-handle-displayed-p handle)))
5761 (gnus-insert-mime-button handle id (list displayed-p))
5762 (if (featurep 'emacs)
5765 (next-single-property-change (point) 'gnus-data nil (point-max)))
5766 (let* ((end (next-single-property-change (point) 'gnus-data))
5767 (annots (annotations-at (or end (point-max)))))
5768 (delete-region (point)
5770 (if annots (1+ end) end)
5772 (dolist (annot annots)
5773 (set-extent-endpoints annot (point) (point)))))
5774 (setq start (point))
5775 (if (search-backward "\n\n" nil t)
5778 (unless (or displayed-p (eolp))
5779 ;; Add extra newline.
5780 (insert (propertize (buffer-substring (1- start) start)
5781 'gnus-undeletable t))))
5782 ;; We're in the article header.
5784 (dolist (ovl (gnus-overlays-in point (point)))
5785 (gnus-overlay-put ovl 'gnus-button-attachment-extra t)
5786 (gnus-overlay-put ovl 'face nil))
5788 (message-narrow-to-field)
5789 (let ((gnus-treatment-function-alist
5790 '((gnus-treat-highlight-headers
5791 gnus-article-highlight-headers))))
5792 (gnus-treat-article 'head)))))
5794 (if (window-live-p window)
5795 (select-window window)))
5798 (defun gnus-article-goto-part (n)
5799 "Go to MIME part N."
5800 (when gnus-break-pages
5804 (let ((start (or (text-property-any (point) (point-max) 'gnus-part n)
5805 ;; There may be header buttons.
5806 (text-property-any (point-min) (point) 'gnus-part n)))
5807 part handle end next handles)
5810 (if (setq handle (get-text-property start 'gnus-data))
5812 ;; Go to the displayed subpart, assuming this is
5813 ;; multipart/alternative.
5816 (while (and (not handle)
5819 (setq next (text-property-not-all part end
5822 handle (get-text-property part 'gnus-data))
5823 (push (cons handle part) handles)
5824 (unless (mm-handle-displayed-p handle)
5826 part (text-property-any part end 'gnus-data nil))))
5828 ;; No subpart is displayed, so we find preferred one.
5830 (cdr (assq (mm-preferred-alternative
5831 (nreverse (mapcar 'car handles)))
5834 (goto-char (1+ part))
5836 (when gnus-break-pages
5837 (gnus-narrow-to-page))))
5839 (defun gnus-insert-mime-button (handle gnus-tmp-id &optional displayed)
5840 (let ((gnus-tmp-name
5841 (or (mm-handle-filename handle)
5842 (mail-content-type-get (mm-handle-type handle) 'url)
5844 (gnus-tmp-type (mm-handle-media-type handle))
5845 (gnus-tmp-description (or (mm-handle-description handle) ""))
5847 (if (if displayed (car displayed)
5848 (mm-handle-displayed-p handle))
5850 (gnus-tmp-length (with-current-buffer (mm-handle-buffer handle)
5852 gnus-tmp-type-long b e)
5853 (when (string-match ".*/" gnus-tmp-name)
5854 (setq gnus-tmp-name (replace-match "" t t gnus-tmp-name)))
5855 (setq gnus-tmp-type-long (concat gnus-tmp-type
5856 (and (not (equal gnus-tmp-name ""))
5857 (concat "; " gnus-tmp-name))))
5858 (unless (equal gnus-tmp-description "")
5859 (setq gnus-tmp-type-long (concat " --- " gnus-tmp-type-long)))
5862 gnus-mime-button-line-format gnus-mime-button-line-format-alist
5863 `(keymap ,gnus-mime-button-map
5864 gnus-callback gnus-mm-display-part
5865 gnus-part ,gnus-tmp-id
5866 article-type annotation
5870 ;; Exclude a newline.
5873 (when gnus-article-button-face
5874 (gnus-overlay-put (gnus-make-overlay b e nil t)
5875 'face gnus-article-button-face))
5876 (widget-convert-button
5879 :action 'gnus-widget-press-button
5880 :button-keymap gnus-mime-button-map
5883 ;; Needed to properly clear the message due to a bug in
5884 ;; wid-edit (XEmacs only).
5885 (if (boundp 'help-echo-owns-message)
5886 (setq help-echo-owns-message t))
5888 "%S: %s the MIME part; %S: more options"
5889 (aref gnus-mouse-2 0)
5890 (if (mm-handle-displayed-p (widget-get widget :mime-handle))
5892 (aref gnus-down-mouse-3 0))))))
5894 (defun gnus-widget-press-button (elems el)
5895 (goto-char (widget-get elems :from))
5896 (gnus-article-press-button))
5898 (defvar gnus-displaying-mime nil)
5900 (defun gnus-display-mime (&optional ihandles)
5901 "Display the MIME parts."
5903 (save-selected-window
5904 (let ((window (get-buffer-window gnus-article-buffer))
5907 (select-window window)
5908 ;; We have to do this since selecting the window
5909 ;; may change the point. So we set the window point.
5910 (set-window-point window point)))
5911 (let ((handles ihandles)
5912 (inhibit-read-only t)
5915 ((setq handles (mm-dissect-buffer nil gnus-article-loose-mime))
5916 (when gnus-article-emulate-mime
5917 (mm-uu-dissect-text-parts handles)))
5918 (gnus-article-emulate-mime
5919 (setq handles (mm-uu-dissect))))
5920 (when (and (not ihandles)
5921 (not gnus-displaying-mime))
5922 ;; Top-level call; we clean up.
5923 (when gnus-article-mime-handles
5924 (mm-destroy-parts gnus-article-mime-handles)
5925 (setq gnus-article-mime-handle-alist nil));; A trick.
5926 (setq gnus-article-mime-handles handles)
5927 ;; We allow users to glean info from the handles.
5928 (when gnus-article-mime-part-function
5929 (gnus-mime-part-function handles)))
5931 (or (not (stringp (car handles)))
5934 (when (and (not ihandles)
5935 (not gnus-displaying-mime))
5936 ;; Clean up for mime parts.
5938 (delete-region (point) (point-max)))
5939 (let ((gnus-displaying-mime t))
5940 (gnus-mime-display-part handles)))
5943 (narrow-to-region (point) (point-max))
5944 (gnus-treat-article nil 1 1 "text/plain")
5947 ;; Highlight the headers.
5951 (narrow-to-region (point-min) (point))
5952 (gnus-article-save-original-date
5953 (gnus-treat-article 'head)))))))
5954 ;; Cope with broken MIME messages.
5955 (goto-char (point-max))
5959 (defcustom gnus-mime-display-multipart-as-mixed nil
5960 "Display \"multipart\" parts as \"multipart/mixed\".
5962 If t, it overrides nil values of
5963 `gnus-mime-display-multipart-alternative-as-mixed' and
5964 `gnus-mime-display-multipart-related-as-mixed'."
5965 :group 'gnus-article-mime
5968 (defcustom gnus-mime-display-multipart-alternative-as-mixed nil
5969 "Display \"multipart/alternative\" parts as \"multipart/mixed\"."
5971 :group 'gnus-article-mime
5974 (defcustom gnus-mime-display-multipart-related-as-mixed nil
5975 "Display \"multipart/related\" parts as \"multipart/mixed\".
5977 If displaying \"text/html\" is discouraged \(see
5978 `mm-discouraged-alternatives'\) images or other material inside a
5979 \"multipart/related\" part might be overlooked when this variable is nil."
5981 :group 'gnus-article-mime
5984 (defcustom gnus-mime-display-attachment-buttons-in-header t
5985 "Add attachment buttons in the end of the header of an article.
5986 Since MIME attachments tend to be put at the end of an article, we may
5987 overlook them if there is a huge body. This option offers you a copy
5988 of all non-inlinable MIME parts as buttons shown in front of an article.
5989 If nil, don't show those extra buttons."
5991 :group 'gnus-article-mime
5994 (defun gnus-mime-display-part (handle)
5996 ;; Maybe a broken MIME message.
5999 ((not (stringp (car handle)))
6000 (gnus-mime-display-single handle))
6001 ;; User-defined multipart
6002 ((cdr (assoc (car handle) gnus-mime-multipart-functions))
6003 (funcall (cdr (assoc (car handle) gnus-mime-multipart-functions))
6005 ;; multipart/alternative
6006 ((and (equal (car handle) "multipart/alternative")
6007 (not (or gnus-mime-display-multipart-as-mixed
6008 gnus-mime-display-multipart-alternative-as-mixed)))
6009 (let ((id (1+ (length gnus-article-mime-handle-alist))))
6010 (push (cons id handle) gnus-article-mime-handle-alist)
6011 (gnus-mime-display-alternative (cdr handle) nil nil id)))
6012 ;; multipart/related
6013 ((and (equal (car handle) "multipart/related")
6014 (not (or gnus-mime-display-multipart-as-mixed
6015 gnus-mime-display-multipart-related-as-mixed)))
6016 (gnus-mime-display-part (cadr handle)))
6017 ((equal (car handle) "multipart/signed")
6018 (gnus-add-wash-type 'signed)
6019 (gnus-mime-display-security handle))
6020 ((equal (car handle) "multipart/encrypted")
6021 (gnus-add-wash-type 'encrypted)
6022 (gnus-mime-display-security handle))
6023 ;; Other multiparts are handled like multipart/mixed.
6025 (gnus-mime-display-mixed (cdr handle)))))
6027 (defun gnus-mime-part-function (handles)
6028 (if (stringp (car handles))
6029 (mapcar 'gnus-mime-part-function (cdr handles))
6030 (funcall gnus-article-mime-part-function handles)))
6032 (defun gnus-mime-display-mixed (handles)
6033 (mapcar 'gnus-mime-display-part handles))
6035 (defun gnus-mime-display-single (handle)
6036 (let ((type (mm-handle-media-type handle))
6037 (ignored gnus-ignored-mime-types)
6043 (when (string-match (pop ignored) type)
6044 (throw 'ignored nil)))
6045 (if (and (not (and (if (gnus-buffer-live-p gnus-summary-buffer)
6046 (with-current-buffer gnus-summary-buffer
6047 gnus-inhibit-images)
6048 gnus-inhibit-images)
6049 (string-match "\\`image/" type)))
6050 (setq not-attachment
6051 (and (not (mm-inline-override-p handle))
6052 (or (not (mm-handle-disposition handle))
6053 (equal (car (mm-handle-disposition handle))
6055 (mm-attachment-override-p handle))))
6056 (mm-automatic-display-p handle)
6058 (mm-inlinable-p handle)
6059 (mm-inlined-p handle))
6060 (mm-automatic-external-display-p type)))
6062 (when (equal (mm-handle-media-supertype handle) "text")
6064 (let ((id (car (rassq handle gnus-article-mime-handle-alist)))
6067 (setq id (1+ (length gnus-article-mime-handle-alist)))
6068 (push (cons id handle) gnus-article-mime-handle-alist))
6070 (equal (mm-handle-media-supertype handle) "message"))
6073 (cond ((not (bolp)) 2)
6074 ((or (bobp) (eq (char-before (1- (point))) ?\n)) 0)
6076 (when (or (not display)
6077 (not (gnus-unbuttonized-mime-type-p type))
6078 (eq id gnus-mime-buttonized-part-id))
6079 (gnus-insert-mime-button
6080 handle id (list (or display (and not-attachment text)))))
6084 (let ((mail-parse-charset gnus-newsgroup-charset)
6085 (mail-parse-ignored-charsets
6086 (save-excursion (condition-case ()
6087 (set-buffer gnus-summary-buffer)
6089 gnus-newsgroup-ignored-charsets)))
6090 (gnus-bind-safe-url-regexp (mm-display-part handle t))))
6091 ((and text not-attachment)
6092 (mm-display-inline handle)))
6093 (goto-char (point-max))
6094 (if (string-match "\\`image/" type)
6095 (gnus-article-insert-newline)
6097 (= (skip-chars-backward "\n") -1)
6099 (gnus-article-insert-newline)
6100 (put-text-property (point) (point-max) 'gnus-undeletable t))
6101 (goto-char (point-max)))
6105 (narrow-to-region beg (point))
6106 (if (eq handle gnus-article-mime-handles)
6107 ;; The format=flowed case.
6108 (gnus-treat-article nil 1 1 (mm-handle-media-type handle))
6109 ;; Don't count signature parts that are never displayed.
6110 ;; The part number should be re-calculated supposing this
6111 ;; might be a message/rfc822 part.
6113 (dolist (part gnus-article-mime-handles)
6114 (unless (or (stringp part)
6115 (equal (car (mm-handle-type part))
6116 "application/pgp-signature"))
6117 (push part handles)))
6119 nil (length (memq handle handles)) (length handles)
6120 (mm-handle-media-type handle)))))))))))
6122 (defun gnus-unbuttonized-mime-type-p (type)
6123 "Say whether TYPE is to be unbuttonized."
6124 (unless gnus-inhibit-mime-unbuttonizing
6126 (let ((types gnus-unbuttonized-mime-types))
6128 (when (string-match (pop types) type)
6129 (throw 'found t)))))
6131 (let ((types gnus-buttonized-mime-types))
6133 (when (string-match (pop types) type)
6134 (throw 'found t)))))))))
6136 (defun gnus-article-insert-newline ()
6137 "Insert a newline, but mark it as undeletable."
6138 (gnus-put-text-property
6139 (point) (progn (insert "\n") (point)) 'gnus-undeletable t))
6141 (defun gnus-mime-display-alternative (handles &optional preferred ibegend id)
6142 (let* ((preferred (or preferred (mm-preferred-alternative handles)))
6145 handle (inhibit-read-only t) from props begend not-pref)
6146 (save-window-excursion
6149 (narrow-to-region (car ibegend)
6152 (goto-char (car ibegend))
6155 (delete-region (point-min) (point-max))
6156 (mm-remove-parts handles))
6157 (setq begend (list (point-marker)))
6159 (unless (setq not-pref (cadr (member preferred ihandles)))
6160 (setq not-pref (car ihandles)))
6163 (not (gnus-unbuttonized-mime-type-p
6164 "multipart/alternative")))
6165 (gnus-add-text-properties
6168 (insert (format "%d. " id))
6172 (unless ,(not ibegend)
6173 (setq gnus-article-mime-handle-alist
6174 ',gnus-article-mime-handle-alist))
6175 (gnus-mime-display-alternative
6176 ',ihandles ',not-pref ',begend ,id))
6177 keymap ,gnus-mime-button-map
6178 ,gnus-mouse-face-prop ,gnus-article-mouse-face
6179 face ,gnus-article-button-face
6181 article-type multipart
6183 (widget-convert-button 'link from (point)
6184 :action 'gnus-widget-press-button
6185 :button-keymap gnus-widget-button-keymap)
6187 (while (setq handle (pop handles))
6188 (gnus-add-text-properties
6191 (insert (format "(%c) %-18s"
6192 (if (equal handle preferred) ?* ? )
6193 (mm-handle-media-type handle)))
6197 (unless ,(not ibegend)
6198 (setq gnus-article-mime-handle-alist
6199 ',gnus-article-mime-handle-alist))
6200 (gnus-mime-display-alternative
6201 ',ihandles ',handle ',begend ,id))
6202 keymap ,gnus-mime-button-map
6203 ,gnus-mouse-face-prop ,gnus-article-mouse-face
6204 face ,gnus-article-button-face
6208 (widget-convert-button 'link from (point)
6209 :action 'gnus-widget-press-button
6210 :button-keymap gnus-widget-button-keymap)
6214 (if (stringp (car preferred))
6215 (gnus-display-mime preferred)
6216 (let ((mail-parse-charset gnus-newsgroup-charset)
6217 (mail-parse-ignored-charsets
6218 (with-current-buffer gnus-summary-buffer
6219 gnus-newsgroup-ignored-charsets)))
6220 (gnus-bind-safe-url-regexp (mm-display-part preferred))
6224 (narrow-to-region (car begend) (point-max))
6226 nil (length gnus-article-mime-handle-alist)
6227 (gnus-article-mime-total-parts)
6228 (mm-handle-media-type preferred))))))
6229 (goto-char (point-max))
6230 (setcdr begend (point-marker)))))
6233 ;; Redraw attachment buttons in the header.
6234 (when gnus-mime-display-attachment-buttons-in-header
6235 (gnus-mime-buttonize-attachments-in-header)))
6237 (defconst gnus-article-wash-status-strings
6238 (let ((alist '((cite "c" "Possible hidden citation text"
6239 " " "All citation text visible")
6240 (headers "h" "Hidden headers"
6241 " " "All headers visible.")
6242 (pgp "p" "Encrypted or signed message status hidden"
6243 " " "No hidden encryption nor digital signature status")
6244 (signature "s" "Signature has been hidden"
6245 " " "Signature is visible")
6246 (overstrike "o" "Overstrike (^H) characters applied"
6247 " " "No overstrike characters applied")
6248 (emphasis "e" "/*_Emphasis_*/ characters applied"
6249 " " "No /*_emphasis_*/ characters applied")))
6251 (dolist (entry alist result)
6252 (let ((key (nth 0 entry))
6253 (on (copy-sequence (nth 1 entry)))
6254 (on-help (nth 2 entry))
6255 (off (copy-sequence (nth 3 entry)))
6256 (off-help (nth 4 entry)))
6257 (put-text-property 0 1 'help-echo on-help on)
6258 (put-text-property 0 1 'help-echo off-help off)
6259 (push (list key on off) result))))
6260 "Alist of strings describing wash status in the mode line.
6261 Each entry has the form (KEY ON OF), where the KEY is a symbol
6262 representing the particular washing function, ON is the string to use
6263 in the article mode line when the washing function is active, and OFF
6264 is the string to use when it is inactive.")
6266 (defun gnus-article-wash-status-entry (key value)
6267 (let ((entry (assoc key gnus-article-wash-status-strings)))
6268 (if value (nth 1 entry) (nth 2 entry))))
6270 (defun gnus-article-wash-status ()
6271 "Return a string which display status of article washing."
6272 (with-current-buffer gnus-article-buffer
6273 (let ((cite (memq 'cite gnus-article-wash-types))
6274 (headers (memq 'headers gnus-article-wash-types))
6275 (boring (memq 'boring-headers gnus-article-wash-types))
6276 (pgp (memq 'pgp gnus-article-wash-types))
6277 (pem (memq 'pem gnus-article-wash-types))
6278 (signed (memq 'signed gnus-article-wash-types))
6279 (encrypted (memq 'encrypted gnus-article-wash-types))
6280 (signature (memq 'signature gnus-article-wash-types))
6281 (overstrike (memq 'overstrike gnus-article-wash-types))
6282 (emphasis (memq 'emphasis gnus-article-wash-types)))
6284 (gnus-article-wash-status-entry 'cite cite)
6285 (gnus-article-wash-status-entry 'headers (or headers boring))
6286 (gnus-article-wash-status-entry 'pgp (or pgp pem signed encrypted))
6287 (gnus-article-wash-status-entry 'signature signature)
6288 (gnus-article-wash-status-entry 'overstrike overstrike)
6289 (gnus-article-wash-status-entry 'emphasis emphasis)))))
6291 (defun gnus-add-wash-type (type)
6292 "Add a washing of TYPE to the current status."
6293 (add-to-list 'gnus-article-wash-types type))
6295 (defun gnus-delete-wash-type (type)
6296 "Add a washing of TYPE to the current status."
6297 (setq gnus-article-wash-types (delq type gnus-article-wash-types)))
6299 (defun gnus-add-image (category image)
6300 "Add IMAGE of CATEGORY to the list of displayed images."
6301 (let ((entry (assq category gnus-article-image-alist)))
6303 (setq entry (list category))
6304 (push entry gnus-article-image-alist))
6305 (nconc entry (list image))))
6307 (defun gnus-delete-images (category)
6308 "Delete all images in CATEGORY."
6309 (let ((entry (assq category gnus-article-image-alist)))
6310 (dolist (image (cdr entry))
6311 (gnus-remove-image image category))
6312 (setq gnus-article-image-alist (delq entry gnus-article-image-alist))
6313 (gnus-delete-wash-type category)))
6315 (defalias 'gnus-article-hide-headers-if-wanted 'gnus-article-maybe-hide-headers)
6317 (defun gnus-article-maybe-hide-headers ()
6318 "Hide unwanted headers if `gnus-have-all-headers' is nil.
6319 Provided for backwards compatibility."
6320 (when (and (or (not (gnus-buffer-live-p gnus-summary-buffer))
6321 (not (with-current-buffer gnus-summary-buffer
6322 gnus-have-all-headers)))
6323 (not gnus-inhibit-hiding))
6324 (gnus-article-hide-headers)))
6326 (declare-function shr-put-image "shr" (data alt &optional flags))
6328 (defun gnus-shr-put-image (data alt &optional flags)
6329 "Put image DATA with a string ALT. Enable image to be deleted."
6330 (let ((image (if flags
6331 (shr-put-image data (propertize (or alt "*")
6332 'gnus-image-category 'shr)
6334 ;; Old `shr-put-image' doesn't take the optional `flags'
6336 (shr-put-image data (propertize (or alt "*")
6337 'gnus-image-category 'shr)))))
6339 (gnus-add-image 'shr image))))
6341 (defun gnus-mime-buttonize-attachments-in-header (&optional interactive)
6342 "Show attachments as buttons in the end of the header of an article.
6343 This function toggles the display when called interactively. Note that
6344 buttons to be added to the header are only the ones that aren't inlined
6345 in the body. Use `gnus-header-face-alist' to highlight buttons."
6346 (interactive (list t))
6347 (gnus-with-article-buffer
6349 ;; Function that returns a flattened version of
6350 ;; `gnus-article-mime-handle-alist'.
6352 (&optional alist id all)
6354 (let ((i 1) newid flat)
6355 (dolist (handle alist flat)
6356 (setq newid (append id (list i))
6358 (if (stringp (car handle))
6359 (setq flat (nconc flat (flattened-alist (cdr handle)
6361 (delq (rassq handle all) all)
6362 (setq flat (nconc flat (list (cons newid handle)))))))
6363 (let ((flat (list nil)))
6364 ;; Assume that elements of `gnus-article-mime-handle-alist'
6365 ;; are in the decreasing order, but unnumbered subsidiaries
6366 ;; in each element are in the increasing order.
6367 (dolist (handle (reverse gnus-article-mime-handle-alist))
6368 (if (stringp (cadr handle))
6369 (setq flat (nconc flat (flattened-alist (cddr handle)
6372 (delq (rassq (cdr handle) flat) flat)
6373 (setq flat (nconc flat (list (cons (list (car handle))
6375 (setq flat (cdr flat))
6376 (mapc (lambda (handle)
6378 ;; This is a hidden (i.e. unnumbered) handle.
6381 (1+ (caar gnus-article-mime-handle-alist)))
6382 (push handle gnus-article-mime-handle-alist))
6383 (setcar handle (caar handle))))
6386 (let ((case-fold-search t) buttons handle type st)
6390 (article-narrow-to-head)
6391 ;; Header buttons exist?
6392 (while (and (not buttons)
6393 (re-search-forward "^attachments?:[\n ]+" nil t))
6394 (when (get-char-property (match-end 0)
6395 'gnus-button-attachment-extra)
6396 (setq buttons (match-beginning 0))))
6399 ;; Delete header buttons.
6400 (delete-region buttons (if (re-search-forward "^[^ ]" nil t)
6403 (unless (and interactive buttons)
6406 (dolist (button (flattened-alist))
6407 (setq handle (cdr button)
6408 type (mm-handle-media-type handle))
6409 (when (or (and (if (gnus-buffer-live-p gnus-summary-buffer)
6410 (with-current-buffer gnus-summary-buffer
6411 gnus-inhibit-images)
6412 gnus-inhibit-images)
6413 (string-match "\\`image/" type))
6414 (mm-inline-override-p handle)
6415 (and (mm-handle-disposition handle)
6416 (not (equal (car (mm-handle-disposition handle))
6418 (not (mm-attachment-override-p handle)))
6419 (not (mm-automatic-display-p handle))
6420 (not (or (and (mm-inlinable-p handle)
6421 (mm-inlined-p handle))
6422 (mm-automatic-external-display-p type))))
6423 (push button buttons)))
6425 ;; Add header buttons.
6428 (narrow-to-region (point) (point))
6429 (insert "Attachment" (if (cdr buttons) "s" "") ":")
6430 (dolist (button (nreverse buttons))
6433 (mm-handle-set-undisplayer
6434 (setq handle (copy-sequence (cdr button))) nil)
6435 (gnus-insert-mime-button handle (car button))
6436 (skip-chars-backward "\t\n ")
6437 (delete-region (point) (point-max))
6438 (when (> (current-column) (window-width))
6443 (dolist (ovl (gnus-overlays-in (point-min) (point)))
6444 (gnus-overlay-put ovl 'gnus-button-attachment-extra t)
6445 (gnus-overlay-put ovl 'face nil))
6446 (let ((gnus-treatment-function-alist
6447 '((gnus-treat-highlight-headers
6448 gnus-article-highlight-headers))))
6449 (gnus-treat-article 'head))))))))))
6453 (defun gnus-output-to-file (file-name)
6454 "Append the current article to a file named FILE-NAME.
6455 If `gnus-article-save-coding-system' is non-nil, it is used to encode
6456 text and used as the value of the coding cookie which is added to the
6457 top of a file. Otherwise, this function saves a raw article without
6459 (let* ((artbuf (current-buffer))
6460 (file-name-coding-system nnmail-pathname-coding-system)
6461 (coding gnus-article-save-coding-system)
6462 (coding-system-for-read (if coding
6463 nil ;; Rely on the coding cookie.
6464 mm-text-coding-system))
6465 (coding-system-for-write (or coding
6466 mm-text-coding-system-for-write
6467 mm-text-coding-system))
6468 (exists (file-exists-p file-name)))
6471 (insert-file-contents file-name)
6472 (goto-char (point-min))
6473 ;; Remove the existing coding cookie.
6474 (when (looking-at "X-Gnus-Coding-System: .+\n\n")
6475 (delete-region (match-beginning 0) (match-end 0))))
6476 (goto-char (point-max))
6477 (insert-buffer-substring artbuf)
6478 ;; Append newline at end of the buffer as separator, and then
6480 (goto-char (point-max))
6483 ;; If the coding system is not suitable to encode the text,
6484 ;; ask a user for a proper one.
6485 (when (fboundp 'select-safe-coding-system)
6486 (setq coding (coding-system-base
6487 (save-window-excursion
6488 (select-safe-coding-system (point-min) (point-max)
6490 (setq coding-system-for-write
6491 (or (cdr (assq coding '((mule-utf-8 . utf-8))))
6493 (goto-char (point-min))
6494 ;; Add the coding cookie.
6495 (insert (format "X-Gnus-Coding-System: -*- coding: %s; -*-\n\n"
6496 coding-system-for-write)))
6499 (write-region (point-min) (point-max) file-name nil 'no-message)
6500 (message "Appended to %s" file-name))
6501 (write-region (point-min) (point-max) file-name))))
6504 (defun gnus-narrow-to-page (&optional arg)
6505 "Narrow the article buffer to a page.
6506 If given a numerical ARG, move forward ARG pages."
6508 (setq arg (if arg (prefix-numeric-value arg) 0))
6509 (with-current-buffer gnus-article-buffer
6511 ;; Remove any old next/prev buttons.
6512 (when (gnus-visual-p 'page-marker)
6513 (let ((inhibit-read-only t))
6514 (gnus-remove-text-with-property 'gnus-prev)
6515 (gnus-remove-text-with-property 'gnus-next)))
6517 (when (save-excursion
6519 (if (re-search-backward page-delimiter nil 'move (abs arg))
6521 (setq nd (match-beginning 0)
6523 (when (re-search-backward page-delimiter nil t)
6524 (setq st (match-end 0))))
6525 (when (re-search-forward page-delimiter nil t)
6526 (setq nd (match-beginning 0)
6529 (if (re-search-forward page-delimiter nil 'move arg)
6531 (setq st (match-end 0)
6533 (when (re-search-forward page-delimiter nil t)
6534 (setq nd (match-beginning 0))))
6535 (when (re-search-backward page-delimiter nil t)
6536 (setq st (match-end 0)
6539 (when (re-search-backward page-delimiter nil t)
6540 (goto-char (setq st (match-end 0))))
6541 (when (re-search-forward page-delimiter nil t)
6542 (setq nd (match-beginning 0)))
6544 (setq gnus-page-broken t)
6545 (when pt (goto-char pt))
6546 (narrow-to-region (or st (point-min)) (or nd (point-max)))
6547 (when (gnus-visual-p 'page-marker)
6551 (gnus-insert-next-page-button))
6554 (gnus-insert-prev-page-button))))))))
6556 ;; Article mode commands
6558 (defun gnus-article-goto-next-page ()
6559 "Show the next page of the article."
6561 (when (gnus-article-next-page)
6562 (goto-char (point-min))
6563 (gnus-article-read-summary-keys nil (gnus-character-to-event ?n))))
6566 (defun gnus-article-goto-prev-page ()
6567 "Show the previous page of the article."
6569 (if (save-restriction (widen) (bobp)) ;; Real beginning-of-buffer?
6570 (gnus-article-read-summary-keys nil (gnus-character-to-event ?p))
6571 (gnus-article-prev-page nil)))
6573 ;; This is cleaner but currently breaks `gnus-pick-mode':
6575 ;; (defun gnus-article-goto-next-page ()
6576 ;; "Show the next page of the article."
6578 ;; (gnus-eval-in-buffer-window gnus-summary-buffer
6579 ;; (gnus-summary-next-page)))
6581 ;; (defun gnus-article-goto-prev-page ()
6582 ;; "Show the next page of the article."
6584 ;; (gnus-eval-in-buffer-window gnus-summary-buffer
6585 ;; (gnus-summary-prev-page)))
6587 (defun gnus-article-next-page (&optional lines)
6588 "Show the next page of the current article.
6589 If end of article, return non-nil. Otherwise return nil.
6590 Argument LINES specifies lines to be scrolled up."
6592 (move-to-window-line (if (featurep 'xemacs) -1 (- -1 scroll-margin)))
6593 (if (and (not (and gnus-article-over-scroll
6594 (> (count-lines (window-start) (point-max))
6595 (if (featurep 'xemacs)
6596 (or lines (1- (window-height)))
6597 (+ (or lines (1- (window-height))) scroll-margin)))))
6600 (and (pos-visible-in-window-p) ;Not continuation line.
6601 (>= (point) (point-max)))))
6602 ;; Nothing in this page.
6603 (if (or (not gnus-page-broken)
6608 (eobp)))) ;Real end-of-buffer?
6610 (when gnus-article-over-scroll
6611 (gnus-article-next-page-1 lines))
6613 (gnus-narrow-to-page 1) ;Go to next page.
6615 ;; More in this page.
6616 (gnus-article-next-page-1 lines)
6619 (defun gnus-article-beginning-of-window ()
6620 "Move point to the beginning of the window.
6621 In Emacs, the point is placed at the line number which `scroll-margin'
6623 (if (featurep 'xemacs)
6624 (move-to-window-line 0)
6625 ;; There is an obscure bug in Emacs that makes it impossible to
6626 ;; scroll past big pictures in the article buffer. Try to fix
6627 ;; this by adding a sanity check by counting the lines visible.
6628 (when (> (count-lines (window-start) (window-end)) 30)
6629 (move-to-window-line
6630 (min (max 0 scroll-margin)
6631 (max 1 (- (window-height)
6632 (if mode-line-format 1 0)
6633 (if header-line-format 1 0)
6636 (defun gnus-article-next-page-1 (lines)
6638 (let ((scroll-in-place nil)
6639 (auto-window-vscroll nil))
6642 ;; Long lines may cause an end-of-buffer error.
6643 (goto-char (point-max))))
6644 (gnus-article-beginning-of-window))
6646 (defun gnus-article-prev-page (&optional lines)
6647 "Show previous page of current article.
6648 Argument LINES specifies lines to be scrolled down."
6650 (move-to-window-line 0)
6651 (if (and gnus-page-broken
6653 (not (save-restriction (widen) (bobp)))) ;Real beginning-of-buffer?
6655 (gnus-narrow-to-page -1) ;Go to previous page.
6656 (goto-char (point-max))
6657 (recenter (if gnus-article-over-scroll
6659 (max (if (featurep 'xemacs)
6661 (+ lines scroll-margin))
6663 (- (window-height) 2))
6667 (let ((scroll-in-place nil))
6668 (scroll-down lines))
6669 (beginning-of-buffer
6670 (goto-char (point-min))))
6671 (gnus-article-beginning-of-window))))
6673 (defun gnus-article-only-boring-p ()
6674 "Decide whether there is only boring text remaining in the article.
6675 Something \"interesting\" is a word of at least two letters that does
6676 not have a face in `gnus-article-boring-faces'."
6677 (when (and gnus-article-skip-boring
6678 (boundp 'gnus-article-boring-faces)
6679 (symbol-value 'gnus-article-boring-faces))
6681 (let ((inhibit-point-motion-hooks t))
6683 (while (re-search-forward "\\b\\w\\w" nil t)
6685 (when (not (gnus-intersection
6686 (gnus-faces-at (point))
6687 (symbol-value 'gnus-article-boring-faces)))
6688 (throw 'only-boring nil)))
6689 (throw 'only-boring t))))))
6691 (defun gnus-article-refer-article ()
6692 "Read article specified by message-id around point."
6695 (re-search-backward "[ \t]\\|^" (point-at-bol) t)
6696 (re-search-forward "<?news:<?\\|<" (point-at-eol) t)
6697 (if (re-search-forward "[^@ ]+@[^ \t>]+" (point-at-eol) t)
6698 (let ((msg-id (concat "<" (match-string 0) ">")))
6699 (set-buffer gnus-summary-buffer)
6700 (gnus-summary-refer-article msg-id))
6701 (error "No references around point"))))
6703 (defun gnus-article-show-summary ()
6704 "Reconfigure windows to show summary buffer."
6706 (if (not (gnus-buffer-live-p gnus-summary-buffer))
6707 (error "There is no summary buffer for this article buffer")
6708 (gnus-article-set-globals)
6709 (gnus-configure-windows 'article)
6710 (gnus-summary-goto-subject gnus-current-article)
6711 (gnus-summary-position-point)))
6713 (defun gnus-article-describe-briefly ()
6714 "Describe article mode commands briefly."
6716 (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")))
6718 (defun gnus-article-check-buffer ()
6719 "Beep if not in an article buffer."
6720 (unless (derived-mode-p 'gnus-article-mode)
6721 (error "Command invoked outside of a Gnus article buffer")))
6723 (defun gnus-article-read-summary-keys (&optional arg key not-restore-window)
6724 "Read a summary buffer key sequence and execute it from the article buffer."
6726 (gnus-article-check-buffer)
6728 '("q" "Q" "c" "r" "\C-c\C-f" "m" "a" "f"
6729 "Zc" "ZC" "ZE" "ZQ" "ZZ" "Zn" "ZR" "ZG" "ZN" "ZP"
6730 "=" "^" "\M-^" "|"))
6732 '("A " "A<" "A>" "AM" "AP" "AR" "AT" "A\C-?" "A\M-\r" "A\r" "Ab" "Ae"
6733 "An" "Ap" [?A (meta return)] [?A delete]))
6737 '("n" "Gn" "p" "Gp"))
6739 (with-current-buffer gnus-article-current-summary
6740 (let (gnus-pick-mode)
6741 (setq unread-command-events (nconc unread-command-events
6742 (list (or key last-command-event)))
6743 keys (if (featurep 'xemacs)
6744 (events-to-keys (read-key-sequence nil t))
6745 (read-key-sequence nil t)))))
6750 ((eq (aref keys (1- (length keys))) ?\C-h)
6751 (gnus-article-describe-bindings (substring keys 0 -1)))
6752 ((or (member keys nosaves)
6753 (member keys nosave-but-article)
6754 (member keys nosave-in-article))
6756 (save-window-excursion
6757 (pop-to-buffer gnus-article-current-summary)
6758 ;; We disable the pick minor mode commands.
6759 (let (gnus-pick-mode)
6760 (setq func (key-binding keys t))))
6764 (unless (member keys nosave-in-article)
6765 (set-buffer gnus-article-current-summary))
6766 (when (and (symbolp func)
6767 (get func 'disabled))
6768 (error "Function %s disabled" func))
6769 (call-interactively func)
6770 (setq new-sum-point (point)))
6771 (when (member keys nosave-but-article)
6772 (pop-to-buffer gnus-article-buffer))))
6774 ;; These commands should restore window configuration.
6775 (let ((obuf (current-buffer))
6776 (owin (current-window-configuration))
6777 win func in-buffer selected new-sum-start new-sum-hscroll err)
6778 (cond (not-restore-window
6779 (pop-to-buffer gnus-article-current-summary)
6780 (setq win (selected-window)))
6781 ((setq win (get-buffer-window gnus-article-current-summary))
6782 (select-window win))
6784 (let ((summary-buffer gnus-article-current-summary))
6785 (gnus-configure-windows 'article)
6786 (unless (setq win (get-buffer-window summary-buffer 'visible))
6787 (let ((gnus-buffer-configuration
6788 '((article ((vertical 1.0
6789 (summary 0.25 point)
6791 (gnus-configure-windows 'article))
6792 (setq win (get-buffer-window summary-buffer 'visible)))
6793 (gnus-select-frame-set-input-focus (window-frame win))
6794 (select-window win))))
6795 (setq in-buffer (current-buffer))
6796 ;; We disable the pick minor mode commands.
6797 (setq func (let (gnus-pick-mode)
6798 (key-binding keys t)))
6799 (when (get func 'disabled)
6800 (error "Function %s disabled" func))
6803 (condition-case code
6805 (call-interactively func)
6811 (when (eq win (selected-window))
6812 (setq new-sum-point (point)
6813 new-sum-start (window-start win)
6814 new-sum-hscroll (window-hscroll win)))
6815 (when (or (eq in-buffer (current-buffer))
6816 (when (eq obuf (current-buffer))
6817 (set-buffer in-buffer)
6819 (setq selected (ignore-errors (gnus-summary-select-article)))
6821 (unless not-restore-window
6822 (set-window-configuration owin))
6823 (when (and (eq selected 'old)
6825 (set-window-start (get-buffer-window (current-buffer))
6827 (set-window-point (get-buffer-window (current-buffer))
6828 (if (article-goto-body)
6831 (when (and (not not-restore-window)
6834 (with-current-buffer (window-buffer win)
6835 (derived-mode-p 'gnus-summary-mode)))
6836 (set-window-point win new-sum-point)
6837 (set-window-start win new-sum-start)
6838 (set-window-hscroll win new-sum-hscroll))))
6839 (set-window-configuration owin)
6841 (signal (car err) (cdr err))
6844 (defun gnus-article-read-summary-send-keys ()
6846 (let ((unread-command-events (list (gnus-character-to-event ?S))))
6847 (gnus-article-read-summary-keys)))
6849 (defun gnus-article-describe-key (key)
6850 "Display documentation of the function invoked by KEY.
6851 KEY is a string or a vector."
6852 (interactive (list (let ((cursor-in-echo-area t)) ;; better for XEmacs.
6853 (read-key-sequence "Describe key: "))))
6854 (gnus-article-check-buffer)
6855 (if (memq (key-binding key t) '(gnus-article-read-summary-keys
6856 gnus-article-read-summary-send-keys))
6857 (with-current-buffer gnus-article-current-summary
6858 (setq unread-command-events
6859 (if (featurep 'xemacs)
6861 (mapcar (lambda (x) (if (and (integerp x) (>= x 128))
6862 (list 'meta (- x 128))
6865 (let ((cursor-in-echo-area t)
6867 (describe-key (read-key-sequence nil t))))
6868 (describe-key key)))
6870 (defun gnus-article-describe-key-briefly (key &optional insert)
6871 "Display documentation of the function invoked by KEY.
6872 KEY is a string or a vector."
6873 (interactive (list (let ((cursor-in-echo-area t)) ;; better for XEmacs.
6874 (read-key-sequence "Describe key: "))
6875 current-prefix-arg))
6876 (gnus-article-check-buffer)
6877 (if (memq (key-binding key t) '(gnus-article-read-summary-keys
6878 gnus-article-read-summary-send-keys))
6879 (with-current-buffer gnus-article-current-summary
6880 (setq unread-command-events
6881 (if (featurep 'xemacs)
6883 (mapcar (lambda (x) (if (and (integerp x) (>= x 128))
6884 (list 'meta (- x 128))
6887 (let ((cursor-in-echo-area t)
6889 (describe-key-briefly (read-key-sequence nil t) insert)))
6890 (describe-key-briefly key insert)))
6892 ;;`gnus-agent-mode' in gnus-agent.el will define it.
6893 (defvar gnus-agent-summary-mode)
6894 (defvar gnus-draft-mode)
6895 (defvar help-xref-stack-item)
6897 (defun gnus-article-describe-bindings (&optional prefix)
6898 "Show a list of all defined keys, and their definitions.
6899 The optional argument PREFIX, if non-nil, should be a key sequence;
6900 then we display only bindings that start with that prefix."
6902 (gnus-article-check-buffer)
6903 (let ((keymap (copy-keymap gnus-article-mode-map))
6904 (map (copy-keymap gnus-article-send-map))
6905 (sumkeys (where-is-internal 'gnus-article-read-summary-keys))
6907 (define-key keymap "S" map)
6908 (define-key map [t] nil)
6909 (with-current-buffer gnus-article-current-summary
6912 (if (setq parent (keymap-parent gnus-article-mode-map))
6914 (setq parent (copy-keymap parent))
6915 (set-keymap-parent parent (current-local-map)))
6916 (current-local-map)))
6917 (set-keymap-parent map (key-binding "S"))
6918 (let (key def gnus-pick-mode)
6920 (setq key (pop sumkeys))
6921 (cond ((and (vectorp key) (= (length key) 1)
6922 (consp (setq def (aref key 0)))
6923 (numberp (car def)) (numberp (cdr def)))
6924 (when (< (max (car def) (cdr def)) 128)
6928 (nreverse (gnus-uncompress-range def)))
6930 ((setq def (key-binding key))
6931 (unless (eq def 'undefined)
6932 (define-key keymap key def))))))
6933 (when (boundp 'gnus-agent-summary-mode)
6934 (setq agent gnus-agent-summary-mode))
6935 (when (boundp 'gnus-draft-mode)
6936 (setq draft gnus-draft-mode)))
6938 (use-local-map keymap)
6939 (set (make-local-variable 'gnus-agent-summary-mode) agent)
6940 (set (make-local-variable 'gnus-draft-mode) draft)
6941 (describe-bindings prefix))
6942 (let ((item `((lambda (prefix)
6943 (with-current-buffer ,(current-buffer)
6944 (gnus-article-describe-bindings prefix)))
6946 ;; Loading `help-mode' here is necessary if `describe-bindings'
6947 ;; is replaced with something, e.g. `helm-descbinds'.
6948 (require 'help-mode)
6949 (with-current-buffer (let (help-xref-following) (help-buffer))
6950 (setq help-xref-stack-item item)))))
6952 (defun gnus-article-reply-with-original (&optional wide)
6953 "Start composing a reply mail to the current message.
6954 The text in the region will be yanked. If the region isn't active,
6955 the entire article will be yanked."
6957 (let ((article (cdr gnus-article-current))
6959 (if (not (gnus-region-active-p))
6960 (with-current-buffer gnus-summary-buffer
6961 (gnus-summary-reply (list (list article)) wide))
6962 (setq contents (buffer-substring (point) (mark t)))
6963 ;; Deactivate active regions.
6964 (when (and (boundp 'transient-mark-mode)
6965 transient-mark-mode)
6966 (setq mark-active nil))
6967 (with-current-buffer gnus-summary-buffer
6969 (list (list article contents)) wide)))))
6971 (defun gnus-article-wide-reply-with-original ()
6972 "Start composing a wide reply mail to the current message.
6973 The text in the region will be yanked. If the region isn't active,
6974 the entire article will be yanked."
6976 (gnus-article-reply-with-original t))
6978 (defun gnus-article-followup-with-original ()
6979 "Compose a followup to the current article.
6980 The text in the region will be yanked. If the region isn't active,
6981 the entire article will be yanked."
6983 (let ((article (cdr gnus-article-current))
6985 (if (not (gnus-region-active-p))
6986 (with-current-buffer gnus-summary-buffer
6987 (gnus-summary-followup (list (list article))))
6988 (setq contents (buffer-substring (point) (mark t)))
6989 ;; Deactivate active regions.
6990 (when (and (boundp 'transient-mark-mode)
6991 transient-mark-mode)
6992 (setq mark-active nil))
6993 (with-current-buffer gnus-summary-buffer
6994 (gnus-summary-followup
6995 (list (list article contents)))))))
6997 (defun gnus-article-hide (&optional arg force)
6998 "Hide all the gruft in the current article.
6999 This means that signatures, cited text and (some) headers will be
7001 If given a prefix, show the hidden text instead."
7002 (interactive (append (gnus-article-hidden-arg) (list 'force)))
7003 (gnus-article-hide-headers arg)
7004 (gnus-article-hide-list-identifiers arg)
7005 (gnus-article-hide-citation-maybe arg force)
7006 (gnus-article-hide-signature arg))
7008 (defun gnus-check-group-server ()
7009 ;; Make sure the connection to the server is alive.
7010 (unless (gnus-server-opened
7011 (gnus-find-method-for-group gnus-newsgroup-name))
7012 (gnus-check-server (gnus-find-method-for-group gnus-newsgroup-name))
7013 (gnus-request-group gnus-newsgroup-name t)))
7016 (autoload 'nneething-get-file-name "nneething"))
7018 (defun gnus-request-article-this-buffer (article group)
7019 "Get an article and insert it into this buffer."
7020 (let (do-update-line sparse-header)
7024 (gnus-kill-all-overlays)
7025 (setq group (or group gnus-newsgroup-name))
7027 ;; Using `gnus-request-article' directly will insert the article into
7028 ;; `nntp-server-buffer' - so we'll save some time by not having to
7029 ;; copy it from the server buffer into the article buffer.
7031 ;; We only request an article by message-id when we do not have the
7032 ;; headers for it, so we'll have to get those.
7033 (when (stringp article)
7034 (gnus-read-header article))
7036 ;; If the article number is negative, that means that this article
7037 ;; doesn't belong in this newsgroup (possibly), so we find its
7038 ;; message-id and request it by id instead of number.
7039 (when (and (numberp article)
7041 (get-buffer gnus-summary-buffer)
7042 (gnus-buffer-exists-p gnus-summary-buffer))
7043 (with-current-buffer gnus-summary-buffer
7044 (let ((header (gnus-summary-article-header article)))
7047 ((memq article gnus-newsgroup-sparse)
7048 ;; This is a sparse gap article.
7049 (setq do-update-line article)
7050 (setq article (mail-header-id header))
7051 (setq sparse-header (gnus-read-header article))
7052 (setq gnus-newsgroup-sparse
7053 (delq article gnus-newsgroup-sparse)))
7055 ;; It's a real article.
7056 (setq article (mail-header-id header)))
7058 ;; It is an extracted pseudo-article.
7059 (setq article 'pseudo)
7060 (gnus-request-pseudo-article header))))
7062 (let ((method (gnus-find-method-for-group
7063 gnus-newsgroup-name)))
7064 (when (and (eq (car method) 'nneething)
7066 (let ((dir (nneething-get-file-name
7067 (mail-header-id header))))
7068 (when (and (stringp dir)
7069 (file-directory-p dir))
7070 (setq article 'nneething)
7071 (gnus-group-enter-directory dir))))))))
7074 ;; Refuse to select canceled articles.
7075 ((and (numberp article)
7077 (get-buffer gnus-summary-buffer)
7078 (gnus-buffer-exists-p gnus-summary-buffer)
7079 (eq (cdr (with-current-buffer gnus-summary-buffer
7080 (assq article gnus-newsgroup-reads)))
7081 gnus-canceled-mark))
7083 ;; We first check `gnus-original-article-buffer'.
7084 ((and (get-buffer gnus-original-article-buffer)
7086 (with-current-buffer gnus-original-article-buffer
7087 (and (equal (car gnus-original-article) group)
7088 (eq (cdr gnus-original-article) article))))
7089 ;; `insert-buffer-substring' would incorrectly use the
7090 ;; equivalent of string-make-multibyte which amount to decoding
7091 ;; with locale-coding-system, causing failure of
7092 ;; subsequent decoding.
7093 (insert (mm-string-to-multibyte
7094 (with-current-buffer gnus-original-article-buffer
7095 (buffer-substring (point-min) (point-max)))))
7097 ;; Check the backlog.
7098 ((and gnus-keep-backlog
7099 (gnus-backlog-request-article group article (current-buffer)))
7101 ;; Check asynchronous pre-fetch.
7102 ((gnus-async-request-fetched-article group article (current-buffer))
7103 (gnus-async-prefetch-next group article gnus-summary-buffer)
7104 (when (and (numberp article) gnus-keep-backlog)
7105 (gnus-backlog-enter-article group article (current-buffer)))
7108 ((and gnus-use-cache
7110 (gnus-cache-request-article article group))
7112 ;; Check the agent cache.
7113 ((gnus-agent-request-article article group)
7115 ;; Get the article and put into the article buffer.
7116 ((or (stringp article)
7118 (let ((gnus-override-method gnus-override-method)
7119 (methods (and (stringp article)
7120 (with-current-buffer gnus-summary-buffer
7121 (gnus-refer-article-methods))))
7122 (backend (car (gnus-find-method-for-group
7123 gnus-newsgroup-name)))
7125 (inhibit-read-only t))
7126 (when (and (null gnus-override-method)
7128 (setq gnus-override-method (pop methods)))
7131 (gnus-kill-all-overlays)
7132 (let ((gnus-newsgroup-name group))
7133 (gnus-check-group-server))
7135 ((gnus-request-article article group (current-buffer))
7136 (when (numberp article)
7137 (gnus-async-prefetch-next group article
7138 gnus-summary-buffer)
7139 (when gnus-keep-backlog
7140 (gnus-backlog-enter-article
7141 group article (current-buffer)))
7142 (when (and gnus-agent
7143 (gnus-agent-group-covered-p group))
7144 (gnus-agent-store-article article group)))
7145 (setq result 'article))
7147 (setq gnus-override-method (pop methods)))
7148 ((not (string-match "^400 "
7149 (nnheader-get-report backend)))
7150 ;; If we get 400 server disconnect, reconnect and
7151 ;; retry; otherwise, assume the article has expired.
7152 (setq result 'done))))
7153 (and (eq result 'article) 'article)))
7157 ;; Associate this article with the current summary buffer.
7158 (setq gnus-article-current-summary gnus-summary-buffer)
7160 ;; Take the article from the original article buffer
7161 ;; and place it in the buffer it's supposed to be in.
7162 (when (and (get-buffer gnus-article-buffer)
7163 (equal (buffer-name (current-buffer))
7164 (buffer-name (get-buffer gnus-article-buffer))))
7166 (if (get-buffer gnus-original-article-buffer)
7167 (set-buffer gnus-original-article-buffer)
7168 (set-buffer (gnus-get-buffer-create gnus-original-article-buffer))
7169 (buffer-disable-undo)
7170 (setq major-mode 'gnus-original-article-mode)
7171 (setq buffer-read-only t))
7172 (let ((inhibit-read-only t))
7174 (insert-buffer-substring gnus-article-buffer))
7175 (setq gnus-original-article (cons group article)))
7178 (run-hooks 'gnus-article-decode-hook)
7179 ;; Mark article as decoded or not.
7180 (setq gnus-article-decoded-p gnus-article-decode-hook))
7182 ;; Update sparse articles.
7183 (when (and do-update-line
7184 (or (numberp article)
7186 (let ((buf (current-buffer)))
7187 (set-buffer gnus-summary-buffer)
7188 (gnus-summary-update-article do-update-line sparse-header)
7189 (gnus-summary-goto-subject do-update-line nil t)
7190 (set-window-point (gnus-get-buffer-window (current-buffer) t)
7192 (set-buffer buf))))))
7194 (defun gnus-block-private-groups (group)
7195 (if (or (gnus-news-group-p group)
7196 (gnus-member-of-valid 'global group))
7197 ;; Block nothing in news groups.
7199 ;; Block everything anywhere else.
7202 (defun gnus-blocked-images ()
7203 (if (functionp gnus-blocked-images)
7204 (funcall gnus-blocked-images gnus-newsgroup-name)
7205 gnus-blocked-images))
7211 (defcustom gnus-article-edit-mode-hook nil
7212 "Hook run in article edit mode buffers."
7213 :group 'gnus-article-various
7216 (defvar gnus-article-edit-done-function nil)
7218 (defvar gnus-article-edit-mode-map nil)
7220 ;; Should we be using derived.el for this?
7221 (unless gnus-article-edit-mode-map
7222 (setq gnus-article-edit-mode-map (make-keymap))
7223 (set-keymap-parent gnus-article-edit-mode-map text-mode-map)
7225 (gnus-define-keys gnus-article-edit-mode-map
7226 "\C-c?" describe-mode
7227 "\C-c\C-c" gnus-article-edit-done
7228 "\C-c\C-k" gnus-article-edit-exit
7229 "\C-c\C-f\C-t" message-goto-to
7230 "\C-c\C-f\C-o" message-goto-from
7231 "\C-c\C-f\C-b" message-goto-bcc
7232 ;;"\C-c\C-f\C-w" message-goto-fcc
7233 "\C-c\C-f\C-c" message-goto-cc
7234 "\C-c\C-f\C-s" message-goto-subject
7235 "\C-c\C-f\C-r" message-goto-reply-to
7236 "\C-c\C-f\C-n" message-goto-newsgroups
7237 "\C-c\C-f\C-d" message-goto-distribution
7238 "\C-c\C-f\C-f" message-goto-followup-to
7239 "\C-c\C-f\C-m" message-goto-mail-followup-to
7240 "\C-c\C-f\C-k" message-goto-keywords
7241 "\C-c\C-f\C-u" message-goto-summary
7242 "\C-c\C-f\C-i" message-insert-or-toggle-importance
7243 "\C-c\C-f\C-a" message-generate-unsubscribed-mail-followup-to
7244 "\C-c\C-b" message-goto-body
7245 "\C-c\C-i" message-goto-signature
7247 "\C-c\C-t" message-insert-to
7248 "\C-c\C-n" message-insert-newsgroups
7249 "\C-c\C-o" message-sort-headers
7250 "\C-c\C-e" message-elide-region
7251 "\C-c\C-v" message-delete-not-region
7252 "\C-c\C-z" message-kill-to-signature
7253 "\M-\r" message-newline-and-reformat
7254 "\C-c\C-a" mml-attach-file
7255 "\C-a" message-beginning-of-line
7257 "\M-;" comment-region)
7259 (gnus-define-keys (gnus-article-edit-wash-map
7260 "\C-c\C-w" gnus-article-edit-mode-map)
7261 "f" gnus-article-edit-full-stops))
7264 gnus-article-edit-mode-field-menu gnus-article-edit-mode-map ""
7266 ["Fetch To" message-insert-to t]
7267 ["Fetch Newsgroups" message-insert-newsgroups t]
7269 ["To" message-goto-to t]
7270 ["From" message-goto-from t]
7271 ["Subject" message-goto-subject t]
7272 ["Cc" message-goto-cc t]
7273 ["Reply-To" message-goto-reply-to t]
7274 ["Summary" message-goto-summary t]
7275 ["Keywords" message-goto-keywords t]
7276 ["Newsgroups" message-goto-newsgroups t]
7277 ["Followup-To" message-goto-followup-to t]
7278 ["Mail-Followup-To" message-goto-mail-followup-to t]
7279 ["Distribution" message-goto-distribution t]
7280 ["Body" message-goto-body t]
7281 ["Signature" message-goto-signature t]))
7283 (define-derived-mode gnus-article-edit-mode message-mode "Article Edit"
7284 "Major mode for editing articles.
7285 This is an extended text-mode.
7287 \\{gnus-article-edit-mode-map}"
7288 (make-local-variable 'gnus-article-edit-done-function)
7289 (make-local-variable 'gnus-prev-winconf)
7290 (set (make-local-variable 'font-lock-defaults)
7291 '(message-font-lock-keywords t))
7292 (set (make-local-variable 'mail-header-separator) "")
7293 (set (make-local-variable 'gnus-article-edit-mode) t)
7294 (easy-menu-add message-mode-field-menu message-mode-map)
7296 (setq buffer-read-only nil)
7297 (buffer-enable-undo)
7300 (defun gnus-article-edit (&optional force)
7301 "Edit the current article.
7302 This will have permanent effect only in mail groups.
7303 If FORCE is non-nil, allow editing of articles even in read-only
7306 (when (and (not force)
7307 (gnus-group-read-only-p))
7308 (error "The current newsgroup does not support article editing"))
7309 (gnus-article-date-original)
7310 (gnus-article-edit-article
7312 `(lambda (no-highlight)
7314 (gnus-summary-edit-article-done
7315 ,(or (mail-header-references gnus-current-headers) "")
7316 ,(gnus-group-read-only-p) ,gnus-summary-buffer no-highlight))))
7318 (defun gnus-article-edit-article (start-func exit-func &optional quiet)
7319 "Start editing the contents of the current article buffer."
7320 (let ((winconf (current-window-configuration)))
7321 (set-buffer gnus-article-buffer)
7322 (let ((message-auto-save-directory
7323 ;; Don't associate the article buffer with a draft file.
7325 (gnus-article-edit-mode))
7326 (funcall start-func)
7327 (set-buffer-modified-p nil)
7328 (gnus-configure-windows 'edit-article)
7329 (setq gnus-article-edit-done-function exit-func)
7330 (setq gnus-prev-winconf winconf)
7332 (gnus-message 6 "C-c C-c to end edits"))))
7334 (defun gnus-article-edit-done (&optional arg)
7335 "Update the article edits and exit."
7337 (let ((func gnus-article-edit-done-function)
7338 (buf (current-buffer))
7339 (start (window-start))
7341 (winconf gnus-prev-winconf))
7342 (widen) ;; Widen it in case that users narrowed the buffer.
7345 ;; The cache and backlog have to be flushed somewhat.
7346 (when gnus-keep-backlog
7347 (gnus-backlog-remove-article
7348 (car gnus-article-current) (cdr gnus-article-current)))
7349 ;; Flush original article as well.
7350 (gnus-flush-original-article-buffer)
7351 (when gnus-use-cache
7352 (gnus-cache-update-article
7353 (car gnus-article-current) (cdr gnus-article-current)))
7354 ;; We remove all text props from the article buffer.
7355 (kill-all-local-variables)
7356 (set-text-properties (point-min) (point-max) nil)
7358 (set-window-configuration winconf)
7360 (set-window-start (get-buffer-window buf) start)
7361 (set-window-point (get-buffer-window buf) (point)))
7362 (gnus-summary-show-article))
7364 (defun gnus-flush-original-article-buffer ()
7365 (when (get-buffer gnus-original-article-buffer)
7366 (with-current-buffer gnus-original-article-buffer
7367 (setq gnus-original-article nil))))
7369 (defun gnus-article-edit-exit ()
7370 "Exit the article editing without updating."
7372 (when (or (not (buffer-modified-p))
7373 (yes-or-no-p "Article modified; kill anyway? "))
7374 (let ((curbuf (current-buffer))
7376 (window-start (window-start)))
7378 (if (gnus-buffer-live-p gnus-original-article-buffer)
7379 (insert-buffer-substring gnus-original-article-buffer))
7380 (let ((winconf gnus-prev-winconf))
7381 (kill-all-local-variables)
7383 (set-window-configuration winconf)
7384 ;; Tippy-toe some to make sure that point remains where it was.
7385 (save-current-buffer
7387 (set-window-start (get-buffer-window (current-buffer)) window-start)
7389 (gnus-summary-show-article)))
7391 (defun gnus-article-edit-full-stops ()
7392 "Interactively repair spacing at end of sentences."
7395 (goto-char (point-min))
7396 (search-forward-regexp "^$" nil t)
7397 (let ((case-fold-search nil))
7398 (query-replace-regexp "\\([.!?][])}]* \\)\\([[({A-Z]\\)" "\\1 \\2"))))
7401 ;;; Article highlights
7404 ;; Written by Per Abrahamsen <abraham@iesd.auc.dk>.
7406 ;;; Internal Variables:
7408 (defcustom gnus-button-url-regexp
7410 "\\b\\(\\(www\\.\\|\\(s?https?\\|ftp\\|file\\|gopher\\|"
7411 "nntp\\|news\\|telnet\\|wais\\|mailto\\|info\\):\\)"
7412 "\\(//[-a-z0-9_.]+:[0-9]*\\)?"
7413 (if (string-match "[[:digit:]]" "1") ;; Support POSIX?
7414 (let ((chars "-a-z0-9_=#$@~%&*+\\/[:word:]")
7418 ;; Match paired parentheses, e.g. in Wikipedia URLs:
7419 ;; http://thread.gmane.org/47B4E3B2.3050402@gmail.com
7420 "[" chars punct "]+" "(" "[" chars punct "]+" "[" chars "]*)"
7421 "\\(?:" "[" chars punct "]+" "[" chars "]" "\\)?"
7423 "[" chars punct "]+" "[" chars "]"
7425 (concat ;; XEmacs 21.4 doesn't support POSIX.
7426 "\\([-a-z0-9_=!?#$@~%&*+\\/:;.,]\\|\\w\\)+"
7427 "\\([-a-z0-9_=#$@~%&*+\\/]\\|\\w\\)"))
7429 "Regular expression that matches URLs."
7431 :group 'gnus-article-buttons
7434 (defcustom gnus-button-valid-fqdn-regexp
7435 message-valid-fqdn-regexp
7436 "Regular expression that matches a valid FQDN."
7438 :group 'gnus-article-buttons
7441 ;; Regexp suggested by Felix Wiemann in <87oeuomcz9.fsf@news2.ososo.de>
7442 (defcustom gnus-button-valid-localpart-regexp
7443 "[a-z0-9$%(*-=?[_][^<>\")!;:,{}\n\t @]*"
7444 "Regular expression that matches a localpart of mail addresses or MIDs."
7446 :group 'gnus-article-buttons
7449 (defcustom gnus-button-man-handler 'manual-entry
7450 "Function to use for displaying man pages.
7451 The function must take at least one argument with a string naming the
7454 :type '(choice (function-item :tag "Man" manual-entry)
7455 (function-item :tag "Woman" woman)
7456 (function :tag "Other"))
7457 :group 'gnus-article-buttons)
7459 (defcustom gnus-button-mid-or-mail-regexp
7460 (concat "\\b\\(<?" gnus-button-valid-localpart-regexp "@"
7461 gnus-button-valid-fqdn-regexp
7463 "Regular expression that matches a message ID or a mail address."
7465 :group 'gnus-article-buttons
7468 (defcustom gnus-button-prefer-mid-or-mail 'gnus-button-mid-or-mail-heuristic
7469 "What to do when the button on a string as \"foo123@bar.invalid\" is pushed.
7470 Strings like this can be either a message ID or a mail address. If it is one
7471 of the symbols `mid' or `mail', Gnus will always assume that the string is a
7472 message ID or a mail address, respectively. If this variable is set to the
7473 symbol `ask', always query the user what do do. If it is a function, this
7474 function will be called with the string as its only argument. The function
7475 must return `mid', `mail', `invalid' or `ask'."
7477 :group 'gnus-article-buttons
7478 :type '(choice (function-item :tag "Heuristic function"
7479 gnus-button-mid-or-mail-heuristic)
7484 (defcustom gnus-button-mid-or-mail-heuristic-alist
7485 '((-10.0 . ".+\\$.+@")
7488 (-5.0 . "\\+[^+]*\\+.*@") ;; # two plus signs
7489 (-5.0 . "@[Nn][Ee][Ww][Ss]") ;; /\@news/i
7490 (-5.0 . "@.*[Dd][Ii][Aa][Ll][Uu][Pp]") ;; /\@.*dialup/i;
7491 (-1.0 . "^[^a-z]+@")
7493 (-5.0 . "\\.[0-9][0-9]+.*@") ;; "\.[0-9]{2,}.*\@"
7494 (-5.0 . "[a-z].*[A-Z].*[a-z].*[A-Z].*@") ;; "([a-z].*[A-Z].*){2,}\@"
7495 (-3.0 . "[A-Z][A-Z][a-z][a-z].*@")
7496 (-5.0 . "\\...?.?@") ;; (-5.0 . "\..{1,3}\@")
7499 (-1.0 . "^[0-9][0-9]")
7501 ;; -3.0 /^[0-9][0-9a-fA-F]{2,2}/;
7502 (-3.0 . "^[0-9][0-9a-fA-F][0-9a-fA-F][^0-9a-fA-F]")
7503 ;; -5.0 /^[0-9][0-9a-fA-F]{3,3}/;
7504 (-5.0 . "^[0-9][0-9a-fA-F][0-9a-fA-F][0-9a-fA-F][^0-9a-fA-F]")
7506 (-3.0 . "[0-9][0-9][0-9][0-9][0-9][^0-9].*@") ;; "[0-9]{5,}.*\@"
7507 (-3.0 . "[0-9][0-9][0-9][0-9][0-9][0-9][0-9][0-9][^0-9].*@")
7510 . "[0-9][0-9][0-9][0-9][0-9][0-9][0-9][0-9][0-9][0-9][0-9][0-9].*@")
7512 ;; compensation for TDMA dated mail addresses:
7513 (25.0 . "-dated-[0-9][0-9][0-9][0-9][0-9][0-9][0-9][0-9]+.*@")
7515 (-20.0 . "\\.fsf@") ;; Gnus
7518 (-20.0 . "^alpine\\.")
7519 (-20.0 . "_-_") ;; Subject change in thread
7521 (-20.0 . "\\.ln@") ;; leafnode
7522 (-30.0 . "@ID-[0-9]+\\.[a-zA-Z]+\\.dfncis\\.de")
7523 (-30.0 . "@4[Aa][Xx]\\.com") ;; Forte Agent
7525 ;; (5.0 . "") ;; $local_part_len <= 7
7526 (10.0 . "^[^0-9]+@")
7527 (3.0 . "^[^0-9]+[0-9][0-9]?[0-9]?@")
7528 ;; ^[^0-9]+[0-9]{1,3}\@ digits only at end of local part
7531 (2.0 . "[a-z][a-z][._-][A-Z][a-z].*@")
7533 (0.5 . "^[A-Z][a-z]")
7534 (0.5 . "^[A-Z][a-z][a-z]")
7535 (1.5 . "^[A-Z][a-z][A-Z][a-z][^a-z]") ;; ^[A-Z][a-z]{3,3}
7536 (2.0 . "^[A-Z][a-z][A-Z][a-z][a-z][^a-z]")) ;; ^[A-Z][a-z]{4,4}
7537 "An alist of \(RATE . REGEXP\) pairs for `gnus-button-mid-or-mail-heuristic'.
7539 A negative RATE indicates a message IDs, whereas a positive indicates a mail
7540 address. The REGEXP is processed with `case-fold-search' set to nil."
7542 :group 'gnus-article-buttons
7543 :type '(repeat (cons (number :tag "Rate")
7544 (regexp :tag "Regexp"))))
7546 (defun gnus-button-mid-or-mail-heuristic (mid-or-mail)
7547 "Guess whether MID-OR-MAIL is a message ID or a mail address.
7548 Returns `mid' if MID-OR-MAIL is a message IDs, `mail' if it's a mail
7549 address, `ask' if unsure and `invalid' if the string is invalid."
7550 (let ((case-fold-search nil)
7551 (list gnus-button-mid-or-mail-heuristic-alist)
7552 (result 0) rate regexp lpartlen elem)
7554 (length (gnus-replace-in-string mid-or-mail "^\\(.*\\)@.*$" "\\1")))
7555 (gnus-message 8 "`%s', length of local part=`%s'." mid-or-mail lpartlen)
7556 ;; Certain special cases...
7559 "^0[0-9]+-[0-9][0-9][0-9][0-9]@t-online\\.de$\\|"
7560 "^[0-9]+\\.[0-9]+@compuserve\\|"
7561 "@public\\.gmane\\.org")
7563 (gnus-message 8 "`%s' is a known mail address." mid-or-mail)
7564 (setq result 'mail))
7565 (when (string-match "@.*@\\| " mid-or-mail)
7566 (gnus-message 8 "`%s' is invalid." mid-or-mail)
7567 (setq result 'invalid))
7568 ;; Nothing more to do, if result is not a number here...
7569 (when (numberp result)
7571 (setq elem (car list)
7575 (when (string-match regexp mid-or-mail)
7576 (setq result (+ result rate))
7578 9 "`%s' matched `%s', rate `%s', result `%s'."
7579 mid-or-mail regexp rate result)))
7580 (when (<= lpartlen 7)
7581 (setq result (+ result 5.0))
7582 (gnus-message 9 "`%s' matched (<= lpartlen 7), result `%s'."
7583 mid-or-mail result))
7584 (when (>= lpartlen 12)
7585 (gnus-message 9 "`%s' matched (>= lpartlen 12)" mid-or-mail)
7587 ((string-match "[0-9][^0-9]+[0-9].*@" mid-or-mail)
7588 ;; Long local part should contain realname if e-mail address,
7589 ;; too many digits: message-id.
7590 ;; $score -= 5.0 + 0.1 * $local_part_len;
7591 (setq rate (* -1.0 (+ 5.0 (* 0.1 lpartlen))))
7592 (setq result (+ result rate))
7594 9 "Many digits in `%s', rate `%s', result `%s'."
7595 mid-or-mail rate result))
7596 ((string-match "[^aeiouy][^aeiouy][^aeiouy][^aeiouy]+.*\@"
7598 ;; Too few vowels [^aeiouy]{4,}.*\@
7599 (setq result (+ result -5.0))
7601 9 "Few vowels in `%s', rate `%s', result `%s'."
7602 mid-or-mail -5.0 result))
7604 (setq result (+ result 5.0))
7606 9 "`%s', rate `%s', result `%s'." mid-or-mail 5.0 result)))))
7607 (gnus-message 8 "`%s': Final rate is `%s'." mid-or-mail result)
7608 ;; Maybe we should make this a customizable alist: (condition . 'result)
7610 ((symbolp result) result)
7611 ;; Now convert number into proper results:
7612 ((< result -10.0) 'mid)
7613 ((> result 10.0) 'mail)
7616 (defun gnus-button-handle-mid-or-mail (mid-or-mail)
7617 (let* ((pref gnus-button-prefer-mid-or-mail) guessed
7618 (url-mid (concat "news" ":" mid-or-mail))
7619 (url-mailto (concat "mailto" ":" mid-or-mail)))
7620 (gnus-message 9 "mid-or-mail=%s" mid-or-mail)
7621 (when (fboundp pref)
7623 ;; get rid of surrounding angles...
7625 (gnus-replace-in-string mid-or-mail "^<\\|>$" "")))
7626 (if (or (eq 'mid guessed) (eq 'mail guessed))
7630 (save-window-excursion
7631 (if (y-or-n-p (concat "Is <" mid-or-mail "> a mail address? "))
7634 (cond ((eq pref 'mid)
7635 (gnus-message 8 "calling `gnus-button-handle-news' %s" url-mid)
7636 (gnus-button-handle-news url-mid))
7638 (gnus-message 8 "calling `gnus-url-mailto' %s" url-mailto)
7639 (gnus-url-mailto url-mailto))
7640 (t (gnus-message 3 "Invalid string.")))))
7642 (defun gnus-button-handle-custom (fun arg)
7643 "Call function FUN on argument ARG.
7644 Both FUN and ARG are supposed to be strings. ARG will be passed
7645 as a symbol to FUN."
7646 (funcall (intern fun)
7647 (if (string-match "^customize-apropos" fun)
7651 (defvar gnus-button-handle-describe-prefix "^\\(C-h\\|<?[Ff]1>?\\)")
7653 (defun gnus-button-handle-describe-function (url)
7654 "Call `describe-function' when pushing the corresponding URL button."
7657 (gnus-replace-in-string url gnus-button-handle-describe-prefix ""))))
7659 (defun gnus-button-handle-describe-variable (url)
7660 "Call `describe-variable' when pushing the corresponding URL button."
7663 (gnus-replace-in-string url gnus-button-handle-describe-prefix ""))))
7665 (defun gnus-button-handle-symbol (url)
7666 "Display help on variable or function.
7667 Calls `describe-variable' or `describe-function'."
7668 (let ((sym (intern url)))
7670 ((fboundp sym) (describe-function sym))
7671 ((boundp sym) (describe-variable sym))
7672 (t (gnus-message 3 "`%s' is not a known function of variable." url)))))
7674 (defun gnus-button-handle-describe-key (url)
7675 "Call `describe-key' when pushing the corresponding URL button."
7677 (gnus-replace-in-string url gnus-button-handle-describe-prefix ""))
7678 (keys (ignore-errors (eval `(kbd ,key-string)))))
7681 (gnus-message 3 "Invalid key sequence in button: %s" key-string))))
7683 (defun gnus-button-handle-apropos (url)
7684 "Call `apropos' when pushing the corresponding URL button."
7685 (apropos (gnus-replace-in-string url gnus-button-handle-describe-prefix "")))
7687 (defun gnus-button-handle-apropos-command (url)
7688 "Call `apropos' when pushing the corresponding URL button."
7690 (gnus-replace-in-string url gnus-button-handle-describe-prefix "")))
7692 (defun gnus-button-handle-apropos-variable (url)
7693 "Call `apropos' when pushing the corresponding URL button."
7695 (if (fboundp 'apropos-variable) 'apropos-variable 'apropos)
7696 (gnus-replace-in-string url gnus-button-handle-describe-prefix "")))
7698 (defun gnus-button-handle-apropos-documentation (url)
7699 "Call `apropos' when pushing the corresponding URL button."
7701 (if (fboundp 'apropos-documentation) 'apropos-documentation 'apropos)
7702 (gnus-replace-in-string url gnus-button-handle-describe-prefix "")))
7704 (defun gnus-button-handle-library (url)
7705 "Call `locate-library' when pushing the corresponding URL button."
7706 (gnus-message 9 "url=`%s'" url)
7707 (let* ((lib (locate-library url))
7708 (file (gnus-replace-in-string (or lib "") "\.elc" ".el")))
7710 (gnus-message 1 "Cannot locale library `%s'." url)
7711 (find-file-read-only file))))
7713 (defcustom gnus-button-man-level 5
7714 "*Integer that says how many man-related buttons Gnus will show.
7715 The higher the number, the more buttons will appear and the more false
7716 positives are possible. Note that you can set this variable local to
7717 specific groups. Setting it higher in Unix groups is probably a good idea.
7718 See Info node `(gnus)Group Parameters' and the variable `gnus-parameters' on
7719 how to set variables in specific groups."
7721 :group 'gnus-article-buttons
7722 :link '(custom-manual "(gnus)Group Parameters")
7725 (defcustom gnus-button-emacs-level 5
7726 "*Integer that says how many emacs-related buttons Gnus will show.
7727 The higher the number, the more buttons will appear and the more false
7728 positives are possible. Note that you can set this variable local to
7729 specific groups. Setting it higher in Emacs or Gnus related groups is
7730 probably a good idea. See Info node `(gnus)Group Parameters' and the variable
7731 `gnus-parameters' on how to set variables in specific groups."
7733 :group 'gnus-article-buttons
7734 :link '(custom-manual "(gnus)Group Parameters")
7737 (defcustom gnus-button-message-level 5
7738 "*Integer that says how many buttons for news or mail messages will appear.
7739 The higher the number, the more buttons will appear and the more false
7740 positives are possible."
7741 ;; mail addresses, MIDs, URLs for news, ...
7743 :group 'gnus-article-buttons
7746 (defcustom gnus-button-browse-level 5
7747 "*Integer that says how many buttons for browsing will appear.
7748 The higher the number, the more buttons will appear and the more false
7749 positives are possible."
7750 ;; stuff handled by `browse-url' or `gnus-button-embedded-url'
7752 :group 'gnus-article-buttons
7755 (defcustom gnus-button-alist
7756 '(("<\\(url:[>\n\t ]*?\\)?\\(nntp\\|news\\):[>\n\t ]*\\([^>\n\t ]*@[^>\n\t ]*\\)>"
7757 0 (>= gnus-button-message-level 0) gnus-button-handle-news 3)
7758 ((concat "\\b\\(nntp\\|news\\):\\("
7759 gnus-button-valid-localpart-regexp "@[a-z0-9.-]+[a-z]\\)")
7760 0 t gnus-button-handle-news 2)
7761 ("\\(\\b<\\(url:[>\n\t ]*\\)?\\(nntp\\|news\\):[>\n\t ]*\\(//\\)?\\([^>\n\t ]*\\)>\\)"
7762 1 (>= gnus-button-message-level 0) gnus-button-fetch-group 5)
7763 ("\\b\\(nntp\\|news\\):\\(//\\)?\\([^'\">\n\t ]+\\)"
7764 0 (>= gnus-button-message-level 0) gnus-button-fetch-group 3)
7765 ;; RFC 2392 (Don't allow `/' in domain part --> CID)
7766 ("\\bmid:\\(//\\)?\\([^'\">\n\t ]+@[^'\">\n\t /]+\\)"
7767 0 (>= gnus-button-message-level 0) gnus-button-message-id 2)
7768 ("\\bin\\( +article\\| +message\\)? +\\(<\\([^\n @<>]+@[^\n @<>]+\\)>\\)"
7769 2 (>= gnus-button-message-level 0) gnus-button-message-id 3)
7770 ("\\b\\(mid\\|message-id\\):? +\\(<\\([^\n @<>]+@[^\n @<>]+\\)>\\)"
7771 2 (>= gnus-button-message-level 0) gnus-button-message-id 3)
7772 ("\\(<URL: *\\)mailto: *\\([^> \n\t]+\\)>"
7773 0 (>= gnus-button-message-level 0) gnus-url-mailto 2)
7774 ;; RFC 2368 (The mailto URL scheme)
7775 ("\\bmailto:\\([-a-z.@_+0-9%=?&/]+\\)"
7776 0 (>= gnus-button-message-level 0) gnus-url-mailto 1)
7777 ("\\bmailto:\\([^ \n\t]+\\)"
7778 0 (>= gnus-button-message-level 0) gnus-url-mailto 1)
7779 ;; Info Konqueror style <info:/foo/bar baz>.
7780 ;; Must come before " Gnus home-grown style".
7781 ("\\binfo://?\\([^'\">\n\t]+\\)"
7782 0 (>= gnus-button-emacs-level 1) gnus-button-handle-info-url 1)
7783 ;; Info, Gnus home-grown style (deprecated) <info://foo/bar+baz>
7784 ("\\binfo://\\([^'\">\n\t ]+\\)"
7785 0 (>= gnus-button-emacs-level 1) gnus-button-handle-info-url 1)
7786 ;; Info GNOME style <info:foo#bar_baz>
7787 ("\\binfo:\\([^('\n\t\r \"><][^'\n\t\r \"><]*\\)"
7788 0 (>= gnus-button-emacs-level 1) gnus-button-handle-info-url-gnome 1)
7789 ;; Info KDE style <info:(foo)bar baz>
7790 ("<\\(info:\\(([^)]+)[^>\n\r]*\\)\\)>"
7791 1 (>= gnus-button-emacs-level 1) gnus-button-handle-info-url-kde 2)
7792 ("\\((Info-goto-node\\|(info\\)[ \t\n]*\\(\"[^\"]*\"\\))" 0
7793 (>= gnus-button-emacs-level 1) gnus-button-handle-info-url 2)
7794 ("\\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,]*\\)\\)?"
7795 ;; Info links like `C-h i d m Gnus RET' or `C-h i d m Gnus RET i partial RET'
7796 0 (>= gnus-button-emacs-level 1) gnus-button-handle-info-keystrokes 0)
7798 ("M-x[ \t\n]\\(customize-[^ ]+\\)[ \t\n]RET[ \t\n]\\([^ ]+\\)[ \t\n]RET\\>" 0
7799 (>= gnus-button-emacs-level 1) gnus-button-handle-custom 1 2)
7800 ;; Emacs help commands
7801 ("M-x[ \t\n]+apropos[ \t\n]+RET[ \t\n]+\\([^ \t\n]+\\)[ \t\n]+RET\\>"
7802 ;; regexp doesn't match arguments containing ` '.
7803 0 (>= gnus-button-emacs-level 1) gnus-button-handle-apropos 1)
7804 ("M-x[ \t\n]+apropos-command[ \t\n]+RET[ \t\n]+\\([^ \t\n]+\\)[ \t\n]+RET\\>"
7805 0 (>= gnus-button-emacs-level 1) gnus-button-handle-apropos-command 1)
7806 ("M-x[ \t\n]+apropos-variable[ \t\n]+RET[ \t\n]+\\([^ \t\n]+\\)[ \t\n]+RET\\>"
7807 0 (>= gnus-button-emacs-level 1) gnus-button-handle-apropos-variable 1)
7808 ("M-x[ \t\n]+apropos-documentation[ \t\n]+RET[ \t\n]+\\([^ \t\n]+\\)[ \t\n]+RET\\>"
7809 0 (>= gnus-button-emacs-level 1) gnus-button-handle-apropos-documentation 1)
7810 ;; The following entries may lead to many false positives so don't enable
7811 ;; them by default (use a high button level).
7812 ("/\\([a-z][-a-z0-9]+\\.el\\)\\>[^.?]"
7813 ;; Exclude [.?] for URLs in gmane.emacs.cvs
7814 1 (>= gnus-button-emacs-level 8) gnus-button-handle-library 1)
7815 ("`\\([a-z][-a-z0-9]+\\.el\\)'"
7816 1 (>= gnus-button-emacs-level 8) gnus-button-handle-library 1)
7817 ("`\\([a-z][a-z0-9]+-[a-z0-9]+-[-a-z0-9]*[a-z]\\|\\(gnus\\|message\\)-[-a-z]+\\)'"
7818 0 (>= gnus-button-emacs-level 8) gnus-button-handle-symbol 1)
7819 ("`\\([a-z][a-z0-9]+-[a-z]+\\)'"
7820 0 (>= gnus-button-emacs-level 9) gnus-button-handle-symbol 1)
7821 ("(setq[ \t\n]+\\([a-z][a-z0-9]+-[-a-z0-9]+\\)[ \t\n]+.+)"
7822 1 (>= gnus-button-emacs-level 7) gnus-button-handle-describe-variable 1)
7823 ("\\bM-x[ \t\n]+\\([^ \t\n]+\\)[ \t\n]+RET\\>"
7824 1 (>= gnus-button-emacs-level 7) gnus-button-handle-describe-function 1)
7825 ("\\b\\(C-h\\|<?[Ff]1>?\\)[ \t\n]+f[ \t\n]+\\([^ \t\n]+\\)[ \t\n]+RET\\>"
7826 0 (>= gnus-button-emacs-level 1) gnus-button-handle-describe-function 2)
7827 ("\\b\\(C-h\\|<?[Ff]1>?\\)[ \t\n]+v[ \t\n]+\\([^ \t\n]+\\)[ \t\n]+RET\\>"
7828 0 (>= gnus-button-emacs-level 1) gnus-button-handle-describe-variable 2)
7829 ("`\\(\\(C-h\\|<?[Ff]1>?\\)[ \t\n]+k[ \t\n]+\\([^']+\\)\\)'"
7830 ;; Unlike the other regexps we really have to require quoting
7831 ;; here to determine where it ends.
7832 1 (>= gnus-button-emacs-level 1) gnus-button-handle-describe-key 3)
7833 ;; This is how URLs _should_ be embedded in text (RFC 1738, RFC 2396)...
7834 ("<URL: *\\([^\n<>]*\\)>"
7835 1 (>= gnus-button-browse-level 0) gnus-button-embedded-url 1)
7836 ;; RFC 2396 (2.4.3., delims) ...
7837 ("\"URL: *\\([^\n\"]*\\)\""
7838 1 (>= gnus-button-browse-level 0) gnus-button-embedded-url 1)
7840 (gnus-button-url-regexp
7841 0 (>= gnus-button-browse-level 0) browse-url 0)
7843 ("\\b\\([a-z][a-z]+([1-9])\\)\\W"
7844 0 (and (>= gnus-button-man-level 1) (< gnus-button-man-level 3))
7845 gnus-button-handle-man 1)
7846 ;; more man pages: resolv.conf(5), iso_8859-1(7), xterm(1x)
7847 ("\\b\\([a-z][-_.a-z0-9]+([1-9])\\)\\W"
7848 0 (and (>= gnus-button-man-level 3) (< gnus-button-man-level 5))
7849 gnus-button-handle-man 1)
7850 ;; even more: Apache::PerlRun(3pm), PDL::IO::FastRaw(3pm),
7851 ;; SoWWWAnchor(3iv), XSelectInput(3X11), X(1), X(7)
7852 ("\\b\\(\\(?:[a-z][-+_.:a-z0-9]+([1-9][X1a-z]*)\\)\\|\\b\\(?:X([1-9])\\)\\)\\W"
7853 0 (>= gnus-button-man-level 5) gnus-button-handle-man 1)
7854 ;; Recognizing patches to .el files. This is somewhat obscure,
7855 ;; but considering the percentage of Gnus users who hack Emacs
7857 ("^--- \\([^ .]+\\.el\\).*\n.*\n@@ -?\\([0-9]+\\)" 1
7858 (>= gnus-button-message-level 4) gnus-button-patch 1 2)
7859 ("^\\*\\*\\* \\([^ .]+\\.el\\).*\n.*\n\\*+\n\\*\\*\\* \\([0-9]+\\)" 1
7860 (>= gnus-button-message-level 4) gnus-button-patch 1 2)
7861 ;; MID or mail: To avoid too many false positives we don't try to catch
7862 ;; all kind of allowed MIDs or mail addresses. Domain part must contain
7863 ;; at least one dot. TLD must contain two or three chars or be a know TLD
7864 ;; (info|name|...). Put this entry near the _end_ of `gnus-button-alist'
7865 ;; so that non-ambiguous entries (see above) match first.
7866 (gnus-button-mid-or-mail-regexp
7867 0 (>= gnus-button-message-level 5) gnus-button-handle-mid-or-mail 1))
7868 "*Alist of regexps matching buttons in article bodies.
7870 Each entry has the form (REGEXP BUTTON FORM CALLBACK PAR...), where
7871 REGEXP: is the string (case insensitive) matching text around the button (can
7872 also be Lisp expression evaluating to a string),
7873 BUTTON: is the number of the regexp grouping actually matching the button,
7874 FORM: is a Lisp expression which must eval to true for the button to
7876 CALLBACK: is the function to call when the user push this button, and each
7877 PAR: is a number of a regexp grouping whose text will be passed to CALLBACK.
7879 CALLBACK can also be a variable, in that case the value of that
7880 variable it the real callback function."
7881 :group 'gnus-article-buttons
7882 :type '(repeat (list (choice regexp variable sexp)
7883 (integer :tag "Button")
7885 (function :tag "Callback")
7888 (integer :tag "Regexp group")))))
7889 (put 'gnus-button-alist 'risky-local-variable t)
7891 (defcustom gnus-header-button-alist
7892 '(("^\\(References\\|Message-I[Dd]\\|^In-Reply-To\\):" "<[^<>]+>"
7893 0 (>= gnus-button-message-level 0) gnus-button-message-id 0)
7894 ("^\\(From\\|Reply-To\\):" ": *\\(.+\\)$"
7895 1 (>= gnus-button-message-level 0) gnus-button-reply 1)
7896 ("^\\(Cc\\|To\\):" "[^ \t\n<>,()\"]+@[^ \t\n<>,()\"]+"
7897 0 (>= gnus-button-message-level 0) gnus-msg-mail 0)
7898 ("^X-[Uu][Rr][Ll]:" gnus-button-url-regexp
7899 0 (>= gnus-button-browse-level 0) browse-url 0)
7900 ("^Subject:" gnus-button-url-regexp
7901 0 (>= gnus-button-browse-level 0) browse-url 0)
7902 ("^[^:]+:" gnus-button-url-regexp
7903 0 (>= gnus-button-browse-level 0) browse-url 0)
7904 ("^OpenPGP:.*url=" gnus-button-url-regexp
7905 0 (>= gnus-button-browse-level 0) gnus-button-openpgp 0)
7906 ("^[^:]+:" "\\bmailto:\\([-a-z.@_+0-9%=?&/]+\\)"
7907 0 (>= gnus-button-message-level 0) gnus-url-mailto 1)
7908 ("^[^:]+:" "\\(<\\(url: \\)?\\(nntp\\|news\\):\\([^>\n ]*\\)>\\)"
7909 1 (>= gnus-button-message-level 0) gnus-button-message-id 4))
7910 "*Alist of headers and regexps to match buttons in article heads.
7912 This alist is very similar to `gnus-button-alist', except that each
7913 alist has an additional HEADER element first in each entry:
7915 \(HEADER REGEXP BUTTON FORM CALLBACK PAR)
7917 HEADER is a regexp to match a header. For a fuller explanation, see
7918 `gnus-button-alist'."
7919 :group 'gnus-article-buttons
7920 :group 'gnus-article-headers
7921 :type '(repeat (list (regexp :tag "Header")
7922 (choice regexp variable)
7923 (integer :tag "Button")
7925 (function :tag "Callback")
7928 (integer :tag "Regexp group")))))
7929 (put 'gnus-header-button-alist 'risky-local-variable t)
7933 (defun gnus-article-push-button (event)
7934 "Check text under the mouse pointer for a callback function.
7935 If the text under the mouse pointer has a `gnus-callback' property,
7936 call it with the value of the `gnus-data' text property."
7938 (set-buffer (window-buffer (posn-window (event-start event))))
7939 (let* ((pos (posn-point (event-start event)))
7940 (data (get-text-property pos 'gnus-data))
7941 (fun (get-text-property pos 'gnus-callback)))
7944 (funcall fun data))))
7946 (defun gnus-article-press-button ()
7947 "Check text at point for a callback function.
7948 If the text at point has a `gnus-callback' property,
7949 call it with the value of the `gnus-data' text property."
7951 (let ((data (get-text-property (point) 'gnus-data))
7952 (fun (get-text-property (point) 'gnus-callback)))
7954 (funcall fun data))))
7956 (defun gnus-article-highlight (&optional force)
7957 "Highlight current article.
7958 This function calls `gnus-article-highlight-headers',
7959 `gnus-article-highlight-citation',
7960 `gnus-article-highlight-signature', and `gnus-article-add-buttons' to
7961 do the highlighting. See the documentation for those functions."
7962 (interactive (list 'force))
7963 (gnus-article-highlight-headers)
7964 (gnus-article-highlight-citation force)
7965 (gnus-article-highlight-signature)
7966 (gnus-article-add-buttons)
7967 (gnus-article-add-buttons-to-head))
7969 (defun gnus-article-highlight-some (&optional force)
7970 "Highlight current article.
7971 This function calls `gnus-article-highlight-headers',
7972 `gnus-article-highlight-signature', and `gnus-article-add-buttons' to
7973 do the highlighting. See the documentation for those functions."
7974 (interactive (list 'force))
7975 (gnus-article-highlight-headers)
7976 (gnus-article-highlight-signature)
7977 (gnus-article-add-buttons))
7979 (defun gnus-article-highlight-headers ()
7980 "Highlight article headers as specified by `gnus-header-face-alist'."
7982 (gnus-with-article-headers
7983 (let (regexp header-face field-face from hpoints fpoints)
7984 (dolist (entry gnus-header-face-alist)
7985 (goto-char (point-min))
7986 (setq regexp (concat "^\\("
7987 (if (string-equal "" (nth 0 entry))
7991 header-face (nth 1 entry)
7992 field-face (nth 2 entry))
7993 (while (and (re-search-forward regexp nil t)
7997 (unless (search-forward ":" nil t)
7999 (when (and header-face
8000 (not (memq (point) hpoints)))
8001 (push (point) hpoints)
8002 (gnus-put-text-property from (point) 'face header-face))
8003 (when (and field-face
8004 (not (memq (setq from (point)) fpoints)))
8006 (if (re-search-forward "^[^ \t]" nil t)
8008 (goto-char (point-max)))
8009 (gnus-put-text-property from (point) 'face field-face)))))))
8011 (defun gnus-article-highlight-signature ()
8012 "Highlight the signature in an article.
8013 It does this by highlighting everything after
8014 `gnus-signature-separator' using the face `gnus-signature'."
8016 (gnus-with-article-buffer
8017 (let ((inhibit-point-motion-hooks t))
8019 (when (and gnus-signature-face
8020 (gnus-article-narrow-to-signature))
8021 (gnus-overlay-put (gnus-make-overlay (point-min) (point-max) nil t)
8022 'face gnus-signature-face)
8024 (gnus-article-search-signature)
8025 (let ((start (match-beginning 0))
8026 (end (set-marker (make-marker) (1+ (match-end 0)))))
8027 (gnus-article-add-button start (1- end) 'gnus-signature-toggle
8030 (defun gnus-button-in-region-p (b e prop)
8031 "Say whether PROP exists in the region."
8032 (text-property-not-all b e prop nil))
8034 (defun gnus-article-add-buttons ()
8035 "Find external references in the article and make buttons of them.
8036 \"External references\" are things like Message-IDs and URLs, as
8037 specified by `gnus-button-alist'."
8039 (gnus-with-article-buffer
8040 (let ((inhibit-point-motion-hooks t)
8041 (case-fold-search t)
8042 (alist gnus-button-alist)
8044 ;; We skip the headers.
8047 (while (setq entry (pop alist))
8048 (setq regexp (eval (car entry)))
8050 (while (re-search-forward regexp nil t)
8051 (let ((start (match-beginning (nth 1 entry)))
8052 (end (match-end (nth 1 entry)))
8053 (from (match-beginning 0)))
8054 (when (and (eval (nth 2 entry))
8055 (not (gnus-button-in-region-p
8056 start end 'gnus-callback)))
8057 ;; That optional form returned non-nil, so we add the
8059 (setq from (set-marker (make-marker) from))
8060 (unless (and (eq (car entry) 'gnus-button-url-regexp)
8061 (gnus-article-extend-url-button from start end))
8062 (gnus-article-add-button start end
8063 'gnus-button-push (list from entry))
8064 (gnus-put-text-property
8066 'gnus-string (buffer-substring-no-properties
8069 (defun gnus-article-extend-url-button (beg start end)
8070 "Extend url button if url is folded into two or more lines.
8071 Return non-nil if button is extended. BEG is a marker that points to
8072 the beginning position of a text containing url. START and END are
8073 the endpoints of a url button before it is extended. The concatenated
8074 url is put as the `gnus-button-url' overlay property on the button."
8075 (let ((opoint (point))
8076 (points (list start end))
8081 (not (looking-at "[\t ]*[\">]")))
8085 "\\(?:\"\\|\\(<\\)\\)[\t ]*\\(?:url[\t ]*:[\t ]*\\)?\\'"
8086 (buffer-substring (point-at-bol) start)))
8088 (setq url (list (buffer-substring start end))
8089 delim (if (match-beginning 1) ">" "\""))
8091 (setq regexp (concat
8092 (when (and (looking-at
8093 message-cite-prefix-regexp)
8094 (< (match-end 0) start))
8095 (regexp-quote (match-string 0)))
8097 \[\t ]*\\(?:\\([^\t\n \">]+\\)[\t ]*$\\|\\([^\t\n \">]*\\)[\t ]*"
8101 (and (looking-at regexp)
8104 (push (or (match-string 2)
8107 (push (setq end (or (match-end 2)
8110 (push (or (match-beginning 2)
8111 (match-beginning 1))
8113 (match-beginning 2)))
8114 (let (gnus-article-mouse-face widget-mouse-face)
8116 (gnus-article-add-button (pop points) (pop points)
8118 (list beg (assq 'gnus-button-url-regexp
8119 gnus-button-alist)))))
8120 (let ((overlay (gnus-make-overlay start end)))
8121 (gnus-overlay-put overlay 'evaporate t)
8122 (gnus-overlay-put overlay 'gnus-button-url
8123 (list (mapconcat 'identity (nreverse url) "")))
8124 (when gnus-article-mouse-face
8125 (gnus-overlay-put overlay 'mouse-face gnus-article-mouse-face)))
8127 (goto-char opoint))))
8129 ;; Add buttons to the head of an article.
8130 (defun gnus-article-add-buttons-to-head ()
8131 "Add buttons to the head of the article."
8133 (gnus-with-article-headers
8135 (dolist (entry gnus-header-button-alist)
8136 ;; Each alist entry.
8137 (goto-char (point-min))
8138 (while (re-search-forward (car entry) nil t)
8139 ;; Each header matching the entry.
8140 (setq beg (match-beginning 0))
8141 (setq end (or (and (re-search-forward "^[^ \t]" nil t)
8142 (match-beginning 0))
8145 (while (re-search-forward (eval (nth 1 entry)) end t)
8146 ;; Each match within a header.
8147 (let* ((entry (cdr entry))
8148 (start (match-beginning (nth 1 entry)))
8149 (end (match-end (nth 1 entry)))
8150 (form (nth 2 entry)))
8151 (goto-char (match-end 0))
8153 (gnus-article-add-button
8154 start end (nth 3 entry)
8155 (buffer-substring (match-beginning (nth 4 entry))
8156 (match-end (nth 4 entry)))))))
8157 (goto-char end))))))
8159 ;;; External functions:
8161 (defun gnus-article-add-button (from to fun &optional data text)
8162 "Create a button between FROM and TO with callback FUN and data DATA."
8163 (when gnus-article-button-face
8164 (gnus-overlay-put (gnus-make-overlay from to nil t)
8165 'face gnus-article-button-face))
8166 (gnus-add-text-properties
8168 (nconc (and gnus-article-mouse-face
8169 (list gnus-mouse-face-prop gnus-article-mouse-face))
8170 (list 'gnus-callback fun)
8171 (and data (list 'gnus-data data))))
8172 (widget-convert-button 'link from to :action 'gnus-widget-press-button
8173 :help-echo (or text "Follow the link")
8174 :keymap gnus-url-button-map
8175 :button-keymap gnus-widget-button-keymap))
8177 (defun gnus-article-copy-string ()
8178 "Copy the string in the button to the kill ring."
8180 (gnus-article-check-buffer)
8181 (let ((data (get-text-property (point) 'gnus-string)))
8185 (copy-region-as-kill (point-min) (point-max))
8186 (message "Copied %s" data)))))
8188 ;;; Internal functions:
8190 (defun gnus-article-set-globals ()
8191 (with-current-buffer gnus-summary-buffer
8192 (gnus-set-global-variables)))
8194 (defun gnus-signature-toggle (end)
8195 (gnus-with-article-buffer
8196 (let ((inhibit-point-motion-hooks t))
8197 (if (text-property-any end (point-max) 'article-type 'signature)
8199 (gnus-delete-wash-type 'signature)
8200 (gnus-remove-text-properties-when
8201 'article-type 'signature end (point-max)
8202 (cons 'article-type (cons 'signature
8203 gnus-hidden-properties))))
8204 (gnus-add-wash-type 'signature)
8205 (gnus-add-text-properties-when
8206 'article-type nil end (point-max)
8207 (cons 'article-type (cons 'signature
8208 gnus-hidden-properties)))))
8209 (let ((gnus-article-mime-handle-alist-1 gnus-article-mime-handle-alist))
8210 (gnus-set-mode-line 'article))))
8212 (defun gnus-button-push (marker-and-entry)
8213 ;; Push button starting at MARKER.
8215 (let* ((marker (car marker-and-entry))
8216 (entry (cadr marker-and-entry))
8217 (regexp (car entry))
8218 (inhibit-point-motion-hooks t))
8220 ;; This is obviously true, or something bad is happening :)
8221 ;; But we need it to have the match-data
8222 (when (looking-at (or (if (symbolp regexp)
8223 (symbol-value regexp)
8225 (let ((fun (nth 3 entry))
8226 (args (or (and (eq (car entry) 'gnus-button-url-regexp)
8227 (get-char-property marker 'gnus-button-url))
8228 (mapcar (lambda (group)
8229 (let ((string (match-string group)))
8230 (set-text-properties
8231 0 (length string) nil string)
8233 (nthcdr 4 entry)))))
8239 (fboundp (symbol-value fun)))
8240 (apply (symbol-value fun) args))
8242 (gnus-message 1 "You must define `%S' to use this button"
8243 (cons fun args)))))))))
8245 (defun gnus-parse-news-url (url)
8246 (let (scheme server port group message-id articles)
8249 (goto-char (point-min))
8250 (when (looking-at "\\([A-Za-z]+\\):")
8251 (setq scheme (match-string 1))
8252 (goto-char (match-end 0)))
8253 (when (looking-at "//\\([^:/]+\\)\\(:?\\)\\([0-9]+\\)?/")
8254 (setq server (match-string 1))
8255 (setq port (if (stringp (match-string 3))
8256 (string-to-number (match-string 3))
8258 (goto-char (match-end 0)))
8261 ((looking-at "\\(.*@.*\\)")
8262 (setq message-id (match-string 1)))
8263 ((looking-at "\\([^/]+\\)/\\([-0-9]+\\)")
8264 (setq group (match-string 1)
8265 articles (split-string (match-string 2) "-")))
8266 ((looking-at "\\([^/]+\\)/?")
8267 (setq group (match-string 1)))
8269 (error "Unknown news URL syntax"))))
8270 (list scheme server port group message-id articles)))
8272 (defun gnus-button-handle-news (url)
8274 (destructuring-bind (scheme server port group message-id articles)
8275 (gnus-parse-news-url url)
8278 (with-current-buffer gnus-summary-buffer
8280 (let ((gnus-refer-article-method
8281 (nconc (list (list 'nntp server))
8282 gnus-refer-article-method))
8283 (nntp-port-number (or port "nntp")))
8284 (gnus-message 7 "Fetching %s with %s"
8285 message-id gnus-refer-article-method)
8286 (gnus-summary-refer-article message-id))
8287 (gnus-summary-refer-article message-id))))
8289 (gnus-button-fetch-group url)))))
8291 (defun gnus-button-patch (library line)
8292 "Visit an Emacs Lisp library LIBRARY on line LINE."
8294 (let ((file (locate-library (file-name-nondirectory library))))
8296 (error "Couldn't find library %s" library))
8298 (goto-char (point-min))
8299 (forward-line (1- (string-to-number line)))))
8301 (defun gnus-button-handle-man (url)
8303 (gnus-message 9 "`%s' `%s'" gnus-button-man-handler url)
8304 (when (eq gnus-button-man-handler 'woman)
8305 (setq url (gnus-replace-in-string url "([1-9][X1a-z]*).*\\'" "")))
8306 (gnus-message 9 "`%s' `%s'" gnus-button-man-handler url)
8307 (funcall gnus-button-man-handler url))
8309 (defun gnus-button-handle-info-url (url)
8310 "Fetch an info URL."
8311 (setq url (mm-subst-char-in-string ?+ ?\ url))
8313 ((string-match "^\\([^:/]+\\)?/\\(.*\\)" url)
8314 (gnus-info-find-node
8315 (concat "(" (or (gnus-url-unhex-string (match-string 1 url))
8317 ")" (gnus-url-unhex-string (match-string 2 url)))))
8318 ((string-match "([^)\"]+)[^\"]+" url)
8320 (gnus-replace-in-string
8321 (gnus-replace-in-string url "[\n\t ]+" " ") "\"" ""))
8322 (gnus-info-find-node url))
8323 (t (error "Can't parse %s" url))))
8325 (defun gnus-button-handle-info-url-gnome (url)
8326 "Fetch GNOME style info URL."
8327 (setq url (mm-subst-char-in-string ?_ ?\ url))
8328 (if (string-match "\\([^#]+\\)#?\\(.*\\)" url)
8329 (gnus-info-find-node
8331 (gnus-url-unhex-string
8332 (match-string 1 url))
8334 (or (gnus-url-unhex-string
8335 (match-string 2 url))
8337 (error "Can't parse %s" url)))
8339 (defun gnus-button-handle-info-url-kde (url)
8340 "Fetch KDE style info URL."
8341 (gnus-info-find-node (gnus-url-unhex-string url)))
8343 ;; (info) will autoload info.el
8344 (declare-function Info-menu "info" (menu-item &optional fork))
8345 (declare-function Info-index-next "info" (num))
8347 (defun gnus-button-handle-info-keystrokes (url)
8348 "Call `info' when pushing the corresponding URL button."
8349 ;; For links like `C-h i d m gnus RET part RET , ,', `C-h i d m CC Mode RET'.
8350 (let (node indx comma)
8352 (concat "\\b\\(C-h\\|<?[Ff]1>?\\)[ \t\n]+i[ \t\n]+d?[ \t\n]?m[ \t\n]+"
8353 "\\([^ ]+ ?[^ ]+\\)[ \t\n]+RET"
8354 "\\([ \t\n]+i[ \t\n]+[^ ]+ ?[^ ]+[ \t\n]+RET\\>"
8355 "\\(?:[ \t\n,]*\\)\\)?")
8357 (setq node (match-string 2 url)
8358 indx (match-string 3 url))
8359 (error "Can't parse %s" url))
8363 (when (> (length indx) 0)
8364 (string-match (concat "[ \t\n]+i[ \t\n]+\\([^ ]+ ?[^ ]+\\)[ \t\n]+RET\\>"
8367 (setq comma (match-string 2 indx))
8368 (setq indx (match-string 1 indx))
8371 (dotimes (i (with-temp-buffer
8373 ;; Note: the XEmacs version of `how-many' takes
8374 ;; no optional argument.
8375 (goto-char (point-min))
8377 (Info-index-next 1)))
8380 (autoload 'pgg-snarf-keys-region "pgg")
8381 ;; Called after pgg-snarf-keys-region, which autoloads pgg.el.
8382 (declare-function pgg-display-output-buffer "pgg" (start end status))
8384 (defun gnus-button-openpgp (url)
8385 "Retrieve and add an OpenPGP key given URL from an OpenPGP header."
8387 (mm-url-insert-file-contents-external url)
8388 (pgg-snarf-keys-region (point-min) (point-max))
8389 (pgg-display-output-buffer nil nil nil)))
8391 (defun gnus-button-message-id (message-id)
8393 (with-current-buffer gnus-summary-buffer
8394 (gnus-summary-refer-article message-id)))
8396 (defun gnus-button-fetch-group (address &rest ignore)
8397 "Fetch GROUP specified by ADDRESS."
8398 (when (string-match "\\`\\(nntp\\|news\\):\\(//\\)?\\(.*\\)\\'"
8400 ;; Allow to use `gnus-button-fetch-group' in `browse-url-browser-function'
8401 ;; for nntp:// and news://
8402 (setq address (match-string 3 address)))
8403 (if (not (string-match "[:/]" address))
8404 ;; This is just a simple group url.
8405 (gnus-group-read-ephemeral-group address gnus-select-method)
8408 "^\\([^:/]+\\)\\(:\\([^/]+\\)\\)?/\\([^/]+\\)\\(/\\([0-9]+\\)\\)?"
8410 (error "Can't parse %s" address)
8411 (gnus-group-read-ephemeral-group
8412 (match-string 4 address)
8413 `(nntp ,(match-string 1 address)
8414 (nntp-address ,(match-string 1 address))
8415 (nntp-port-number ,(if (match-end 3)
8416 (match-string 3 address)
8419 (and (match-end 6) (list (string-to-number (match-string 6 address))))))))
8421 (defun gnus-url-parse-query-string (query &optional downcase)
8422 (let (retval pairs cur key val)
8423 (setq pairs (split-string query "&"))
8425 (setq cur (car pairs)
8427 (if (not (string-match "=" cur))
8429 (setq key (gnus-url-unhex-string (substring cur 0 (match-beginning 0)))
8430 val (gnus-url-unhex-string (substring cur (match-end 0) nil) t))
8432 (setq key (downcase key)))
8433 (setq cur (assoc key retval))
8435 (setcdr cur (cons val (cdr cur)))
8436 (setq retval (cons (list key val) retval)))))
8439 (defun gnus-url-mailto (url)
8440 ;; Send mail to someone
8441 (setq url (replace-regexp-in-string "\n" " " url))
8442 (when (string-match "mailto:/*\\(.*\\)" url)
8443 (setq url (substring url (match-beginning 1) nil)))
8444 (let (to args subject func)
8445 (setq args (gnus-url-parse-query-string
8446 (if (string-match "^\\?" url)
8448 (if (string-match "^\\([^?]+\\)\\?\\(.*\\)" url)
8449 (concat "to=" (match-string 1 url) "&"
8450 (match-string 2 url))
8451 (concat "to=" url))))
8452 subject (cdr-safe (assoc "subject" args)))
8455 (setq func (intern-soft (concat "message-goto-" (downcase (caar args)))))
8458 (message-position-on-field (caar args)))
8459 (insert (gnus-replace-in-string
8460 (mapconcat 'identity (reverse (cdar args)) ", ")
8462 (setq args (cdr args)))
8465 (message-goto-subject))))
8467 (defun gnus-button-embedded-url (address)
8468 "Activate ADDRESS with `browse-url'."
8469 (browse-url (gnus-strip-whitespace address)))
8471 ;;; Next/prev buttons in the article buffer.
8473 (defvar gnus-next-page-line-format "%{%(Next page...%)%}\n")
8474 (defvar gnus-prev-page-line-format "%{%(Previous page...%)%}\n")
8476 (defvar gnus-prev-page-map
8477 (let ((map (make-sparse-keymap)))
8478 (define-key map gnus-mouse-2 'gnus-button-prev-page)
8479 (define-key map "\r" 'gnus-button-prev-page)
8482 (defvar gnus-next-page-map
8483 (let ((map (make-sparse-keymap)))
8484 (define-key map gnus-mouse-2 'gnus-button-next-page)
8485 (define-key map "\r" 'gnus-button-next-page)
8488 (defun gnus-insert-prev-page-button ()
8490 (inhibit-read-only t))
8492 gnus-prev-page-line-format nil
8493 `(keymap ,gnus-prev-page-map
8495 gnus-callback gnus-article-button-prev-page
8496 article-type annotation))
8498 ;; Exclude a newline.
8501 (when gnus-article-button-face
8502 (gnus-overlay-put (gnus-make-overlay b e nil t)
8503 'face gnus-article-button-face))
8504 (widget-convert-button
8506 :action 'gnus-button-prev-page
8507 :button-keymap gnus-prev-page-map)))
8509 (defun gnus-button-next-page (&optional args more-args)
8510 "Go to the next page."
8512 (let ((win (selected-window)))
8513 (select-window (gnus-get-buffer-window gnus-article-buffer t))
8514 (gnus-article-next-page)
8515 (select-window win)))
8517 (defun gnus-button-prev-page (&optional args more-args)
8518 "Go to the prev page."
8520 (let ((win (selected-window)))
8521 (select-window (gnus-get-buffer-window gnus-article-buffer t))
8522 (gnus-article-prev-page)
8523 (select-window win)))
8525 (defun gnus-insert-next-page-button ()
8527 (inhibit-read-only t))
8528 (gnus-eval-format gnus-next-page-line-format nil
8529 `(keymap ,gnus-next-page-map
8531 gnus-callback gnus-article-button-next-page
8532 article-type annotation))
8534 ;; Exclude a newline.
8537 (when gnus-article-button-face
8538 (gnus-overlay-put (gnus-make-overlay b e nil t)
8539 'face gnus-article-button-face))
8540 (widget-convert-button
8542 :action 'gnus-button-next-page
8543 :button-keymap gnus-next-page-map)))
8545 (defun gnus-article-button-next-page (arg)
8546 "Go to the next page."
8548 (let ((win (selected-window)))
8549 (select-window (gnus-get-buffer-window gnus-article-buffer t))
8550 (gnus-article-next-page)
8551 (select-window win)))
8553 (defun gnus-article-button-prev-page (arg)
8554 "Go to the prev page."
8556 (let ((win (selected-window)))
8557 (select-window (gnus-get-buffer-window gnus-article-buffer t))
8558 (gnus-article-prev-page)
8559 (select-window win)))
8561 (defvar gnus-decode-header-methods
8562 '(mail-decode-encoded-word-region)
8563 "List of methods used to decode headers.
8565 This variable is a list of FUNCTION or (REGEXP . FUNCTION). If item
8566 is FUNCTION, FUNCTION will be applied to all newsgroups. If item is a
8567 \(REGEXP . FUNCTION), FUNCTION will be only apply to the newsgroups
8568 whose names match REGEXP.
8571 \((\"chinese\" . gnus-decode-encoded-word-region-by-guess)
8572 mail-decode-encoded-word-region
8573 (\"chinese\" . rfc1843-decode-region))
8576 (defvar gnus-decode-header-methods-cache nil)
8578 (defun gnus-multi-decode-header (start end)
8579 "Apply the functions from `gnus-encoded-word-methods' that match."
8580 (unless (and gnus-decode-header-methods-cache
8581 (eq gnus-newsgroup-name
8582 (car gnus-decode-header-methods-cache)))
8583 (setq gnus-decode-header-methods-cache (list gnus-newsgroup-name))
8584 (dolist (x gnus-decode-header-methods)
8586 (nconc gnus-decode-header-methods-cache (list x))
8587 (if (and gnus-newsgroup-name
8588 (string-match (car x) gnus-newsgroup-name))
8589 (nconc gnus-decode-header-methods-cache
8591 (let ((xlist gnus-decode-header-methods-cache))
8594 (narrow-to-region start end)
8596 (funcall (pop xlist) (point-min) (point-max))))))
8599 ;;; Treatment top-level handling.
8602 (defvar gnus-inhibit-article-treatments nil)
8604 (defun gnus-treat-article (gnus-treat-condition
8605 &optional part-number total-parts gnus-treat-type)
8606 (let ((gnus-treat-length (- (point-max) (point-min)))
8607 (alist gnus-treatment-function-alist)
8608 (article-goto-body-goes-to-point-min-p t)
8610 (or (not gnus-treat-type)
8612 (let ((list gnus-article-treat-types))
8614 (when (string-match (pop list) gnus-treat-type)
8615 (throw 'found t)))))))
8616 (highlightp (gnus-visual-p 'article-highlight 'highlight))
8618 (gnus-run-hooks 'gnus-part-display-hook)
8619 (dolist (elem alist)
8622 (when (gnus-buffer-live-p gnus-summary-buffer)
8623 (set-buffer gnus-summary-buffer))
8624 (symbol-value (car elem))))
8625 (when (and (or (consp val)
8627 (or (not gnus-inhibit-article-treatments)
8628 (eq gnus-treat-condition 'head))
8629 (gnus-treat-predicate val)
8630 (or (not (get (car elem) 'highlight))
8633 (funcall (cadr elem)))))))
8635 ;; Dynamic variables.
8636 (defvar part-number)
8637 (defvar total-parts)
8638 (defvar gnus-treat-type)
8639 (defvar gnus-treat-condition)
8640 (defvar gnus-treat-length)
8642 (defun gnus-treat-predicate (val)
8646 (gnus-treat-condition
8647 (eq gnus-treat-condition val))
8649 (stringp (car val)))
8650 (apply 'gnus-or (mapcar `(lambda (s)
8651 (string-match s ,(or gnus-newsgroup-name "")))
8654 (let ((pred (pop val)))
8657 (apply 'gnus-or (mapcar 'gnus-treat-predicate val)))
8659 (apply 'gnus-and (mapcar 'gnus-treat-predicate val)))
8661 (not (gnus-treat-predicate (car val))))
8663 (equal (car val) gnus-treat-type))
8667 (error "%S is not a valid predicate" pred)))))
8675 (eq part-number total-parts))
8677 (< gnus-treat-length val))
8679 (error "%S is not a valid value" val))))
8681 (defun gnus-article-encrypt-body (protocol &optional n)
8682 "Encrypt the article body."
8685 (or gnus-article-encrypt-protocol
8686 (gnus-completing-read "Encrypt protocol"
8687 (mapcar 'car gnus-article-encrypt-protocol-alist)
8689 current-prefix-arg))
8690 ;; User might hit `K E' instead of `K e', so prompt once.
8691 (when (and gnus-article-encrypt-protocol
8693 (unless (gnus-y-or-n-p "Really encrypt article(s)? ")
8694 (error "Encrypt aborted")))
8695 (let ((func (cdr (assoc protocol gnus-article-encrypt-protocol-alist))))
8697 (error "Can't find the encrypt protocol %s" protocol))
8698 (if (member gnus-newsgroup-name '("nndraft:delayed"
8701 (error "Can't encrypt the article in group %s"
8702 gnus-newsgroup-name))
8703 (gnus-summary-iterate n
8704 (with-current-buffer gnus-summary-buffer
8705 (let ((mail-parse-charset gnus-newsgroup-charset)
8706 (mail-parse-ignored-charsets gnus-newsgroup-ignored-charsets)
8707 (summary-buffer gnus-summary-buffer)
8709 (gnus-set-global-variables)
8710 (when (gnus-group-read-only-p)
8711 (error "The current newsgroup does not support article encrypt"))
8712 (gnus-summary-show-article t)
8714 (or (mail-header-references gnus-current-headers) ""))
8715 (set-buffer gnus-article-buffer)
8716 (let* ((inhibit-read-only t)
8718 (mapcar (lambda (field)
8719 (and (save-restriction
8720 (message-narrow-to-head)
8721 (goto-char (point-min))
8722 (search-forward field nil t))
8724 (message-narrow-to-field)
8726 (delete-region (point-min) (point-max))
8728 '("Content-Type:" "Content-Transfer-Encoding:"
8729 "Content-Disposition:"))))
8730 (message-narrow-to-head)
8731 (message-remove-header "MIME-Version")
8732 (goto-char (point-max))
8733 (setq point (point))
8734 (insert (apply 'concat headers))
8736 (narrow-to-region point (point-max))
8737 (let ((message-options message-options))
8738 (message-options-set 'message-sender user-mail-address)
8739 (message-options-set 'message-recipients user-mail-address)
8740 (message-options-set 'message-sign-encrypt 'not)
8742 (goto-char (point-min))
8743 (insert "MIME-Version: 1.0\n")
8745 (gnus-summary-edit-article-done
8746 references nil summary-buffer t))
8747 (when gnus-keep-backlog
8748 (gnus-backlog-remove-article
8749 (car gnus-article-current) (cdr gnus-article-current)))
8750 (gnus-flush-original-article-buffer)
8751 (when gnus-use-cache
8752 (gnus-cache-update-article
8753 (car gnus-article-current) (cdr gnus-article-current))))))))
8755 (defvar gnus-mime-security-button-line-format "%{%([[%t:%i]%D]%)%}\n"
8756 "The following specs can be used:
8757 %t The security MIME type
8760 %D Details if button is pressed")
8762 (defvar gnus-mime-security-button-end-line-format "%{%([[End of %t]%D]%)%}\n"
8763 "The following specs can be used:
8764 %t The security MIME type
8767 %D Details if button is pressed")
8769 (defvar gnus-mime-security-button-line-format-alist
8770 '((?t gnus-tmp-type ?s)
8771 (?i gnus-tmp-info ?s)
8772 (?d gnus-tmp-details ?s)
8773 (?D gnus-tmp-pressed-details ?s)))
8775 (defvar gnus-mime-security-button-commands
8776 '((gnus-article-press-button "\r" "Show Detail")
8780 (gnus-mime-security-save-part "o" "Save...")
8789 (gnus-mime-security-pipe-part "|" "Pipe To Command...")
8792 (defvar gnus-mime-security-button-map
8793 (let ((map (make-sparse-keymap)))
8794 (define-key map gnus-mouse-2 'gnus-article-push-button)
8795 (define-key map gnus-down-mouse-3 'gnus-mime-security-button-menu)
8796 (dolist (c gnus-mime-security-button-commands)
8797 (define-key map (cadr c) (car c)))
8801 gnus-mime-security-button-menu gnus-mime-security-button-map
8802 "Security button menu."
8806 (unless (eq (car c) 'undefined)
8807 (vector (caddr c) (car c) :active t)))
8808 gnus-mime-security-button-commands))))
8810 (defun gnus-mime-security-button-menu (event prefix)
8811 "Construct a context-sensitive menu of security commands."
8812 (interactive "e\nP")
8813 (save-window-excursion
8814 (let ((pos (event-start event)))
8815 (select-window (posn-window pos))
8816 (goto-char (posn-point pos))
8817 (gnus-article-check-buffer)
8818 (popup-menu gnus-mime-security-button-menu nil prefix))))
8820 (defvar gnus-mime-security-details-buffer nil)
8822 (defvar gnus-mime-security-button-pressed nil)
8824 (defvar gnus-mime-security-show-details-inline t
8825 "If non-nil, show details in the article buffer.")
8827 (defun gnus-mime-security-verify-or-decrypt (handle)
8828 (mm-remove-parts (cdr handle))
8829 (let ((region (mm-handle-multipart-ctl-parameter handle 'gnus-region))
8830 point (inhibit-read-only t))
8832 (goto-char (car region)))
8833 (setq point (point))
8834 (with-current-buffer (mm-handle-multipart-original-buffer handle)
8835 (let* ((mm-verify-option 'known)
8836 (mm-decrypt-option 'known)
8837 (nparts (mm-possibly-verify-or-decrypt (cdr handle) handle)))
8838 (unless (eq nparts (cdr handle))
8839 (mm-destroy-parts (cdr handle))
8840 (setcdr handle nparts))))
8841 (gnus-mime-display-security handle)
8843 (delete-region (point) (cdr region))
8844 (set-marker (car region) nil)
8845 (set-marker (cdr region) nil))
8848 (defun gnus-mime-security-show-details (handle)
8849 (let ((details (mm-handle-multipart-ctl-parameter handle 'gnus-details)))
8851 (gnus-message 5 "No details.")
8852 (if gnus-mime-security-show-details-inline
8853 (let ((gnus-mime-security-button-pressed
8854 (not (get-text-property (point) 'gnus-mime-details)))
8855 (gnus-mime-security-button-line-format
8856 (get-text-property (point) 'gnus-line-format))
8857 (inhibit-read-only t))
8859 (while (eq (get-text-property (point) 'gnus-line-format)
8860 gnus-mime-security-button-line-format)
8864 (narrow-to-region (point) (point))
8865 (gnus-insert-mime-security-button handle))
8866 (delete-region (point)
8867 (or (text-property-not-all
8870 gnus-mime-security-button-line-format)
8873 (if (gnus-buffer-live-p gnus-mime-security-details-buffer)
8874 (with-current-buffer gnus-mime-security-details-buffer
8877 (setq gnus-mime-security-details-buffer
8878 (gnus-get-buffer-create "*MIME Security Details*")))
8879 (with-current-buffer gnus-mime-security-details-buffer
8881 (goto-char (point-min)))
8882 (pop-to-buffer gnus-mime-security-details-buffer)))))
8884 (defun gnus-mime-security-press-button (handle)
8886 (if (mm-handle-multipart-ctl-parameter handle 'gnus-info)
8887 (gnus-mime-security-show-details handle)
8888 (gnus-mime-security-verify-or-decrypt handle))))
8890 (defun gnus-insert-mime-security-button (handle &optional displayed)
8891 (let* ((protocol (mm-handle-multipart-ctl-parameter handle 'protocol))
8894 (or (nth 2 (assoc protocol mm-verify-function-alist))
8895 (nth 2 (assoc protocol mm-decrypt-function-alist))
8897 (if (equal (car handle) "multipart/signed")
8898 " Signed" " Encrypted")
8901 (or (mm-handle-multipart-ctl-parameter handle 'gnus-info)
8904 (mm-handle-multipart-ctl-parameter handle 'gnus-details))
8905 gnus-tmp-pressed-details
8907 (setq gnus-tmp-details
8908 (if gnus-tmp-details
8909 (concat "\n" gnus-tmp-details)
8911 (setq gnus-tmp-pressed-details
8912 (if gnus-mime-security-button-pressed gnus-tmp-details ""))
8917 gnus-mime-security-button-line-format
8918 gnus-mime-security-button-line-format-alist
8919 `(keymap ,gnus-mime-security-button-map
8920 gnus-callback gnus-mime-security-press-button
8921 gnus-line-format ,gnus-mime-security-button-line-format
8922 gnus-mime-details ,gnus-mime-security-button-pressed
8923 article-type annotation
8926 ;; Exclude a newline.
8929 (when gnus-article-button-face
8930 (gnus-overlay-put (gnus-make-overlay b e nil t)
8931 'face gnus-article-button-face))
8932 (widget-convert-button
8935 :action 'gnus-widget-press-button
8936 :button-keymap gnus-mime-security-button-map
8939 ;; Needed to properly clear the message due to a bug in
8940 ;; wid-edit (XEmacs only).
8941 (when (boundp 'help-echo-owns-message)
8942 (setq help-echo-owns-message t))
8944 "%S: show detail; %S: more options"
8945 (aref gnus-mouse-2 0)
8946 (aref gnus-down-mouse-3 0))))))
8948 (defun gnus-mime-display-security (handle)
8950 (narrow-to-region (point) (point))
8951 (unless (gnus-unbuttonized-mime-type-p (car handle))
8952 (gnus-insert-mime-security-button handle))
8953 (gnus-mime-display-part (cadr handle))
8956 (unless (gnus-unbuttonized-mime-type-p (car handle))
8957 (let ((gnus-mime-security-button-line-format
8958 gnus-mime-security-button-end-line-format))
8959 (gnus-insert-mime-security-button handle)))
8960 (mm-set-handle-multipart-parameter
8961 handle 'gnus-region (cons (point-min-marker) (point-max-marker)))
8962 (goto-char (point-max))))
8964 (defun gnus-mime-security-run-function (function)
8965 "Run FUNCTION with the security part under point."
8966 (gnus-article-check-buffer)
8967 (let ((data (get-text-property (point) 'gnus-data))
8969 (when (and (stringp (car-safe data))
8970 (setq buffer (mm-handle-multipart-original-buffer data))
8971 (setq handle (cadr data)))
8972 (if (bufferp (mm-handle-buffer handle))
8974 (setq handle (cons buffer (copy-sequence (cdr handle))))
8975 (mm-handle-set-undisplayer handle nil))
8976 (setq handle (mm-make-handle
8978 (mm-handle-multipart-ctl-parameter handle 'protocol)
8979 nil nil nil nil nil nil)))
8980 (funcall function handle))))
8982 (defun gnus-mime-security-save-part ()
8983 "Save the security part under point."
8985 (gnus-mime-security-run-function 'mm-save-part))
8987 (defun gnus-mime-security-pipe-part ()
8988 "Pipe the security part under point to a process."
8990 (gnus-mime-security-run-function 'mm-pipe-part))
8996 (run-hooks 'gnus-art-load-hook)
8998 ;;; gnus-art.el ends here