Commit | Line | Data |
---|---|---|
eec82323 | 1 | ;;; gnus-art.el --- article mode commands for Gnus |
e84b4b86 | 2 | |
ba318903 | 3 | ;; Copyright (C) 1996-2014 Free Software Foundation, Inc. |
eec82323 | 4 | |
6748645f | 5 | ;; Author: Lars Magne Ingebrigtsen <larsi@gnus.org> |
eec82323 LMI |
6 | ;; Keywords: news |
7 | ||
8 | ;; This file is part of GNU Emacs. | |
9 | ||
5e809f55 | 10 | ;; GNU Emacs is free software: you can redistribute it and/or modify |
eec82323 | 11 | ;; it under the terms of the GNU General Public License as published by |
5e809f55 GM |
12 | ;; the Free Software Foundation, either version 3 of the License, or |
13 | ;; (at your option) any later version. | |
eec82323 LMI |
14 | |
15 | ;; GNU Emacs is distributed in the hope that it will be useful, | |
16 | ;; but WITHOUT ANY WARRANTY; without even the implied warranty of | |
2ff9f5b4 | 17 | ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
eec82323 LMI |
18 | ;; GNU General Public License for more details. |
19 | ||
20 | ;; You should have received a copy of the GNU General Public License | |
5e809f55 | 21 | ;; along with GNU Emacs. If not, see <http://www.gnu.org/licenses/>. |
eec82323 LMI |
22 | |
23 | ;;; Commentary: | |
24 | ||
25 | ;;; Code: | |
26 | ||
f0b7f5a8 | 27 | ;; For Emacs <22.2 and XEmacs. |
9640c3bc GM |
28 | (eval-and-compile |
29 | (unless (fboundp 'declare-function) (defmacro declare-function (&rest r)))) | |
23f87bed | 30 | (eval-when-compile |
9efa445f DN |
31 | (require 'cl)) |
32 | (defvar tool-bar-map) | |
33 | (defvar w3m-minor-mode-map) | |
5ab7173c | 34 | |
eec82323 | 35 | (require 'gnus) |
5843126b | 36 | (require 'gnus-sum) |
eec82323 LMI |
37 | (require 'gnus-spec) |
38 | (require 'gnus-int) | |
23f87bed | 39 | (require 'gnus-win) |
16409b0b GM |
40 | (require 'mm-bodies) |
41 | (require 'mail-parse) | |
42 | (require 'mm-decode) | |
43 | (require 'mm-view) | |
44 | (require 'wid-edit) | |
45 | (require 'mm-uu) | |
23f87bed | 46 | (require 'message) |
1518e4f0 | 47 | (require 'mouse) |
23f87bed MB |
48 | |
49 | (autoload 'gnus-msg-mail "gnus-msg" nil t) | |
50 | (autoload 'gnus-button-mailto "gnus-msg") | |
51 | (autoload 'gnus-button-reply "gnus-msg" nil t) | |
498063ec | 52 | (autoload 'parse-time-string "parse-time" nil nil) |
01c52d31 MB |
53 | (autoload 'ansi-color-apply-on-region "ansi-color") |
54 | (autoload 'mm-url-insert-file-contents-external "mm-url") | |
531bedc3 | 55 | (autoload 'mm-extern-cache-contents "mm-extern") |
eec82323 LMI |
56 | |
57 | (defgroup gnus-article nil | |
58 | "Article display." | |
23f87bed | 59 | :link '(custom-manual "(gnus)Article Buffer") |
eec82323 LMI |
60 | :group 'gnus) |
61 | ||
16409b0b GM |
62 | (defgroup gnus-article-treat nil |
63 | "Treating article parts." | |
64 | :link '(custom-manual "(gnus)Article Hiding") | |
65 | :group 'gnus-article) | |
66 | ||
eec82323 LMI |
67 | (defgroup gnus-article-hiding nil |
68 | "Hiding article parts." | |
69 | :link '(custom-manual "(gnus)Article Hiding") | |
70 | :group 'gnus-article) | |
71 | ||
72 | (defgroup gnus-article-highlight nil | |
73 | "Article highlighting." | |
74 | :link '(custom-manual "(gnus)Article Highlighting") | |
75 | :group 'gnus-article | |
76 | :group 'gnus-visual) | |
77 | ||
78 | (defgroup gnus-article-signature nil | |
79 | "Article signatures." | |
80 | :link '(custom-manual "(gnus)Article Signature") | |
81 | :group 'gnus-article) | |
82 | ||
83 | (defgroup gnus-article-headers nil | |
84 | "Article headers." | |
85 | :link '(custom-manual "(gnus)Hiding Headers") | |
86 | :group 'gnus-article) | |
87 | ||
88 | (defgroup gnus-article-washing nil | |
89 | "Special commands on articles." | |
90 | :link '(custom-manual "(gnus)Article Washing") | |
91 | :group 'gnus-article) | |
92 | ||
93 | (defgroup gnus-article-emphasis nil | |
94 | "Fontisizing articles." | |
95 | :link '(custom-manual "(gnus)Article Fontisizing") | |
96 | :group 'gnus-article) | |
97 | ||
98 | (defgroup gnus-article-saving nil | |
99 | "Saving articles." | |
100 | :link '(custom-manual "(gnus)Saving Articles") | |
101 | :group 'gnus-article) | |
102 | ||
103 | (defgroup gnus-article-mime nil | |
104 | "Worshiping the MIME wonder." | |
105 | :link '(custom-manual "(gnus)Using MIME") | |
106 | :group 'gnus-article) | |
107 | ||
108 | (defgroup gnus-article-buttons nil | |
109 | "Pushable buttons in the article buffer." | |
110 | :link '(custom-manual "(gnus)Article Buttons") | |
111 | :group 'gnus-article) | |
112 | ||
113 | (defgroup gnus-article-various nil | |
114 | "Other article options." | |
115 | :link '(custom-manual "(gnus)Misc Article") | |
116 | :group 'gnus-article) | |
117 | ||
118 | (defcustom gnus-ignored-headers | |
23f87bed MB |
119 | (mapcar |
120 | (lambda (header) | |
121 | (concat "^" header ":")) | |
122 | '("Path" "Expires" "Date-Received" "References" "Xref" "Lines" | |
123 | "Relay-Version" "Message-ID" "Approved" "Sender" "Received" | |
124 | "X-UIDL" "MIME-Version" "Return-Path" "In-Reply-To" | |
125 | "Content-Type" "Content-Transfer-Encoding" "X-WebTV-Signature" | |
126 | "X-MimeOLE" "X-MSMail-Priority" "X-Priority" "X-Loop" | |
127 | "X-Authentication-Warning" "X-MIME-Autoconverted" "X-Face" | |
128 | "X-Attribution" "X-Originating-IP" "Delivered-To" | |
129 | "NNTP-[-A-Za-z]+" "Distribution" "X-no-archive" "X-Trace" | |
130 | "X-Complaints-To" "X-NNTP-Posting-Host" "X-Orig.*" | |
131 | "Abuse-Reports-To" "Cache-Post-Path" "X-Article-Creation-Date" | |
132 | "X-Poster" "X-Mail2News-Path" "X-Server-Date" "X-Cache" | |
133 | "Originator" "X-Problems-To" "X-Auth-User" "X-Post-Time" | |
134 | "X-Admin" "X-UID" "Resent-[-A-Za-z]+" "X-Mailing-List" | |
135 | "Precedence" "Original-[-A-Za-z]+" "X-filename" "X-Orcpt" | |
136 | "Old-Received" "X-Pgp" "X-Auth" "X-From-Line" | |
137 | "X-Gnus-Article-Number" "X-Majordomo" "X-Url" "X-Sender" | |
138 | "MBOX-Line" "Priority" "X400-[-A-Za-z]+" | |
139 | "Status" "X-Gnus-Mail-Source" "Cancel-Lock" | |
140 | "X-FTN" "X-EXP32-SerialNo" "Encoding" "Importance" | |
141 | "Autoforwarded" "Original-Encoded-Information-Types" "X-Ya-Pop3" | |
142 | "X-Face-Version" "X-Vms-To" "X-ML-NAME" "X-ML-COUNT" | |
143 | "Mailing-List" "X-finfo" "X-md5sum" "X-md5sum-Origin" | |
144 | "X-Sun-Charset" "X-Accept-Language" "X-Envelope-Sender" | |
145 | "List-[A-Za-z]+" "X-Listprocessor-Version" | |
146 | "X-Received" "X-Distribute" "X-Sequence" "X-Juno-Line-Breaks" | |
147 | "X-Notes-Item" "X-MS-TNEF-Correlator" "x-uunet-gateway" | |
148 | "X-Received" "Content-length" "X-precedence" | |
149 | "X-Authenticated-User" "X-Comment" "X-Report" "X-Abuse-Info" | |
150 | "X-HTTP-Proxy" "X-Mydeja-Info" "X-Copyright" "X-No-Markup" | |
151 | "X-Abuse-Info" "X-From_" "X-Accept-Language" "Errors-To" | |
152 | "X-BeenThere" "X-Mailman-Version" "List-Help" "List-Post" | |
153 | "List-Subscribe" "List-Id" "List-Unsubscribe" "List-Archive" | |
154 | "X-Content-length" "X-Posting-Agent" "Original-Received" | |
155 | "X-Request-PGP" "X-Fingerprint" "X-WRIEnvto" "X-WRIEnvfrom" | |
156 | "X-Virus-Scanned" "X-Delivery-Agent" "Posted-Date" "X-Gateway" | |
157 | "X-Local-Origin" "X-Local-Destination" "X-UserInfo1" | |
158 | "X-Received-Date" "X-Hashcash" "Face" "X-DMCA-Notifications" | |
01c52d31 MB |
159 | "X-Abuse-and-DMCA-Info" "X-Postfilter" "X-Gpg-.*" "X-Disclaimer" |
160 | "Envelope-To" "X-Spam-Score" "System-Type" "X-Injected-Via-Gmane" | |
161 | "X-Gmane-NNTP-Posting-Host" "Jabber-ID" "Archived-At" | |
162 | "Envelope-Sender" "Envelope-Recipients")) | |
6748645f | 163 | "*All headers that start with this regexp will be hidden. |
eec82323 LMI |
164 | This variable can also be a list of regexps of headers to be ignored. |
165 | If `gnus-visible-headers' is non-nil, this variable will be ignored." | |
72aba33f | 166 | :type '(choice regexp |
eec82323 LMI |
167 | (repeat regexp)) |
168 | :group 'gnus-article-hiding) | |
169 | ||
170 | (defcustom gnus-visible-headers | |
12e3ca0a | 171 | "^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:" |
6748645f | 172 | "*All headers that do not match this regexp will be hidden. |
eec82323 LMI |
173 | This variable can also be a list of regexp of headers to remain visible. |
174 | If this variable is non-nil, `gnus-ignored-headers' will be ignored." | |
9b3ebcb6 MB |
175 | :type '(choice |
176 | (repeat :value-to-internal (lambda (widget value) | |
177 | (custom-split-regexp-maybe value)) | |
178 | :match (lambda (widget value) | |
179 | (or (stringp value) | |
180 | (widget-editable-list-match widget value))) | |
181 | regexp) | |
182 | (const :tag "Use gnus-ignored-headers" nil) | |
183 | regexp) | |
eec82323 LMI |
184 | :group 'gnus-article-hiding) |
185 | ||
186 | (defcustom gnus-sorted-header-list | |
187 | '("^From:" "^Subject:" "^Summary:" "^Keywords:" "^Newsgroups:" | |
188 | "^Followup-To:" "^To:" "^Cc:" "^Date:" "^Organization:") | |
6748645f | 189 | "*This variable is a list of regular expressions. |
eec82323 LMI |
190 | If it is non-nil, headers that match the regular expressions will |
191 | be placed first in the article buffer in the sequence specified by | |
192 | this list." | |
193 | :type '(repeat regexp) | |
194 | :group 'gnus-article-hiding) | |
195 | ||
196 | (defcustom gnus-boring-article-headers '(empty followup-to reply-to) | |
197 | "Headers that are only to be displayed if they have interesting data. | |
23f87bed MB |
198 | Possible values in this list are: |
199 | ||
200 | 'empty Headers with no content. | |
201 | 'newsgroups Newsgroup identical to Gnus group. | |
202 | 'to-address To identical to To-address. | |
203 | 'to-list To identical to To-list. | |
204 | 'cc-list CC identical to To-list. | |
205 | 'followup-to Followup-to identical to Newsgroups. | |
206 | 'reply-to Reply-to identical to From. | |
207 | 'date Date less than four days old. | |
208 | 'long-to To and/or Cc longer than 1024 characters. | |
209 | 'many-to Multiple To and/or Cc." | |
eec82323 | 210 | :type '(set (const :tag "Headers with no content." empty) |
23f87bed MB |
211 | (const :tag "Newsgroups identical to Gnus group." newsgroups) |
212 | (const :tag "To identical to To-address." to-address) | |
213 | (const :tag "To identical to To-list." to-list) | |
214 | (const :tag "CC identical to To-list." cc-list) | |
215 | (const :tag "Followup-to identical to Newsgroups." followup-to) | |
216 | (const :tag "Reply-to identical to From." reply-to) | |
6748645f | 217 | (const :tag "Date less than four days old." date) |
23f87bed | 218 | (const :tag "To and/or Cc longer than 1024 characters." long-to) |
16409b0b | 219 | (const :tag "Multiple To and/or Cc headers." many-to)) |
eec82323 LMI |
220 | :group 'gnus-article-hiding) |
221 | ||
23f87bed MB |
222 | (defcustom gnus-article-skip-boring nil |
223 | "Skip over text that is not worth reading. | |
224 | By default, if you set this t, then Gnus will display citations and | |
225 | signatures, but will never scroll down to show you a page consisting | |
226 | only of boring text. Boring text is controlled by | |
227 | `gnus-article-boring-faces'." | |
bf247b6e | 228 | :version "22.1" |
23f87bed MB |
229 | :type 'boolean |
230 | :group 'gnus-article-hiding) | |
231 | ||
eec82323 LMI |
232 | (defcustom gnus-signature-separator '("^-- $" "^-- *$") |
233 | "Regexp matching signature separator. | |
234 | This can also be a list of regexps. In that case, it will be checked | |
235 | from head to tail looking for a separator. Searches will be done from | |
236 | the end of the buffer." | |
3031d8b0 MB |
237 | :type '(choice :format "%{%t%}: %[Value Menu%]\n%v" |
238 | (regexp) | |
239 | (repeat :tag "List of regexp" regexp)) | |
eec82323 LMI |
240 | :group 'gnus-article-signature) |
241 | ||
242 | (defcustom gnus-signature-limit nil | |
16409b0b | 243 | "Provide a limit to what is considered a signature. |
eec82323 LMI |
244 | If it is a number, no signature may not be longer (in characters) than |
245 | that number. If it is a floating point number, no signature may be | |
246 | longer (in lines) than that number. If it is a function, the function | |
247 | will be called without any parameters, and if it returns nil, there is | |
248 | no signature in the buffer. If it is a string, it will be used as a | |
01c52d31 MB |
249 | regexp. If it matches, the text in question is not a signature. |
250 | ||
251 | This can also be a list of the above values." | |
4a2358e9 MB |
252 | :type '(choice (const nil) |
253 | (integer :value 200) | |
6748645f | 254 | (number :value 4.0) |
b28080e3 | 255 | function |
6748645f | 256 | (regexp :value ".*")) |
eec82323 LMI |
257 | :group 'gnus-article-signature) |
258 | ||
259 | (defcustom gnus-hidden-properties '(invisible t intangible t) | |
260 | "Property list to use for hiding text." | |
261 | :type 'sexp | |
262 | :group 'gnus-article-hiding) | |
263 | ||
23f87bed MB |
264 | ;; Fixme: This isn't the right thing for mixed graphical and non-graphical |
265 | ;; frames in a session. | |
eec82323 | 266 | (defcustom gnus-article-x-face-command |
23f87bed MB |
267 | (if (featurep 'xemacs) |
268 | (if (or (gnus-image-type-available-p 'xface) | |
269 | (gnus-image-type-available-p 'pbm)) | |
270 | 'gnus-display-x-face-in-from | |
71c90957 KY |
271 | "{ echo \ |
272 | '/* Format_version=1, Width=48, Height=48, Depth=1, Valid_bits_per_item=16 */'\ | |
273 | ; uncompface; } | icontopbm | ee -") | |
23f87bed MB |
274 | (if (gnus-image-type-available-p 'pbm) |
275 | 'gnus-display-x-face-in-from | |
71c90957 KY |
276 | "{ echo \ |
277 | '/* Format_version=1, Width=48, Height=48, Depth=1, Valid_bits_per_item=16 */'\ | |
278 | ; uncompface; } | icontopbm | display -")) | |
6748645f | 279 | "*String or function to be executed to display an X-Face header. |
eec82323 | 280 | If it is a string, the command will be executed in a sub-shell |
2ff9f5b4 | 281 | asynchronously. The compressed face will be piped to this command." |
23f87bed MB |
282 | :type `(choice string |
283 | (function-item gnus-display-x-face-in-from) | |
16409b0b | 284 | function) |
b5a206e7 | 285 | :version "21.1" |
23f87bed | 286 | :group 'gnus-picon |
eec82323 LMI |
287 | :group 'gnus-article-washing) |
288 | ||
289 | (defcustom gnus-article-x-face-too-ugly nil | |
290 | "Regexp matching posters whose face shouldn't be shown automatically." | |
4bb6a3a6 | 291 | :type '(choice regexp (const nil)) |
eec82323 LMI |
292 | :group 'gnus-article-washing) |
293 | ||
e0bad764 DL |
294 | (defcustom gnus-article-banner-alist nil |
295 | "Banner alist for stripping. | |
a1506d29 | 296 | For example, |
23f87bed | 297 | ((egroups . \"^[ \\t\\n]*-------------------+\\\\( \\\\(e\\\\|Yahoo! \\\\)Groups Sponsor -+\\\\)?....\\n\\\\(.+\\n\\\\)+\"))" |
fc2c2db8 | 298 | :version "21.1" |
e0bad764 DL |
299 | :type '(repeat (cons symbol regexp)) |
300 | :group 'gnus-article-washing) | |
301 | ||
23f87bed MB |
302 | (gnus-define-group-parameter |
303 | banner | |
304 | :variable-document | |
305 | "Alist of regexps (to match group names) and banner." | |
306 | :variable-group gnus-article-washing | |
307 | :parameter-type | |
308 | '(choice :tag "Banner" | |
309 | :value nil | |
310 | (const :tag "Remove signature" signature) | |
311 | (symbol :tag "Item in `gnus-article-banner-alist'" none) | |
312 | regexp | |
313 | (const :tag "None" nil)) | |
314 | :parameter-document | |
315 | "If non-nil, specify how to remove `banners' from articles. | |
316 | ||
317 | Symbol `signature' means to remove signatures delimited by | |
318 | `gnus-signature-separator'. Any other symbol is used to look up a | |
319 | regular expression to match the banner in `gnus-article-banner-alist'. | |
320 | A string is used as a regular expression to match the banner | |
321 | directly.") | |
322 | ||
323 | (defcustom gnus-article-address-banner-alist nil | |
324 | "Alist of mail addresses and banners. | |
325 | Each element has the form (ADDRESS . BANNER), where ADDRESS is a regexp | |
326 | to match a mail address in the From: header, BANNER is one of a symbol | |
327 | `signature', an item in `gnus-article-banner-alist', a regexp and nil. | |
328 | If ADDRESS matches author's mail address, it will remove things like | |
329 | advertisements. For example: | |
330 | ||
331 | \((\"@yoo-hoo\\\\.co\\\\.jp\\\\'\" . \"\\n_+\\nDo You Yoo-hoo!\\\\?\\n.*\\n.*\\n\")) | |
332 | " | |
333 | :type '(repeat | |
334 | (cons | |
335 | (regexp :tag "Address") | |
336 | (choice :tag "Banner" :value nil | |
337 | (const :tag "Remove signature" signature) | |
338 | (symbol :tag "Item in `gnus-article-banner-alist'" none) | |
339 | regexp | |
340 | (const :tag "None" nil)))) | |
bf247b6e | 341 | :version "22.1" |
23f87bed MB |
342 | :group 'gnus-article-washing) |
343 | ||
ae465fa7 MB |
344 | (defmacro gnus-emphasis-custom-with-format (&rest body) |
345 | `(let ((format "\ | |
346 | \\(\\s-\\|^\\|\\=\\|[-\"]\\|\\s(\\)\\(%s\\(\\w+\\(\\s-+\\w+\\)*[.,]?\\)%s\\)\ | |
347 | \\(\\([-,.;:!?\"]\\|\\s)\\)+\\s-\\|[?!.]\\s-\\|\\s)\\|\\s-\\)")) | |
348 | ,@body)) | |
349 | ||
350 | (defun gnus-emphasis-custom-value-to-external (value) | |
351 | (gnus-emphasis-custom-with-format | |
352 | (if (consp (car value)) | |
353 | (list (format format (car (car value)) (cdr (car value))) | |
354 | 2 | |
355 | (if (nth 1 value) 2 3) | |
356 | (nth 2 value)) | |
357 | value))) | |
358 | ||
359 | (defun gnus-emphasis-custom-value-to-internal (value) | |
360 | (gnus-emphasis-custom-with-format | |
361 | (let ((regexp (concat "\\`" | |
362 | (format (regexp-quote format) | |
363 | "\\([^()]+\\)" "\\([^()]+\\)") | |
364 | "\\'")) | |
365 | pattern) | |
366 | (if (string-match regexp (setq pattern (car value))) | |
367 | (list (cons (match-string 1 pattern) (match-string 2 pattern)) | |
368 | (= (nth 2 value) 2) | |
369 | (nth 3 value)) | |
370 | value)))) | |
371 | ||
eec82323 | 372 | (defcustom gnus-emphasis-alist |
ae465fa7 MB |
373 | (let ((types |
374 | '(("\\*" "\\*" bold nil 2) | |
23f87bed | 375 | ("_" "_" underline) |
eec82323 | 376 | ("/" "/" italic) |
eec82323 LMI |
377 | ("_/" "/_" underline-italic) |
378 | ("_\\*" "\\*_" underline-bold) | |
379 | ("\\*/" "/\\*" bold-italic) | |
380 | ("_\\*/" "/\\*_" underline-bold-italic)))) | |
ae465fa7 MB |
381 | (nconc |
382 | (gnus-emphasis-custom-with-format | |
383 | (mapcar (lambda (spec) | |
384 | (list (format format (car spec) (cadr spec)) | |
385 | (or (nth 3 spec) 2) | |
386 | (or (nth 4 spec) 3) | |
387 | (intern (format "gnus-emphasis-%s" (nth 2 spec))))) | |
388 | types)) | |
95f75c75 SM |
389 | '(;; I've never seen anyone use this strikethru convention whereas I've |
390 | ;; several times seen it triggered by normal text. --Stef | |
391 | ;; Miles suggests that this form is sometimes used but for italics, | |
392 | ;; so maybe we should map it to `italic'. | |
393 | ;; ("\\(\\s-\\|^\\)\\(-\\(\\(\\w\\|-[^-]\\)+\\)-\\)\\(\\s-\\|[?!.,;]\\)" | |
394 | ;; 2 3 gnus-emphasis-strikethru) | |
ae465fa7 MB |
395 | ("\\(\\s-\\|^\\)\\(_\\(\\(\\w\\|_[^_]\\)+\\)_\\)\\(\\s-\\|[?!.,;]\\)" |
396 | 2 3 gnus-emphasis-underline)))) | |
6748645f | 397 | "*Alist that says how to fontify certain phrases. |
eec82323 LMI |
398 | Each item looks like this: |
399 | ||
400 | (\"_\\\\(\\\\w+\\\\)_\" 0 1 'underline) | |
401 | ||
402 | The first element is a regular expression to be matched. The second | |
403 | is a number that says what regular expression grouping used to find | |
404 | the entire emphasized word. The third is a number that says what | |
405 | regexp grouping should be displayed and highlighted. The fourth | |
406 | is the face used for highlighting." | |
ae465fa7 MB |
407 | :type |
408 | '(repeat | |
409 | (menu-choice | |
410 | :format "%[Customizing Style%]\n%v" | |
411 | :indent 2 | |
412 | (group :tag "Default" | |
413 | :value ("" 0 0 default) | |
414 | :value-create | |
415 | (lambda (widget) | |
416 | (let ((value (widget-get | |
417 | (cadr (widget-get (widget-get widget :parent) | |
418 | :args)) | |
419 | :value))) | |
420 | (if (not (eq (nth 2 value) 'default)) | |
421 | (widget-put | |
422 | widget | |
423 | :value | |
424 | (gnus-emphasis-custom-value-to-external value)))) | |
425 | (widget-group-value-create widget)) | |
ad136a7c MB |
426 | regexp |
427 | (integer :format "Match group: %v") | |
01c52d31 | 428 | (integer :format "Emphasize group: %v") |
ae465fa7 MB |
429 | face) |
430 | (group :tag "Simple" | |
431 | :value (("_" . "_") nil default) | |
432 | (cons :format "%v" | |
ad136a7c MB |
433 | (regexp :format "Start regexp: %v") |
434 | (regexp :format "End regexp: %v")) | |
ae465fa7 MB |
435 | (boolean :format "Show start and end patterns: %[%v%]\n" |
436 | :on " On " :off " Off ") | |
437 | face))) | |
438 | :get (lambda (symbol) | |
439 | (mapcar 'gnus-emphasis-custom-value-to-internal | |
440 | (default-value symbol))) | |
441 | :set (lambda (symbol value) | |
442 | (set-default symbol (mapcar 'gnus-emphasis-custom-value-to-external | |
443 | value))) | |
eec82323 LMI |
444 | :group 'gnus-article-emphasis) |
445 | ||
16409b0b GM |
446 | (defcustom gnus-emphasize-whitespace-regexp "^[ \t]+\\|[ \t]*\n" |
447 | "A regexp to describe whitespace which should not be emphasized. | |
448 | Typical values are \"^[ \\t]+\\\\|[ \\t]*\\n\" and \"[ \\t]+\\\\|[ \\t]*\\n\". | |
449 | The former avoids underlining of leading and trailing whitespace, | |
450 | and the latter avoids underlining any whitespace at all." | |
fc2c2db8 | 451 | :version "21.1" |
16409b0b GM |
452 | :group 'gnus-article-emphasis |
453 | :type 'regexp) | |
454 | ||
23f87bed | 455 | (defface gnus-emphasis-bold '((t (:bold t))) |
eec82323 LMI |
456 | "Face used for displaying strong emphasized text (*word*)." |
457 | :group 'gnus-article-emphasis) | |
458 | ||
23f87bed | 459 | (defface gnus-emphasis-italic '((t (:italic t))) |
eec82323 LMI |
460 | "Face used for displaying italic emphasized text (/word/)." |
461 | :group 'gnus-article-emphasis) | |
462 | ||
463 | (defface gnus-emphasis-underline '((t (:underline t))) | |
464 | "Face used for displaying underlined emphasized text (_word_)." | |
465 | :group 'gnus-article-emphasis) | |
466 | ||
23f87bed | 467 | (defface gnus-emphasis-underline-bold '((t (:bold t :underline t))) |
eec82323 LMI |
468 | "Face used for displaying underlined bold emphasized text (_*word*_)." |
469 | :group 'gnus-article-emphasis) | |
470 | ||
23f87bed | 471 | (defface gnus-emphasis-underline-italic '((t (:italic t :underline t))) |
8de38c21 | 472 | "Face used for displaying underlined italic emphasized text (_/word/_)." |
eec82323 LMI |
473 | :group 'gnus-article-emphasis) |
474 | ||
23f87bed | 475 | (defface gnus-emphasis-bold-italic '((t (:bold t :italic t))) |
eec82323 LMI |
476 | "Face used for displaying bold italic emphasized text (/*word*/)." |
477 | :group 'gnus-article-emphasis) | |
478 | ||
479 | (defface gnus-emphasis-underline-bold-italic | |
23f87bed | 480 | '((t (:bold t :italic t :underline t))) |
eec82323 | 481 | "Face used for displaying underlined bold italic emphasized text. |
8f688cb0 | 482 | Example: (_/*word*/_)." |
eec82323 LMI |
483 | :group 'gnus-article-emphasis) |
484 | ||
23f87bed MB |
485 | (defface gnus-emphasis-strikethru (if (featurep 'xemacs) |
486 | '((t (:strikethru t))) | |
487 | '((t (:strike-through t)))) | |
488 | "Face used for displaying strike-through text (-word-)." | |
489 | :group 'gnus-article-emphasis) | |
490 | ||
16409b0b GM |
491 | (defface gnus-emphasis-highlight-words |
492 | '((t (:background "black" :foreground "yellow"))) | |
493 | "Face used for displaying highlighted words." | |
494 | :group 'gnus-article-emphasis) | |
495 | ||
01c52d31 | 496 | (defcustom gnus-article-time-format "%a, %d %b %Y %T %Z" |
eec82323 | 497 | "Format for display of Date headers in article bodies. |
6748645f LMI |
498 | See `format-time-string' for the possible values. |
499 | ||
500 | The variable can also be function, which should return a complete Date | |
501 | header. The function is called with one argument, the time, which can | |
502 | be fed to `format-time-string'." | |
01c52d31 | 503 | :type '(choice string function) |
eec82323 LMI |
504 | :link '(custom-manual "(gnus)Article Date") |
505 | :group 'gnus-article-washing) | |
506 | ||
eec82323 | 507 | (defcustom gnus-save-all-headers t |
26c9afc3 MB |
508 | "*If non-nil, don't remove any headers before saving. |
509 | This will be overridden by the `:headers' property that the symbol of | |
510 | the saver function, which is specified by `gnus-default-article-saver', | |
511 | might have." | |
eec82323 LMI |
512 | :group 'gnus-article-saving |
513 | :type 'boolean) | |
514 | ||
515 | (defcustom gnus-prompt-before-saving 'always | |
516 | "*This variable says how much prompting is to be done when saving articles. | |
517 | If it is nil, no prompting will be done, and the articles will be | |
518 | saved to the default files. If this variable is `always', each and | |
519 | every article that is saved will be preceded by a prompt, even when | |
520 | saving large batches of articles. If this variable is neither nil not | |
521 | `always', there the user will be prompted once for a file name for | |
522 | each invocation of the saving commands." | |
523 | :group 'gnus-article-saving | |
524 | :type '(choice (item always) | |
525 | (item :tag "never" nil) | |
6748645f | 526 | (sexp :tag "once" :format "%t\n" :value t))) |
eec82323 LMI |
527 | |
528 | (defcustom gnus-saved-headers gnus-visible-headers | |
529 | "Headers to keep if `gnus-save-all-headers' is nil. | |
530 | If `gnus-save-all-headers' is non-nil, this variable will be ignored. | |
531 | If that variable is nil, however, all headers that match this regexp | |
26c9afc3 MB |
532 | will be kept while the rest will be deleted before saving. This and |
533 | `gnus-save-all-headers' will be overridden by the `:headers' property | |
534 | that the symbol of the saver function, which is specified by | |
535 | `gnus-default-article-saver', might have." | |
eec82323 | 536 | :group 'gnus-article-saving |
4bb6a3a6 | 537 | :type 'regexp) |
eec82323 | 538 | |
fef8d38e | 539 | ;; Note that "Rmail format" is mbox since Emacs 23, but Babyl before. |
eec82323 | 540 | (defcustom gnus-default-article-saver 'gnus-summary-save-in-rmail |
c5e87d10 | 541 | "A function to save articles in your favorite format. |
26c9afc3 MB |
542 | The function will be called by way of the `gnus-summary-save-article' |
543 | command, and friends such as `gnus-summary-save-article-rmail'. | |
eec82323 LMI |
544 | |
545 | Gnus provides the following functions: | |
546 | ||
547 | * gnus-summary-save-in-rmail (Rmail format) | |
548 | * gnus-summary-save-in-mail (Unix mail format) | |
549 | * gnus-summary-save-in-folder (MH folder) | |
550 | * gnus-summary-save-in-file (article format) | |
23f87bed | 551 | * gnus-summary-save-body-in-file (article body) |
eec82323 | 552 | * gnus-summary-save-in-vm (use VM's folder format) |
26c9afc3 MB |
553 | * gnus-summary-write-to-file (article format -- overwrite) |
554 | * gnus-summary-write-body-to-file (article body -- overwrite) | |
89167438 | 555 | * gnus-summary-save-in-pipe (article format) |
26c9afc3 MB |
556 | |
557 | The symbol of each function may have the following properties: | |
558 | ||
559 | * :decode | |
560 | The value non-nil means save decoded articles. This is meaningful | |
561 | only with `gnus-summary-save-in-file', `gnus-summary-save-body-in-file', | |
89167438 MB |
562 | `gnus-summary-write-to-file', `gnus-summary-write-body-to-file', and |
563 | `gnus-summary-save-in-pipe'. | |
26c9afc3 MB |
564 | |
565 | * :function | |
566 | The value specifies an alternative function which appends, not | |
567 | overwrites, articles to a file. This implies that when saving many | |
568 | articles at a time, `gnus-prompt-before-saving' is bound to t and all | |
569 | articles are saved in a single file. This is meaningful only with | |
570 | `gnus-summary-write-to-file' and `gnus-summary-write-body-to-file'. | |
571 | ||
572 | * :headers | |
573 | The value specifies the symbol of a variable of which the value | |
574 | specifies headers to be saved. If it is omitted, | |
575 | `gnus-save-all-headers' and `gnus-saved-headers' control what | |
576 | headers should be saved." | |
eec82323 LMI |
577 | :group 'gnus-article-saving |
578 | :type '(radio (function-item gnus-summary-save-in-rmail) | |
579 | (function-item gnus-summary-save-in-mail) | |
580 | (function-item gnus-summary-save-in-folder) | |
581 | (function-item gnus-summary-save-in-file) | |
23f87bed | 582 | (function-item gnus-summary-save-body-in-file) |
eec82323 | 583 | (function-item gnus-summary-save-in-vm) |
58090a8d | 584 | (function-item gnus-summary-write-to-file) |
26c9afc3 | 585 | (function-item gnus-summary-write-body-to-file) |
89167438 | 586 | (function-item gnus-summary-save-in-pipe) |
58090a8d | 587 | (function))) |
eec82323 | 588 | |
26c9afc3 MB |
589 | (defcustom gnus-article-save-coding-system |
590 | (or (and (mm-coding-system-p 'utf-8) 'utf-8) | |
591 | (and (mm-coding-system-p 'iso-2022-7bit) 'iso-2022-7bit) | |
592 | (and (mm-coding-system-p 'emacs-mule) 'emacs-mule) | |
593 | (and (mm-coding-system-p 'escape-quoted) 'escape-quoted)) | |
594 | "Coding system used to save decoded articles to a file. | |
595 | ||
596 | The recommended coding systems are `utf-8', `iso-2022-7bit' and so on, | |
597 | which can safely encode any characters in text. This is used by the | |
598 | commands including: | |
599 | ||
600 | * gnus-summary-save-article-file | |
601 | * gnus-summary-save-article-body-file | |
602 | * gnus-summary-write-article-file | |
603 | * gnus-summary-write-article-body-file | |
604 | ||
605 | and the functions to which you may set `gnus-default-article-saver': | |
606 | ||
607 | * gnus-summary-save-in-file | |
608 | * gnus-summary-save-body-in-file | |
609 | * gnus-summary-write-to-file | |
610 | * gnus-summary-write-body-to-file | |
611 | ||
612 | Those commands and functions save just text displayed in the article | |
613 | buffer to a file if the value of this variable is non-nil. Note that | |
614 | buttonized MIME parts will be lost in a saved file in that case. | |
615 | Otherwise, raw articles will be saved." | |
616 | :group 'gnus-article-saving | |
617 | :type `(choice | |
618 | :format "%{%t%}:\n %[Value Menu%] %v" | |
619 | (const :tag "Save raw articles" nil) | |
620 | ,@(delq nil | |
621 | (mapcar | |
622 | (lambda (arg) (if (mm-coding-system-p (nth 3 arg)) arg)) | |
623 | '((const :tag "UTF-8" utf-8) | |
624 | (const :tag "iso-2022-7bit" iso-2022-7bit) | |
625 | (const :tag "Emacs internal" emacs-mule) | |
626 | (const :tag "escape-quoted" escape-quoted)))) | |
627 | (symbol :tag "Coding system"))) | |
628 | ||
eec82323 LMI |
629 | (defcustom gnus-rmail-save-name 'gnus-plain-save-name |
630 | "A function generating a file name to save articles in Rmail format. | |
631 | The function is called with NEWSGROUP, HEADERS, and optional LAST-FILE." | |
632 | :group 'gnus-article-saving | |
633 | :type 'function) | |
634 | ||
635 | (defcustom gnus-mail-save-name 'gnus-plain-save-name | |
636 | "A function generating a file name to save articles in Unix mail format. | |
637 | The function is called with NEWSGROUP, HEADERS, and optional LAST-FILE." | |
638 | :group 'gnus-article-saving | |
639 | :type 'function) | |
640 | ||
641 | (defcustom gnus-folder-save-name 'gnus-folder-save-name | |
642 | "A function generating a file name to save articles in MH folder. | |
643 | The function is called with NEWSGROUP, HEADERS, and optional LAST-FOLDER." | |
644 | :group 'gnus-article-saving | |
645 | :type 'function) | |
646 | ||
647 | (defcustom gnus-file-save-name 'gnus-numeric-save-name | |
648 | "A function generating a file name to save articles in article format. | |
649 | The function is called with NEWSGROUP, HEADERS, and optional | |
650 | LAST-FILE." | |
651 | :group 'gnus-article-saving | |
652 | :type 'function) | |
653 | ||
654 | (defcustom gnus-split-methods | |
655 | '((gnus-article-archive-name) | |
656 | (gnus-article-nndoc-name)) | |
6748645f | 657 | "*Variable used to suggest where articles are to be saved. |
eec82323 LMI |
658 | For instance, if you would like to save articles related to Gnus in |
659 | the file \"gnus-stuff\", and articles related to VM in \"vm-stuff\", | |
660 | you could set this variable to something like: | |
661 | ||
662 | '((\"^Subject:.*gnus\\|^Newsgroups:.*gnus\" \"gnus-stuff\") | |
663 | (\"^Subject:.*vm\\|^Xref:.*vm\" \"vm-stuff\")) | |
664 | ||
01c52d31 MB |
665 | This variable is an alist where the key is the match and the |
666 | value is a list of possible files to save in if the match is | |
667 | non-nil. | |
eec82323 LMI |
668 | |
669 | If the match is a string, it is used as a regexp match on the | |
670 | article. If the match is a symbol, that symbol will be funcalled | |
671 | from the buffer of the article to be saved with the newsgroup as the | |
99d99081 | 672 | parameter. If it is a list, it will be evalled in the same buffer. |
eec82323 | 673 | |
01c52d31 MB |
674 | If this form or function returns a string, this string will be used as a |
675 | possible file name; and if it returns a non-nil list, that list will be | |
676 | used as possible file names." | |
eec82323 | 677 | :group 'gnus-article-saving |
6748645f LMI |
678 | :type '(repeat (choice (list :value (fun) function) |
679 | (cons :value ("" "") regexp (repeat string)) | |
680 | (sexp :value nil)))) | |
eec82323 | 681 | |
eec82323 LMI |
682 | (defcustom gnus-page-delimiter "^\^L" |
683 | "*Regexp describing what to use as article page delimiters. | |
684 | The default value is \"^\^L\", which is a form linefeed at the | |
685 | beginning of a line." | |
686 | :type 'regexp | |
687 | :group 'gnus-article-various) | |
688 | ||
12295c5d | 689 | (defcustom gnus-article-mode-line-format "Gnus: %g %S%m" |
eec82323 | 690 | "*The format specification for the article mode line. |
16409b0b GM |
691 | See `gnus-summary-mode-line-format' for a closer description. |
692 | ||
693 | The following additional specs are available: | |
694 | ||
695 | %w The article washing status. | |
696 | %m The number of MIME parts in the article." | |
12295c5d | 697 | :version "24.1" |
eec82323 LMI |
698 | :type 'string |
699 | :group 'gnus-article-various) | |
700 | ||
701 | (defcustom gnus-article-mode-hook nil | |
702 | "*A hook for Gnus article mode." | |
703 | :type 'hook | |
704 | :group 'gnus-article-various) | |
705 | ||
23f87bed MB |
706 | (when (featurep 'xemacs) |
707 | ;; Extracted from gnus-xmas-define in order to preserve user settings | |
708 | (when (fboundp 'turn-off-scroll-in-place) | |
709 | (add-hook 'gnus-article-mode-hook 'turn-off-scroll-in-place)) | |
710 | ;; Extracted from gnus-xmas-redefine in order to preserve user settings | |
711 | (add-hook 'gnus-article-mode-hook 'gnus-xmas-article-menu-add)) | |
712 | ||
eec82323 LMI |
713 | (defcustom gnus-article-menu-hook nil |
714 | "*Hook run after the creation of the article mode menu." | |
715 | :type 'hook | |
716 | :group 'gnus-article-various) | |
717 | ||
718 | (defcustom gnus-article-prepare-hook nil | |
16409b0b | 719 | "*A hook called after an article has been prepared in the article buffer." |
eec82323 LMI |
720 | :type 'hook |
721 | :group 'gnus-article-various) | |
722 | ||
01c52d31 MB |
723 | (defcustom gnus-copy-article-ignored-headers nil |
724 | "List of headers to be removed when copying an article. | |
725 | Each element is a regular expression." | |
330f707b | 726 | :version "23.1" ;; No Gnus |
01c52d31 MB |
727 | :type '(repeat regexp) |
728 | :group 'gnus-article-various) | |
729 | ||
265ac10b | 730 | (make-obsolete-variable 'gnus-article-hide-pgp-hook nil |
6b958814 | 731 | "Gnus 5.10 (Emacs 22.1)") |
a8151ef7 | 732 | |
01c52d31 MB |
733 | (defface gnus-button |
734 | '((t (:weight bold))) | |
735 | "Face used for highlighting a button in the article buffer." | |
736 | :group 'gnus-article-buttons) | |
737 | ||
738 | (defcustom gnus-article-button-face 'gnus-button | |
eec82323 LMI |
739 | "Face used for highlighting buttons in the article buffer. |
740 | ||
741 | An article button is a piece of text that you can activate by pressing | |
742 | `RET' or `mouse-2' above it." | |
743 | :type 'face | |
744 | :group 'gnus-article-buttons) | |
745 | ||
746 | (defcustom gnus-article-mouse-face 'highlight | |
747 | "Face used for mouse highlighting in the article buffer. | |
748 | ||
749 | Article buttons will be displayed in this face when the cursor is | |
750 | above them." | |
751 | :type 'face | |
752 | :group 'gnus-article-buttons) | |
753 | ||
0f49874b | 754 | (defcustom gnus-signature-face 'gnus-signature |
a8151ef7 | 755 | "Face used for highlighting a signature in the article buffer. |
0f49874b | 756 | Obsolete; use the face `gnus-signature' for customizations instead." |
eec82323 LMI |
757 | :type 'face |
758 | :group 'gnus-article-highlight | |
759 | :group 'gnus-article-signature) | |
760 | ||
0f49874b | 761 | (defface gnus-signature |
f59a3415 | 762 | '((t |
23f87bed | 763 | (:italic t))) |
a8151ef7 LMI |
764 | "Face used for highlighting a signature in the article buffer." |
765 | :group 'gnus-article-highlight | |
766 | :group 'gnus-article-signature) | |
0f49874b MB |
767 | ;; backward-compatibility alias |
768 | (put 'gnus-signature-face 'face-alias 'gnus-signature) | |
3d493bef | 769 | (put 'gnus-signature-face 'obsolete-face "22.1") |
a8151ef7 | 770 | |
0f49874b | 771 | (defface gnus-header-from |
eec82323 LMI |
772 | '((((class color) |
773 | (background dark)) | |
01c52d31 | 774 | (:foreground "PaleGreen1")) |
eec82323 LMI |
775 | (((class color) |
776 | (background light)) | |
6748645f | 777 | (:foreground "red3")) |
eec82323 | 778 | (t |
23f87bed | 779 | (:italic t))) |
eec82323 LMI |
780 | "Face used for displaying from headers." |
781 | :group 'gnus-article-headers | |
782 | :group 'gnus-article-highlight) | |
0f49874b MB |
783 | ;; backward-compatibility alias |
784 | (put 'gnus-header-from-face 'face-alias 'gnus-header-from) | |
3d493bef | 785 | (put 'gnus-header-from-face 'obsolete-face "22.1") |
eec82323 | 786 | |
0f49874b | 787 | (defface gnus-header-subject |
eec82323 LMI |
788 | '((((class color) |
789 | (background dark)) | |
01c52d31 | 790 | (:foreground "SeaGreen1")) |
eec82323 LMI |
791 | (((class color) |
792 | (background light)) | |
6748645f | 793 | (:foreground "red4")) |
eec82323 | 794 | (t |
23f87bed | 795 | (:bold t :italic t))) |
eec82323 LMI |
796 | "Face used for displaying subject headers." |
797 | :group 'gnus-article-headers | |
798 | :group 'gnus-article-highlight) | |
0f49874b MB |
799 | ;; backward-compatibility alias |
800 | (put 'gnus-header-subject-face 'face-alias 'gnus-header-subject) | |
3d493bef | 801 | (put 'gnus-header-subject-face 'obsolete-face "22.1") |
eec82323 | 802 | |
0f49874b | 803 | (defface gnus-header-newsgroups |
eec82323 LMI |
804 | '((((class color) |
805 | (background dark)) | |
23f87bed | 806 | (:foreground "yellow" :italic t)) |
eec82323 LMI |
807 | (((class color) |
808 | (background light)) | |
23f87bed | 809 | (:foreground "MidnightBlue" :italic t)) |
eec82323 | 810 | (t |
23f87bed MB |
811 | (:italic t))) |
812 | "Face used for displaying newsgroups headers. | |
813 | In the default setup this face is only used for crossposted | |
814 | articles." | |
eec82323 LMI |
815 | :group 'gnus-article-headers |
816 | :group 'gnus-article-highlight) | |
0f49874b MB |
817 | ;; backward-compatibility alias |
818 | (put 'gnus-header-newsgroups-face 'face-alias 'gnus-header-newsgroups) | |
3d493bef | 819 | (put 'gnus-header-newsgroups-face 'obsolete-face "22.1") |
eec82323 | 820 | |
0f49874b | 821 | (defface gnus-header-name |
eec82323 LMI |
822 | '((((class color) |
823 | (background dark)) | |
01c52d31 | 824 | (:foreground "SpringGreen2")) |
eec82323 LMI |
825 | (((class color) |
826 | (background light)) | |
827 | (:foreground "maroon")) | |
828 | (t | |
23f87bed | 829 | (:bold t))) |
eec82323 LMI |
830 | "Face used for displaying header names." |
831 | :group 'gnus-article-headers | |
832 | :group 'gnus-article-highlight) | |
0f49874b MB |
833 | ;; backward-compatibility alias |
834 | (put 'gnus-header-name-face 'face-alias 'gnus-header-name) | |
3d493bef | 835 | (put 'gnus-header-name-face 'obsolete-face "22.1") |
eec82323 | 836 | |
0f49874b | 837 | (defface gnus-header-content |
eec82323 LMI |
838 | '((((class color) |
839 | (background dark)) | |
01c52d31 | 840 | (:foreground "SpringGreen1" :italic t)) |
eec82323 LMI |
841 | (((class color) |
842 | (background light)) | |
23f87bed | 843 | (:foreground "indianred4" :italic t)) |
eec82323 | 844 | (t |
23f87bed | 845 | (:italic t))) "Face used for displaying header content." |
eec82323 LMI |
846 | :group 'gnus-article-headers |
847 | :group 'gnus-article-highlight) | |
0f49874b MB |
848 | ;; backward-compatibility alias |
849 | (put 'gnus-header-content-face 'face-alias 'gnus-header-content) | |
3d493bef | 850 | (put 'gnus-header-content-face 'obsolete-face "22.1") |
eec82323 LMI |
851 | |
852 | (defcustom gnus-header-face-alist | |
0f49874b MB |
853 | '(("From" nil gnus-header-from) |
854 | ("Subject" nil gnus-header-subject) | |
855 | ("Newsgroups:.*," nil gnus-header-newsgroups) | |
856 | ("" gnus-header-name gnus-header-content)) | |
23f87bed | 857 | "*Controls highlighting of article headers. |
eec82323 LMI |
858 | |
859 | An alist of the form (HEADER NAME CONTENT). | |
860 | ||
23f87bed MB |
861 | HEADER is a regular expression which should match the name of a |
862 | header and NAME and CONTENT are either face names or nil. | |
eec82323 LMI |
863 | |
864 | The name of each header field will be displayed using the face | |
23f87bed MB |
865 | specified by the first element in the list where HEADER matches |
866 | the header name and NAME is non-nil. Similarly, the content will | |
867 | be displayed by the first non-nil matching CONTENT face." | |
eec82323 LMI |
868 | :group 'gnus-article-headers |
869 | :group 'gnus-article-highlight | |
870 | :type '(repeat (list (regexp :tag "Header") | |
871 | (choice :tag "Name" | |
872 | (item :tag "skip" nil) | |
873 | (face :value default)) | |
874 | (choice :tag "Content" | |
875 | (item :tag "skip" nil) | |
876 | (face :value default))))) | |
877 | ||
01c52d31 MB |
878 | (defcustom gnus-face-properties-alist (if (featurep 'xemacs) |
879 | '((xface . (:face gnus-x-face))) | |
880 | '((pbm . (:face gnus-x-face)) | |
881 | (png . nil))) | |
882 | "Alist of image types and properties applied to Face and X-Face images. | |
883 | Here are examples: | |
884 | ||
885 | ;; Specify the altitude of Face images in the From header. | |
886 | \(setq gnus-face-properties-alist | |
887 | '((pbm . (:face gnus-x-face :ascent 80)) | |
888 | (png . (:ascent 80)))) | |
889 | ||
890 | ;; Show Face images as pressed buttons. | |
891 | \(setq gnus-face-properties-alist | |
892 | '((pbm . (:face gnus-x-face :relief -2)) | |
893 | (png . (:relief -2)))) | |
894 | ||
895 | See the manual for the valid properties for various image types. | |
896 | Currently, `pbm' is used for X-Face images and `png' is used for Face | |
897 | images in Emacs. Only the `:face' property is effective on the `xface' | |
898 | image type in XEmacs if it is built with the libcompface library." | |
330f707b | 899 | :version "23.1" ;; No Gnus |
01c52d31 MB |
900 | :group 'gnus-article-headers |
901 | :type '(repeat (cons :format "%v" (symbol :tag "Image type") plist))) | |
902 | ||
16409b0b | 903 | (defcustom gnus-article-decode-hook |
23f87bed MB |
904 | '(article-decode-charset article-decode-encoded-words |
905 | article-decode-group-name article-decode-idna-rhs) | |
16409b0b GM |
906 | "*Hook run to decode charsets in articles." |
907 | :group 'gnus-article-headers | |
908 | :type 'hook) | |
909 | ||
910 | (defcustom gnus-display-mime-function 'gnus-display-mime | |
911 | "Function to display MIME articles." | |
912 | :group 'gnus-article-mime | |
913 | :type 'function) | |
914 | ||
915 | (defvar gnus-decode-header-function 'mail-decode-encoded-word-region | |
916 | "Function used to decode headers.") | |
917 | ||
343d6628 MB |
918 | (defvar gnus-decode-address-function 'mail-decode-encoded-address-region |
919 | "Function used to decode addresses.") | |
920 | ||
16409b0b | 921 | (defvar gnus-article-dumbquotes-map |
7cad71ad G |
922 | '((?\200 "EUR") |
923 | (?\202 ",") | |
924 | (?\203 "f") | |
925 | (?\204 ",,") | |
926 | (?\205 "...") | |
927 | (?\213 "<") | |
928 | (?\214 "OE") | |
929 | (?\221 "`") | |
930 | (?\222 "'") | |
931 | (?\223 "``") | |
932 | (?\224 "\"") | |
933 | (?\225 "*") | |
934 | (?\226 "-") | |
935 | (?\227 "--") | |
936 | (?\230 "~") | |
937 | (?\231 "(TM)") | |
938 | (?\233 ">") | |
939 | (?\234 "oe") | |
940 | (?\264 "'")) | |
16409b0b GM |
941 | "Table for MS-to-Latin1 translation.") |
942 | ||
943 | (defcustom gnus-ignored-mime-types nil | |
944 | "List of MIME types that should be ignored by Gnus." | |
fc2c2db8 | 945 | :version "21.1" |
16409b0b GM |
946 | :group 'gnus-article-mime |
947 | :type '(repeat regexp)) | |
948 | ||
949 | (defcustom gnus-unbuttonized-mime-types '(".*/.*") | |
23f87bed MB |
950 | "List of MIME types that should not be given buttons when rendered inline. |
951 | See also `gnus-buttonized-mime-types' which may override this variable. | |
952 | This variable is only used when `gnus-inhibit-mime-unbuttonizing' is nil." | |
953 | :version "21.1" | |
954 | :group 'gnus-article-mime | |
955 | :type '(repeat regexp)) | |
956 | ||
957 | (defcustom gnus-buttonized-mime-types nil | |
958 | "List of MIME types that should be given buttons when rendered inline. | |
959 | If set, this variable overrides `gnus-unbuttonized-mime-types'. | |
960 | To see e.g. security buttons you could set this to | |
3031d8b0 MB |
961 | `(\"multipart/signed\")'. You could also add \"multipart/alternative\" to |
962 | this list to display radio buttons that allow you to choose one of two | |
963 | media types those mails include. See also `mm-discouraged-alternatives'. | |
23f87bed | 964 | This variable is only used when `gnus-inhibit-mime-unbuttonizing' is nil." |
bf247b6e | 965 | :version "22.1" |
16409b0b GM |
966 | :group 'gnus-article-mime |
967 | :type '(repeat regexp)) | |
968 | ||
23f87bed MB |
969 | (defcustom gnus-inhibit-mime-unbuttonizing nil |
970 | "If non-nil, all MIME parts get buttons. | |
971 | When nil (the default value), then some MIME parts do not get buttons, | |
972 | as described by the variables `gnus-buttonized-mime-types' and | |
973 | `gnus-unbuttonized-mime-types'." | |
bf247b6e | 974 | :version "22.1" |
d0859c9a | 975 | :group 'gnus-article-mime |
23f87bed MB |
976 | :type 'boolean) |
977 | ||
978 | (defcustom gnus-body-boundary-delimiter "_" | |
979 | "String used to delimit header and body. | |
980 | This variable is used by `gnus-article-treat-body-boundary' which can | |
981 | be controlled by `gnus-treat-body-boundary'." | |
bf247b6e | 982 | :version "22.1" |
23f87bed MB |
983 | :group 'gnus-article-various |
984 | :type '(choice (item :tag "None" :value nil) | |
985 | string)) | |
986 | ||
97f78c9b MB |
987 | (defcustom gnus-picon-databases '("/usr/lib/picon" "/usr/local/faces" |
988 | "/usr/share/picons") | |
23f87bed MB |
989 | "Defines the location of the faces database. |
990 | For information on obtaining this database of pretty pictures, please | |
991 | see http://www.cs.indiana.edu/picons/ftp/index.html" | |
bf247b6e | 992 | :version "22.1" |
23f87bed MB |
993 | :type '(repeat directory) |
994 | :link '(url-link :tag "download" | |
995 | "http://www.cs.indiana.edu/picons/ftp/index.html") | |
996 | :link '(custom-manual "(gnus)Picons") | |
997 | :group 'gnus-picon) | |
998 | ||
999 | (defun gnus-picons-installed-p () | |
1000 | "Say whether picons are installed on your machine." | |
1001 | (let ((installed nil)) | |
1002 | (dolist (database gnus-picon-databases) | |
1003 | (when (file-exists-p database) | |
1004 | (setq installed t))) | |
1005 | installed)) | |
1006 | ||
16409b0b GM |
1007 | (defcustom gnus-article-mime-part-function nil |
1008 | "Function called with a MIME handle as the argument. | |
1009 | This is meant for people who want to do something automatic based | |
1010 | on parts -- for instance, adding Vcard info to a database." | |
1011 | :group 'gnus-article-mime | |
4a2358e9 MB |
1012 | :type '(choice (const nil) |
1013 | function)) | |
16409b0b GM |
1014 | |
1015 | (defcustom gnus-mime-multipart-functions nil | |
fc2c2db8 DL |
1016 | "An alist of MIME types to functions to display them." |
1017 | :version "21.1" | |
1018 | :group 'gnus-article-mime | |
01c52d31 | 1019 | :type '(repeat (cons :format "%v" (string :tag "MIME type") function))) |
16409b0b | 1020 | |
c61a8b44 | 1021 | (defcustom gnus-article-date-headers '(combined-lapsed) |
12e3ca0a LI |
1022 | "A list of Date header formats to display. |
1023 | Valid formats are `ut' (universal time), `local' (local time | |
1024 | zone), `english' (readable English), `lapsed' (elapsed time), | |
1025 | `combined-lapsed' (both the original date and the elapsed time), | |
1026 | `original' (the original date header), `iso8601' (ISO8601 | |
1027 | format), and `user-defined' (a user-defined format defined by the | |
1028 | `gnus-article-time-format' variable). | |
1029 | ||
1030 | You have as many date headers as you want in the article buffer. | |
1031 | Some of these headers are updated automatically. See | |
1032 | `gnus-article-update-date-headers' for details." | |
1033 | :version "24.1" | |
16409b0b | 1034 | :group 'gnus-article-headers |
a931698a GM |
1035 | :type '(set |
1036 | (const :tag "Universal time (UT)" ut) | |
1037 | (const :tag "Local time zone" local) | |
1038 | (const :tag "Readable English" english) | |
1039 | (const :tag "Elapsed time" lapsed) | |
1040 | (const :tag "Original and elapsed time" combined-lapsed) | |
1041 | (const :tag "Original date header" original) | |
1042 | (const :tag "ISO8601 format" iso8601) | |
1043 | (const :tag "User-defined" user-defined))) | |
12e3ca0a | 1044 | |
138c0212 | 1045 | (defcustom gnus-article-update-date-headers nil |
8e22bee0 | 1046 | "A number that says how often to update the date header (in seconds). |
647559c2 LI |
1047 | If nil, don't update it at all." |
1048 | :version "24.1" | |
1049 | :group 'gnus-article-headers | |
1050 | :type '(choice | |
1051 | (item :tag "Don't update" :value nil) | |
1052 | integer)) | |
1053 | ||
16409b0b GM |
1054 | (defcustom gnus-article-mime-match-handle-function 'undisplayed-alternative |
1055 | "Function called with a MIME handle as the argument. | |
1056 | This is meant for people who want to view first matched part. | |
a1506d29 JB |
1057 | For `undisplayed-alternative' (default), the first undisplayed |
1058 | part or alternative part is used. For `undisplayed', the first | |
1059 | undisplayed part is used. For a function, the first part which | |
f20b2f5c | 1060 | the function return t is used. For nil, the first part is |
16409b0b | 1061 | used." |
fc2c2db8 | 1062 | :version "21.1" |
16409b0b | 1063 | :group 'gnus-article-mime |
a1506d29 | 1064 | :type '(choice |
16409b0b GM |
1065 | (item :tag "first" :value nil) |
1066 | (item :tag "undisplayed" :value undisplayed) | |
a1506d29 | 1067 | (item :tag "undisplayed or alternative" |
16409b0b GM |
1068 | :value undisplayed-alternative) |
1069 | (function))) | |
1070 | ||
e0bad764 DL |
1071 | (defcustom gnus-mime-action-alist |
1072 | '(("save to file" . gnus-mime-save-part) | |
23f87bed | 1073 | ("save and strip" . gnus-mime-save-part-and-strip) |
01c52d31 | 1074 | ("replace with file" . gnus-mime-replace-part) |
23f87bed | 1075 | ("delete part" . gnus-mime-delete-part) |
e0bad764 DL |
1076 | ("display as text" . gnus-mime-inline-part) |
1077 | ("view the part" . gnus-mime-view-part) | |
1078 | ("pipe to command" . gnus-mime-pipe-part) | |
1079 | ("toggle display" . gnus-article-press-button) | |
23f87bed | 1080 | ("toggle display" . gnus-article-view-part-as-charset) |
e0bad764 | 1081 | ("view as type" . gnus-mime-view-part-as-type) |
23f87bed MB |
1082 | ("view internally" . gnus-mime-view-part-internally) |
1083 | ("view externally" . gnus-mime-view-part-externally)) | |
e0bad764 DL |
1084 | "An alist of actions that run on the MIME attachment." |
1085 | :group 'gnus-article-mime | |
1086 | :type '(repeat (cons (string :tag "name") | |
1087 | (function)))) | |
1088 | ||
01c52d31 MB |
1089 | (defcustom gnus-auto-select-part 1 |
1090 | "Advance to next MIME part when deleting or stripping parts. | |
1091 | ||
1092 | When 0, point will be placed on the same part as before. When | |
1093 | positive (negative), move point forward (backwards) this many | |
1094 | parts. When nil, redisplay article." | |
330f707b | 1095 | :version "23.1" ;; No Gnus |
01c52d31 MB |
1096 | :group 'gnus-article-mime |
1097 | :type '(choice (const nil :tag "Redisplay article.") | |
1098 | (const 1 :tag "Next part.") | |
1099 | (const 0 :tag "Current part.") | |
1100 | integer)) | |
1101 | ||
16409b0b GM |
1102 | ;;; |
1103 | ;;; The treatment variables | |
1104 | ;;; | |
1105 | ||
1106 | (defvar gnus-part-display-hook nil | |
1107 | "Hook called on parts that are to receive treatment.") | |
1108 | ||
1109 | (defvar gnus-article-treat-custom | |
1110 | '(choice (const :tag "Off" nil) | |
1111 | (const :tag "On" t) | |
1112 | (const :tag "Header" head) | |
01c52d31 | 1113 | (const :tag "First" first) |
16409b0b GM |
1114 | (const :tag "Last" last) |
1115 | (integer :tag "Less") | |
1116 | (repeat :tag "Groups" regexp) | |
1117 | (sexp :tag "Predicate"))) | |
1118 | ||
1119 | (defvar gnus-article-treat-head-custom | |
1120 | '(choice (const :tag "Off" nil) | |
1121 | (const :tag "Header" head))) | |
1122 | ||
01c52d31 | 1123 | (defvar gnus-article-treat-types '("text/plain" "text/x-verbatim" |
da42d41a G |
1124 | "text/x-patch" "text/html") |
1125 | "Part types eligible for treatment.") | |
16409b0b GM |
1126 | |
1127 | (defvar gnus-inhibit-treatment nil | |
1128 | "Whether to inhibit treatment.") | |
1129 | ||
23f87bed | 1130 | (defcustom gnus-treat-highlight-signature '(or t (typep "text/x-vcard")) |
16409b0b | 1131 | "Highlight the signature. |
01c52d31 MB |
1132 | Valid values are nil, t, `head', `first', `last', an integer or a |
1133 | predicate. See Info node `(gnus)Customizing Articles'." | |
16409b0b | 1134 | :group 'gnus-article-treat |
23f87bed | 1135 | :link '(custom-manual "(gnus)Customizing Articles") |
16409b0b GM |
1136 | :type gnus-article-treat-custom) |
1137 | (put 'gnus-treat-highlight-signature 'highlight t) | |
1138 | ||
1139 | (defcustom gnus-treat-buttonize 100000 | |
1140 | "Add buttons. | |
01c52d31 MB |
1141 | Valid values are nil, t, `head', `first', `last', an integer or a |
1142 | predicate. See Info node `(gnus)Customizing Articles'." | |
16409b0b | 1143 | :group 'gnus-article-treat |
23f87bed | 1144 | :link '(custom-manual "(gnus)Customizing Articles") |
16409b0b GM |
1145 | :type gnus-article-treat-custom) |
1146 | (put 'gnus-treat-buttonize 'highlight t) | |
1147 | ||
1148 | (defcustom gnus-treat-buttonize-head 'head | |
1149 | "Add buttons to the head. | |
01c52d31 MB |
1150 | Valid values are nil, t, `head', `first', `last', an integer or a |
1151 | predicate. See Info node `(gnus)Customizing Articles'." | |
16409b0b | 1152 | :group 'gnus-article-treat |
23f87bed | 1153 | :link '(custom-manual "(gnus)Customizing Articles") |
16409b0b GM |
1154 | :type gnus-article-treat-head-custom) |
1155 | (put 'gnus-treat-buttonize-head 'highlight t) | |
1156 | ||
12e3ca0a LI |
1157 | (defcustom gnus-treat-date 'head |
1158 | "Display dates according to the `gnus-article-date-headers' variable. | |
1159 | Valid values are nil, t, `head', `first', `last', an integer or a | |
1160 | predicate. See Info node `(gnus)Customizing Articles'." | |
1161 | :version "24.1" | |
1162 | :group 'gnus-article-treat | |
1163 | :link '(custom-manual "(gnus)Customizing Articles") | |
1164 | :type gnus-article-treat-head-custom) | |
1165 | ||
437ce4be | 1166 | (defcustom gnus-treat-emphasize 50000 |
16409b0b | 1167 | "Emphasize text. |
01c52d31 MB |
1168 | Valid values are nil, t, `head', `first', `last', an integer or a |
1169 | predicate. See Info node `(gnus)Customizing Articles'." | |
16409b0b | 1170 | :group 'gnus-article-treat |
23f87bed | 1171 | :link '(custom-manual "(gnus)Customizing Articles") |
16409b0b GM |
1172 | :type gnus-article-treat-custom) |
1173 | (put 'gnus-treat-emphasize 'highlight t) | |
1174 | ||
1175 | (defcustom gnus-treat-strip-cr nil | |
1176 | "Remove carriage returns. | |
01c52d31 MB |
1177 | Valid values are nil, t, `head', `first', `last', an integer or a |
1178 | predicate. See Info node `(gnus)Customizing Articles'." | |
bf247b6e | 1179 | :version "22.1" |
16409b0b | 1180 | :group 'gnus-article-treat |
23f87bed MB |
1181 | :link '(custom-manual "(gnus)Customizing Articles") |
1182 | :type gnus-article-treat-custom) | |
1183 | ||
1184 | (defcustom gnus-treat-unsplit-urls nil | |
1185 | "Remove newlines from within URLs. | |
01c52d31 MB |
1186 | Valid values are nil, t, `head', `first', `last', an integer or a |
1187 | predicate. See Info node `(gnus)Customizing Articles'." | |
bf247b6e | 1188 | :version "22.1" |
23f87bed MB |
1189 | :group 'gnus-article-treat |
1190 | :link '(custom-manual "(gnus)Customizing Articles") | |
1191 | :type gnus-article-treat-custom) | |
1192 | ||
1193 | (defcustom gnus-treat-leading-whitespace nil | |
1194 | "Remove leading whitespace in headers. | |
01c52d31 MB |
1195 | Valid values are nil, t, `head', `first', `last', an integer or a |
1196 | predicate. See Info node `(gnus)Customizing Articles'." | |
bf247b6e | 1197 | :version "22.1" |
23f87bed MB |
1198 | :group 'gnus-article-treat |
1199 | :link '(custom-manual "(gnus)Customizing Articles") | |
16409b0b GM |
1200 | :type gnus-article-treat-custom) |
1201 | ||
1202 | (defcustom gnus-treat-hide-headers 'head | |
1203 | "Hide headers. | |
01c52d31 MB |
1204 | Valid values are nil, t, `head', `first', `last', an integer or a |
1205 | predicate. See Info node `(gnus)Customizing Articles'." | |
16409b0b | 1206 | :group 'gnus-article-treat |
23f87bed | 1207 | :link '(custom-manual "(gnus)Customizing Articles") |
16409b0b GM |
1208 | :type gnus-article-treat-head-custom) |
1209 | ||
1210 | (defcustom gnus-treat-hide-boring-headers nil | |
1211 | "Hide boring headers. | |
01c52d31 MB |
1212 | Valid values are nil, t, `head', `first', `last', an integer or a |
1213 | predicate. See Info node `(gnus)Customizing Articles'." | |
16409b0b | 1214 | :group 'gnus-article-treat |
23f87bed | 1215 | :link '(custom-manual "(gnus)Customizing Articles") |
16409b0b GM |
1216 | :type gnus-article-treat-head-custom) |
1217 | ||
1218 | (defcustom gnus-treat-hide-signature nil | |
1219 | "Hide the signature. | |
01c52d31 MB |
1220 | Valid values are nil, t, `head', `first', `last', an integer or a |
1221 | predicate. See Info node `(gnus)Customizing Articles'." | |
16409b0b | 1222 | :group 'gnus-article-treat |
23f87bed | 1223 | :link '(custom-manual "(gnus)Customizing Articles") |
16409b0b GM |
1224 | :type gnus-article-treat-custom) |
1225 | ||
1226 | (defcustom gnus-treat-fill-article nil | |
1227 | "Fill the article. | |
01c52d31 MB |
1228 | Valid values are nil, t, `head', `first', `last', an integer or a |
1229 | predicate. See Info node `(gnus)Customizing Articles'." | |
16409b0b | 1230 | :group 'gnus-article-treat |
23f87bed | 1231 | :link '(custom-manual "(gnus)Customizing Articles") |
16409b0b GM |
1232 | :type gnus-article-treat-custom) |
1233 | ||
1234 | (defcustom gnus-treat-hide-citation nil | |
1235 | "Hide cited text. | |
01c52d31 | 1236 | Valid values are nil, t, `head', `first', `last', an integer or a |
a5166359 LMI |
1237 | predicate. See Info node `(gnus)Customizing Articles'. |
1238 | ||
1239 | See `gnus-article-highlight-citation' for variables used to | |
1240 | control what it hides." | |
16409b0b | 1241 | :group 'gnus-article-treat |
23f87bed | 1242 | :link '(custom-manual "(gnus)Customizing Articles") |
16409b0b GM |
1243 | :type gnus-article-treat-custom) |
1244 | ||
e0bad764 | 1245 | (defcustom gnus-treat-hide-citation-maybe nil |
e21bac42 | 1246 | "Hide cited text according to certain conditions. |
01c52d31 | 1247 | Valid values are nil, t, `head', `first', `last', an integer or a |
e21bac42 G |
1248 | predicate. See Info node `(gnus)Customizing Articles'. |
1249 | ||
1250 | See `gnus-cite-hide-percentage' and `gnus-cite-hide-absolute' for | |
1251 | how to control what it hides." | |
e0bad764 | 1252 | :group 'gnus-article-treat |
23f87bed | 1253 | :link '(custom-manual "(gnus)Customizing Articles") |
e0bad764 DL |
1254 | :type gnus-article-treat-custom) |
1255 | ||
16409b0b GM |
1256 | (defcustom gnus-treat-strip-list-identifiers 'head |
1257 | "Strip list identifiers from `gnus-list-identifiers`. | |
01c52d31 MB |
1258 | Valid values are nil, t, `head', `first', `last', an integer or a |
1259 | predicate. See Info node `(gnus)Customizing Articles'." | |
fc2c2db8 | 1260 | :version "21.1" |
16409b0b | 1261 | :group 'gnus-article-treat |
23f87bed | 1262 | :link '(custom-manual "(gnus)Customizing Articles") |
16409b0b GM |
1263 | :type gnus-article-treat-custom) |
1264 | ||
fb9b91be JD |
1265 | (gnus-define-group-parameter |
1266 | list-identifier | |
1267 | :variable-document | |
1268 | "Alist of regexps and correspondent identifiers." | |
1269 | :variable-group gnus-article-washing | |
1270 | :parameter-type | |
1271 | '(choice :tag "Identifier" | |
1272 | :value nil | |
1273 | (symbol :tag "Item in `gnus-list-identifiers'" none) | |
1274 | regexp | |
1275 | (const :tag "None" nil)) | |
1276 | :parameter-document | |
1277 | "If non-nil, specify how to remove `identifiers' from articles' subject. | |
1278 | ||
1279 | Any symbol is used to look up a regular expression to match the | |
1280 | banner in `gnus-list-identifiers'. A string is used as a regular | |
1281 | expression to match the identifier directly.") | |
1282 | ||
265ac10b SM |
1283 | (make-obsolete-variable 'gnus-treat-strip-pgp nil |
1284 | "Gnus 5.10 (Emacs 22.1)") | |
16409b0b GM |
1285 | |
1286 | (defcustom gnus-treat-strip-pem nil | |
1287 | "Strip PEM signatures. | |
01c52d31 MB |
1288 | Valid values are nil, t, `head', `first', `last', an integer or a |
1289 | predicate. See Info node `(gnus)Customizing Articles'." | |
16409b0b | 1290 | :group 'gnus-article-treat |
23f87bed | 1291 | :link '(custom-manual "(gnus)Customizing Articles") |
16409b0b GM |
1292 | :type gnus-article-treat-custom) |
1293 | ||
1294 | (defcustom gnus-treat-strip-banner t | |
1295 | "Strip banners from articles. | |
1296 | The banner to be stripped is specified in the `banner' group parameter. | |
01c52d31 MB |
1297 | Valid values are nil, t, `head', `first', `last', an integer or a |
1298 | predicate. See Info node `(gnus)Customizing Articles'." | |
16409b0b | 1299 | :group 'gnus-article-treat |
23f87bed | 1300 | :link '(custom-manual "(gnus)Customizing Articles") |
16409b0b GM |
1301 | :type gnus-article-treat-custom) |
1302 | ||
1303 | (defcustom gnus-treat-highlight-headers 'head | |
1304 | "Highlight the headers. | |
01c52d31 MB |
1305 | Valid values are nil, t, `head', `first', `last', an integer or a |
1306 | predicate. See Info node `(gnus)Customizing Articles'." | |
16409b0b | 1307 | :group 'gnus-article-treat |
23f87bed | 1308 | :link '(custom-manual "(gnus)Customizing Articles") |
16409b0b GM |
1309 | :type gnus-article-treat-head-custom) |
1310 | (put 'gnus-treat-highlight-headers 'highlight t) | |
1311 | ||
1312 | (defcustom gnus-treat-highlight-citation t | |
1313 | "Highlight cited text. | |
01c52d31 MB |
1314 | Valid values are nil, t, `head', `first', `last', an integer or a |
1315 | predicate. See Info node `(gnus)Customizing Articles'." | |
16409b0b | 1316 | :group 'gnus-article-treat |
23f87bed | 1317 | :link '(custom-manual "(gnus)Customizing Articles") |
16409b0b GM |
1318 | :type gnus-article-treat-custom) |
1319 | (put 'gnus-treat-highlight-citation 'highlight t) | |
1320 | ||
16409b0b GM |
1321 | (defcustom gnus-treat-strip-headers-in-body t |
1322 | "Strip the X-No-Archive header line from the beginning of the body. | |
01c52d31 MB |
1323 | Valid values are nil, t, `head', `first', `last', an integer or a |
1324 | predicate. See Info node `(gnus)Customizing Articles'." | |
fc2c2db8 | 1325 | :version "21.1" |
16409b0b | 1326 | :group 'gnus-article-treat |
23f87bed | 1327 | :link '(custom-manual "(gnus)Customizing Articles") |
16409b0b GM |
1328 | :type gnus-article-treat-custom) |
1329 | ||
1330 | (defcustom gnus-treat-strip-trailing-blank-lines nil | |
1331 | "Strip trailing blank lines. | |
01c52d31 MB |
1332 | Valid values are nil, t, `head', `first', `last', an integer or a |
1333 | predicate. See Info node `(gnus)Customizing Articles'. | |
292f71fe MB |
1334 | |
1335 | When set to t, it also strips trailing blanks in all MIME parts. | |
1336 | Consider to use `last' instead." | |
16409b0b | 1337 | :group 'gnus-article-treat |
23f87bed | 1338 | :link '(custom-manual "(gnus)Customizing Articles") |
16409b0b GM |
1339 | :type gnus-article-treat-custom) |
1340 | ||
1341 | (defcustom gnus-treat-strip-leading-blank-lines nil | |
1342 | "Strip leading blank lines. | |
01c52d31 MB |
1343 | Valid values are nil, t, `head', `first', `last', an integer or a |
1344 | predicate. See Info node `(gnus)Customizing Articles'. | |
292f71fe MB |
1345 | |
1346 | When set to t, it also strips trailing blanks in all MIME parts." | |
16409b0b | 1347 | :group 'gnus-article-treat |
23f87bed | 1348 | :link '(custom-manual "(gnus)Customizing Articles") |
16409b0b GM |
1349 | :type gnus-article-treat-custom) |
1350 | ||
1351 | (defcustom gnus-treat-strip-multiple-blank-lines nil | |
1352 | "Strip multiple blank lines. | |
01c52d31 MB |
1353 | Valid values are nil, t, `head', `first', `last', an integer or a |
1354 | predicate. See Info node `(gnus)Customizing Articles'." | |
16409b0b | 1355 | :group 'gnus-article-treat |
23f87bed MB |
1356 | :link '(custom-manual "(gnus)Customizing Articles") |
1357 | :type gnus-article-treat-custom) | |
1358 | ||
1359 | (defcustom gnus-treat-unfold-headers 'head | |
1360 | "Unfold folded header lines. | |
01c52d31 MB |
1361 | Valid values are nil, t, `head', `first', `last', an integer or a |
1362 | predicate. See Info node `(gnus)Customizing Articles'." | |
bf247b6e | 1363 | :version "22.1" |
23f87bed MB |
1364 | :group 'gnus-article-treat |
1365 | :link '(custom-manual "(gnus)Customizing Articles") | |
1366 | :type gnus-article-treat-custom) | |
1367 | ||
01c52d31 MB |
1368 | (defcustom gnus-article-unfold-long-headers nil |
1369 | "If non-nil, allow unfolding headers even if the header is long. | |
1370 | If it is a regexp, only long headers matching this regexp are unfolded. | |
1371 | If it is t, all long headers are unfolded. | |
1372 | ||
1373 | This variable has no effect if `gnus-treat-unfold-headers' is nil." | |
330f707b | 1374 | :version "23.1" ;; No Gnus |
01c52d31 MB |
1375 | :group 'gnus-article-treat |
1376 | :type '(choice (const nil) | |
1377 | (const :tag "all" t) | |
1378 | (regexp))) | |
1379 | ||
23f87bed MB |
1380 | (defcustom gnus-treat-fold-headers nil |
1381 | "Fold headers. | |
01c52d31 MB |
1382 | Valid values are nil, t, `head', `first', `last', an integer or a |
1383 | predicate. See Info node `(gnus)Customizing Articles'." | |
bf247b6e | 1384 | :version "22.1" |
23f87bed MB |
1385 | :group 'gnus-article-treat |
1386 | :link '(custom-manual "(gnus)Customizing Articles") | |
1387 | :type gnus-article-treat-custom) | |
1388 | ||
1389 | (defcustom gnus-treat-fold-newsgroups 'head | |
1390 | "Fold the Newsgroups and Followup-To headers. | |
01c52d31 MB |
1391 | Valid values are nil, t, `head', `first', `last', an integer or a |
1392 | predicate. See Info node `(gnus)Customizing Articles'." | |
bf247b6e | 1393 | :version "22.1" |
23f87bed MB |
1394 | :group 'gnus-article-treat |
1395 | :link '(custom-manual "(gnus)Customizing Articles") | |
16409b0b GM |
1396 | :type gnus-article-treat-custom) |
1397 | ||
1398 | (defcustom gnus-treat-overstrike t | |
1399 | "Treat overstrike highlighting. | |
01c52d31 MB |
1400 | Valid values are nil, t, `head', `first', `last', an integer or a |
1401 | predicate. See Info node `(gnus)Customizing Articles'." | |
16409b0b | 1402 | :group 'gnus-article-treat |
23f87bed | 1403 | :link '(custom-manual "(gnus)Customizing Articles") |
16409b0b GM |
1404 | :type gnus-article-treat-custom) |
1405 | (put 'gnus-treat-overstrike 'highlight t) | |
1406 | ||
01c52d31 MB |
1407 | (defcustom gnus-treat-ansi-sequences (if (locate-library "ansi-color") t) |
1408 | "Treat ANSI SGR control sequences. | |
1409 | Valid values are nil, t, `head', `first', `last', an integer or a | |
1410 | predicate. See Info node `(gnus)Customizing Articles'." | |
1411 | :group 'gnus-article-treat | |
1412 | :link '(custom-manual "(gnus)Customizing Articles") | |
1413 | :type gnus-article-treat-custom) | |
1414 | ||
23f87bed | 1415 | (make-obsolete-variable 'gnus-treat-display-xface |
6b958814 | 1416 | 'gnus-treat-display-x-face "Emacs 22.1") |
23f87bed MB |
1417 | |
1418 | (defcustom gnus-treat-display-x-face | |
1419 | (and (not noninteractive) | |
11e95b02 MB |
1420 | (gnus-image-type-available-p 'xbm) |
1421 | (if (featurep 'xemacs) | |
1422 | (featurep 'xface) | |
86f5c034 SM |
1423 | (condition-case nil |
1424 | (and (string-match "^0x" (shell-command-to-string "uncompface")) | |
1425 | (executable-find "icontopbm")) | |
1426 | ;; shell-command-to-string may signal an error, e.g. if | |
1427 | ;; shell-file-name is not found. | |
1428 | (error nil))) | |
8b93df01 | 1429 | 'head) |
16409b0b | 1430 | "Display X-Face headers. |
87ba2830 | 1431 | Valid values are nil and `head'. |
23f87bed MB |
1432 | See Info node `(gnus)Customizing Articles' and Info node |
1433 | `(gnus)X-Face' for details." | |
1434 | :group 'gnus-article-treat | |
1435 | :version "21.1" | |
1436 | :link '(custom-manual "(gnus)Customizing Articles") | |
1437 | :link '(custom-manual "(gnus)X-Face") | |
1438 | :type gnus-article-treat-head-custom | |
1439 | :set (lambda (symbol value) | |
1440 | (set-default | |
1441 | symbol | |
1442 | (cond ((or (boundp symbol) (get symbol 'saved-value)) | |
1443 | value) | |
1444 | ((boundp 'gnus-treat-display-xface) | |
1445 | (message "\ | |
1446 | ** gnus-treat-display-xface is an obsolete variable;\ | |
1447 | use gnus-treat-display-x-face instead") | |
1448 | (default-value 'gnus-treat-display-xface)) | |
1449 | ((get 'gnus-treat-display-xface 'saved-value) | |
1450 | (message "\ | |
1451 | ** gnus-treat-display-xface is an obsolete variable;\ | |
1452 | use gnus-treat-display-x-face instead") | |
1453 | (eval (car (get 'gnus-treat-display-xface 'saved-value)))) | |
1454 | (t | |
1455 | value))))) | |
1456 | (put 'gnus-treat-display-x-face 'highlight t) | |
1457 | ||
1458 | (defcustom gnus-treat-display-face | |
1459 | (and (not noninteractive) | |
11e95b02 | 1460 | (gnus-image-type-available-p 'png) |
23f87bed MB |
1461 | 'head) |
1462 | "Display Face headers. | |
01c52d31 MB |
1463 | Valid values are nil, t, `head', `first', `last', an integer or a |
1464 | predicate. See Info node `(gnus)Customizing Articles' and Info | |
41ec3f54 | 1465 | node `(gnus)Face' for details." |
16409b0b | 1466 | :group 'gnus-article-treat |
bf247b6e | 1467 | :version "22.1" |
23f87bed MB |
1468 | :link '(custom-manual "(gnus)Customizing Articles") |
1469 | :link '(custom-manual "(gnus)X-Face") | |
16409b0b | 1470 | :type gnus-article-treat-head-custom) |
23f87bed | 1471 | (put 'gnus-treat-display-face 'highlight t) |
16409b0b | 1472 | |
11e95b02 | 1473 | (defcustom gnus-treat-display-smileys (gnus-image-type-available-p 'xpm) |
16409b0b | 1474 | "Display smileys. |
01c52d31 MB |
1475 | Valid values are nil, t, `head', `first', `last', an integer or a |
1476 | predicate. See Info node `(gnus)Customizing Articles' and Info | |
1477 | node `(gnus)Smileys' for details." | |
16409b0b | 1478 | :group 'gnus-article-treat |
b5a206e7 | 1479 | :version "21.1" |
23f87bed MB |
1480 | :link '(custom-manual "(gnus)Customizing Articles") |
1481 | :link '(custom-manual "(gnus)Smileys") | |
16409b0b GM |
1482 | :type gnus-article-treat-custom) |
1483 | (put 'gnus-treat-display-smileys 'highlight t) | |
1484 | ||
23f87bed MB |
1485 | (defcustom gnus-treat-from-picon |
1486 | (if (and (gnus-image-type-available-p 'xpm) | |
1487 | (gnus-picons-installed-p)) | |
1488 | 'head nil) | |
1489 | "Display picons in the From header. | |
01c52d31 MB |
1490 | Valid values are nil, t, `head', `first', `last', an integer or a |
1491 | predicate. See Info node `(gnus)Customizing Articles' and Info | |
1492 | node `(gnus)Picons' for details." | |
bf247b6e | 1493 | :version "22.1" |
16409b0b | 1494 | :group 'gnus-article-treat |
23f87bed MB |
1495 | :group 'gnus-picon |
1496 | :link '(custom-manual "(gnus)Customizing Articles") | |
1497 | :link '(custom-manual "(gnus)Picons") | |
1498 | :type gnus-article-treat-head-custom) | |
1499 | (put 'gnus-treat-from-picon 'highlight t) | |
1500 | ||
1501 | (defcustom gnus-treat-mail-picon | |
1502 | (if (and (gnus-image-type-available-p 'xpm) | |
1503 | (gnus-picons-installed-p)) | |
1504 | 'head nil) | |
1505 | "Display picons in To and Cc headers. | |
01c52d31 MB |
1506 | Valid values are nil, t, `head', `first', `last', an integer or a |
1507 | predicate. See Info node `(gnus)Customizing Articles' and Info | |
1508 | node `(gnus)Picons' for details." | |
bf247b6e | 1509 | :version "22.1" |
23f87bed MB |
1510 | :group 'gnus-article-treat |
1511 | :group 'gnus-picon | |
1512 | :link '(custom-manual "(gnus)Customizing Articles") | |
1513 | :link '(custom-manual "(gnus)Picons") | |
1514 | :type gnus-article-treat-head-custom) | |
1515 | (put 'gnus-treat-mail-picon 'highlight t) | |
1516 | ||
1517 | (defcustom gnus-treat-newsgroups-picon | |
1518 | (if (and (gnus-image-type-available-p 'xpm) | |
1519 | (gnus-picons-installed-p)) | |
1520 | 'head nil) | |
1521 | "Display picons in the Newsgroups and Followup-To headers. | |
01c52d31 MB |
1522 | Valid values are nil, t, `head', `first', `last', an integer or a |
1523 | predicate. See Info node `(gnus)Customizing Articles' and Info | |
1524 | node `(gnus)Picons' for details." | |
bf247b6e | 1525 | :version "22.1" |
23f87bed MB |
1526 | :group 'gnus-article-treat |
1527 | :group 'gnus-picon | |
1528 | :link '(custom-manual "(gnus)Customizing Articles") | |
1529 | :link '(custom-manual "(gnus)Picons") | |
1530 | :type gnus-article-treat-head-custom) | |
1531 | (put 'gnus-treat-newsgroups-picon 'highlight t) | |
1532 | ||
6688abe0 | 1533 | (defcustom gnus-treat-from-gravatar nil |
61b1af82 G |
1534 | "Display gravatars in the From header. |
1535 | Valid values are nil, t, `head', `first', `last', an integer or a | |
1536 | predicate. See Info node `(gnus)Customizing Articles' and Info | |
1537 | node `(gnus)Gravatars' for details." | |
1538 | :version "24.1" | |
1539 | :group 'gnus-article-treat | |
1540 | :group 'gnus-gravatar | |
1541 | :link '(custom-manual "(gnus)Customizing Articles") | |
1542 | :link '(custom-manual "(gnus)Gravatars") | |
1543 | :type gnus-article-treat-head-custom) | |
1544 | (put 'gnus-treat-from-gravatar 'highlight t) | |
1545 | ||
6688abe0 | 1546 | (defcustom gnus-treat-mail-gravatar nil |
61b1af82 G |
1547 | "Display gravatars in To and Cc headers. |
1548 | Valid values are nil, t, `head', `first', `last', an integer or a | |
1549 | predicate. See Info node `(gnus)Customizing Articles' and Info | |
1550 | node `(gnus)Gravatars' for details." | |
1551 | :version "24.1" | |
1552 | :group 'gnus-article-treat | |
1553 | :group 'gnus-gravatar | |
1554 | :link '(custom-manual "(gnus)Customizing Articles") | |
1555 | :link '(custom-manual "(gnus)Gravatars") | |
1556 | :type gnus-article-treat-head-custom) | |
1557 | (put 'gnus-treat-mail-gravatar 'highlight t) | |
1558 | ||
23f87bed | 1559 | (defcustom gnus-treat-body-boundary |
437ce4be MB |
1560 | (if (or gnus-treat-newsgroups-picon |
1561 | gnus-treat-mail-picon | |
61b1af82 G |
1562 | gnus-treat-from-picon |
1563 | gnus-treat-from-gravatar | |
1564 | gnus-treat-mail-gravatar) | |
91af3942 | 1565 | ;; If there's much decoration, the user might prefer a boundary. |
437ce4be MB |
1566 | 'head |
1567 | nil) | |
23f87bed MB |
1568 | "Draw a boundary at the end of the headers. |
1569 | Valid values are nil and `head'. | |
1570 | See Info node `(gnus)Customizing Articles' for details." | |
bf247b6e | 1571 | :version "22.1" |
23f87bed MB |
1572 | :group 'gnus-article-treat |
1573 | :link '(custom-manual "(gnus)Customizing Articles") | |
16409b0b | 1574 | :type gnus-article-treat-head-custom) |
16409b0b GM |
1575 | |
1576 | (defcustom gnus-treat-capitalize-sentences nil | |
1577 | "Capitalize sentence-starting words. | |
01c52d31 MB |
1578 | Valid values are nil, t, `head', `first', `last', an integer or a |
1579 | predicate. See Info node `(gnus)Customizing Articles'." | |
fc2c2db8 | 1580 | :version "21.1" |
16409b0b | 1581 | :group 'gnus-article-treat |
23f87bed MB |
1582 | :link '(custom-manual "(gnus)Customizing Articles") |
1583 | :type gnus-article-treat-custom) | |
1584 | ||
1585 | (defcustom gnus-treat-wash-html nil | |
1586 | "Format as HTML. | |
01c52d31 MB |
1587 | Valid values are nil, t, `head', `first', `last', an integer or a |
1588 | predicate. See Info node `(gnus)Customizing Articles'." | |
bf247b6e | 1589 | :version "22.1" |
23f87bed MB |
1590 | :group 'gnus-article-treat |
1591 | :link '(custom-manual "(gnus)Customizing Articles") | |
16409b0b GM |
1592 | :type gnus-article-treat-custom) |
1593 | ||
389b76fa | 1594 | (defcustom gnus-treat-fill-long-lines '(typep "text/plain") |
16409b0b | 1595 | "Fill long lines. |
01c52d31 MB |
1596 | Valid values are nil, t, `head', `first', `last', an integer or a |
1597 | predicate. See Info node `(gnus)Customizing Articles'." | |
37657cbd | 1598 | :version "24.1" |
16409b0b | 1599 | :group 'gnus-article-treat |
23f87bed | 1600 | :link '(custom-manual "(gnus)Customizing Articles") |
16409b0b GM |
1601 | :type gnus-article-treat-custom) |
1602 | ||
23f87bed MB |
1603 | (defcustom gnus-treat-x-pgp-sig nil |
1604 | "Verify X-PGP-Sig. | |
1605 | To automatically treat X-PGP-Sig, set it to head. | |
01c52d31 MB |
1606 | Valid values are nil, t, `head', `first', `last', an integer or a |
1607 | predicate. See Info node `(gnus)Customizing Articles'." | |
bf247b6e | 1608 | :version "22.1" |
23f87bed MB |
1609 | :group 'gnus-article-treat |
1610 | :group 'mime-security | |
1611 | :link '(custom-manual "(gnus)Customizing Articles") | |
1612 | :type gnus-article-treat-custom) | |
1613 | ||
1614 | (defvar gnus-article-encrypt-protocol-alist | |
1615 | '(("PGP" . mml2015-self-encrypt))) | |
1616 | ||
1617 | ;; Set to nil if more than one protocol added to | |
1618 | ;; gnus-article-encrypt-protocol-alist. | |
1619 | (defcustom gnus-article-encrypt-protocol "PGP" | |
1620 | "The protocol used for encrypt articles. | |
1621 | It is a string, such as \"PGP\". If nil, ask user." | |
bf247b6e | 1622 | :version "22.1" |
23f87bed MB |
1623 | :type 'string |
1624 | :group 'mime-security) | |
1625 | ||
23f87bed MB |
1626 | (defcustom gnus-use-idna (and (condition-case nil (require 'idna) (file-error)) |
1627 | (mm-coding-system-p 'utf-8) | |
1628 | (executable-find idna-program)) | |
1629 | "Whether IDNA decoding of headers is used when viewing messages. | |
1630 | This requires GNU Libidn, and by default only enabled if it is found." | |
bf247b6e | 1631 | :version "22.1" |
23f87bed MB |
1632 | :group 'gnus-article-headers |
1633 | :type 'boolean) | |
1634 | ||
1635 | (defcustom gnus-article-over-scroll nil | |
1636 | "If non-nil, allow scrolling the article buffer even when there no more text." | |
bf247b6e | 1637 | :version "22.1" |
23f87bed MB |
1638 | :group 'gnus-article |
1639 | :type 'boolean) | |
1640 | ||
40de2c6d KY |
1641 | (defcustom gnus-inhibit-images nil |
1642 | "Non-nil means inhibit displaying of images inline in the article body." | |
1643 | :version "24.1" | |
1644 | :group 'gnus-article | |
1645 | :type 'boolean) | |
1646 | ||
2526f423 G |
1647 | (defcustom gnus-blocked-images 'gnus-block-private-groups |
1648 | "Images that have URLs matching this regexp will be blocked. | |
1649 | This can also be a function to be evaluated. If so, it will be | |
1650 | called with the group name as the parameter, and should return a | |
1651 | regexp." | |
130e977f LMI |
1652 | :version "24.1" |
1653 | :group 'gnus-art | |
a931698a | 1654 | :type '(choice regexp function)) |
130e977f | 1655 | |
eec82323 LMI |
1656 | ;;; Internal variables |
1657 | ||
23f87bed MB |
1658 | (defvar gnus-english-month-names |
1659 | '("January" "February" "March" "April" "May" "June" "July" "August" | |
1660 | "September" "October" "November" "December")) | |
1661 | ||
16409b0b GM |
1662 | (defvar article-goto-body-goes-to-point-min-p nil) |
1663 | (defvar gnus-article-wash-types nil) | |
1664 | (defvar gnus-article-emphasis-alist nil) | |
23f87bed | 1665 | (defvar gnus-article-image-alist nil) |
16409b0b GM |
1666 | |
1667 | (defvar gnus-article-mime-handle-alist-1 nil) | |
1668 | (defvar gnus-treatment-function-alist | |
052bd38a LMI |
1669 | '((gnus-treat-strip-cr gnus-article-remove-cr) |
1670 | (gnus-treat-x-pgp-sig gnus-article-verify-x-pgp-sig) | |
23f87bed | 1671 | (gnus-treat-strip-banner gnus-article-strip-banner) |
16409b0b GM |
1672 | (gnus-treat-strip-headers-in-body gnus-article-strip-headers-in-body) |
1673 | (gnus-treat-highlight-signature gnus-article-highlight-signature) | |
1674 | (gnus-treat-buttonize gnus-article-add-buttons) | |
1675 | (gnus-treat-fill-article gnus-article-fill-cited-article) | |
389b76fa | 1676 | (gnus-treat-fill-long-lines gnus-article-fill-cited-long-lines) |
23f87bed | 1677 | (gnus-treat-unsplit-urls gnus-article-unsplit-urls) |
23f87bed MB |
1678 | (gnus-treat-display-x-face gnus-article-display-x-face) |
1679 | (gnus-treat-display-face gnus-article-display-face) | |
16409b0b GM |
1680 | (gnus-treat-hide-headers gnus-article-maybe-hide-headers) |
1681 | (gnus-treat-hide-boring-headers gnus-article-hide-boring-headers) | |
1682 | (gnus-treat-hide-signature gnus-article-hide-signature) | |
16409b0b | 1683 | (gnus-treat-strip-list-identifiers gnus-article-hide-list-identifiers) |
23f87bed | 1684 | (gnus-treat-leading-whitespace gnus-article-remove-leading-whitespace) |
2696d88f G |
1685 | (gnus-treat-from-picon gnus-treat-from-picon) |
1686 | (gnus-treat-mail-picon gnus-treat-mail-picon) | |
1687 | (gnus-treat-newsgroups-picon gnus-treat-newsgroups-picon) | |
16409b0b | 1688 | (gnus-treat-strip-pem gnus-article-hide-pem) |
12e3ca0a | 1689 | (gnus-treat-date gnus-article-treat-date) |
61b1af82 G |
1690 | (gnus-treat-from-gravatar gnus-treat-from-gravatar) |
1691 | (gnus-treat-mail-gravatar gnus-treat-mail-gravatar) | |
16409b0b | 1692 | (gnus-treat-highlight-headers gnus-article-highlight-headers) |
16409b0b | 1693 | (gnus-treat-highlight-signature gnus-article-highlight-signature) |
16409b0b GM |
1694 | (gnus-treat-strip-trailing-blank-lines |
1695 | gnus-article-remove-trailing-blank-lines) | |
1696 | (gnus-treat-strip-leading-blank-lines | |
1697 | gnus-article-strip-leading-blank-lines) | |
1698 | (gnus-treat-strip-multiple-blank-lines | |
1699 | gnus-article-strip-multiple-blank-lines) | |
1700 | (gnus-treat-overstrike gnus-article-treat-overstrike) | |
01c52d31 | 1701 | (gnus-treat-ansi-sequences gnus-article-treat-ansi-sequences) |
23f87bed | 1702 | (gnus-treat-unfold-headers gnus-article-treat-unfold-headers) |
23f87bed | 1703 | (gnus-treat-fold-newsgroups gnus-article-treat-fold-newsgroups) |
01c52d31 | 1704 | (gnus-treat-fold-headers gnus-article-treat-fold-headers) |
16409b0b | 1705 | (gnus-treat-buttonize-head gnus-article-add-buttons-to-head) |
23f87bed | 1706 | (gnus-treat-display-smileys gnus-treat-smiley) |
16409b0b | 1707 | (gnus-treat-capitalize-sentences gnus-article-capitalize-sentences) |
23f87bed MB |
1708 | (gnus-treat-wash-html gnus-article-wash-html) |
1709 | (gnus-treat-emphasize gnus-article-emphasize) | |
1710 | (gnus-treat-hide-citation gnus-article-hide-citation) | |
1711 | (gnus-treat-hide-citation-maybe gnus-article-hide-citation-maybe) | |
1712 | (gnus-treat-highlight-citation gnus-article-highlight-citation) | |
8ccbef23 | 1713 | (gnus-treat-body-boundary gnus-article-treat-body-boundary))) |
16409b0b GM |
1714 | |
1715 | (defvar gnus-article-mime-handle-alist nil) | |
6748645f LMI |
1716 | (defvar article-lapsed-timer nil) |
1717 | (defvar gnus-article-current-summary nil) | |
1718 | ||
eec82323 LMI |
1719 | (defvar gnus-article-mode-syntax-table |
1720 | (let ((table (copy-syntax-table text-mode-syntax-table))) | |
23f87bed MB |
1721 | ;; This causes the citation match run O(2^n). |
1722 | ;; (modify-syntax-entry ?- "w" table) | |
1723 | (modify-syntax-entry ?> ")<" table) | |
1724 | (modify-syntax-entry ?< "(>" table) | |
1725 | ;; make M-. in article buffers work for `foo' strings | |
1726 | (modify-syntax-entry ?' " " table) | |
1727 | (modify-syntax-entry ?` " " table) | |
eec82323 LMI |
1728 | table) |
1729 | "Syntax table used in article mode buffers. | |
1730 | Initialized from `text-mode-syntax-table.") | |
1731 | ||
1732 | (defvar gnus-save-article-buffer nil) | |
1733 | ||
eec82323 LMI |
1734 | (defvar gnus-number-of-articles-to-be-saved nil) |
1735 | ||
1736 | (defvar gnus-inhibit-hiding nil) | |
1737 | ||
c1d7d285 MB |
1738 | (defvar gnus-article-edit-mode nil) |
1739 | ||
23f87bed MB |
1740 | ;;; Macros for dealing with the article buffer. |
1741 | ||
1742 | (defmacro gnus-with-article-headers (&rest forms) | |
80de1778 | 1743 | `(with-current-buffer gnus-article-buffer |
23f87bed MB |
1744 | (save-restriction |
1745 | (let ((inhibit-read-only t) | |
1746 | (inhibit-point-motion-hooks t) | |
1747 | (case-fold-search t)) | |
1748 | (article-narrow-to-head) | |
1749 | ,@forms)))) | |
1750 | ||
1751 | (put 'gnus-with-article-headers 'lisp-indent-function 0) | |
1752 | (put 'gnus-with-article-headers 'edebug-form-spec '(body)) | |
1753 | ||
1754 | (defmacro gnus-with-article-buffer (&rest forms) | |
e1a135a9 | 1755 | `(when (buffer-live-p (get-buffer gnus-article-buffer)) |
3b0468c4 JD |
1756 | (with-current-buffer gnus-article-buffer |
1757 | (let ((inhibit-read-only t)) | |
1758 | ,@forms)))) | |
23f87bed MB |
1759 | |
1760 | (put 'gnus-with-article-buffer 'lisp-indent-function 0) | |
1761 | (put 'gnus-with-article-buffer 'edebug-form-spec '(body)) | |
1762 | ||
1763 | (defun gnus-article-goto-header (header) | |
1764 | "Go to HEADER, which is a regular expression." | |
1765 | (re-search-forward (concat "^\\(" header "\\):") nil t)) | |
1766 | ||
eec82323 LMI |
1767 | (defsubst gnus-article-hide-text (b e props) |
1768 | "Set text PROPS on the B to E region, extending `intangible' 1 past B." | |
520aa572 | 1769 | (gnus-add-text-properties-when 'article-type nil b e props) |
eec82323 LMI |
1770 | (when (memq 'intangible props) |
1771 | (put-text-property | |
1772 | (max (1- b) (point-min)) | |
1773 | b 'intangible (cddr (memq 'intangible props))))) | |
520aa572 | 1774 | |
eec82323 LMI |
1775 | (defsubst gnus-article-unhide-text (b e) |
1776 | "Remove hidden text properties from region between B and E." | |
1777 | (remove-text-properties b e gnus-hidden-properties) | |
1778 | (when (memq 'intangible gnus-hidden-properties) | |
1779 | (put-text-property (max (1- b) (point-min)) | |
1780 | b 'intangible nil))) | |
1781 | ||
1782 | (defun gnus-article-hide-text-type (b e type) | |
1783 | "Hide text of TYPE between B and E." | |
23f87bed | 1784 | (gnus-add-wash-type type) |
eec82323 LMI |
1785 | (gnus-article-hide-text |
1786 | b e (cons 'article-type (cons type gnus-hidden-properties)))) | |
1787 | ||
1788 | (defun gnus-article-unhide-text-type (b e type) | |
6748645f | 1789 | "Unhide text of TYPE between B and E." |
23f87bed | 1790 | (gnus-delete-wash-type type) |
eec82323 LMI |
1791 | (remove-text-properties |
1792 | b e (cons 'article-type (cons type gnus-hidden-properties))) | |
1793 | (when (memq 'intangible gnus-hidden-properties) | |
1794 | (put-text-property (max (1- b) (point-min)) | |
1795 | b 'intangible nil))) | |
1796 | ||
eec82323 LMI |
1797 | (defun gnus-article-delete-text-of-type (type) |
1798 | "Delete text of TYPE in the current buffer." | |
1799 | (save-excursion | |
a8151ef7 | 1800 | (let ((b (point-min))) |
7dafe00b MB |
1801 | (if (eq type 'multipart) |
1802 | ;; Remove MIME buttons associated with multipart/alternative parts. | |
1803 | (progn | |
1804 | (goto-char b) | |
1805 | (while (if (get-text-property (point) 'gnus-part) | |
1806 | (setq b (point)) | |
1807 | (when (setq b (next-single-property-change (point) | |
1808 | 'gnus-part)) | |
1809 | (goto-char b) | |
1810 | t)) | |
1811 | (end-of-line) | |
1812 | (skip-chars-forward "\n") | |
1813 | (when (eq (get-text-property b 'article-type) 'multipart) | |
1814 | (delete-region b (point))))) | |
1815 | (while (setq b (text-property-any b (point-max) 'article-type type)) | |
1816 | (delete-region | |
1817 | b (or (text-property-not-all b (point-max) 'article-type type) | |
1818 | (point-max)))))))) | |
eec82323 LMI |
1819 | |
1820 | (defun gnus-article-delete-invisible-text () | |
1821 | "Delete all invisible text in the current buffer." | |
1822 | (save-excursion | |
a8151ef7 LMI |
1823 | (let ((b (point-min))) |
1824 | (while (setq b (text-property-any b (point-max) 'invisible t)) | |
1825 | (delete-region | |
1826 | b (or (text-property-not-all b (point-max) 'invisible t) | |
1827 | (point-max))))))) | |
eec82323 | 1828 | |
eec82323 LMI |
1829 | (defsubst gnus-article-header-rank () |
1830 | "Give the rank of the string HEADER as given by `gnus-sorted-header-list'." | |
1831 | (let ((list gnus-sorted-header-list) | |
23f87bed | 1832 | (i 1)) |
eec82323 | 1833 | (while list |
23f87bed MB |
1834 | (if (looking-at (car list)) |
1835 | (setq list nil) | |
1836 | (setq list (cdr list)) | |
1837 | (incf i))) | |
1838 | i)) | |
eec82323 LMI |
1839 | |
1840 | (defun article-hide-headers (&optional arg delete) | |
16409b0b GM |
1841 | "Hide unwanted headers and possibly sort them as well." |
1842 | (interactive) | |
1843 | ;; This function might be inhibited. | |
1844 | (unless gnus-inhibit-hiding | |
37cc095b | 1845 | (let ((inhibit-read-only t) |
23f87bed MB |
1846 | (case-fold-search t) |
1847 | (max (1+ (length gnus-sorted-header-list))) | |
1848 | (inhibit-point-motion-hooks t) | |
1849 | (cur (current-buffer)) | |
1850 | ignored visible beg) | |
1851 | (save-excursion | |
1852 | ;; `gnus-ignored-headers' and `gnus-visible-headers' may be | |
1853 | ;; group parameters, so we should go to the summary buffer. | |
1854 | (when (prog1 | |
1855 | (condition-case nil | |
1856 | (progn (set-buffer gnus-summary-buffer) t) | |
1857 | (error nil)) | |
1858 | (setq ignored (when (not gnus-visible-headers) | |
1859 | (cond ((stringp gnus-ignored-headers) | |
1860 | gnus-ignored-headers) | |
1861 | ((listp gnus-ignored-headers) | |
1862 | (mapconcat 'identity | |
1863 | gnus-ignored-headers | |
1864 | "\\|")))) | |
1865 | visible (cond ((stringp gnus-visible-headers) | |
1866 | gnus-visible-headers) | |
1867 | ((and gnus-visible-headers | |
1868 | (listp gnus-visible-headers)) | |
1869 | (mapconcat 'identity | |
1870 | gnus-visible-headers | |
1871 | "\\|"))))) | |
1872 | (set-buffer cur)) | |
1873 | (save-restriction | |
16409b0b GM |
1874 | ;; First we narrow to just the headers. |
1875 | (article-narrow-to-head) | |
1876 | ;; Hide any "From " lines at the beginning of (mail) articles. | |
1877 | (while (looking-at "From ") | |
1878 | (forward-line 1)) | |
1879 | (unless (bobp) | |
1880 | (delete-region (point-min) (point))) | |
1881 | ;; Then treat the rest of the header lines. | |
1882 | ;; Then we use the two regular expressions | |
1883 | ;; `gnus-ignored-headers' and `gnus-visible-headers' to | |
1884 | ;; select which header lines is to remain visible in the | |
1885 | ;; article buffer. | |
23f87bed | 1886 | (while (re-search-forward "^[^ \t:]*:" nil t) |
16409b0b GM |
1887 | (beginning-of-line) |
1888 | ;; Mark the rank of the header. | |
1889 | (put-text-property | |
1890 | (point) (1+ (point)) 'message-rank | |
1891 | (if (or (and visible (looking-at visible)) | |
1892 | (and ignored | |
1893 | (not (looking-at ignored)))) | |
1894 | (gnus-article-header-rank) | |
1895 | (+ 2 max))) | |
1896 | (forward-line 1)) | |
1897 | (message-sort-headers-1) | |
1898 | (when (setq beg (text-property-any | |
1899 | (point-min) (point-max) 'message-rank (+ 2 max))) | |
1900 | ;; We delete the unwanted headers. | |
23f87bed | 1901 | (gnus-add-wash-type 'headers) |
16409b0b GM |
1902 | (add-text-properties (point-min) (+ 5 (point-min)) |
1903 | '(article-type headers dummy-invisible t)) | |
1904 | (delete-region beg (point-max)))))))) | |
eec82323 LMI |
1905 | |
1906 | (defun article-hide-boring-headers (&optional arg) | |
1907 | "Toggle hiding of headers that aren't very interesting. | |
1908 | If given a negative prefix, always show; if given a positive prefix, | |
1909 | always hide." | |
1910 | (interactive (gnus-article-hidden-arg)) | |
1911 | (when (and (not (gnus-article-check-hidden-text 'boring-headers arg)) | |
1912 | (not gnus-show-all-headers)) | |
1913 | (save-excursion | |
1914 | (save-restriction | |
4e7d0221 | 1915 | (let ((inhibit-read-only t) |
01c52d31 | 1916 | (inhibit-point-motion-hooks t)) |
16409b0b | 1917 | (article-narrow-to-head) |
01c52d31 | 1918 | (dolist (elem gnus-boring-article-headers) |
eec82323 LMI |
1919 | (goto-char (point-min)) |
1920 | (cond | |
1921 | ;; Hide empty headers. | |
1922 | ((eq elem 'empty) | |
16409b0b | 1923 | (while (re-search-forward "^[^: \t]+:[ \t]*\n[^ \t]" nil t) |
eec82323 LMI |
1924 | (forward-line -1) |
1925 | (gnus-article-hide-text-type | |
01c52d31 | 1926 | (point-at-bol) |
eec82323 LMI |
1927 | (progn |
1928 | (end-of-line) | |
1929 | (if (re-search-forward "^[^ \t]" nil t) | |
1930 | (match-beginning 0) | |
1931 | (point-max))) | |
1932 | 'boring-headers))) | |
1933 | ;; Hide boring Newsgroups header. | |
1934 | ((eq elem 'newsgroups) | |
23f87bed MB |
1935 | (when (gnus-string-equal |
1936 | (gnus-fetch-field "newsgroups") | |
1937 | (gnus-group-real-name | |
1938 | (if (boundp 'gnus-newsgroup-name) | |
1939 | gnus-newsgroup-name | |
1940 | ""))) | |
eec82323 | 1941 | (gnus-article-hide-header "newsgroups"))) |
23f87bed MB |
1942 | ((eq elem 'to-address) |
1943 | (let ((to (message-fetch-field "to")) | |
1944 | (to-address | |
1945 | (gnus-parameter-to-address | |
1946 | (if (boundp 'gnus-newsgroup-name) | |
1947 | gnus-newsgroup-name "")))) | |
1948 | (when (and to to-address | |
1949 | (ignore-errors | |
1950 | (gnus-string-equal | |
1951 | ;; only one address in To | |
1952 | (nth 1 (mail-extract-address-components to)) | |
1953 | to-address))) | |
1954 | (gnus-article-hide-header "to")))) | |
1955 | ((eq elem 'to-list) | |
1956 | (let ((to (message-fetch-field "to")) | |
1957 | (to-list | |
1958 | (gnus-parameter-to-list | |
1959 | (if (boundp 'gnus-newsgroup-name) | |
1960 | gnus-newsgroup-name "")))) | |
1961 | (when (and to to-list | |
1962 | (ignore-errors | |
1963 | (gnus-string-equal | |
1964 | ;; only one address in To | |
1965 | (nth 1 (mail-extract-address-components to)) | |
1966 | to-list))) | |
1967 | (gnus-article-hide-header "to")))) | |
1968 | ((eq elem 'cc-list) | |
1969 | (let ((cc (message-fetch-field "cc")) | |
1970 | (to-list | |
1971 | (gnus-parameter-to-list | |
1972 | (if (boundp 'gnus-newsgroup-name) | |
1973 | gnus-newsgroup-name "")))) | |
1974 | (when (and cc to-list | |
1975 | (ignore-errors | |
1976 | (gnus-string-equal | |
1977 | ;; only one address in CC | |
1978 | (nth 1 (mail-extract-address-components cc)) | |
1979 | to-list))) | |
1980 | (gnus-article-hide-header "cc")))) | |
eec82323 | 1981 | ((eq elem 'followup-to) |
23f87bed MB |
1982 | (when (gnus-string-equal |
1983 | (message-fetch-field "followup-to") | |
1984 | (message-fetch-field "newsgroups")) | |
eec82323 LMI |
1985 | (gnus-article-hide-header "followup-to"))) |
1986 | ((eq elem 'reply-to) | |
23f87bed MB |
1987 | (if (gnus-group-find-parameter |
1988 | gnus-newsgroup-name 'broken-reply-to) | |
1989 | (gnus-article-hide-header "reply-to") | |
1990 | (let ((from (message-fetch-field "from")) | |
1991 | (reply-to (message-fetch-field "reply-to"))) | |
1992 | (when | |
1993 | (and | |
eec82323 LMI |
1994 | from reply-to |
1995 | (ignore-errors | |
1996 | (equal | |
23f87bed MB |
1997 | (sort (mapcar |
1998 | (lambda (x) (downcase (cadr x))) | |
1999 | (mail-extract-address-components from t)) | |
2000 | 'string<) | |
2001 | (sort (mapcar | |
2002 | (lambda (x) (downcase (cadr x))) | |
2003 | (mail-extract-address-components reply-to t)) | |
2004 | 'string<)))) | |
2005 | (gnus-article-hide-header "reply-to"))))) | |
eec82323 | 2006 | ((eq elem 'date) |
b193caa3 MB |
2007 | (let ((date (with-current-buffer gnus-original-article-buffer |
2008 | ;; If date in `gnus-article-buffer' is localized | |
2009 | ;; (`gnus-treat-date-user-defined'), | |
2010 | ;; `days-between' might fail. | |
2011 | (message-fetch-field "date")))) | |
eec82323 | 2012 | (when (and date |
16409b0b | 2013 | (< (days-between (current-time-string) date) |
eec82323 | 2014 | 4)) |
6748645f LMI |
2015 | (gnus-article-hide-header "date")))) |
2016 | ((eq elem 'long-to) | |
16409b0b GM |
2017 | (let ((to (message-fetch-field "to")) |
2018 | (cc (message-fetch-field "cc"))) | |
6748645f | 2019 | (when (> (length to) 1024) |
16409b0b GM |
2020 | (gnus-article-hide-header "to")) |
2021 | (when (> (length cc) 1024) | |
2022 | (gnus-article-hide-header "cc")))) | |
6748645f | 2023 | ((eq elem 'many-to) |
16409b0b GM |
2024 | (let ((to-count 0) |
2025 | (cc-count 0)) | |
6748645f LMI |
2026 | (goto-char (point-min)) |
2027 | (while (re-search-forward "^to:" nil t) | |
2028 | (setq to-count (1+ to-count))) | |
2029 | (when (> to-count 1) | |
2030 | (while (> to-count 0) | |
2031 | (goto-char (point-min)) | |
2032 | (save-restriction | |
2033 | (re-search-forward "^to:" nil nil to-count) | |
2034 | (forward-line -1) | |
2035 | (narrow-to-region (point) (point-max)) | |
2036 | (gnus-article-hide-header "to")) | |
16409b0b GM |
2037 | (setq to-count (1- to-count)))) |
2038 | (goto-char (point-min)) | |
2039 | (while (re-search-forward "^cc:" nil t) | |
2040 | (setq cc-count (1+ cc-count))) | |
2041 | (when (> cc-count 1) | |
2042 | (while (> cc-count 0) | |
2043 | (goto-char (point-min)) | |
2044 | (save-restriction | |
2045 | (re-search-forward "^cc:" nil nil cc-count) | |
2046 | (forward-line -1) | |
2047 | (narrow-to-region (point) (point-max)) | |
2048 | (gnus-article-hide-header "cc")) | |
2049 | (setq cc-count (1- cc-count))))))))))))) | |
eec82323 LMI |
2050 | |
2051 | (defun gnus-article-hide-header (header) | |
2052 | (save-excursion | |
2053 | (goto-char (point-min)) | |
2054 | (when (re-search-forward (concat "^" header ":") nil t) | |
2055 | (gnus-article-hide-text-type | |
01c52d31 | 2056 | (point-at-bol) |
eec82323 LMI |
2057 | (progn |
2058 | (end-of-line) | |
2059 | (if (re-search-forward "^[^ \t]" nil t) | |
2060 | (match-beginning 0) | |
2061 | (point-max))) | |
2062 | 'boring-headers)))) | |
2063 | ||
16409b0b GM |
2064 | (defvar gnus-article-normalized-header-length 40 |
2065 | "Length of normalized headers.") | |
2066 | ||
2067 | (defun article-normalize-headers () | |
2068 | "Make all header lines 40 characters long." | |
2069 | (interactive) | |
4e7d0221 | 2070 | (let ((inhibit-read-only t) |
16409b0b GM |
2071 | column) |
2072 | (save-excursion | |
2073 | (save-restriction | |
2074 | (article-narrow-to-head) | |
2075 | (while (not (eobp)) | |
2076 | (cond | |
01c52d31 | 2077 | ((< (setq column (- (point-at-eol) (point))) |
16409b0b GM |
2078 | gnus-article-normalized-header-length) |
2079 | (end-of-line) | |
2080 | (insert (make-string | |
2081 | (- gnus-article-normalized-header-length column) | |
2082 | ? ))) | |
2083 | ((> column gnus-article-normalized-header-length) | |
2084 | (gnus-put-text-property | |
2085 | (progn | |
2086 | (forward-char gnus-article-normalized-header-length) | |
2087 | (point)) | |
01c52d31 | 2088 | (point-at-eol) |
16409b0b GM |
2089 | 'invisible t)) |
2090 | (t | |
2091 | ;; Do nothing. | |
2092 | )) | |
2093 | (forward-line 1)))))) | |
2094 | ||
6748645f | 2095 | (defun article-treat-dumbquotes () |
23f87bed | 2096 | "Translate M****s*** sm*rtq**t*s and other symbols into proper text. |
16409b0b | 2097 | Note that this function guesses whether a character is a sm*rtq**t* or |
74dd1b0d SZ |
2098 | not, so it should only be used interactively. |
2099 | ||
23f87bed MB |
2100 | Sm*rtq**t*s are M****s***'s unilateral extension to the |
2101 | iso-8859-1 character map in an attempt to provide more quoting | |
2102 | characters. If you see something like \\222 or \\264 where | |
2103 | you're expecting some kind of apostrophe or quotation mark, then | |
2104 | try this wash." | |
6748645f | 2105 | (interactive) |
16409b0b | 2106 | (article-translate-strings gnus-article-dumbquotes-map)) |
6748645f | 2107 | |
16c1b3bc KY |
2108 | (defvar org-entities) |
2109 | ||
be3c11b3 LMI |
2110 | (defun article-treat-non-ascii () |
2111 | "Translate many Unicode characters into their ASCII equivalents." | |
2112 | (interactive) | |
2113 | (require 'org-entities) | |
9c1d3f98 | 2114 | (let ((table (make-char-table (if (featurep 'xemacs) 'generic)))) |
be3c11b3 LMI |
2115 | (dolist (elem org-entities) |
2116 | (when (and (listp elem) | |
2117 | (= (length (nth 6 elem)) 1)) | |
fdf14191 KY |
2118 | (if (featurep 'xemacs) |
2119 | (put-char-table (aref (nth 6 elem) 0) (nth 4 elem) table) | |
2120 | (set-char-table-range table (aref (nth 6 elem) 0) (nth 4 elem))))) | |
be3c11b3 LMI |
2121 | (save-excursion |
2122 | (when (article-goto-body) | |
2123 | (let ((inhibit-read-only t) | |
2f0e0dc8 | 2124 | replace props) |
be3c11b3 | 2125 | (while (not (eobp)) |
9c1d3f98 KY |
2126 | (if (not (setq replace (if (featurep 'xemacs) |
2127 | (get-char-table (following-char) table) | |
2128 | (aref table (following-char))))) | |
be3c11b3 | 2129 | (forward-char 1) |
2f0e0dc8 KY |
2130 | (if (prog1 |
2131 | (setq props (text-properties-at (point))) | |
2132 | (delete-char 1)) | |
2133 | (add-text-properties (point) (progn (insert replace) (point)) | |
2134 | props) | |
2135 | (insert replace))))))))) | |
be3c11b3 | 2136 | |
16409b0b GM |
2137 | (defun article-translate-strings (map) |
2138 | "Translate all string in the body of the article according to MAP. | |
2139 | MAP is an alist where the elements are on the form (\"from\" \"to\")." | |
2140 | (save-excursion | |
2141 | (when (article-goto-body) | |
01c52d31 MB |
2142 | (let ((inhibit-read-only t)) |
2143 | (dolist (elem map) | |
7cad71ad G |
2144 | (let ((from (car elem)) |
2145 | (to (cadr elem))) | |
2146 | (save-excursion | |
2147 | (if (stringp from) | |
2148 | (while (search-forward from nil t) | |
2149 | (replace-match to)) | |
2150 | (while (not (eobp)) | |
2151 | (if (eq (following-char) from) | |
2152 | (progn | |
2153 | (delete-char 1) | |
2154 | (insert to)) | |
2155 | (forward-char 1))))))))))) | |
16409b0b | 2156 | |
eec82323 LMI |
2157 | (defun article-treat-overstrike () |
2158 | "Translate overstrikes into bold text." | |
2159 | (interactive) | |
2160 | (save-excursion | |
16409b0b | 2161 | (when (article-goto-body) |
4e7d0221 | 2162 | (let ((inhibit-read-only t)) |
eec82323 | 2163 | (while (search-forward "\b" nil t) |
16409b0b | 2164 | (let ((next (char-after)) |
eec82323 LMI |
2165 | (previous (char-after (- (point) 2)))) |
2166 | ;; We do the boldification/underlining by hiding the | |
2167 | ;; overstrikes and putting the proper text property | |
2168 | ;; on the letters. | |
2169 | (cond | |
2170 | ((eq next previous) | |
2171 | (gnus-article-hide-text-type (- (point) 2) (point) 'overstrike) | |
2172 | (put-text-property (point) (1+ (point)) 'face 'bold)) | |
2173 | ((eq next ?_) | |
2174 | (gnus-article-hide-text-type | |
2175 | (1- (point)) (1+ (point)) 'overstrike) | |
2176 | (put-text-property | |
2177 | (- (point) 2) (1- (point)) 'face 'underline)) | |
2178 | ((eq previous ?_) | |
2179 | (gnus-article-hide-text-type (- (point) 2) (point) 'overstrike) | |
2180 | (put-text-property | |
2181 | (point) (1+ (point)) 'face 'underline))))))))) | |
2182 | ||
01c52d31 MB |
2183 | (defun article-treat-ansi-sequences () |
2184 | "Translate ANSI SGR control sequences into overlays or extents." | |
2185 | (interactive) | |
2186 | (save-excursion | |
2187 | (when (article-goto-body) | |
2188 | (let ((inhibit-read-only t)) | |
2189 | (ansi-color-apply-on-region (point) (point-max)))))) | |
2190 | ||
23f87bed MB |
2191 | (defun gnus-article-treat-unfold-headers () |
2192 | "Unfold folded message headers. | |
2193 | Only the headers that fit into the current window width will be | |
2194 | unfolded." | |
2195 | (interactive) | |
2196 | (gnus-with-article-headers | |
2197 | (let (length) | |
2198 | (while (not (eobp)) | |
2199 | (save-restriction | |
2200 | (mail-header-narrow-to-field) | |
01c52d31 MB |
2201 | (let* ((header (buffer-string)) |
2202 | (unfoldable | |
2203 | (or (equal gnus-article-unfold-long-headers t) | |
2204 | (and (stringp gnus-article-unfold-long-headers) | |
89b163db G |
2205 | (string-match gnus-article-unfold-long-headers |
2206 | header))))) | |
23f87bed MB |
2207 | (with-temp-buffer |
2208 | (insert header) | |
2209 | (goto-char (point-min)) | |
2210 | (while (re-search-forward "\n[\t ]" nil t) | |
2211 | (replace-match " " t t))) | |
01c52d31 MB |
2212 | (setq length (- (point-max) (point-min) 1)) |
2213 | (when (or unfoldable | |
2214 | (< length (window-width))) | |
2215 | (while (re-search-forward "\n[\t ]" nil t) | |
2216 | (replace-match " " t t)))) | |
23f87bed MB |
2217 | (goto-char (point-max))))))) |
2218 | ||
2219 | (defun gnus-article-treat-fold-headers () | |
2220 | "Fold message headers." | |
2221 | (interactive) | |
2222 | (gnus-with-article-headers | |
2223 | (while (not (eobp)) | |
2224 | (save-restriction | |
2225 | (mail-header-narrow-to-field) | |
2226 | (mail-header-fold-field) | |
2227 | (goto-char (point-max)))))) | |
2228 | ||
2229 | (defun gnus-treat-smiley () | |
2230 | "Toggle display of textual emoticons (\"smileys\") as small graphical icons." | |
2231 | (interactive) | |
2232 | (gnus-with-article-buffer | |
2233 | (if (memq 'smiley gnus-article-wash-types) | |
2234 | (gnus-delete-images 'smiley) | |
2235 | (article-goto-body) | |
2236 | (let ((images (smiley-region (point) (point-max)))) | |
2237 | (when images | |
2238 | (gnus-add-wash-type 'smiley) | |
2239 | (dolist (image images) | |
2240 | (gnus-add-image 'smiley image))))))) | |
2241 | ||
2242 | (defun gnus-article-remove-images () | |
2243 | "Remove all images from the article buffer." | |
2244 | (interactive) | |
2245 | (gnus-with-article-buffer | |
9695908d KY |
2246 | (save-restriction |
2247 | (widen) | |
2248 | (dolist (elem gnus-article-image-alist) | |
2249 | (gnus-delete-images (car elem)))))) | |
23f87bed | 2250 | |
ae97e645 G |
2251 | (autoload 'w3m-toggle-inline-images "w3m") |
2252 | ||
8b6f6573 LMI |
2253 | (defun gnus-article-show-images () |
2254 | "Show any images that are in the HTML-rendered article buffer. | |
2255 | This only works if the article in question is HTML." | |
2256 | (interactive) | |
2257 | (gnus-with-article-buffer | |
9695908d KY |
2258 | (save-restriction |
2259 | (widen) | |
ae97e645 G |
2260 | (if (eq mm-text-html-renderer 'w3m) |
2261 | (let ((mm-inline-text-html-with-images nil)) | |
2262 | (w3m-toggle-inline-images)) | |
2263 | (dolist (region (gnus-find-text-property-region (point-min) (point-max) | |
2264 | 'image-displayer)) | |
2265 | (destructuring-bind (start end function) region | |
2266 | (funcall function (get-text-property start 'image-url) | |
2267 | start end))))))) | |
8b6f6573 | 2268 | |
23f87bed MB |
2269 | (defun gnus-article-treat-fold-newsgroups () |
2270 | "Unfold folded message headers. | |
2271 | Only the headers that fit into the current window width will be | |
2272 | unfolded." | |
2273 | (interactive) | |
2274 | (gnus-with-article-headers | |
2275 | (while (gnus-article-goto-header "newsgroups\\|followup-to") | |
2276 | (save-restriction | |
2277 | (mail-header-narrow-to-field) | |
2278 | (while (re-search-forward ", *" nil t) | |
2279 | (replace-match ", " t t)) | |
2280 | (mail-header-fold-field) | |
2281 | (goto-char (point-max)))))) | |
2282 | ||
b7b80032 | 2283 | (defcustom gnus-article-truncate-lines (default-value 'truncate-lines) |
01c52d31 MB |
2284 | "Value of `truncate-lines' in Gnus Article buffer. |
2285 | Valid values are nil, t, `head', `first', `last', an integer or a | |
2286 | predicate. See Info node `(gnus)Customizing Articles'." | |
330f707b | 2287 | :version "23.1" ;; No Gnus |
01c52d31 MB |
2288 | :group 'gnus-article |
2289 | ;; :link '(custom-manual "(gnus)Customizing Articles") | |
2290 | :type 'boolean) | |
2291 | ||
2292 | (defun gnus-article-toggle-truncate-lines (&optional arg) | |
2293 | "Toggle whether to fold or truncate long lines in article the buffer. | |
2294 | If ARG is non-nil and not a number, toggle | |
2295 | `gnus-article-truncate-lines' too. If ARG is a number, truncate | |
5229211e | 2296 | long lines if and only if arg is positive." |
01c52d31 MB |
2297 | (interactive "P") |
2298 | (cond | |
2299 | ((and (numberp arg) (> arg 0)) | |
2300 | (setq gnus-article-truncate-lines t)) | |
2301 | ((numberp arg) | |
2302 | (setq gnus-article-truncate-lines nil)) | |
2303 | (arg | |
2304 | (setq gnus-article-truncate-lines | |
2305 | (not gnus-article-truncate-lines)))) | |
2306 | (gnus-with-article-buffer | |
2307 | (cond | |
2308 | ((and (numberp arg) (> arg 0)) | |
2309 | (setq truncate-lines nil)) | |
2310 | ((numberp arg) | |
2311 | (setq truncate-lines t))) | |
2312 | ;; In versions of Emacs 22 (CVS) before 2006-05-26, | |
2313 | ;; `toggle-truncate-lines' needs an argument. | |
2314 | (toggle-truncate-lines))) | |
2315 | ||
23f87bed MB |
2316 | (defun gnus-article-treat-body-boundary () |
2317 | "Place a boundary line at the end of the headers." | |
2318 | (interactive) | |
2319 | (when (and gnus-body-boundary-delimiter | |
2320 | (> (length gnus-body-boundary-delimiter) 0)) | |
2321 | (gnus-with-article-headers | |
2322 | (goto-char (point-max)) | |
2323 | (let ((start (point))) | |
2324 | (insert "X-Boundary: ") | |
2325 | (gnus-add-text-properties start (point) '(invisible t intangible t)) | |
a123622d G |
2326 | (insert (let (str (max (window-width))) |
2327 | (if (featurep 'xemacs) | |
2328 | (setq max (1- max))) | |
2329 | (while (>= max (length str)) | |
23f87bed | 2330 | (setq str (concat str gnus-body-boundary-delimiter))) |
a123622d | 2331 | (substring str 0 max)) |
23f87bed MB |
2332 | "\n") |
2333 | (gnus-put-text-property start (point) 'gnus-decoration 'header))))) | |
2334 | ||
16409b0b GM |
2335 | (defun article-fill-long-lines () |
2336 | "Fill lines that are wider than the window width." | |
eec82323 LMI |
2337 | (interactive) |
2338 | (save-excursion | |
4e7d0221 | 2339 | (let ((inhibit-read-only t) |
16409b0b GM |
2340 | (width (window-width (get-buffer-window (current-buffer))))) |
2341 | (save-restriction | |
2342 | (article-goto-body) | |
80b47379 | 2343 | (let ((adaptive-fill-mode nil)) ;Why? -sm |
16409b0b GM |
2344 | (while (not (eobp)) |
2345 | (end-of-line) | |
2346 | (when (>= (current-column) (min fill-column width)) | |
23f87bed | 2347 | (narrow-to-region (min (1+ (point)) (point-max)) |
01c52d31 | 2348 | (point-at-bol)) |
23f87bed MB |
2349 | (let ((goback (point-marker))) |
2350 | (fill-paragraph nil) | |
2351 | (goto-char (marker-position goback))) | |
16409b0b GM |
2352 | (widen)) |
2353 | (forward-line 1))))))) | |
2354 | ||
2355 | (defun article-capitalize-sentences () | |
2356 | "Capitalize the first word in each sentence." | |
2357 | (interactive) | |
2358 | (save-excursion | |
4e7d0221 | 2359 | (let ((inhibit-read-only t) |
16409b0b GM |
2360 | (paragraph-start "^[\n\^L]")) |
2361 | (article-goto-body) | |
2362 | (while (not (eobp)) | |
2363 | (capitalize-word 1) | |
2364 | (forward-sentence))))) | |
eec82323 LMI |
2365 | |
2366 | (defun article-remove-cr () | |
16409b0b | 2367 | "Remove trailing CRs and then translate remaining CRs into LFs." |
eec82323 LMI |
2368 | (interactive) |
2369 | (save-excursion | |
4e7d0221 | 2370 | (let ((inhibit-read-only t)) |
eec82323 | 2371 | (goto-char (point-min)) |
16409b0b GM |
2372 | (while (re-search-forward "\r+$" nil t) |
2373 | (replace-match "" t t)) | |
2374 | (goto-char (point-min)) | |
eec82323 | 2375 | (while (search-forward "\r" nil t) |
16409b0b | 2376 | (replace-match "\n" t t))))) |
eec82323 LMI |
2377 | |
2378 | (defun article-remove-trailing-blank-lines () | |
2379 | "Remove all trailing blank lines from the article." | |
2380 | (interactive) | |
2381 | (save-excursion | |
4e7d0221 | 2382 | (let ((inhibit-read-only t)) |
eec82323 LMI |
2383 | (goto-char (point-max)) |
2384 | (delete-region | |
2385 | (point) | |
2386 | (progn | |
2387 | (while (and (not (bobp)) | |
16409b0b GM |
2388 | (looking-at "^[ \t]*$") |
2389 | (not (gnus-annotation-in-region-p | |
01c52d31 | 2390 | (point) (point-at-eol)))) |
eec82323 LMI |
2391 | (forward-line -1)) |
2392 | (forward-line 1) | |
2393 | (point)))))) | |
2394 | ||
9efa445f | 2395 | (defvar gnus-face-properties-alist) |
01c52d31 | 2396 | |
b890d447 | 2397 | (defun article-display-face (&optional force) |
23f87bed | 2398 | "Display any Face headers in the header." |
b890d447 | 2399 | (interactive (list 'force)) |
23f87bed MB |
2400 | (let ((wash-face-p buffer-read-only)) |
2401 | (gnus-with-article-headers | |
2402 | ;; When displaying parts, this function can be called several times on | |
2403 | ;; the same article, without any intended toggle semantic (as typing `W | |
2404 | ;; D d' would have). So face deletion must occur only when we come from | |
2405 | ;; an interactive command, that is when the *Article* buffer is | |
2406 | ;; read-only. | |
2407 | (if (and wash-face-p (memq 'face gnus-article-wash-types)) | |
2408 | (gnus-delete-images 'face) | |
b890d447 MB |
2409 | (let ((from (message-fetch-field "from")) |
2410 | face faces) | |
7d0c69be | 2411 | (save-current-buffer |
23f87bed | 2412 | (when (and wash-face-p |
7d0c69be MB |
2413 | (gnus-buffer-live-p gnus-original-article-buffer) |
2414 | (not (re-search-forward "^Face:[\t ]*" nil t))) | |
23f87bed MB |
2415 | (set-buffer gnus-original-article-buffer)) |
2416 | (save-restriction | |
2417 | (mail-narrow-to-head) | |
b890d447 MB |
2418 | (when (or force |
2419 | ;; Check whether this face is censored. | |
2420 | (not (and gnus-article-x-face-too-ugly | |
2421 | (or from | |
2422 | (setq from (message-fetch-field "from"))) | |
2423 | (string-match gnus-article-x-face-too-ugly | |
2424 | from)))) | |
2425 | (while (gnus-article-goto-header "Face") | |
2426 | (push (mail-header-field-value) faces))))) | |
d6697c02 | 2427 | (when faces |
7d0c69be | 2428 | (goto-char (point-min)) |
b890d447 MB |
2429 | (let (png image) |
2430 | (unless (setq from (gnus-article-goto-header "from")) | |
7d0c69be MB |
2431 | (insert "From:") |
2432 | (setq from (point)) | |
b890d447 | 2433 | (insert " [no `from' set]\n")) |
7d0c69be MB |
2434 | (while faces |
2435 | (when (setq png (gnus-convert-face-to-png (pop faces))) | |
01c52d31 MB |
2436 | (setq image |
2437 | (apply 'gnus-create-image png 'png t | |
2438 | (cdr (assq 'png gnus-face-properties-alist)))) | |
d6697c02 | 2439 | (goto-char from) |
b4599732 CY |
2440 | (when image |
2441 | (gnus-add-wash-type 'face) | |
2442 | (gnus-add-image 'face image) | |
2443 | (gnus-put-image image nil 'face))))))))))) | |
23f87bed | 2444 | |
eec82323 LMI |
2445 | (defun article-display-x-face (&optional force) |
2446 | "Look for an X-Face header and display it if present." | |
2447 | (interactive (list 'force)) | |
23f87bed MB |
2448 | (let ((wash-face-p buffer-read-only)) ;; When type `W f' |
2449 | (gnus-with-article-headers | |
2450 | ;; Delete the old process, if any. | |
2451 | (when (process-status "article-x-face") | |
2452 | (delete-process "article-x-face")) | |
2453 | ;; See the comment in `article-display-face'. | |
2454 | (if (and wash-face-p (memq 'xface gnus-article-wash-types)) | |
2455 | ;; We have already displayed X-Faces, so we remove them | |
2456 | ;; instead. | |
2457 | (gnus-delete-images 'xface) | |
2458 | ;; Display X-Faces. | |
b890d447 MB |
2459 | (let ((from (message-fetch-field "from")) |
2460 | x-faces face) | |
7d0c69be | 2461 | (save-current-buffer |
23f87bed | 2462 | (when (and wash-face-p |
7d0c69be MB |
2463 | (gnus-buffer-live-p gnus-original-article-buffer) |
2464 | (not (re-search-forward "^X-Face:[\t ]*" nil t))) | |
23f87bed MB |
2465 | ;; If type `W f', use gnus-original-article-buffer, |
2466 | ;; otherwise use the current buffer because displaying | |
2467 | ;; RFC822 parts calls this function too. | |
2468 | (set-buffer gnus-original-article-buffer)) | |
2469 | (save-restriction | |
2470 | (mail-narrow-to-head) | |
b890d447 MB |
2471 | (and gnus-article-x-face-command |
2472 | (or force | |
2473 | ;; Check whether this face is censored. | |
2474 | (not (and gnus-article-x-face-too-ugly | |
2475 | (or from | |
2476 | (setq from (message-fetch-field "from"))) | |
2477 | (string-match gnus-article-x-face-too-ugly | |
2478 | from)))) | |
2479 | (while (gnus-article-goto-header "X-Face") | |
2480 | (push (mail-header-field-value) x-faces))))) | |
2481 | (when x-faces | |
2482 | ;; We display the face. | |
2483 | (cond ((functionp gnus-article-x-face-command) | |
2484 | ;; The command is a lisp function, so we call it. | |
2485 | (mapc gnus-article-x-face-command x-faces)) | |
2486 | ((stringp gnus-article-x-face-command) | |
2487 | ;; The command is a string, so we interpret the command | |
2488 | ;; as a, well, command, and fork it off. | |
2489 | (let ((process-connection-type nil)) | |
2490 | (gnus-set-process-query-on-exit-flag | |
2491 | (start-process | |
2492 | "article-x-face" nil shell-file-name | |
2493 | shell-command-switch gnus-article-x-face-command) | |
2494 | nil) | |
2495 | ;; Sending multiple EOFs to xv doesn't work, | |
2496 | ;; so we only do a single external face. | |
2497 | (with-temp-buffer | |
2498 | (insert (car x-faces)) | |
2499 | (process-send-region "article-x-face" | |
2500 | (point-min) (point-max))) | |
2501 | (process-send-eof "article-x-face"))) | |
2502 | (t | |
2503 | (error "`%s' set to `%s' is not a function" | |
2504 | gnus-article-x-face-command | |
2505 | 'gnus-article-x-face-command))))))))) | |
a8151ef7 | 2506 | |
16409b0b GM |
2507 | (defun article-decode-mime-words () |
2508 | "Decode all MIME-encoded words in the article." | |
2509 | (interactive) | |
01c52d31 | 2510 | (gnus-with-article-buffer |
16409b0b | 2511 | (let ((inhibit-point-motion-hooks t) |
16409b0b | 2512 | (mail-parse-charset gnus-newsgroup-charset) |
a1506d29 | 2513 | (mail-parse-ignored-charsets |
01c52d31 MB |
2514 | (with-current-buffer gnus-summary-buffer |
2515 | gnus-newsgroup-ignored-charsets))) | |
16409b0b GM |
2516 | (mail-decode-encoded-word-region (point-min) (point-max))))) |
2517 | ||
2518 | (defun article-decode-charset (&optional prompt) | |
2519 | "Decode charset-encoded text in the article. | |
2520 | If PROMPT (the prefix), prompt for a coding system to use." | |
2521 | (interactive "P") | |
2522 | (let ((inhibit-point-motion-hooks t) (case-fold-search t) | |
23f87bed | 2523 | (inhibit-read-only t) |
16409b0b | 2524 | (mail-parse-charset gnus-newsgroup-charset) |
a1506d29 | 2525 | (mail-parse-ignored-charsets |
16409b0b GM |
2526 | (save-excursion (condition-case nil |
2527 | (set-buffer gnus-summary-buffer) | |
2528 | (error)) | |
2529 | gnus-newsgroup-ignored-charsets)) | |
2530 | ct cte ctl charset format) | |
c96ec15a MB |
2531 | (save-excursion |
2532 | (save-restriction | |
2533 | (article-narrow-to-head) | |
2534 | (setq ct (message-fetch-field "Content-Type" t) | |
2535 | cte (message-fetch-field "Content-Transfer-Encoding" t) | |
2536 | ctl (and ct (mail-header-parse-content-type ct)) | |
2537 | charset (cond | |
2538 | (prompt | |
2539 | (mm-read-coding-system "Charset to decode: ")) | |
2540 | (ctl | |
2541 | (mail-content-type-get ctl 'charset))) | |
2542 | format (and ctl (mail-content-type-get ctl 'format))) | |
2543 | (when cte | |
2544 | (setq cte (mail-header-strip cte))) | |
2545 | (if (and ctl (not (string-match "/" (car ctl)))) | |
2546 | (setq ctl nil)) | |
2547 | (goto-char (point-max))) | |
2548 | (forward-line 1) | |
2549 | (save-restriction | |
2550 | (narrow-to-region (point) (point-max)) | |
2551 | (when (and (eq mail-parse-charset 'gnus-decoded) | |
2552 | (eq (mm-body-7-or-8) '8bit)) | |
2553 | ;; The text code could have been decoded. | |
2554 | (setq charset mail-parse-charset)) | |
2555 | (when (and (or (not ctl) | |
2556 | (equal (car ctl) "text/plain")) | |
2557 | (not format)) ;; article with format will decode later. | |
2558 | (mm-decode-body | |
2559 | charset (and cte (intern (downcase | |
2560 | (gnus-strip-whitespace cte)))) | |
2561 | (car ctl))))))) | |
16409b0b GM |
2562 | |
2563 | (defun article-decode-encoded-words () | |
2564 | "Remove encoded-word encoding from headers." | |
2565 | (let ((inhibit-point-motion-hooks t) | |
2566 | (mail-parse-charset gnus-newsgroup-charset) | |
a1506d29 | 2567 | (mail-parse-ignored-charsets |
16409b0b GM |
2568 | (save-excursion (condition-case nil |
2569 | (set-buffer gnus-summary-buffer) | |
2570 | (error)) | |
2571 | gnus-newsgroup-ignored-charsets)) | |
343d6628 | 2572 | (inhibit-read-only t) |
8fbdffe5 MB |
2573 | end start) |
2574 | (goto-char (point-min)) | |
2575 | (when (search-forward "\n\n" nil 'move) | |
2576 | (forward-line -1)) | |
2577 | (setq end (point)) | |
2578 | (while (not (bobp)) | |
2579 | (while (progn | |
2580 | (forward-line -1) | |
2581 | (and (not (bobp)) | |
2582 | (memq (char-after) '(?\t ? ))))) | |
2583 | (setq start (point)) | |
2584 | (if (looking-at "\ | |
343d6628 MB |
2585 | \\(?:Resent-\\)?\\(?:From\\|Cc\\|To\\|Bcc\\|\\(?:In-\\)?Reply-To\\|Sender\ |
2586 | \\|Mail-Followup-To\\|Mail-Copies-To\\|Approved\\):") | |
8fbdffe5 MB |
2587 | (funcall gnus-decode-address-function start end) |
2588 | (funcall gnus-decode-header-function start end)) | |
2589 | (goto-char (setq end start))))) | |
eec82323 | 2590 | |
23f87bed | 2591 | (defun article-decode-group-name () |
01c52d31 | 2592 | "Decode group names in Newsgroups, Followup-To and Xref headers." |
23f87bed MB |
2593 | (let ((inhibit-point-motion-hooks t) |
2594 | (inhibit-read-only t) | |
01c52d31 MB |
2595 | (method (gnus-find-method-for-group gnus-newsgroup-name)) |
2596 | regexp) | |
23f87bed MB |
2597 | (when (and (or gnus-group-name-charset-method-alist |
2598 | gnus-group-name-charset-group-alist) | |
2599 | (gnus-buffer-live-p gnus-original-article-buffer)) | |
2600 | (save-restriction | |
2601 | (article-narrow-to-head) | |
01c52d31 MB |
2602 | (dolist (header '("Newsgroups" "Followup-To" "Xref")) |
2603 | (with-current-buffer gnus-original-article-buffer | |
2604 | (goto-char (point-min))) | |
2605 | (setq regexp (concat "^" header | |
2606 | ":\\([^\n]*\\(?:\n[\t ]+[^\n]+\\)*\\)\n")) | |
2607 | (while (re-search-forward regexp nil t) | |
2608 | (replace-match (save-match-data | |
2609 | (gnus-decode-newsgroups | |
2610 | ;; XXX how to use data in article buffer? | |
2611 | (with-current-buffer gnus-original-article-buffer | |
2612 | (re-search-forward regexp nil t) | |
2613 | (match-string 1)) | |
2614 | gnus-newsgroup-name method)) | |
2615 | t t nil 1)) | |
2616 | (goto-char (point-min))))))) | |
23f87bed MB |
2617 | |
2618 | (autoload 'idna-to-unicode "idna") | |
2619 | ||
2620 | (defun article-decode-idna-rhs () | |
53cfefc8 MB |
2621 | "Decode IDNA strings in RHS in various headers in current buffer. |
2622 | The following headers are decoded: From:, To:, Cc:, Reply-To:, | |
2623 | Mail-Reply-To: and Mail-Followup-To:." | |
23f87bed MB |
2624 | (when gnus-use-idna |
2625 | (save-restriction | |
2626 | (let ((inhibit-point-motion-hooks t) | |
2627 | (inhibit-read-only t)) | |
2628 | (article-narrow-to-head) | |
2629 | (goto-char (point-min)) | |
53cfefc8 | 2630 | (while (re-search-forward "@[^ \t\n\r,>]*\\(xn--[-A-Za-z0-9.]*\\)[ \t\n\r,>]" nil t) |
23f87bed MB |
2631 | (let (ace unicode) |
2632 | (when (save-match-data | |
2633 | (and (setq ace (match-string 1)) | |
2634 | (save-excursion | |
2635 | (and (re-search-backward "^[^ \t]" nil t) | |
53cfefc8 | 2636 | (looking-at "From\\|To\\|Cc\\|Reply-To\\|Mail-Reply-To\\|Mail-Followup-To"))) |
23f87bed MB |
2637 | (setq unicode (idna-to-unicode ace)))) |
2638 | (unless (string= ace unicode) | |
2639 | (replace-match unicode nil nil nil 1))))))))) | |
2640 | ||
2641 | (defun article-de-quoted-unreadable (&optional force read-charset) | |
16409b0b | 2642 | "Translate a quoted-printable-encoded article. |
eec82323 | 2643 | If FORCE, decode the article whether it is marked as quoted-printable |
23f87bed MB |
2644 | or not. |
2645 | If READ-CHARSET, ask for a coding system." | |
2646 | (interactive (list 'force current-prefix-arg)) | |
eec82323 | 2647 | (save-excursion |
4e7d0221 | 2648 | (let ((inhibit-read-only t) type charset) |
8b93df01 DL |
2649 | (if (gnus-buffer-live-p gnus-original-article-buffer) |
2650 | (with-current-buffer gnus-original-article-buffer | |
2651 | (setq type | |
2652 | (gnus-fetch-field "content-transfer-encoding")) | |
2653 | (let* ((ct (gnus-fetch-field "content-type")) | |
c96ec15a | 2654 | (ctl (and ct (mail-header-parse-content-type ct)))) |
8b93df01 DL |
2655 | (setq charset (and ctl |
2656 | (mail-content-type-get ctl 'charset))) | |
2657 | (if (stringp charset) | |
2658 | (setq charset (intern (downcase charset))))))) | |
23f87bed MB |
2659 | (if read-charset |
2660 | (setq charset (mm-read-coding-system "Charset: " charset))) | |
a1506d29 | 2661 | (unless charset |
8b93df01 | 2662 | (setq charset gnus-newsgroup-charset)) |
eec82323 | 2663 | (when (or force |
eb806ef3 DL |
2664 | (and type (let ((case-fold-search t)) |
2665 | (string-match "quoted-printable" type)))) | |
16409b0b | 2666 | (article-goto-body) |
eb806ef3 | 2667 | (quoted-printable-decode-region |
07178229 | 2668 | (point) (point-max) (mm-charset-to-coding-system charset nil t)))))) |
16409b0b | 2669 | |
23f87bed | 2670 | (defun article-de-base64-unreadable (&optional force read-charset) |
16409b0b | 2671 | "Translate a base64 article. |
23f87bed MB |
2672 | If FORCE, decode the article whether it is marked as base64 not. |
2673 | If READ-CHARSET, ask for a coding system." | |
2674 | (interactive (list 'force current-prefix-arg)) | |
16409b0b | 2675 | (save-excursion |
4e7d0221 | 2676 | (let ((inhibit-read-only t) type charset) |
8b93df01 DL |
2677 | (if (gnus-buffer-live-p gnus-original-article-buffer) |
2678 | (with-current-buffer gnus-original-article-buffer | |
2679 | (setq type | |
2680 | (gnus-fetch-field "content-transfer-encoding")) | |
2681 | (let* ((ct (gnus-fetch-field "content-type")) | |
c96ec15a | 2682 | (ctl (and ct (mail-header-parse-content-type ct)))) |
8b93df01 DL |
2683 | (setq charset (and ctl |
2684 | (mail-content-type-get ctl 'charset))) | |
2685 | (if (stringp charset) | |
2686 | (setq charset (intern (downcase charset))))))) | |
23f87bed MB |
2687 | (if read-charset |
2688 | (setq charset (mm-read-coding-system "Charset: " charset))) | |
a1506d29 | 2689 | (unless charset |
8b93df01 | 2690 | (setq charset gnus-newsgroup-charset)) |
16409b0b | 2691 | (when (or force |
eb806ef3 DL |
2692 | (and type (let ((case-fold-search t)) |
2693 | (string-match "base64" type)))) | |
16409b0b GM |
2694 | (article-goto-body) |
2695 | (save-restriction | |
2696 | (narrow-to-region (point) (point-max)) | |
2697 | (base64-decode-region (point-min) (point-max)) | |
eb806ef3 | 2698 | (mm-decode-coding-region |
07178229 KY |
2699 | (point-min) (point-max) |
2700 | (mm-charset-to-coding-system charset nil t))))))) | |
16409b0b GM |
2701 | |
2702 | (eval-when-compile | |
2703 | (require 'rfc1843)) | |
2704 | ||
2705 | (defun article-decode-HZ () | |
2706 | "Translate a HZ-encoded article." | |
2707 | (interactive) | |
2708 | (require 'rfc1843) | |
2709 | (save-excursion | |
4e7d0221 | 2710 | (let ((inhibit-read-only t)) |
16409b0b GM |
2711 | (rfc1843-decode-region (point-min) (point-max))))) |
2712 | ||
23f87bed MB |
2713 | (defun article-unsplit-urls () |
2714 | "Remove the newlines that some other mailers insert into URLs." | |
16409b0b | 2715 | (interactive) |
23f87bed MB |
2716 | (save-excursion |
2717 | (let ((inhibit-read-only t)) | |
2718 | (goto-char (point-min)) | |
2719 | (while (re-search-forward | |
97f78c9b | 2720 | "\\(\\(https?\\|ftp\\)://\\S-+\\) *\n\\(\\S-+\\)" nil t) |
23f87bed | 2721 | (replace-match "\\1\\3" t))) |
da946239 | 2722 | (when (gmm-called-interactively-p 'any) |
23f87bed MB |
2723 | (gnus-treat-article nil)))) |
2724 | ||
2526f423 G |
2725 | (defun article-wash-html () |
2726 | "Format an HTML article." | |
2727 | (interactive) | |
2728 | (let ((handles nil) | |
2729 | (buffer-read-only nil)) | |
2730 | (when (gnus-buffer-live-p gnus-original-article-buffer) | |
dc2ab667 LMI |
2731 | (with-current-buffer gnus-original-article-buffer |
2732 | (setq handles (mm-dissect-buffer t t)))) | |
2526f423 G |
2733 | (article-goto-body) |
2734 | (delete-region (point) (point-max)) | |
dc2ab667 | 2735 | (mm-enable-multibyte) |
2526f423 | 2736 | (mm-inline-text-html handles))) |
73043f7d | 2737 | |
01c52d31 MB |
2738 | (defvar gnus-article-browse-html-temp-list nil |
2739 | "List of temporary files created by `gnus-article-browse-html-parts'. | |
2740 | Internal variable.") | |
2741 | ||
2742 | (defcustom gnus-article-browse-delete-temp 'ask | |
2743 | "What to do with temporary files from `gnus-article-browse-html-parts'. | |
2744 | If nil, don't delete temporary files. If it is t, delete them on | |
2745 | exit from the summary buffer. If it is the symbol `file', query | |
2746 | on each file, if it is `ask' ask once when exiting from the | |
2747 | summary buffer." | |
2748 | :group 'gnus-article | |
330f707b | 2749 | :version "23.1" ;; No Gnus |
01c52d31 MB |
2750 | :type '(choice (const :tag "Don't delete" nil) |
2751 | (const :tag "Don't ask" t) | |
2752 | (const :tag "Ask" ask) | |
2753 | (const :tag "Ask for each file" file))) | |
2754 | ||
2755 | ;; Cf. mm-postponed-undisplay-list / mm-destroy-postponed-undisplay-list. | |
2756 | ||
2757 | (defun gnus-article-browse-delete-temp-files (&optional how) | |
2758 | "Delete temp-files created by `gnus-article-browse-html-parts'." | |
2759 | (when (and gnus-article-browse-html-temp-list | |
3aeb9402 KY |
2760 | (progn |
2761 | (or how (setq how gnus-article-browse-delete-temp)) | |
2762 | (if (eq how 'ask) | |
5c11868c KY |
2763 | (let ((files (length gnus-article-browse-html-temp-list))) |
2764 | (or (gnus-y-or-n-p | |
2765 | (if (= files 1) | |
2766 | "Delete the temporary HTML file? " | |
2767 | (format "Delete all %s temporary HTML files? " | |
2768 | files))) | |
2eff54ba | 2769 | (setq gnus-article-browse-html-temp-list nil))) |
3aeb9402 | 2770 | how))) |
01c52d31 | 2771 | (dolist (file gnus-article-browse-html-temp-list) |
3aeb9402 KY |
2772 | (cond ((file-directory-p file) |
2773 | (when (or (not (eq how 'file)) | |
2774 | (gnus-y-or-n-p | |
2775 | (format | |
2776 | "Delete temporary HTML file(s) in directory `%s'? " | |
2777 | (file-name-as-directory file)))) | |
2778 | (gnus-delete-directory file))) | |
2779 | ((file-exists-p file) | |
2780 | (when (or (not (eq how 'file)) | |
2781 | (gnus-y-or-n-p | |
2782 | (format "Delete temporary HTML file `%s'? " file))) | |
2783 | (delete-file file))))) | |
01c52d31 MB |
2784 | ;; Also remove file from the list when not deleted or if file doesn't |
2785 | ;; exist anymore. | |
2786 | (setq gnus-article-browse-html-temp-list nil)) | |
2787 | gnus-article-browse-html-temp-list) | |
2788 | ||
d40d713a KY |
2789 | (defun gnus-article-browse-html-save-cid-content (cid handles directory) |
2790 | "Find CID content in HANDLES and save it in a file in DIRECTORY. | |
2791 | Return file name." | |
20c0b2ce | 2792 | (save-match-data |
d40d713a KY |
2793 | (let (file type) |
2794 | (catch 'found | |
2795 | (dolist (handle handles) | |
2796 | (cond | |
2797 | ((not (listp handle))) | |
0b575a33 KY |
2798 | ;; Exclude broken handles that `gnus-summary-enter-digest-group' |
2799 | ;; may create. | |
2800 | ((not (or (bufferp (car handle)) (stringp (car handle))))) | |
d40d713a KY |
2801 | ((equal (mm-handle-media-supertype handle) "multipart") |
2802 | (when (setq file (gnus-article-browse-html-save-cid-content | |
2803 | cid handle directory)) | |
2804 | (throw 'found file))) | |
2805 | ((equal (concat "<" cid ">") (mm-handle-id handle)) | |
2806 | (setq file | |
2807 | (expand-file-name | |
0b575a33 KY |
2808 | (or (mm-handle-filename handle) |
2809 | (concat | |
2810 | (make-temp-name "cid") | |
2811 | (car (rassoc (car (mm-handle-type handle)) | |
2812 | mailcap-mime-extensions)))) | |
2813 | directory)) | |
d40d713a KY |
2814 | (mm-save-part-to-file handle file) |
2815 | (throw 'found file)))))))) | |
20c0b2ce | 2816 | |
87035689 | 2817 | (defun gnus-article-browse-html-parts (list &optional header) |
01c52d31 | 2818 | "View all \"text/html\" parts from LIST. |
87035689 MB |
2819 | Recurse into multiparts. The optional HEADER that should be a decoded |
2820 | message header will be added to the bodies of the \"text/html\" parts." | |
01c52d31 | 2821 | ;; Internal function used by `gnus-article-browse-html-article'. |
d40d713a | 2822 | (let (type file charset content cid-dir tmp-file showed) |
01c52d31 MB |
2823 | ;; Find and show the html-parts. |
2824 | (dolist (handle list) | |
2825 | ;; If HTML, show it: | |
bbbe940b MB |
2826 | (cond ((not (listp handle))) |
2827 | ((or (equal (car (setq type (mm-handle-type handle))) "text/html") | |
2828 | (and (equal (car type) "message/external-body") | |
87035689 | 2829 | (or header |
247c22e1 | 2830 | (setq file (mm-handle-filename handle))) |
bbbe940b MB |
2831 | (or (mm-handle-cache handle) |
2832 | (condition-case code | |
2833 | (progn (mm-extern-cache-contents handle) t) | |
2834 | (error | |
2835 | (gnus-message 3 "%s" (error-message-string code)) | |
2836 | (when (>= gnus-verbose 3) (sit-for 2)) | |
2837 | nil))) | |
2838 | (progn | |
2839 | (setq handle (mm-handle-cache handle) | |
2840 | type (mm-handle-type handle)) | |
2841 | (equal (car type) "text/html")))) | |
d40d713a KY |
2842 | (setq charset (mail-content-type-get type 'charset) |
2843 | content (mm-get-part handle)) | |
2844 | (with-temp-buffer | |
2845 | (if (eq charset 'gnus-decoded) | |
2846 | (mm-enable-multibyte) | |
2847 | (mm-disable-multibyte)) | |
2848 | (insert content) | |
2849 | ;; resolve cid contents | |
2850 | (let ((case-fold-search t) | |
2851 | cid-file) | |
2852 | (goto-char (point-min)) | |
2853 | (while (re-search-forward "\ | |
2854 | <img[\t\n ]+\\(?:[^\t\n >]+[\t\n ]+\\)*src=\"\\(cid:\\([^\"]+\\)\\)\"" | |
2855 | nil t) | |
2856 | (unless cid-dir | |
765d4319 | 2857 | (setq cid-dir (mm-make-temp-file "cid" t)) |
d40d713a KY |
2858 | (add-to-list 'gnus-article-browse-html-temp-list cid-dir)) |
2859 | (setq file nil | |
2860 | content nil) | |
2861 | (when (setq cid-file | |
2862 | (gnus-article-browse-html-save-cid-content | |
2863 | (match-string 2) | |
2864 | (with-current-buffer gnus-article-buffer | |
2865 | gnus-article-mime-handles) | |
2866 | cid-dir)) | |
df103ffb | 2867 | (when (eq system-type 'cygwin) |
dfdbf7af KY |
2868 | (setq cid-file |
2869 | (concat "/" (substring | |
2870 | (with-output-to-string | |
2871 | (call-process "cygpath" nil | |
2872 | standard-output | |
2873 | nil "-m" cid-file)) | |
2874 | 0 -1)))) | |
d40d713a KY |
2875 | (replace-match (concat "file://" cid-file) |
2876 | nil nil nil 1)))) | |
2877 | (unless content (setq content (buffer-string)))) | |
2878 | (when (or charset header (not file)) | |
bbbe940b MB |
2879 | (setq tmp-file (mm-make-temp-file |
2880 | ;; Do we need to care for 8.3 filenames? | |
2881 | "mm-" nil ".html"))) | |
87035689 MB |
2882 | ;; Add a meta html tag to specify charset and a header. |
2883 | (cond | |
2884 | (header | |
c01f0213 | 2885 | (let (title eheader body hcharset coding) |
87035689 MB |
2886 | (with-temp-buffer |
2887 | (mm-enable-multibyte) | |
2888 | (setq case-fold-search t) | |
2889 | (insert header "\n") | |
2890 | (setq title (message-fetch-field "subject")) | |
2891 | (goto-char (point-min)) | |
5ea1a8d1 KY |
2892 | (while (re-search-forward "\\(<\\)\\|\\(>\\)\\|\\(&\\)\\|\n" |
2893 | nil t) | |
87035689 MB |
2894 | (replace-match (cond ((match-beginning 1) "<") |
2895 | ((match-beginning 2) ">") | |
5ea1a8d1 KY |
2896 | ((match-beginning 3) "&") |
2897 | (t "<br>\n")))) | |
87035689 | 2898 | (goto-char (point-min)) |
4cbac8e9 KY |
2899 | (while (re-search-forward "^[\t ]+" nil t) |
2900 | (dotimes (i (prog1 | |
2901 | (current-column) | |
2902 | (delete-region (match-beginning 0) | |
2903 | (match-end 0)))) | |
2904 | (insert " "))) | |
2905 | (goto-char (point-min)) | |
5ea1a8d1 | 2906 | (insert "<div align=\"left\">\n") |
87035689 | 2907 | (goto-char (point-max)) |
5ea1a8d1 | 2908 | (insert "</div>\n<hr>\n") |
87035689 MB |
2909 | ;; We have to examine charset one by one since |
2910 | ;; charset specified in parts might be different. | |
2911 | (if (eq charset 'gnus-decoded) | |
2912 | (setq charset 'utf-8 | |
2913 | eheader (mm-encode-coding-string (buffer-string) | |
2914 | charset) | |
2915 | title (when title | |
2916 | (mm-encode-coding-string title charset)) | |
c01f0213 | 2917 | body (mm-encode-coding-string content charset)) |
87035689 MB |
2918 | (setq hcharset (mm-find-mime-charset-region (point-min) |
2919 | (point-max))) | |
2920 | (cond ((= (length hcharset) 1) | |
2921 | (setq hcharset (car hcharset) | |
2922 | coding (mm-charset-to-coding-system | |
0b575a33 | 2923 | hcharset nil t))) |
87035689 MB |
2924 | ((> (length hcharset) 1) |
2925 | (setq hcharset 'utf-8 | |
2926 | coding hcharset))) | |
2927 | (if coding | |
2928 | (if charset | |
2929 | (progn | |
2930 | (setq body | |
0b575a33 KY |
2931 | (mm-charset-to-coding-system charset |
2932 | nil t)) | |
87035689 MB |
2933 | (if (eq coding body) |
2934 | (setq eheader (mm-encode-coding-string | |
2935 | (buffer-string) coding) | |
2936 | title (when title | |
2937 | (mm-encode-coding-string | |
2938 | title coding)) | |
d40d713a | 2939 | body content) |
87035689 MB |
2940 | (setq charset 'utf-8 |
2941 | eheader (mm-encode-coding-string | |
2942 | (buffer-string) charset) | |
2943 | title (when title | |
2944 | (mm-encode-coding-string | |
2945 | title charset)) | |
2946 | body (mm-encode-coding-string | |
2947 | (mm-decode-coding-string | |
d40d713a | 2948 | content body) |
c01f0213 | 2949 | charset)))) |
87035689 MB |
2950 | (setq charset hcharset |
2951 | eheader (mm-encode-coding-string | |
2952 | (buffer-string) coding) | |
2953 | title (when title | |
2954 | (mm-encode-coding-string | |
2955 | title coding)) | |
d40d713a | 2956 | body content)) |
87035689 | 2957 | (setq eheader (mm-string-as-unibyte (buffer-string)) |
d40d713a | 2958 | body content))) |
87035689 MB |
2959 | (erase-buffer) |
2960 | (mm-disable-multibyte) | |
2961 | (insert body) | |
2962 | (when charset | |
c01f0213 | 2963 | (mm-add-meta-html-tag handle charset t)) |
87035689 MB |
2964 | (when title |
2965 | (goto-char (point-min)) | |
2966 | (unless (search-forward "<title>" nil t) | |
2967 | (re-search-forward "<head>\\s-*" nil t) | |
2968 | (insert "<title>" title "</title>\n"))) | |
2969 | (goto-char (point-min)) | |
2970 | (or (re-search-forward | |
2971 | "<body\\(?:\\s-+[^>]+\\|\\s-*\\)>\\s-*" nil t) | |
2972 | (re-search-forward | |
2973 | "</head\\(?:\\s-+[^>]+\\|\\s-*\\)>\\s-*" nil t)) | |
2974 | (insert eheader) | |
2975 | (mm-write-region (point-min) (point-max) | |
2976 | tmp-file nil nil nil 'binary t)))) | |
2977 | (charset | |
2978 | (mm-with-unibyte-buffer | |
2979 | (insert (if (eq charset 'gnus-decoded) | |
d40d713a KY |
2980 | (mm-encode-coding-string content |
2981 | (setq charset 'utf-8)) | |
2982 | content)) | |
87035689 MB |
2983 | (if (or (mm-add-meta-html-tag handle charset) |
2984 | (not file)) | |
2985 | (mm-write-region (point-min) (point-max) | |
2986 | tmp-file nil nil nil 'binary t) | |
2987 | (setq tmp-file nil)))) | |
2988 | (tmp-file | |
2989 | (mm-save-part-to-file handle tmp-file))) | |
bbbe940b MB |
2990 | (when tmp-file |
2991 | (add-to-list 'gnus-article-browse-html-temp-list tmp-file)) | |
2992 | (add-hook 'gnus-summary-prepare-exit-hook | |
2993 | 'gnus-article-browse-delete-temp-files) | |
2994 | (add-hook 'gnus-exit-gnus-hook | |
2995 | (lambda () | |
2996 | (gnus-article-browse-delete-temp-files t))) | |
2997 | ;; FIXME: Warn if there's an <img> tag? | |
2998 | (browse-url-of-file (or tmp-file (expand-file-name file))) | |
2999 | (setq showed t)) | |
3000 | ;; If multipart, recurse | |
87035689 MB |
3001 | ((equal (mm-handle-media-supertype handle) "multipart") |
3002 | (when (gnus-article-browse-html-parts handle header) | |
3003 | (setq showed t))) | |
3004 | ((equal (mm-handle-media-type handle) "message/rfc822") | |
3005 | (mm-with-multibyte-buffer | |
3006 | (mm-insert-part handle) | |
3007 | (setq handle (mm-dissect-buffer t t)) | |
3008 | (when (and (bufferp (car handle)) | |
3009 | (stringp (car (mm-handle-type handle)))) | |
3010 | (setq handle (list handle))) | |
3011 | (when header | |
3012 | (article-decode-encoded-words) | |
3013 | (let ((gnus-visible-headers | |
3014 | (or (get 'gnus-visible-headers 'standard-value) | |
3015 | gnus-visible-headers))) | |
3016 | (article-hide-headers)) | |
3017 | (goto-char (point-min)) | |
3018 | (search-forward "\n\n" nil 'move) | |
3019 | (skip-chars-backward "\t\n ") | |
3020 | (setq header (buffer-substring (point-min) (point))))) | |
3021 | (when (prog1 | |
3022 | (gnus-article-browse-html-parts handle header) | |
3023 | (mm-destroy-parts handle)) | |
3024 | (setq showed t))))) | |
01c52d31 MB |
3025 | showed)) |
3026 | ||
87035689 | 3027 | (defun gnus-article-browse-html-article (&optional arg) |
01c52d31 | 3028 | "View \"text/html\" parts of the current article with a WWW browser. |
d40d713a KY |
3029 | Inline images embedded in a message using the cid scheme, as they are |
3030 | generally considered to be safe, will be processed properly. | |
87035689 MB |
3031 | The message header is added to the beginning of every html part unless |
3032 | the prefix argument ARG is given. | |
01c52d31 | 3033 | |
d40d713a KY |
3034 | Warning: Spammers use links to images (using the http scheme) in HTML |
3035 | articles to verify whether you have read the message. As | |
9b3ebcb6 MB |
3036 | `gnus-article-browse-html-article' passes the HTML content to the |
3037 | browser without eliminating these \"web bugs\" you should only | |
3038 | use it for mails from trusted senders. | |
b890d447 | 3039 | |
9b3ebcb6 | 3040 | If you always want to display HTML parts in the browser, set |
d40d713a KY |
3041 | `mm-text-html-renderer' to nil. |
3042 | ||
3043 | This command creates temporary files to pass HTML contents including | |
3044 | images if any to the browser, and deletes them when exiting the group | |
3045 | \(if you want)." | |
01c52d31 | 3046 | ;; Cf. `mm-w3m-safe-url-regexp' |
87035689 MB |
3047 | (interactive "P") |
3048 | (if arg | |
3049 | (gnus-summary-show-article) | |
3050 | (let ((gnus-visible-headers (or (get 'gnus-visible-headers 'standard-value) | |
9b3ebcb6 MB |
3051 | gnus-visible-headers)) |
3052 | ;; As we insert a <hr>, there's no need for the body boundary. | |
3053 | (gnus-treat-body-boundary nil)) | |
87035689 MB |
3054 | (gnus-summary-show-article))) |
3055 | (with-current-buffer gnus-article-buffer | |
3056 | (let ((header (unless arg | |
3057 | (save-restriction | |
3058 | (widen) | |
3059 | (buffer-substring-no-properties | |
3060 | (goto-char (point-min)) | |
3061 | (if (search-forward "\n\n" nil t) | |
3062 | (match-beginning 0) | |
3063 | (goto-char (point-max)) | |
3064 | (skip-chars-backward "\t\n ") | |
3065 | (point)))))) | |
3066 | parts) | |
3067 | (set-buffer gnus-original-article-buffer) | |
3068 | (setq parts (mm-dissect-buffer t t)) | |
01c52d31 MB |
3069 | ;; If singlepart, enforce a list. |
3070 | (when (and (bufferp (car parts)) | |
3071 | (stringp (car (mm-handle-type parts)))) | |
3072 | (setq parts (list parts))) | |
3073 | ;; Process the list | |
87035689 | 3074 | (unless (gnus-article-browse-html-parts parts header) |
01c52d31 | 3075 | (gnus-error 3 "Mail doesn't contain a \"text/html\" part!")) |
87035689 MB |
3076 | (mm-destroy-parts parts) |
3077 | (unless arg | |
3078 | (gnus-summary-show-article))))) | |
01c52d31 | 3079 | |
16409b0b GM |
3080 | (defun article-hide-list-identifiers () |
3081 | "Remove list identifies from the Subject header. | |
3082 | The `gnus-list-identifiers' variable specifies what to do." | |
3083 | (interactive) | |
23f87bed | 3084 | (let ((inhibit-point-motion-hooks t) |
d6cd56f1 | 3085 | (regexp (gnus-group-get-list-identifiers gnus-newsgroup-name)) |
fb9b91be | 3086 | (inhibit-read-only t)) |
23f87bed MB |
3087 | (when regexp |
3088 | (save-excursion | |
3089 | (save-restriction | |
3090 | (article-narrow-to-head) | |
3091 | (goto-char (point-min)) | |
3092 | (while (re-search-forward | |
3093 | (concat "^Subject: +\\(R[Ee]: +\\)*\\(" regexp " *\\)") | |
3094 | nil t) | |
3095 | (delete-region (match-beginning 2) (match-end 0)) | |
3096 | (beginning-of-line)) | |
3097 | (when (re-search-forward | |
3098 | "^Subject: +\\(\\(R[Ee]: +\\)+\\)R[Ee]: +" nil t) | |
3099 | (delete-region (match-beginning 1) (match-end 1)))))))) | |
eec82323 LMI |
3100 | |
3101 | (defun article-hide-pem (&optional arg) | |
3102 | "Toggle hiding of any PEM headers and signatures in the current article. | |
3103 | If given a negative prefix, always show; if given a positive prefix, | |
3104 | always hide." | |
3105 | (interactive (gnus-article-hidden-arg)) | |
3106 | (unless (gnus-article-check-hidden-text 'pem arg) | |
3107 | (save-excursion | |
23f87bed | 3108 | (let ((inhibit-read-only t) end) |
eec82323 | 3109 | (goto-char (point-min)) |
16409b0b GM |
3110 | ;; Hide the horrendously ugly "header". |
3111 | (when (and (search-forward | |
3112 | "\n-----BEGIN PRIVACY-ENHANCED MESSAGE-----\n" | |
3113 | nil t) | |
3114 | (setq end (1+ (match-beginning 0)))) | |
23f87bed | 3115 | (gnus-add-wash-type 'pem) |
16409b0b GM |
3116 | (gnus-article-hide-text-type |
3117 | end | |
3118 | (if (search-forward "\n\n" nil t) | |
3119 | (match-end 0) | |
3120 | (point-max)) | |
3121 | 'pem) | |
3122 | ;; Hide the trailer as well | |
3123 | (when (search-forward "\n-----END PRIVACY-ENHANCED MESSAGE-----\n" | |
3124 | nil t) | |
3125 | (gnus-article-hide-text-type | |
3126 | (match-beginning 0) (match-end 0) 'pem))))))) | |
3127 | ||
3128 | (defun article-strip-banner () | |
23f87bed MB |
3129 | "Strip the banners specified by the `banner' group parameter and by |
3130 | `gnus-article-address-banner-alist'." | |
16409b0b | 3131 | (interactive) |
23f87bed MB |
3132 | (save-excursion |
3133 | (save-restriction | |
3134 | (let ((inhibit-point-motion-hooks t)) | |
3135 | (when (gnus-parameter-banner gnus-newsgroup-name) | |
3136 | (article-really-strip-banner | |
3137 | (gnus-parameter-banner gnus-newsgroup-name))) | |
3138 | (when gnus-article-address-banner-alist | |
cf5a5c38 MB |
3139 | ;; Note that the From header is decoded here, so it is |
3140 | ;; required that the *-extract-address-components function | |
3141 | ;; supports non-ASCII text. | |
d71c0855 MB |
3142 | (let ((from (save-restriction |
3143 | (widen) | |
3144 | (article-narrow-to-head) | |
3145 | (mail-fetch-field "from")))) | |
3146 | (when (and from | |
3147 | (setq from | |
3148 | (cadr (funcall gnus-extract-address-components | |
3149 | from)))) | |
3150 | (catch 'found | |
3151 | (dolist (pair gnus-article-address-banner-alist) | |
3152 | (when (string-match (car pair) from) | |
3153 | (throw 'found | |
3154 | (article-really-strip-banner (cdr pair))))))))))))) | |
23f87bed MB |
3155 | |
3156 | (defun article-really-strip-banner (banner) | |
3157 | "Strip the banner specified by the argument." | |
16409b0b GM |
3158 | (save-excursion |
3159 | (save-restriction | |
3160 | (let ((inhibit-point-motion-hooks t) | |
16409b0b | 3161 | (gnus-signature-limit nil) |
23f87bed MB |
3162 | (inhibit-read-only t)) |
3163 | (article-goto-body) | |
3164 | (cond | |
3165 | ((eq banner 'signature) | |
3166 | (when (gnus-article-narrow-to-signature) | |
3167 | (widen) | |
3168 | (forward-line -1) | |
3169 | (delete-region (point) (point-max)))) | |
3170 | ((symbolp banner) | |
3171 | (if (setq banner (cdr (assq banner gnus-article-banner-alist))) | |
3172 | (while (re-search-forward banner nil t) | |
3173 | (delete-region (match-beginning 0) (match-end 0))))) | |
3174 | ((stringp banner) | |
3175 | (while (re-search-forward banner nil t) | |
3176 | (delete-region (match-beginning 0) (match-end 0))))))))) | |
16409b0b GM |
3177 | |
3178 | (defun article-babel () | |
3179 | "Translate article using an online translation service." | |
3180 | (interactive) | |
3181 | (require 'babel) | |
01c52d31 | 3182 | (gnus-with-article-buffer |
16409b0b | 3183 | (when (article-goto-body) |
01c52d31 | 3184 | (let* ((start (point)) |
16409b0b GM |
3185 | (end (point-max)) |
3186 | (orig (buffer-substring start end)) | |
23f87bed | 3187 | (trans (babel-as-string orig))) |
16409b0b GM |
3188 | (save-restriction |
3189 | (narrow-to-region start end) | |
3190 | (delete-region start end) | |
23f87bed | 3191 | (insert trans)))))) |
eec82323 LMI |
3192 | |
3193 | (defun article-hide-signature (&optional arg) | |
3194 | "Hide the signature in the current article. | |
3195 | If given a negative prefix, always show; if given a positive prefix, | |
3196 | always hide." | |
3197 | (interactive (gnus-article-hidden-arg)) | |
3198 | (unless (gnus-article-check-hidden-text 'signature arg) | |
3199 | (save-excursion | |
3200 | (save-restriction | |
4e7d0221 | 3201 | (let ((inhibit-read-only t)) |
eec82323 LMI |
3202 | (when (gnus-article-narrow-to-signature) |
3203 | (gnus-article-hide-text-type | |
23f87bed MB |
3204 | (point-min) (point-max) 'signature)))))) |
3205 | (gnus-set-mode-line 'article)) | |
eec82323 | 3206 | |
16409b0b GM |
3207 | (defun article-strip-headers-in-body () |
3208 | "Strip offensive headers from bodies." | |
3209 | (interactive) | |
3210 | (save-excursion | |
3211 | (article-goto-body) | |
3212 | (let ((case-fold-search t)) | |
3213 | (when (looking-at "x-no-archive:") | |
3214 | (gnus-delete-line))))) | |
3215 | ||
eec82323 LMI |
3216 | (defun article-strip-leading-blank-lines () |
3217 | "Remove all blank lines from the beginning of the article." | |
3218 | (interactive) | |
3219 | (save-excursion | |
3220 | (let ((inhibit-point-motion-hooks t) | |
23f87bed | 3221 | (inhibit-read-only t)) |
16409b0b | 3222 | (when (article-goto-body) |
eec82323 LMI |
3223 | (while (and (not (eobp)) |
3224 | (looking-at "[ \t]*$")) | |
3225 | (gnus-delete-line)))))) | |
3226 | ||
16409b0b GM |
3227 | (defun article-narrow-to-head () |
3228 | "Narrow the buffer to the head of the message. | |
3229 | Point is left at the beginning of the narrowed-to region." | |
3230 | (narrow-to-region | |
3231 | (goto-char (point-min)) | |
e7719ea1 G |
3232 | (cond |
3233 | ;; Absolutely no headers displayed. | |
3234 | ((looking-at "\n") | |
3235 | (point)) | |
3236 | ;; Normal headers. | |
3237 | ((search-forward "\n\n" nil 1) | |
3238 | (1- (point))) | |
3239 | ;; Nothing but headers. | |
3240 | (t | |
3241 | (point-max)))) | |
16409b0b GM |
3242 | (goto-char (point-min))) |
3243 | ||
3244 | (defun article-goto-body () | |
3245 | "Place point at the start of the body." | |
3246 | (goto-char (point-min)) | |
3247 | (cond | |
3248 | ;; This variable is only bound when dealing with separate | |
3249 | ;; MIME body parts. | |
3250 | (article-goto-body-goes-to-point-min-p | |
3251 | t) | |
3252 | ((search-forward "\n\n" nil t) | |
3253 | t) | |
3254 | (t | |
3255 | (goto-char (point-max)) | |
3256 | nil))) | |
3257 | ||
eec82323 LMI |
3258 | (defun article-strip-multiple-blank-lines () |
3259 | "Replace consecutive blank lines with one empty line." | |
3260 | (interactive) | |
3261 | (save-excursion | |
3262 | (let ((inhibit-point-motion-hooks t) | |
23f87bed | 3263 | (inhibit-read-only t)) |
eec82323 | 3264 | ;; First make all blank lines empty. |
16409b0b | 3265 | (article-goto-body) |
eec82323 | 3266 | (while (re-search-forward "^[ \t]+$" nil t) |
16409b0b GM |
3267 | (unless (gnus-annotation-in-region-p |
3268 | (match-beginning 0) (match-end 0)) | |
3269 | (replace-match "" nil t))) | |
eec82323 | 3270 | ;; Then replace multiple empty lines with a single empty line. |
16409b0b | 3271 | (article-goto-body) |
23f87bed | 3272 | (while (re-search-forward "\n\n\\(\n+\\)" nil t) |
16409b0b GM |
3273 | (unless (gnus-annotation-in-region-p |
3274 | (match-beginning 0) (match-end 0)) | |
23f87bed | 3275 | (delete-region (match-beginning 1) (match-end 1))))))) |
eec82323 LMI |
3276 | |
3277 | (defun article-strip-leading-space () | |
3278 | "Remove all white space from the beginning of the lines in the article." | |
3279 | (interactive) | |
3280 | (save-excursion | |
3281 | (let ((inhibit-point-motion-hooks t) | |
23f87bed | 3282 | (inhibit-read-only t)) |
16409b0b | 3283 | (article-goto-body) |
eec82323 LMI |
3284 | (while (re-search-forward "^[ \t]+" nil t) |
3285 | (replace-match "" t t))))) | |
3286 | ||
16409b0b GM |
3287 | (defun article-strip-trailing-space () |
3288 | "Remove all white space from the end of the lines in the article." | |
3289 | (interactive) | |
3290 | (save-excursion | |
3291 | (let ((inhibit-point-motion-hooks t) | |
23f87bed | 3292 | (inhibit-read-only t)) |
16409b0b GM |
3293 | (article-goto-body) |
3294 | (while (re-search-forward "[ \t]+$" nil t) | |
3295 | (replace-match "" t t))))) | |
3296 | ||
eec82323 LMI |
3297 | (defun article-strip-blank-lines () |
3298 | "Strip leading, trailing and multiple blank lines." | |
3299 | (interactive) | |
3300 | (article-strip-leading-blank-lines) | |
3301 | (article-remove-trailing-blank-lines) | |
3302 | (article-strip-multiple-blank-lines)) | |
3303 | ||
6748645f LMI |
3304 | (defun article-strip-all-blank-lines () |
3305 | "Strip all blank lines." | |
3306 | (interactive) | |
3307 | (save-excursion | |
3308 | (let ((inhibit-point-motion-hooks t) | |
23f87bed | 3309 | (inhibit-read-only t)) |
16409b0b | 3310 | (article-goto-body) |
6748645f LMI |
3311 | (while (re-search-forward "^[ \t]*\n" nil t) |
3312 | (replace-match "" t t))))) | |
3313 | ||
eec82323 LMI |
3314 | (defun gnus-article-narrow-to-signature () |
3315 | "Narrow to the signature; return t if a signature is found, else nil." | |
6748645f | 3316 | (let ((inhibit-point-motion-hooks t)) |
6748645f LMI |
3317 | (when (gnus-article-search-signature) |
3318 | (forward-line 1) | |
3319 | ;; Check whether we have some limits to what we consider | |
3320 | ;; to be a signature. | |
3321 | (let ((limits (if (listp gnus-signature-limit) gnus-signature-limit | |
3322 | (list gnus-signature-limit))) | |
3323 | limit limited) | |
3324 | (while (setq limit (pop limits)) | |
3325 | (if (or (and (integerp limit) | |
3326 | (< (- (point-max) (point)) limit)) | |
3327 | (and (floatp limit) | |
3328 | (< (count-lines (point) (point-max)) limit)) | |
23f87bed | 3329 | (and (functionp limit) |
6748645f LMI |
3330 | (funcall limit)) |
3331 | (and (stringp limit) | |
3332 | (not (re-search-forward limit nil t)))) | |
3333 | () ; This limit did not succeed. | |
3334 | (setq limited t | |
3335 | limits nil))) | |
3336 | (unless limited | |
3337 | (narrow-to-region (point) (point-max)) | |
3338 | t))))) | |
eec82323 LMI |
3339 | |
3340 | (defun gnus-article-search-signature () | |
3341 | "Search the current buffer for the signature separator. | |
3342 | Put point at the beginning of the signature separator." | |
3343 | (let ((cur (point))) | |
3344 | (goto-char (point-max)) | |
3345 | (if (if (stringp gnus-signature-separator) | |
3346 | (re-search-backward gnus-signature-separator nil t) | |
3347 | (let ((seps gnus-signature-separator)) | |
3348 | (while (and seps | |
3349 | (not (re-search-backward (car seps) nil t))) | |
3350 | (pop seps)) | |
3351 | seps)) | |
3352 | t | |
3353 | (goto-char cur) | |
3354 | nil))) | |
3355 | ||
eec82323 LMI |
3356 | (defun gnus-article-hidden-arg () |
3357 | "Return the current prefix arg as a number, or 0 if no prefix." | |
3358 | (list (if current-prefix-arg | |
3359 | (prefix-numeric-value current-prefix-arg) | |
3360 | 0))) | |
3361 | ||
3362 | (defun gnus-article-check-hidden-text (type arg) | |
3363 | "Return nil if hiding is necessary. | |
f0529b5b | 3364 | Arg can be nil or a number. nil and positive means hide, negative |
eec82323 LMI |
3365 | means show, 0 means toggle." |
3366 | (save-excursion | |
3367 | (save-restriction | |
eec82323 LMI |
3368 | (let ((hide (gnus-article-hidden-text-p type))) |
3369 | (cond | |
3370 | ((or (null arg) | |
3371 | (> arg 0)) | |
3372 | nil) | |
3373 | ((< arg 0) | |
4481aa98 SZ |
3374 | (gnus-article-show-hidden-text type) |
3375 | t) | |
eec82323 LMI |
3376 | (t |
3377 | (if (eq hide 'hidden) | |
4481aa98 SZ |
3378 | (progn |
3379 | (gnus-article-show-hidden-text type) | |
3380 | t) | |
eec82323 LMI |
3381 | nil))))))) |
3382 | ||
3383 | (defun gnus-article-hidden-text-p (type) | |
3384 | "Say whether the current buffer contains hidden text of type TYPE." | |
6748645f | 3385 | (let ((pos (text-property-any (point-min) (point-max) 'article-type type))) |
eec82323 | 3386 | (while (and pos |
16409b0b GM |
3387 | (not (get-text-property pos 'invisible)) |
3388 | (not (get-text-property pos 'dummy-invisible))) | |
eec82323 LMI |
3389 | (setq pos |
3390 | (text-property-any (1+ pos) (point-max) 'article-type type))) | |
3391 | (if pos | |
3392 | 'hidden | |
16409b0b | 3393 | nil))) |
eec82323 | 3394 | |
520aa572 | 3395 | (defun gnus-article-show-hidden-text (type &optional dummy) |
eec82323 | 3396 | "Show all hidden text of type TYPE. |
520aa572 | 3397 | Originally it is hide instead of DUMMY." |
4e7d0221 | 3398 | (let ((inhibit-read-only t) |
520aa572 | 3399 | (inhibit-point-motion-hooks t)) |
a1506d29 | 3400 | (gnus-remove-text-properties-when |
520aa572 | 3401 | 'article-type type |
a1506d29 | 3402 | (point-min) (point-max) |
520aa572 | 3403 | (cons 'article-type (cons type |
23f87bed MB |
3404 | gnus-hidden-properties))) |
3405 | (gnus-delete-wash-type type))) | |
eec82323 LMI |
3406 | |
3407 | (defconst article-time-units | |
3408 | `((year . ,(* 365.25 24 60 60)) | |
3409 | (week . ,(* 7 24 60 60)) | |
3410 | (day . ,(* 24 60 60)) | |
3411 | (hour . ,(* 60 60)) | |
3412 | (minute . 60) | |
3413 | (second . 1)) | |
3414 | "Mapping from time units to seconds.") | |
3415 | ||
23f87bed MB |
3416 | (defun gnus-article-forward-header () |
3417 | "Move point to the start of the next header. | |
3418 | If the current header is a continuation header, this can be several | |
3419 | lines forward." | |
3420 | (let ((ended nil)) | |
3421 | (while (not ended) | |
3422 | (forward-line 1) | |
3423 | (if (looking-at "[ \t]+[^ \t]") | |
3424 | (forward-line 1) | |
3425 | (setq ended t))))) | |
3426 | ||
12e3ca0a | 3427 | (defun article-treat-date () |
f8342cf5 KY |
3428 | (article-date-ut (if (gnus-buffer-live-p gnus-summary-buffer) |
3429 | (with-current-buffer gnus-summary-buffer | |
3430 | gnus-article-date-headers) | |
3431 | gnus-article-date-headers) | |
3432 | t)) | |
12e3ca0a LI |
3433 | |
3434 | (defun article-date-ut (&optional type highlight date-position) | |
3435 | "Convert DATE date to TYPE in the current article. | |
3436 | The default type is `ut'. See `gnus-article-date-headers' for | |
3437 | possible values." | |
eec82323 | 3438 | (interactive (list 'ut t)) |
12e3ca0a | 3439 | (let* ((case-fold-search t) |
31640842 | 3440 | (inhibit-read-only t) |
eec82323 | 3441 | (inhibit-point-motion-hooks t) |
12e3ca0a | 3442 | (first t) |
d5e9a4e9 | 3443 | (visible-date (mail-fetch-field "Date")) |
31640842 | 3444 | pos date bface eface) |
16409b0b | 3445 | (save-excursion |
0861eb2e KY |
3446 | (if date-position |
3447 | (progn | |
3448 | (goto-char date-position) | |
3449 | (setq date (get-text-property (point) 'original-date)) | |
923c1bfc KY |
3450 | (when (looking-at "[^:]+:[\t ]*") |
3451 | (setq bface (get-text-property (match-beginning 0) 'face) | |
3452 | eface (get-text-property (match-end 0) 'face))) | |
0861eb2e KY |
3453 | (delete-region (point) |
3454 | (progn | |
3455 | (gnus-article-forward-header) | |
3456 | (point))) | |
3457 | (article-transform-date date type bface eface)) | |
3458 | (save-restriction | |
3459 | (widen) | |
3460 | (goto-char (point-min)) | |
3461 | (while (or (get-text-property (setq pos (point)) 'original-date) | |
3462 | (and (setq pos (next-single-property-change | |
3463 | (point) 'original-date)) | |
3464 | (goto-char pos))) | |
3465 | (narrow-to-region pos (if (search-forward "\n\n" nil t) | |
3466 | (1+ (match-beginning 0)) | |
3467 | (point-max))) | |
923c1bfc KY |
3468 | (while (setq pos (text-property-not-all pos (point-max) |
3469 | 'gnus-date-type nil)) | |
3470 | (setq date (get-text-property pos 'original-date)) | |
3471 | (goto-char pos) | |
3472 | (when (looking-at "[^:]+:[\t ]*") | |
3473 | (setq bface (get-text-property (match-beginning 0) 'face) | |
3474 | eface (get-text-property (match-end 0) 'face))) | |
3475 | (delete-region pos (or (text-property-any pos (point-max) | |
3476 | 'gnus-date-type nil) | |
3477 | (point-max)))) | |
3478 | (unless date ;; the 1st time | |
3479 | (goto-char (point-min)) | |
3480 | (while (re-search-forward "^Date:[\t ]*" nil t) | |
3481 | (setq date (get-text-property (match-beginning 0) | |
3482 | 'original-date) | |
3483 | bface (get-text-property (match-beginning 0) 'face) | |
3484 | eface (get-text-property (match-end 0) 'face)) | |
3485 | (delete-region (point-at-bol) (progn | |
3486 | (gnus-article-forward-header) | |
3487 | (point))))) | |
0861eb2e KY |
3488 | (when (and (not date) |
3489 | visible-date) | |
3490 | (setq date visible-date)) | |
3491 | (when date | |
32a400d4 | 3492 | (article-transform-date date type bface eface)) |
0861eb2e KY |
3493 | (goto-char (point-max)) |
3494 | (widen))))))) | |
32a400d4 LI |
3495 | |
3496 | (defun article-transform-date (date type bface eface) | |
3497 | (dolist (this-type (cond | |
3498 | ((null type) | |
3499 | (list 'ut)) | |
3500 | ((atom type) | |
3501 | (list type)) | |
3502 | (t | |
3503 | type))) | |
923c1bfc KY |
3504 | (goto-char |
3505 | (prog1 | |
3506 | (point) | |
3507 | (add-text-properties | |
3508 | (point) | |
3509 | (progn | |
3510 | (insert (article-make-date-line date (or this-type 'ut)) "\n") | |
3511 | (point)) | |
3512 | (list 'original-date date 'gnus-date-type this-type)))) | |
32a400d4 | 3513 | ;; Do highlighting. |
923c1bfc KY |
3514 | (when (looking-at |
3515 | "\\([^:]+:\\)[\t ]*\\(\\(?:[^\t\n ]+[\t ]+\\)*[^\t\n ]+\\)?") | |
3516 | (put-text-property (match-beginning 1) (match-end 1) 'face bface) | |
3517 | (when (match-beginning 2) | |
3518 | (put-text-property (match-beginning 2) (match-end 2) 'face eface)) | |
3519 | (while (and (zerop (forward-line 1)) | |
3520 | (looking-at "[\t ]+\\(\\(?:[^\t\n ]+[\t ]+\\)*[^\t\n ]+\\)?")) | |
3521 | (when (match-beginning 1) | |
3522 | (put-text-property (match-beginning 1) (match-end 1) 'face eface)))))) | |
eec82323 LMI |
3523 | |
3524 | (defun article-make-date-line (date type) | |
3525 | "Return a DATE line of TYPE." | |
5fe18311 KY |
3526 | (unless (memq type '(local ut original user-defined iso8601 lapsed english |
3527 | combined-lapsed)) | |
23f87bed MB |
3528 | (error "Unknown conversion type: %s" type)) |
3529 | (condition-case () | |
fa41748c | 3530 | (let ((time (ignore-errors (date-to-time date)))) |
16409b0b | 3531 | (cond |
23f87bed MB |
3532 | ;; Convert to the local timezone. |
3533 | ((eq type 'local) | |
01c52d31 | 3534 | (concat "Date: " (message-make-date time))) |
23f87bed MB |
3535 | ;; Convert to Universal Time. |
3536 | ((eq type 'ut) | |
3537 | (concat "Date: " | |
01c52d31 MB |
3538 | (substring |
3539 | (message-make-date | |
3540 | (let* ((e (parse-time-string date)) | |
3541 | (tm (apply 'encode-time e)) | |
3542 | (ms (car tm)) | |
3543 | (ls (- (cadr tm) (car (current-time-zone time))))) | |
3544 | (cond ((< ls 0) (list (1- ms) (+ ls 65536))) | |
3545 | ((> ls 65535) (list (1+ ms) (- ls 65536))) | |
3546 | (t (list ms ls))))) | |
3547 | 0 -5) | |
3548 | "UT")) | |
23f87bed MB |
3549 | ;; Get the original date from the article. |
3550 | ((eq type 'original) | |
3551 | (concat "Date: " (if (string-match "\n+$" date) | |
3552 | (substring date 0 (match-beginning 0)) | |
3553 | date))) | |
3554 | ;; Let the user define the format. | |
c4753373 | 3555 | ((eq type 'user-defined) |
23f87bed MB |
3556 | (let ((format (or (condition-case nil |
3557 | (with-current-buffer gnus-summary-buffer | |
3558 | gnus-article-time-format) | |
3559 | (error nil)) | |
3560 | gnus-article-time-format))) | |
3561 | (if (functionp format) | |
3562 | (funcall format time) | |
3563 | (concat "Date: " (format-time-string format time))))) | |
3564 | ;; ISO 8601. | |
3565 | ((eq type 'iso8601) | |
3566 | (let ((tz (car (current-time-zone time)))) | |
3567 | (concat | |
3568 | "Date: " | |
3569 | (format-time-string "%Y%m%dT%H%M%S" time) | |
3570 | (format "%s%02d%02d" | |
3571 | (if (> tz 0) "+" "-") (/ (abs tz) 3600) | |
3572 | (/ (% (abs tz) 3600) 60))))) | |
12e3ca0a | 3573 | ;; Do a lapsed format. |
23f87bed | 3574 | ((eq type 'lapsed) |
12e3ca0a | 3575 | (concat "Date: " (article-lapsed-string time))) |
647559c2 LI |
3576 | ;; A combined date/lapsed format. |
3577 | ((eq type 'combined-lapsed) | |
19cc6697 G |
3578 | (let ((date-string (article-make-date-line date 'original)) |
3579 | (segments 3) | |
3580 | lapsed-string) | |
3581 | (while (and | |
fa41748c | 3582 | time |
19cc6697 G |
3583 | (setq lapsed-string |
3584 | (concat " (" (article-lapsed-string time segments) ")")) | |
3585 | (> (+ (length date-string) | |
3586 | (length lapsed-string)) | |
d6f13ac8 | 3587 | (+ fill-column 6)) |
19cc6697 G |
3588 | (> segments 0)) |
3589 | (setq segments (1- segments))) | |
3590 | (if (> segments 0) | |
3591 | (concat date-string lapsed-string) | |
3592 | date-string))) | |
23f87bed MB |
3593 | ;; Display the date in proper English |
3594 | ((eq type 'english) | |
3595 | (let ((dtime (decode-time time))) | |
3596 | (concat | |
3597 | "Date: the " | |
3598 | (number-to-string (nth 3 dtime)) | |
3599 | (let ((digit (% (nth 3 dtime) 10))) | |
3600 | (cond | |
3601 | ((memq (nth 3 dtime) '(11 12 13)) "th") | |
3602 | ((= digit 1) "st") | |
3603 | ((= digit 2) "nd") | |
3604 | ((= digit 3) "rd") | |
3605 | (t "th"))) | |
3606 | " of " | |
3607 | (nth (1- (nth 4 dtime)) gnus-english-month-names) | |
3608 | " " | |
3609 | (number-to-string (nth 5 dtime)) | |
3610 | " at " | |
3611 | (format "%02d" (nth 2 dtime)) | |
3612 | ":" | |
3613 | (format "%02d" (nth 1 dtime))))))) | |
647559c2 | 3614 | (foo |
a601fb74 | 3615 | (format "Date: %s (from Gnus)" date)))) |
eec82323 | 3616 | |
647559c2 LI |
3617 | (defun article-lapsed-string (time &optional max-segments) |
3618 | ;; If the date is seriously mangled, the timezone functions are | |
3619 | ;; liable to bug out, so we ignore all errors. | |
3620 | (let* ((now (current-time)) | |
3621 | (real-time (subtract-time now time)) | |
3622 | (real-sec (and real-time | |
3623 | (+ (* (float (car real-time)) 65536) | |
3624 | (cadr real-time)))) | |
3625 | (sec (and real-time (abs real-sec))) | |
3626 | (segments 0) | |
3627 | num prev) | |
3628 | (unless max-segments | |
3629 | (setq max-segments (length article-time-units))) | |
3630 | (cond | |
3631 | ((null real-time) | |
3632 | "Unknown") | |
3633 | ((zerop sec) | |
3634 | "Now") | |
3635 | (t | |
3636 | (concat | |
3637 | ;; This is a bit convoluted, but basically we go | |
3638 | ;; through the time units for years, weeks, etc, | |
3639 | ;; and divide things to see whether that results | |
3640 | ;; in positive answers. | |
3641 | (mapconcat | |
3642 | (lambda (unit) | |
3643 | (if (or (zerop (setq num (ffloor (/ sec (cdr unit))))) | |
3644 | (>= segments max-segments)) | |
3645 | ;; The (remaining) seconds are too few to | |
3646 | ;; be divided into this time unit. | |
3647 | "" | |
3648 | ;; It's big enough, so we output it. | |
3649 | (setq sec (- sec (* num (cdr unit)))) | |
3650 | (prog1 | |
3651 | (concat (if prev ", " "") (int-to-string | |
3652 | (floor num)) | |
3653 | " " (symbol-name (car unit)) | |
3654 | (if (> num 1) "s" "")) | |
3655 | (setq prev t | |
3656 | segments (1+ segments))))) | |
3657 | article-time-units "") | |
3658 | ;; If dates are odd, then it might appear like the | |
3659 | ;; article was sent in the future. | |
3660 | (if (> real-sec 0) | |
3661 | " ago" | |
3662 | " in the future")))))) | |
3663 | ||
eec82323 LMI |
3664 | (defun article-date-local (&optional highlight) |
3665 | "Convert the current article date to the local timezone." | |
3666 | (interactive (list t)) | |
3667 | (article-date-ut 'local highlight)) | |
3668 | ||
23f87bed MB |
3669 | (defun article-date-english (&optional highlight) |
3670 | "Convert the current article date to something that is proper English." | |
3671 | (interactive (list t)) | |
3672 | (article-date-ut 'english highlight)) | |
3673 | ||
eec82323 LMI |
3674 | (defun article-date-original (&optional highlight) |
3675 | "Convert the current article date to what it was originally. | |
3676 | This is only useful if you have used some other date conversion | |
3677 | function and want to see what the date was before converting." | |
3678 | (interactive (list t)) | |
3679 | (article-date-ut 'original highlight)) | |
3680 | ||
3681 | (defun article-date-lapsed (&optional highlight) | |
3682 | "Convert the current article date to time lapsed since it was sent." | |
3683 | (interactive (list t)) | |
3684 | (article-date-ut 'lapsed highlight)) | |
3685 | ||
647559c2 LI |
3686 | (defun article-date-combined-lapsed (&optional highlight) |
3687 | "Convert the current article date to time lapsed since it was sent." | |
3688 | (interactive (list t)) | |
3689 | (article-date-ut 'combined-lapsed highlight)) | |
3690 | ||
6748645f LMI |
3691 | (defun article-update-date-lapsed () |
3692 | "Function to be run from a timer to update the lapsed time line." | |
e0a8aa09 | 3693 | (save-match-data |
0832490d LI |
3694 | (let ((buffer (current-buffer))) |
3695 | (ignore-errors | |
3696 | (walk-windows | |
3697 | (lambda (w) | |
3698 | (set-buffer (window-buffer w)) | |
1b3b87df | 3699 | (when (derived-mode-p 'gnus-article-mode) |
0832490d | 3700 | (let ((old-line (count-lines (point-min) (point))) |
c61a8b44 | 3701 | (old-column (- (point) (line-beginning-position))) |
923c1bfc KY |
3702 | (window-start (window-start w)) |
3703 | (pos (point-min)) | |
3704 | type next end) | |
3705 | (while (setq pos (text-property-not-all pos (point-max) | |
3706 | 'gnus-date-type nil)) | |
3707 | (setq next (or (next-single-property-change pos | |
3708 | 'gnus-date-type) | |
3709 | (point-max))) | |
3710 | (setq type (get-text-property pos 'gnus-date-type)) | |
3711 | (when (memq type '(lapsed combined-lapsed user-defined)) | |
3712 | (article-date-ut type t pos) | |
3713 | (setq end (or (next-single-property-change pos | |
3714 | 'gnus-date-type) | |
3715 | (point-max))) | |
3716 | (when window-start | |
3717 | (if (/= window-start next) | |
3718 | (setq window-start nil) | |
3719 | (set-window-start w end))) | |
3720 | (setq next end)) | |
3721 | (setq pos next)) | |
0832490d LI |
3722 | (goto-char (point-min)) |
3723 | (when (> old-column 0) | |
3724 | (setq old-line (1- old-line))) | |
3725 | (forward-line old-line) | |
3726 | (end-of-line) | |
3727 | (when (> (current-column) old-column) | |
3728 | (beginning-of-line) | |
3729 | (forward-char old-column))))) | |
3730 | nil 'visible)) | |
3731 | (set-buffer buffer)))) | |
6748645f LMI |
3732 | |
3733 | (defun gnus-start-date-timer (&optional n) | |
12e3ca0a | 3734 | "Start a timer to update the Date headers in the article buffers. |
6748645f LMI |
3735 | The numerical prefix says how frequently (in seconds) the function |
3736 | is to run." | |
3737 | (interactive "p") | |
3738 | (unless n | |
3739 | (setq n 1)) | |
3740 | (gnus-stop-date-timer) | |
3741 | (setq article-lapsed-timer | |
01c52d31 | 3742 | (run-at-time 1 n 'article-update-date-lapsed))) |
6748645f LMI |
3743 | |
3744 | (defun gnus-stop-date-timer () | |
12e3ca0a | 3745 | "Stop the Date timer." |
6748645f LMI |
3746 | (interactive) |
3747 | (when article-lapsed-timer | |
3748 | (nnheader-cancel-timer article-lapsed-timer) | |
3749 | (setq article-lapsed-timer nil))) | |
3750 | ||
eec82323 LMI |
3751 | (defun article-date-user (&optional highlight) |
3752 | "Convert the current article date to the user-defined format. | |
3753 | This format is defined by the `gnus-article-time-format' variable." | |
3754 | (interactive (list t)) | |
3755 | (article-date-ut 'user highlight)) | |
3756 | ||
6748645f LMI |
3757 | (defun article-date-iso8601 (&optional highlight) |
3758 | "Convert the current article date to ISO8601." | |
3759 | (interactive (list t)) | |
3760 | (article-date-ut 'iso8601 highlight)) | |
3761 | ||
31640842 MB |
3762 | (defmacro gnus-article-save-original-date (&rest forms) |
3763 | "Save the original date as a text property and evaluate FORMS." | |
3764 | `(let* ((case-fold-search t) | |
3765 | (start (progn | |
3766 | (goto-char (point-min)) | |
3767 | (when (and (re-search-forward "^date:[\t\n ]+" nil t) | |
3768 | (not (bolp))) | |
3769 | (match-end 0)))) | |
3770 | (date (when (and start | |
01c52d31 | 3771 | (re-search-forward "[\t ]*\n\\(?:[^\t ]\\|\\'\\)" |
31640842 MB |
3772 | nil t)) |
3773 | (buffer-substring-no-properties start | |
3774 | (match-beginning 0))))) | |
3775 | (goto-char (point-max)) | |
3776 | (skip-chars-backward "\n") | |
3777 | (put-text-property (point-min) (point) 'original-date date) | |
3778 | ,@forms | |
3779 | (goto-char (point-max)) | |
3780 | (skip-chars-backward "\n") | |
3781 | (put-text-property (point-min) (point) 'original-date date))) | |
3782 | ||
23f87bed MB |
3783 | ;; (defun article-show-all () |
3784 | ;; "Show all hidden text in the article buffer." | |
3785 | ;; (interactive) | |
3786 | ;; (save-excursion | |
3787 | ;; (let ((inhibit-read-only t)) | |
3788 | ;; (gnus-article-unhide-text (point-min) (point-max))))) | |
3789 | ||
3790 | (defun article-remove-leading-whitespace () | |
3791 | "Remove excessive whitespace from all headers." | |
eec82323 LMI |
3792 | (interactive) |
3793 | (save-excursion | |
23f87bed MB |
3794 | (save-restriction |
3795 | (let ((inhibit-read-only t)) | |
3796 | (article-narrow-to-head) | |
3797 | (goto-char (point-min)) | |
3798 | (while (re-search-forward "^[^ :]+: \\([ \t]+\\)" nil t) | |
3799 | (delete-region (match-beginning 1) (match-end 1))))))) | |
eec82323 LMI |
3800 | |
3801 | (defun article-emphasize (&optional arg) | |
3802 | "Emphasize text according to `gnus-emphasis-alist'." | |
3803 | (interactive (gnus-article-hidden-arg)) | |
3804 | (unless (gnus-article-check-hidden-text 'emphasis arg) | |
3805 | (save-excursion | |
a1506d29 | 3806 | (let ((alist (or |
16409b0b | 3807 | (condition-case nil |
a1506d29 JB |
3808 | (with-current-buffer gnus-summary-buffer |
3809 | gnus-article-emphasis-alist) | |
16409b0b GM |
3810 | (error)) |
3811 | gnus-emphasis-alist)) | |
4e7d0221 | 3812 | (inhibit-read-only t) |
eec82323 LMI |
3813 | (props (append '(article-type emphasis) |
3814 | gnus-hidden-properties)) | |
3815 | regexp elem beg invisible visible face) | |
16409b0b | 3816 | (article-goto-body) |
eec82323 LMI |
3817 | (setq beg (point)) |
3818 | (while (setq elem (pop alist)) | |
3819 | (goto-char beg) | |
3820 | (setq regexp (car elem) | |
3821 | invisible (nth 1 elem) | |
3822 | visible (nth 2 elem) | |
3823 | face (nth 3 elem)) | |
3824 | (while (re-search-forward regexp nil t) | |
23f87bed MB |
3825 | (when (and (match-beginning visible) (match-beginning invisible)) |
3826 | (gnus-article-hide-text | |
3827 | (match-beginning invisible) (match-end invisible) props) | |
3828 | (gnus-article-unhide-text-type | |
3829 | (match-beginning visible) (match-end visible) 'emphasis) | |
3830 | (gnus-put-overlay-excluding-newlines | |
3831 | (match-beginning visible) (match-end visible) 'face face) | |
3832 | (gnus-add-wash-type 'emphasis) | |
3833 | (goto-char (match-end invisible))))))))) | |
eec82323 | 3834 | |
16409b0b GM |
3835 | (defun gnus-article-setup-highlight-words (&optional highlight-words) |
3836 | "Setup newsgroup emphasis alist." | |
3837 | (unless gnus-article-emphasis-alist | |
3838 | (let ((name (and gnus-newsgroup-name | |
3839 | (gnus-group-real-name gnus-newsgroup-name)))) | |
3840 | (make-local-variable 'gnus-article-emphasis-alist) | |
a1506d29 JB |
3841 | (setq gnus-article-emphasis-alist |
3842 | (nconc | |
16409b0b GM |
3843 | (let ((alist gnus-group-highlight-words-alist) elem highlight) |
3844 | (while (setq elem (pop alist)) | |
3845 | (when (and name (string-match (car elem) name)) | |
3846 | (setq alist nil | |
3847 | highlight (copy-sequence (cdr elem))))) | |
3848 | highlight) | |
3849 | (copy-sequence highlight-words) | |
3850 | (if gnus-newsgroup-name | |
a1506d29 | 3851 | (copy-sequence (gnus-group-find-parameter |
16409b0b GM |
3852 | gnus-newsgroup-name 'highlight-words t))) |
3853 | gnus-emphasis-alist))))) | |
3854 | ||
9efa445f DN |
3855 | (defvar gnus-summary-article-menu) |
3856 | (defvar gnus-summary-post-menu) | |
eec82323 LMI |
3857 | |
3858 | ;;; Saving functions. | |
3859 | ||
3860 | (defun gnus-article-save (save-buffer file &optional num) | |
3861 | "Save the currently selected article." | |
26c9afc3 MB |
3862 | (when (or (get gnus-default-article-saver :headers) |
3863 | (not gnus-save-all-headers)) | |
3864 | ;; Remove headers according to `gnus-saved-headers' or the value | |
3865 | ;; of the `:headers' property that the saver function might have. | |
eec82323 | 3866 | (let ((gnus-visible-headers |
26c9afc3 MB |
3867 | (or (symbol-value (get gnus-default-article-saver :headers)) |
3868 | gnus-saved-headers gnus-visible-headers)) | |
16c85f26 MB |
3869 | ;; Ignore group parameter. See `article-hide-headers'. |
3870 | (gnus-summary-buffer nil)) | |
80de1778 | 3871 | (with-current-buffer save-buffer |
6748645f | 3872 | (article-hide-headers 1 t)))) |
eec82323 LMI |
3873 | (save-window-excursion |
3874 | (if (not gnus-default-article-saver) | |
a8151ef7 | 3875 | (error "No default saver is defined") |
eec82323 | 3876 | ;; !!! Magic! The saving functions all save |
16409b0b | 3877 | ;; `gnus-save-article-buffer' (or so they think), but we |
eec82323 LMI |
3878 | ;; bind that variable to our save-buffer. |
3879 | (set-buffer gnus-article-buffer) | |
3880 | (let* ((gnus-save-article-buffer save-buffer) | |
3881 | (filename | |
3882 | (cond | |
3883 | ((not gnus-prompt-before-saving) 'default) | |
3884 | ((eq gnus-prompt-before-saving 'always) nil) | |
3885 | (t file))) | |
3886 | (gnus-number-of-articles-to-be-saved | |
3887 | (when (eq gnus-prompt-before-saving t) | |
3888 | num))) ; Magic | |
6748645f | 3889 | (set-buffer gnus-article-current-summary) |
eec82323 LMI |
3890 | (funcall gnus-default-article-saver filename))))) |
3891 | ||
3892 | (defun gnus-read-save-file-name (prompt &optional filename | |
26c9afc3 MB |
3893 | function group headers variable |
3894 | dir-var) | |
eec82323 LMI |
3895 | (let ((default-name |
3896 | (funcall function group headers (symbol-value variable))) | |
3897 | result) | |
4325195c | 3898 | (setq result |
a1506d29 | 3899 | (expand-file-name |
4325195c DL |
3900 | (cond |
3901 | ((eq filename 'default) | |
3902 | default-name) | |
3903 | ((eq filename t) | |
3904 | default-name) | |
3905 | (filename filename) | |
3906 | (t | |
26c9afc3 MB |
3907 | (when (symbol-value dir-var) |
3908 | (setq default-name (expand-file-name | |
3909 | (file-name-nondirectory default-name) | |
3910 | (symbol-value dir-var)))) | |
4325195c DL |
3911 | (let* ((split-name (gnus-get-split-value gnus-split-methods)) |
3912 | (prompt | |
3913 | (format prompt | |
3914 | (if (and gnus-number-of-articles-to-be-saved | |
3915 | (> gnus-number-of-articles-to-be-saved 1)) | |
3916 | (format "these %d articles" | |
3917 | gnus-number-of-articles-to-be-saved) | |
3918 | "this article"))) | |
3919 | (file | |
3920 | ;; Let the split methods have their say. | |
3921 | (cond | |
3922 | ;; No split name was found. | |
3923 | ((null split-name) | |
3924 | (read-file-name | |
3925 | (concat prompt " (default " | |
81df110a | 3926 | (file-name-nondirectory default-name) "): ") |
4325195c DL |
3927 | (file-name-directory default-name) |
3928 | default-name)) | |
3929 | ;; A single group name is returned. | |
3930 | ((stringp split-name) | |
3931 | (setq default-name | |
3932 | (funcall function split-name headers | |
3933 | (symbol-value variable))) | |
3934 | (read-file-name | |
3935 | (concat prompt " (default " | |
81df110a | 3936 | (file-name-nondirectory default-name) "): ") |
4325195c DL |
3937 | (file-name-directory default-name) |
3938 | default-name)) | |
3939 | ;; A single split name was found | |
3940 | ((= 1 (length split-name)) | |
3941 | (let* ((name (expand-file-name | |
23f87bed MB |
3942 | (car split-name) |
3943 | gnus-article-save-directory)) | |
4325195c DL |
3944 | (dir (cond ((file-directory-p name) |
3945 | (file-name-as-directory name)) | |
3946 | ((file-exists-p name) name) | |
3947 | (t gnus-article-save-directory)))) | |
3948 | (read-file-name | |
81df110a | 3949 | (concat prompt " (default " name "): ") |
4325195c DL |
3950 | dir name))) |
3951 | ;; A list of splits was found. | |
3952 | (t | |
3953 | (setq split-name (nreverse split-name)) | |
3954 | (let (result) | |
3955 | (let ((file-name-history | |
3956 | (nconc split-name file-name-history))) | |
3957 | (setq result | |
3958 | (expand-file-name | |
3959 | (read-file-name | |
81df110a | 3960 | (concat prompt " (`M-p' for defaults): ") |
4325195c DL |
3961 | gnus-article-save-directory |
3962 | (car split-name)) | |
3963 | gnus-article-save-directory))) | |
3964 | (car (push result file-name-history))))))) | |
3965 | ;; Create the directory. | |
3966 | (gnus-make-directory (file-name-directory file)) | |
23f87bed | 3967 | ;; If we have read a directory, we append the default file name. |
4325195c | 3968 | (when (file-directory-p file) |
23f87bed MB |
3969 | (setq file (expand-file-name (file-name-nondirectory |
3970 | default-name) | |
4325195c DL |
3971 | (file-name-as-directory file)))) |
3972 | ;; Possibly translate some characters. | |
3973 | (nnheader-translate-file-chars file)))))) | |
eec82323 | 3974 | (gnus-make-directory (file-name-directory result)) |
26c9afc3 MB |
3975 | (when variable |
3976 | (set variable result)) | |
3977 | (when dir-var | |
3978 | (set dir-var (file-name-directory result))) | |
3979 | result)) | |
eec82323 LMI |
3980 | |
3981 | (defun gnus-article-archive-name (group) | |
3982 | "Return the first instance of an \"Archive-name\" in the current buffer." | |
3983 | (let ((case-fold-search t)) | |
3984 | (when (re-search-forward "archive-name: *\\([^ \n\t]+\\)[ \t]*$" nil t) | |
3985 | (nnheader-concat gnus-article-save-directory | |
3986 | (match-string 1))))) | |
3987 | ||
3988 | (defun gnus-article-nndoc-name (group) | |
3989 | "If GROUP is an nndoc group, return the name of the parent group." | |
3990 | (when (eq (car (gnus-find-method-for-group group)) 'nndoc) | |
3991 | (gnus-group-get-parameter group 'save-article-group))) | |
3992 | ||
3993 | (defun gnus-summary-save-in-rmail (&optional filename) | |
3994 | "Append this article to Rmail file. | |
3995 | Optional argument FILENAME specifies file name. | |
3996 | Directory to save to is default to `gnus-article-save-directory'." | |
eec82323 | 3997 | (setq filename (gnus-read-save-file-name |
81df110a | 3998 | "Save %s in rmail file" filename |
eec82323 LMI |
3999 | gnus-rmail-save-name gnus-newsgroup-name |
4000 | gnus-current-headers 'gnus-newsgroup-last-rmail)) | |
a3f57c41 | 4001 | (with-current-buffer gnus-save-article-buffer |
eec82323 LMI |
4002 | (save-excursion |
4003 | (save-restriction | |
4004 | (widen) | |
fef8d38e GM |
4005 | ;; Note that unlike gnus-summary-save-in-mail, there is no |
4006 | ;; check to see if filename is Babyl. Rmail in Emacs 23 does | |
4007 | ;; not use Babyl. | |
6748645f LMI |
4008 | (gnus-output-to-rmail filename)))) |
4009 | filename) | |
eec82323 LMI |
4010 | |
4011 | (defun gnus-summary-save-in-mail (&optional filename) | |
4012 | "Append this article to Unix mail file. | |
4013 | Optional argument FILENAME specifies file name. | |
4014 | Directory to save to is default to `gnus-article-save-directory'." | |
eec82323 | 4015 | (setq filename (gnus-read-save-file-name |
81df110a | 4016 | "Save %s in Unix mail file" filename |
eec82323 LMI |
4017 | gnus-mail-save-name gnus-newsgroup-name |
4018 | gnus-current-headers 'gnus-newsgroup-last-mail)) | |
a3f57c41 | 4019 | (with-current-buffer gnus-save-article-buffer |
eec82323 LMI |
4020 | (save-excursion |
4021 | (save-restriction | |
4022 | (widen) | |
4023 | (if (and (file-readable-p filename) | |
23f87bed | 4024 | (file-regular-p filename) |
eec82323 | 4025 | (mail-file-babyl-p filename)) |
fef8d38e | 4026 | (gnus-output-to-rmail filename) |
6748645f LMI |
4027 | (gnus-output-to-mail filename))))) |
4028 | filename) | |
eec82323 | 4029 | |
26c9afc3 MB |
4030 | (put 'gnus-summary-save-in-file :decode t) |
4031 | (put 'gnus-summary-save-in-file :headers 'gnus-saved-headers) | |
eec82323 LMI |
4032 | (defun gnus-summary-save-in-file (&optional filename overwrite) |
4033 | "Append this article to file. | |
4034 | Optional argument FILENAME specifies file name. | |
4035 | Directory to save to is default to `gnus-article-save-directory'." | |
eec82323 | 4036 | (setq filename (gnus-read-save-file-name |
81df110a | 4037 | "Save %s in file" filename |
eec82323 LMI |
4038 | gnus-file-save-name gnus-newsgroup-name |
4039 | gnus-current-headers 'gnus-newsgroup-last-file)) | |
a3f57c41 | 4040 | (with-current-buffer gnus-save-article-buffer |
eec82323 LMI |
4041 | (save-excursion |
4042 | (save-restriction | |
4043 | (widen) | |
4044 | (when (and overwrite | |
4045 | (file-exists-p filename)) | |
4046 | (delete-file filename)) | |
6748645f LMI |
4047 | (gnus-output-to-file filename)))) |
4048 | filename) | |
eec82323 | 4049 | |
26c9afc3 MB |
4050 | (put 'gnus-summary-write-to-file :decode t) |
4051 | (put 'gnus-summary-write-to-file :function 'gnus-summary-save-in-file) | |
4052 | (put 'gnus-summary-write-to-file :headers 'gnus-saved-headers) | |
eec82323 | 4053 | (defun gnus-summary-write-to-file (&optional filename) |
23f87bed | 4054 | "Write this article to a file, overwriting it if the file exists. |
eec82323 LMI |
4055 | Optional argument FILENAME specifies file name. |
4056 | The directory to save in defaults to `gnus-article-save-directory'." | |
26c9afc3 MB |
4057 | (setq filename (gnus-read-save-file-name |
4058 | "Save %s in file" filename | |
4059 | gnus-file-save-name gnus-newsgroup-name | |
4060 | gnus-current-headers nil 'gnus-newsgroup-last-directory)) | |
4061 | (gnus-summary-save-in-file filename t)) | |
eec82323 | 4062 | |
26c9afc3 MB |
4063 | (put 'gnus-summary-save-body-in-file :decode t) |
4064 | (defun gnus-summary-save-body-in-file (&optional filename overwrite) | |
eec82323 LMI |
4065 | "Append this article body to a file. |
4066 | Optional argument FILENAME specifies file name. | |
4067 | The directory to save in defaults to `gnus-article-save-directory'." | |
eec82323 | 4068 | (setq filename (gnus-read-save-file-name |
81df110a | 4069 | "Save %s body in file" filename |
eec82323 LMI |
4070 | gnus-file-save-name gnus-newsgroup-name |
4071 | gnus-current-headers 'gnus-newsgroup-last-file)) | |
a3f57c41 | 4072 | (with-current-buffer gnus-save-article-buffer |
eec82323 LMI |
4073 | (save-excursion |
4074 | (save-restriction | |
4075 | (widen) | |
16409b0b | 4076 | (when (article-goto-body) |
eec82323 | 4077 | (narrow-to-region (point) (point-max))) |
26c9afc3 MB |
4078 | (when (and overwrite |
4079 | (file-exists-p filename)) | |
4080 | (delete-file filename)) | |
6748645f LMI |
4081 | (gnus-output-to-file filename)))) |
4082 | filename) | |
eec82323 | 4083 | |
26c9afc3 MB |
4084 | (put 'gnus-summary-write-body-to-file :decode t) |
4085 | (put 'gnus-summary-write-body-to-file | |
4086 | :function 'gnus-summary-save-body-in-file) | |
4087 | (defun gnus-summary-write-body-to-file (&optional filename) | |
4088 | "Write this article body to a file, overwriting it if the file exists. | |
4089 | Optional argument FILENAME specifies file name. | |
4090 | The directory to save in defaults to `gnus-article-save-directory'." | |
4091 | (setq filename (gnus-read-save-file-name | |
4092 | "Save %s body in file" filename | |
4093 | gnus-file-save-name gnus-newsgroup-name | |
4094 | gnus-current-headers nil 'gnus-newsgroup-last-directory)) | |
4095 | (gnus-summary-save-body-in-file filename t)) | |
4096 | ||
89167438 MB |
4097 | (put 'gnus-summary-save-in-pipe :decode t) |
4098 | (put 'gnus-summary-save-in-pipe :headers 'gnus-saved-headers) | |
d62672f3 MB |
4099 | (defun gnus-summary-save-in-pipe (&optional command raw) |
4100 | "Pipe this article to subprocess COMMAND. | |
4101 | Valid values for COMMAND include: | |
4102 | a string | |
4103 | The executable command name and possibly arguments. | |
4104 | nil | |
4105 | You will be prompted for the command in the minibuffer. | |
4106 | the symbol `default' | |
4107 | It will be replaced with the command which the variable | |
4108 | `gnus-summary-pipe-output-default-command' holds or the command | |
4109 | last used for saving. | |
4110 | Non-nil value for RAW overrides `:decode' and `:headers' properties | |
4111 | and the raw article including all headers will be piped." | |
6ecfe5c2 MB |
4112 | (let ((article (gnus-summary-article-number)) |
4113 | (decode (unless raw | |
4114 | (get 'gnus-summary-save-in-pipe :decode))) | |
4115 | save-buffer default) | |
4116 | (if article | |
4117 | (if (vectorp (gnus-summary-article-header article)) | |
4118 | (save-current-buffer | |
4119 | (gnus-summary-select-article decode decode nil article) | |
4120 | (insert-buffer-substring | |
4121 | (prog1 | |
4122 | (if decode | |
4123 | gnus-article-buffer | |
4124 | gnus-original-article-buffer) | |
4125 | (setq save-buffer | |
4126 | (nnheader-set-temp-buffer " *Gnus Save*")))) | |
4127 | ;; Remove unwanted headers. | |
4128 | (when (and (not raw) | |
4129 | (or (get 'gnus-summary-save-in-pipe :headers) | |
4130 | (not gnus-save-all-headers))) | |
4131 | (let ((gnus-visible-headers | |
4132 | (or (symbol-value (get 'gnus-summary-save-in-pipe | |
4133 | :headers)) | |
4134 | gnus-saved-headers gnus-visible-headers)) | |
4135 | (gnus-summary-buffer nil)) | |
4136 | (article-hide-headers 1 t)))) | |
4137 | (error "%d is not a real article" article)) | |
4138 | (error "No article to pipe")) | |
4139 | (setq default (or gnus-summary-pipe-output-default-command | |
4140 | gnus-last-shell-command)) | |
89167438 MB |
4141 | (unless (stringp command) |
4142 | (setq command | |
4143 | (if (and (eq command 'default) default) | |
4144 | default | |
6ecfe5c2 MB |
4145 | (gnus-read-shell-command "Shell command on this article: " |
4146 | default)))) | |
89167438 MB |
4147 | (when (string-equal command "") |
4148 | (if default | |
4149 | (setq command default) | |
16c85f26 | 4150 | (error "A command is required"))) |
a3f57c41 | 4151 | (with-current-buffer save-buffer |
16c85f26 MB |
4152 | (save-restriction |
4153 | (widen) | |
4154 | (shell-command-on-region (point-min) (point-max) command nil))) | |
4155 | (gnus-kill-buffer save-buffer)) | |
89167438 | 4156 | (setq gnus-summary-pipe-output-default-command command)) |
eec82323 | 4157 | |
23f87bed MB |
4158 | (defun gnus-summary-pipe-to-muttprint (&optional command) |
4159 | "Pipe this article to muttprint." | |
16c85f26 MB |
4160 | (unless (stringp command) |
4161 | (setq command (read-string | |
4162 | "Print using command: " gnus-summary-muttprint-program | |
4163 | nil gnus-summary-muttprint-program))) | |
4164 | (let ((gnus-summary-pipe-output-default-command | |
4165 | gnus-summary-pipe-output-default-command)) | |
4166 | (gnus-summary-save-in-pipe command)) | |
4167 | (setq gnus-summary-muttprint-program command)) | |
23f87bed | 4168 | |
eec82323 LMI |
4169 | ;;; Article file names when saving. |
4170 | ||
4171 | (defun gnus-capitalize-newsgroup (newsgroup) | |
4172 | "Capitalize NEWSGROUP name." | |
4173 | (when (not (zerop (length newsgroup))) | |
4174 | (concat (char-to-string (upcase (aref newsgroup 0))) | |
4175 | (substring newsgroup 1)))) | |
4176 | ||
4177 | (defun gnus-Numeric-save-name (newsgroup headers &optional last-file) | |
4178 | "Generate file name from NEWSGROUP, HEADERS, and optional LAST-FILE. | |
4179 | If variable `gnus-use-long-file-name' is non-nil, it is ~/News/News.group/num. | |
4180 | Otherwise, it is like ~/News/news/group/num." | |
4181 | (let ((default | |
4182 | (expand-file-name | |
4183 | (concat (if (gnus-use-long-file-name 'not-save) | |
4184 | (gnus-capitalize-newsgroup newsgroup) | |
4185 | (gnus-newsgroup-directory-form newsgroup)) | |
4186 | "/" (int-to-string (mail-header-number headers))) | |
4187 | gnus-article-save-directory))) | |
4188 | (if (and last-file | |
4189 | (string-equal (file-name-directory default) | |
4190 | (file-name-directory last-file)) | |
4191 | (string-match "^[0-9]+$" (file-name-nondirectory last-file))) | |
4192 | default | |
4193 | (or last-file default)))) | |
4194 | ||
4195 | (defun gnus-numeric-save-name (newsgroup headers &optional last-file) | |
4196 | "Generate file name from NEWSGROUP, HEADERS, and optional LAST-FILE. | |
4197 | If variable `gnus-use-long-file-name' is non-nil, it is | |
2ff9f5b4 | 4198 | ~/News/news.group/num. Otherwise, it is like ~/News/news/group/num." |
eec82323 LMI |
4199 | (let ((default |
4200 | (expand-file-name | |
4201 | (concat (if (gnus-use-long-file-name 'not-save) | |
4202 | newsgroup | |
4203 | (gnus-newsgroup-directory-form newsgroup)) | |
4204 | "/" (int-to-string (mail-header-number headers))) | |
4205 | gnus-article-save-directory))) | |
4206 | (if (and last-file | |
4207 | (string-equal (file-name-directory default) | |
4208 | (file-name-directory last-file)) | |
4209 | (string-match "^[0-9]+$" (file-name-nondirectory last-file))) | |
4210 | default | |
4211 | (or last-file default)))) | |
4212 | ||
eec82323 LMI |
4213 | (defun gnus-plain-save-name (newsgroup headers &optional last-file) |
4214 | "Generate file name from NEWSGROUP, HEADERS, and optional LAST-FILE. | |
4215 | If variable `gnus-use-long-file-name' is non-nil, it is | |
4216 | ~/News/news.group. Otherwise, it is like ~/News/news/group/news." | |
4217 | (or last-file | |
4218 | (expand-file-name | |
4219 | (if (gnus-use-long-file-name 'not-save) | |
4220 | newsgroup | |
23f87bed MB |
4221 | (file-relative-name |
4222 | (expand-file-name "news" (gnus-newsgroup-directory-form newsgroup)) | |
4223 | default-directory)) | |
eec82323 LMI |
4224 | gnus-article-save-directory))) |
4225 | ||
23f87bed MB |
4226 | (defun gnus-sender-save-name (newsgroup headers &optional last-file) |
4227 | "Generate file name from sender." | |
4228 | (let ((from (mail-header-from headers))) | |
4229 | (expand-file-name | |
4230 | (if (and from (string-match "\\([^ <]+\\)@" from)) | |
4231 | (match-string 1 from) | |
4232 | "nobody") | |
4233 | gnus-article-save-directory))) | |
4234 | ||
4235 | (defun article-verify-x-pgp-sig () | |
4236 | "Verify X-PGP-Sig." | |
bbbe940b | 4237 | ;; <ftp://ftp.isc.org/pub/pgpcontrol/FORMAT> |
23f87bed MB |
4238 | (interactive) |
4239 | (if (gnus-buffer-live-p gnus-original-article-buffer) | |
4240 | (let ((sig (with-current-buffer gnus-original-article-buffer | |
4241 | (gnus-fetch-field "X-PGP-Sig"))) | |
4242 | items info headers) | |
4243 | (when (and sig | |
4244 | mml2015-use | |
4245 | (mml2015-clear-verify-function)) | |
4246 | (with-temp-buffer | |
4247 | (insert-buffer-substring gnus-original-article-buffer) | |
4248 | (setq items (split-string sig)) | |
4249 | (message-narrow-to-head) | |
4250 | (let ((inhibit-point-motion-hooks t) | |
4251 | (case-fold-search t)) | |
4252 | ;; Don't verify multiple headers. | |
4253 | (setq headers (mapconcat (lambda (header) | |
4254 | (concat header ": " | |
4255 | (mail-fetch-field header) | |
4256 | "\n")) | |
4257 | (split-string (nth 1 items) ",") ""))) | |
4258 | (delete-region (point-min) (point-max)) | |
4259 | (insert "-----BEGIN PGP SIGNED MESSAGE-----\n\n") | |
4260 | (insert "X-Signed-Headers: " (nth 1 items) "\n") | |
4261 | (insert headers) | |
4262 | (widen) | |
4263 | (forward-line) | |
4264 | (while (not (eobp)) | |
4265 | (if (looking-at "^-") | |
4266 | (insert "- ")) | |
4267 | (forward-line)) | |
4268 | (insert "\n-----BEGIN PGP SIGNATURE-----\n") | |
4269 | (insert "Version: " (car items) "\n\n") | |
4270 | (insert (mapconcat 'identity (cddr items) "\n")) | |
4271 | (insert "\n-----END PGP SIGNATURE-----\n") | |
4272 | (let ((mm-security-handle (list (format "multipart/signed")))) | |
4273 | (mml2015-clean-buffer) | |
4274 | (let ((coding-system-for-write (or gnus-newsgroup-charset | |
4275 | 'iso-8859-1))) | |
4276 | (funcall (mml2015-clear-verify-function))) | |
4277 | (setq info | |
4278 | (or (mm-handle-multipart-ctl-parameter | |
4279 | mm-security-handle 'gnus-details) | |
4280 | (mm-handle-multipart-ctl-parameter | |
4281 | mm-security-handle 'gnus-info))))) | |
4282 | (when info | |
4283 | (let ((inhibit-read-only t) bface eface) | |
4284 | (save-restriction | |
4285 | (message-narrow-to-head) | |
4286 | (goto-char (point-max)) | |
4287 | (forward-line -1) | |
01c52d31 MB |
4288 | (setq bface (get-text-property (point-at-bol) 'face) |
4289 | eface (get-text-property (1- (point-at-eol)) 'face)) | |
23f87bed MB |
4290 | (message-remove-header "X-Gnus-PGP-Verify") |
4291 | (if (re-search-forward "^X-PGP-Sig:" nil t) | |
4292 | (forward-line) | |
4293 | (goto-char (point-max))) | |
4294 | (narrow-to-region (point) (point)) | |
4295 | (insert "X-Gnus-PGP-Verify: " info "\n") | |
4296 | (goto-char (point-min)) | |
4297 | (forward-line) | |
4298 | (while (not (eobp)) | |
4299 | (if (not (looking-at "^[ \t]")) | |
4300 | (insert " ")) | |
4301 | (forward-line)) | |
4302 | ;; Do highlighting. | |
4303 | (goto-char (point-min)) | |
4304 | (when (looking-at "\\([^:]+\\): *") | |
4305 | (put-text-property (match-beginning 1) (1+ (match-end 1)) | |
4306 | 'face bface) | |
4307 | (put-text-property (match-end 0) (point-max) | |
4308 | 'face eface))))))))) | |
4309 | ||
5843126b | 4310 | (autoload 'canlock-verify "canlock" nil t) ;; for XEmacs. |
ec7995fa | 4311 | |
23f87bed MB |
4312 | (defun article-verify-cancel-lock () |
4313 | "Verify Cancel-Lock header." | |
4314 | (interactive) | |
4315 | (if (gnus-buffer-live-p gnus-original-article-buffer) | |
4316 | (canlock-verify gnus-original-article-buffer))) | |
4317 | ||
eec82323 | 4318 | (eval-and-compile |
01c52d31 | 4319 | (mapc |
eec82323 LMI |
4320 | (lambda (func) |
4321 | (let (afunc gfunc) | |
4322 | (if (consp func) | |
4323 | (setq afunc (car func) | |
4324 | gfunc (cdr func)) | |
4325 | (setq afunc func | |
4326 | gfunc (intern (format "gnus-%s" func)))) | |
16409b0b | 4327 | (defalias gfunc |
23f87bed | 4328 | (when (fboundp afunc) |
16409b0b GM |
4329 | `(lambda (&optional interactive &rest args) |
4330 | ,(documentation afunc t) | |
4331 | (interactive (list t)) | |
80de1778 | 4332 | (with-current-buffer gnus-article-buffer |
16409b0b GM |
4333 | (if interactive |
4334 | (call-interactively ',afunc) | |
4335 | (apply ',afunc args)))))))) | |
eec82323 | 4336 | '(article-hide-headers |
23f87bed MB |
4337 | article-verify-x-pgp-sig |
4338 | article-verify-cancel-lock | |
eec82323 LMI |
4339 | article-hide-boring-headers |
4340 | article-treat-overstrike | |
01c52d31 | 4341 | article-treat-ansi-sequences |
16409b0b GM |
4342 | article-fill-long-lines |
4343 | article-capitalize-sentences | |
eec82323 | 4344 | article-remove-cr |
23f87bed | 4345 | article-remove-leading-whitespace |
eec82323 | 4346 | article-display-x-face |
23f87bed | 4347 | article-display-face |
eec82323 | 4348 | article-de-quoted-unreadable |
16409b0b GM |
4349 | article-de-base64-unreadable |
4350 | article-decode-HZ | |
4351 | article-wash-html | |
23f87bed | 4352 | article-unsplit-urls |
16409b0b | 4353 | article-hide-list-identifiers |
16409b0b GM |
4354 | article-strip-banner |
4355 | article-babel | |
eec82323 LMI |
4356 | article-hide-pem |
4357 | article-hide-signature | |
16409b0b | 4358 | article-strip-headers-in-body |
eec82323 LMI |
4359 | article-remove-trailing-blank-lines |
4360 | article-strip-leading-blank-lines | |
4361 | article-strip-multiple-blank-lines | |
4362 | article-strip-leading-space | |
16409b0b | 4363 | article-strip-trailing-space |
eec82323 | 4364 | article-strip-blank-lines |
6748645f | 4365 | article-strip-all-blank-lines |
eec82323 | 4366 | article-date-local |
23f87bed | 4367 | article-date-english |
6748645f | 4368 | article-date-iso8601 |
eec82323 | 4369 | article-date-original |
12e3ca0a | 4370 | article-treat-date |
eec82323 | 4371 | article-date-ut |
16409b0b GM |
4372 | article-decode-mime-words |
4373 | article-decode-charset | |
4374 | article-decode-encoded-words | |
eec82323 LMI |
4375 | article-date-user |
4376 | article-date-lapsed | |
647559c2 | 4377 | article-date-combined-lapsed |
eec82323 | 4378 | article-emphasize |
6748645f | 4379 | article-treat-dumbquotes |
be3c11b3 | 4380 | article-treat-non-ascii |
16409b0b | 4381 | article-normalize-headers |
01c52d31 | 4382 | ;;(article-show-all . gnus-article-show-all-headers) |
23f87bed | 4383 | ))) |
eec82323 LMI |
4384 | \f |
4385 | ;;; | |
4386 | ;;; Gnus article mode | |
4387 | ;;; | |
4388 | ||
4389 | (put 'gnus-article-mode 'mode-class 'special) | |
4390 | ||
16409b0b GM |
4391 | (set-keymap-parent gnus-article-mode-map widget-keymap) |
4392 | ||
a8151ef7 LMI |
4393 | (gnus-define-keys gnus-article-mode-map |
4394 | " " gnus-article-goto-next-page | |
9cec74cf | 4395 | [?\S-\ ] gnus-article-goto-prev-page |
a8151ef7 LMI |
4396 | "\177" gnus-article-goto-prev-page |
4397 | [delete] gnus-article-goto-prev-page | |
4398 | "\C-c^" gnus-article-refer-article | |
4399 | "h" gnus-article-show-summary | |
4400 | "s" gnus-article-show-summary | |
4401 | "\C-c\C-m" gnus-article-mail | |
4402 | "?" gnus-article-describe-briefly | |
a8151ef7 LMI |
4403 | "<" beginning-of-buffer |
4404 | ">" end-of-buffer | |
4405 | "\C-c\C-i" gnus-info-find-node | |
4406 | "\C-c\C-b" gnus-bug | |
23f87bed MB |
4407 | "R" gnus-article-reply-with-original |
4408 | "F" gnus-article-followup-with-original | |
520aa572 SZ |
4409 | "\C-hk" gnus-article-describe-key |
4410 | "\C-hc" gnus-article-describe-key-briefly | |
0b6799c3 | 4411 | "\C-hb" gnus-article-describe-bindings |
a8151ef7 | 4412 | |
6ab2c7a8 | 4413 | "e" gnus-article-read-summary-keys |
a8151ef7 LMI |
4414 | "\C-d" gnus-article-read-summary-keys |
4415 | "\M-*" gnus-article-read-summary-keys | |
4416 | "\M-#" gnus-article-read-summary-keys | |
4417 | "\M-^" gnus-article-read-summary-keys | |
4418 | "\M-g" gnus-article-read-summary-keys) | |
4419 | ||
4420 | (substitute-key-definition | |
4421 | 'undefined 'gnus-article-read-summary-keys gnus-article-mode-map) | |
eec82323 | 4422 | |
95838435 MB |
4423 | (gnus-define-keys (gnus-article-send-map "S" gnus-article-mode-map) |
4424 | "W" gnus-article-wide-reply-with-original) | |
4425 | (if (featurep 'xemacs) | |
4426 | (set-keymap-default-binding gnus-article-send-map | |
4427 | 'gnus-article-read-summary-send-keys) | |
4428 | (define-key gnus-article-send-map [t] 'gnus-article-read-summary-send-keys)) | |
4429 | ||
eec82323 | 4430 | (defun gnus-article-make-menu-bar () |
23f87bed MB |
4431 | (unless (boundp 'gnus-article-commands-menu) |
4432 | (gnus-summary-make-menu-bar)) | |
eec82323 LMI |
4433 | (unless (boundp 'gnus-article-article-menu) |
4434 | (easy-menu-define | |
4435 | gnus-article-article-menu gnus-article-mode-map "" | |
4436 | '("Article" | |
4437 | ["Scroll forwards" gnus-article-goto-next-page t] | |
4438 | ["Scroll backwards" gnus-article-goto-prev-page t] | |
4439 | ["Show summary" gnus-article-show-summary t] | |
4440 | ["Fetch Message-ID at point" gnus-article-refer-article t] | |
6748645f LMI |
4441 | ["Mail to address at point" gnus-article-mail t] |
4442 | ["Send a bug report" gnus-bug t])) | |
eec82323 LMI |
4443 | |
4444 | (easy-menu-define | |
4445 | gnus-article-treatment-menu gnus-article-mode-map "" | |
bb367cba | 4446 | ;; Fixme: this should use :active (and maybe :visible). |
eec82323 LMI |
4447 | '("Treatment" |
4448 | ["Hide headers" gnus-article-hide-headers t] | |
4449 | ["Hide signature" gnus-article-hide-signature t] | |
4450 | ["Hide citation" gnus-article-hide-citation t] | |
4451 | ["Treat overstrike" gnus-article-treat-overstrike t] | |
01c52d31 | 4452 | ["Treat ANSI sequences" gnus-article-treat-ansi-sequences t] |
eec82323 | 4453 | ["Remove carriage return" gnus-article-remove-cr t] |
23f87bed | 4454 | ["Remove leading whitespace" gnus-article-remove-leading-whitespace t] |
16409b0b GM |
4455 | ["Remove quoted-unreadable" gnus-article-de-quoted-unreadable t] |
4456 | ["Remove base64" gnus-article-de-base64-unreadable t] | |
4457 | ["Treat html" gnus-article-wash-html t] | |
23f87bed | 4458 | ["Remove newlines from within URLs" gnus-article-unsplit-urls t] |
16409b0b | 4459 | ["Decode HZ" gnus-article-decode-HZ t])) |
eec82323 | 4460 | |
6748645f | 4461 | ;; Note "Commands" menu is defined in gnus-sum.el for consistency |
eec82323 | 4462 | |
23f87bed | 4463 | ;; Note "Post" menu is defined in gnus-sum.el for consistency |
eec82323 | 4464 | |
6748645f | 4465 | (gnus-run-hooks 'gnus-article-menu-hook))) |
eec82323 | 4466 | |
8e7d4ca1 | 4467 | (defvar bookmark-make-record-function) |
ffb54e99 | 4468 | (defvar shr-put-image-function) |
8e7d4ca1 | 4469 | |
1b3b87df | 4470 | (define-derived-mode gnus-article-mode fundamental-mode "Article" |
eec82323 LMI |
4471 | "Major mode for displaying an article. |
4472 | ||
4473 | All normal editing commands are switched off. | |
4474 | ||
4475 | The following commands are available in addition to all summary mode | |
4476 | commands: | |
4477 | \\<gnus-article-mode-map> | |
4478 | \\[gnus-article-next-page]\t Scroll the article one page forwards | |
4479 | \\[gnus-article-prev-page]\t Scroll the article one page backwards | |
4480 | \\[gnus-article-refer-article]\t Go to the article referred to by an article id near point | |
4481 | \\[gnus-article-show-summary]\t Display the summary buffer | |
4482 | \\[gnus-article-mail]\t Send a reply to the address near point | |
4483 | \\[gnus-article-describe-briefly]\t Describe the current mode briefly | |
4484 | \\[gnus-info-find-node]\t Go to the Gnus info node" | |
eec82323 | 4485 | (gnus-simplify-mode-line) |
eec82323 | 4486 | (make-local-variable 'minor-mode-alist) |
1653df0f | 4487 | (when (gnus-visual-p 'article-menu 'menu) |
23f87bed MB |
4488 | (gnus-article-make-menu-bar) |
4489 | (when gnus-summary-tool-bar-map | |
4490 | (set (make-local-variable 'tool-bar-map) gnus-summary-tool-bar-map))) | |
eec82323 LMI |
4491 | (gnus-update-format-specifications nil 'article-mode) |
4492 | (set (make-local-variable 'page-delimiter) gnus-page-delimiter) | |
23f87bed | 4493 | (set (make-local-variable 'gnus-page-broken) nil) |
6748645f | 4494 | (make-local-variable 'gnus-article-current-summary) |
16409b0b GM |
4495 | (make-local-variable 'gnus-article-mime-handles) |
4496 | (make-local-variable 'gnus-article-decoded-p) | |
4497 | (make-local-variable 'gnus-article-mime-handle-alist) | |
4498 | (make-local-variable 'gnus-article-wash-types) | |
23f87bed MB |
4499 | (make-local-variable 'gnus-article-image-alist) |
4500 | (make-local-variable 'gnus-article-charset) | |
4501 | (make-local-variable 'gnus-article-ignored-charsets) | |
33b48483 KF |
4502 | (set (make-local-variable 'bookmark-make-record-function) |
4503 | 'gnus-summary-bookmark-make-record) | |
524705ae MB |
4504 | ;; Prevent Emacs 22 from displaying non-break space with `nobreak-space' |
4505 | ;; face. | |
fc1c32c1 | 4506 | (set (make-local-variable 'nobreak-char-display) nil) |
ffb54e99 KY |
4507 | ;; Enable `gnus-article-remove-images' to delete images shr.el renders. |
4508 | (set (make-local-variable 'shr-put-image-function) 'gnus-shr-put-image) | |
e4a89ccf | 4509 | (setq cursor-in-non-selected-windows nil) |
eec82323 | 4510 | (gnus-set-default-directory) |
16409b0b | 4511 | (buffer-disable-undo) |
01c52d31 MB |
4512 | (setq buffer-read-only t |
4513 | show-trailing-whitespace nil) | |
1b3b87df | 4514 | (mm-enable-multibyte)) |
eec82323 LMI |
4515 | |
4516 | (defun gnus-article-setup-buffer () | |
4517 | "Initialize the article buffer." | |
4518 | (let* ((name (if gnus-single-article-buffer "*Article*" | |
a3e0ee5a KY |
4519 | (concat "*Article " |
4520 | (gnus-group-decoded-name gnus-newsgroup-name) | |
4521 | "*"))) | |
eec82323 LMI |
4522 | (original |
4523 | (progn (string-match "\\*Article" name) | |
4524 | (concat " *Original Article" | |
4525 | (substring name (match-end 0)))))) | |
4526 | (setq gnus-article-buffer name) | |
4527 | (setq gnus-original-article-buffer original) | |
16409b0b | 4528 | (setq gnus-article-mime-handle-alist nil) |
01c52d31 MB |
4529 | (with-current-buffer gnus-summary-buffer |
4530 | ;; This might be a variable local to the summary buffer. | |
4531 | (unless gnus-single-article-buffer | |
eec82323 LMI |
4532 | (setq gnus-article-buffer name) |
4533 | (setq gnus-original-article-buffer original) | |
4534 | (gnus-set-global-variables))) | |
16409b0b | 4535 | (gnus-article-setup-highlight-words) |
eec82323 | 4536 | ;; Init original article buffer. |
80de1778 | 4537 | (with-current-buffer (gnus-get-buffer-create gnus-original-article-buffer) |
16409b0b | 4538 | (mm-enable-multibyte) |
eec82323 | 4539 | (setq major-mode 'gnus-original-article-mode) |
eec82323 | 4540 | (make-local-variable 'gnus-original-article)) |
aba1948a MB |
4541 | (if (and (get-buffer name) |
4542 | (with-current-buffer name | |
4543 | (if gnus-article-edit-mode | |
4544 | (if (y-or-n-p "Article mode edit in progress; discard? ") | |
4545 | (progn | |
4546 | (set-buffer-modified-p nil) | |
4547 | (gnus-kill-buffer name) | |
4548 | (message "") | |
4549 | nil) | |
4550 | (error "Action aborted")) | |
4551 | t))) | |
4e2b87d8 G |
4552 | (let ((summary gnus-summary-buffer)) |
4553 | (with-current-buffer name | |
4554 | (set (make-local-variable 'gnus-article-edit-mode) nil) | |
4555 | (gnus-article-stop-animations) | |
4556 | (when gnus-article-mime-handles | |
4557 | (mm-destroy-parts gnus-article-mime-handles) | |
4558 | (setq gnus-article-mime-handles nil)) | |
4559 | ;; Set it to nil in article-buffer! | |
4560 | (setq gnus-article-mime-handle-alist nil) | |
4561 | (buffer-disable-undo) | |
4562 | (setq buffer-read-only t) | |
4563 | (unless (derived-mode-p 'gnus-article-mode) | |
4564 | (gnus-article-mode)) | |
4565 | (set (make-local-variable 'gnus-summary-buffer) summary) | |
4566 | (setq truncate-lines gnus-article-truncate-lines) | |
4567 | (current-buffer))) | |
cc21c235 G |
4568 | (let ((summary gnus-summary-buffer)) |
4569 | (with-current-buffer (gnus-get-buffer-create name) | |
4570 | (gnus-article-mode) | |
4571 | (setq truncate-lines gnus-article-truncate-lines) | |
4572 | (set (make-local-variable 'gnus-summary-buffer) summary) | |
4573 | (gnus-summary-set-local-parameters gnus-newsgroup-name) | |
4574 | (when article-lapsed-timer | |
4575 | (gnus-stop-date-timer)) | |
4576 | (when gnus-article-update-date-headers | |
4577 | (gnus-start-date-timer gnus-article-update-date-headers)) | |
4578 | (current-buffer)))))) | |
eec82323 | 4579 | |
c146ad85 LMI |
4580 | (defun gnus-article-stop-animations () |
4581 | (dolist (timer (and (boundp 'timer-list) | |
4582 | timer-list)) | |
5e2b4ce1 | 4583 | (when (eq (gnus-timer--function timer) 'image-animate-timeout) |
c146ad85 LMI |
4584 | (cancel-timer timer)))) |
4585 | ||
4eff9c1a LI |
4586 | (defun gnus-stop-downloads () |
4587 | (when (boundp 'url-queue) | |
4588 | (set (intern "url-queue" obarray) nil))) | |
4589 | ||
eec82323 LMI |
4590 | ;; Set article window start at LINE, where LINE is the number of lines |
4591 | ;; from the head of the article. | |
4592 | (defun gnus-article-set-window-start (&optional line) | |
01c52d31 MB |
4593 | (let ((article-window (gnus-get-buffer-window gnus-article-buffer t))) |
4594 | (when article-window | |
4595 | (set-window-start | |
4596 | article-window | |
80de1778 | 4597 | (with-current-buffer gnus-article-buffer |
01c52d31 MB |
4598 | (goto-char (point-min)) |
4599 | (if (not line) | |
4600 | (point-min) | |
4601 | (gnus-message 6 "Moved to bookmark") | |
4602 | (search-forward "\n\n" nil t) | |
4603 | (forward-line line) | |
4604 | (point))))))) | |
eec82323 LMI |
4605 | |
4606 | (defun gnus-article-prepare (article &optional all-headers header) | |
4607 | "Prepare ARTICLE in article mode buffer. | |
4608 | ARTICLE should either be an article number or a Message-ID. | |
4609 | If ARTICLE is an id, HEADER should be the article headers. | |
4610 | If ALL-HEADERS is non-nil, no headers are hidden." | |
4611 | (save-excursion | |
4612 | ;; Make sure we start in a summary buffer. | |
1b3b87df | 4613 | (unless (derived-mode-p 'gnus-summary-mode) |
eec82323 LMI |
4614 | (set-buffer gnus-summary-buffer)) |
4615 | (setq gnus-summary-buffer (current-buffer)) | |
eec82323 LMI |
4616 | (let* ((gnus-article (if header (mail-header-number header) article)) |
4617 | (summary-buffer (current-buffer)) | |
6748645f | 4618 | (gnus-tmp-internal-hook gnus-article-internal-prepare-hook) |
eec82323 LMI |
4619 | (group gnus-newsgroup-name) |
4620 | result) | |
4621 | (save-excursion | |
4622 | (gnus-article-setup-buffer) | |
4623 | (set-buffer gnus-article-buffer) | |
4624 | ;; Deactivate active regions. | |
4625 | (when (and (boundp 'transient-mark-mode) | |
4626 | transient-mark-mode) | |
4627 | (setq mark-active nil)) | |
4e7d0221 | 4628 | (if (not (setq result (let ((inhibit-read-only t)) |
eec82323 LMI |
4629 | (gnus-request-article-this-buffer |
4630 | article group)))) | |
4631 | ;; There is no such article. | |
4632 | (save-excursion | |
4633 | (when (and (numberp article) | |
4634 | (not (memq article gnus-newsgroup-sparse))) | |
4635 | (setq gnus-article-current | |
4636 | (cons gnus-newsgroup-name article)) | |
4637 | (set-buffer gnus-summary-buffer) | |
4638 | (setq gnus-current-article article) | |
23f87bed MB |
4639 | (if (and (memq article gnus-newsgroup-undownloaded) |
4640 | (not (gnus-online (gnus-find-method-for-group | |
4641 | gnus-newsgroup-name)))) | |
6748645f LMI |
4642 | (progn |
4643 | (gnus-summary-set-agent-mark article) | |
4644 | (message "Message marked for downloading")) | |
4645 | (gnus-summary-mark-article article gnus-canceled-mark) | |
4646 | (unless (memq article gnus-newsgroup-sparse) | |
16409b0b | 4647 | (gnus-error 1 "No such article (may have expired or been canceled)"))))) |
6748645f LMI |
4648 | (if (or (eq result 'pseudo) |
4649 | (eq result 'nneething)) | |
eec82323 | 4650 | (progn |
80de1778 | 4651 | (with-current-buffer summary-buffer |
6748645f | 4652 | (push article gnus-newsgroup-history) |
eec82323 | 4653 | (setq gnus-last-article gnus-current-article |
eec82323 LMI |
4654 | gnus-current-article 0 |
4655 | gnus-current-headers nil | |
4656 | gnus-article-current nil) | |
4657 | (if (eq result 'nneething) | |
4658 | (gnus-configure-windows 'summary) | |
4659 | (gnus-configure-windows 'article)) | |
4660 | (gnus-set-global-variables)) | |
16409b0b GM |
4661 | (let ((gnus-article-mime-handle-alist-1 |
4662 | gnus-article-mime-handle-alist)) | |
4663 | (gnus-set-mode-line 'article))) | |
eec82323 LMI |
4664 | ;; The result from the `request' was an actual article - |
4665 | ;; or at least some text that is now displayed in the | |
4666 | ;; article buffer. | |
4667 | (when (and (numberp article) | |
4668 | (not (eq article gnus-current-article))) | |
4669 | ;; Seems like a new article has been selected. | |
4670 | ;; `gnus-current-article' must be an article number. | |
80de1778 | 4671 | (with-current-buffer summary-buffer |
6748645f | 4672 | (push article gnus-newsgroup-history) |
eec82323 | 4673 | (setq gnus-last-article gnus-current-article |
eec82323 LMI |
4674 | gnus-current-article article |
4675 | gnus-current-headers | |
4676 | (gnus-summary-article-header gnus-current-article) | |
4677 | gnus-article-current | |
4678 | (cons gnus-newsgroup-name gnus-current-article)) | |
4679 | (unless (vectorp gnus-current-headers) | |
4680 | (setq gnus-current-headers nil)) | |
6748645f LMI |
4681 | (gnus-summary-goto-subject gnus-current-article) |
4682 | (when (gnus-summary-show-thread) | |
4683 | ;; If the summary buffer really was folded, the | |
4684 | ;; previous goto may not actually have gone to | |
4685 | ;; the right article, but the thread root instead. | |
4686 | ;; So we go again. | |
4687 | (gnus-summary-goto-subject gnus-current-article)) | |
4688 | (gnus-run-hooks 'gnus-mark-article-hook) | |
eec82323 LMI |
4689 | (gnus-set-mode-line 'summary) |
4690 | (when (gnus-visual-p 'article-highlight 'highlight) | |
6748645f | 4691 | (gnus-run-hooks 'gnus-visual-mark-article-hook)) |
eec82323 | 4692 | ;; Set the global newsgroup variables here. |
eec82323 LMI |
4693 | (gnus-set-global-variables) |
4694 | (setq gnus-have-all-headers | |
6748645f | 4695 | (or all-headers gnus-show-all-headers)))) |
e0bad764 DL |
4696 | (save-excursion |
4697 | (gnus-configure-windows 'article)) | |
eec82323 LMI |
4698 | (when (or (numberp article) |
4699 | (stringp article)) | |
16409b0b | 4700 | (gnus-article-prepare-display) |
eec82323 LMI |
4701 | ;; Do page break. |
4702 | (goto-char (point-min)) | |
23f87bed MB |
4703 | (when gnus-break-pages |
4704 | (gnus-narrow-to-page))) | |
16409b0b GM |
4705 | (let ((gnus-article-mime-handle-alist-1 |
4706 | gnus-article-mime-handle-alist)) | |
4707 | (gnus-set-mode-line 'article)) | |
4708 | (article-goto-body) | |
23f87bed MB |
4709 | (unless (bobp) |
4710 | (forward-line -1)) | |
6748645f | 4711 | (set-window-point (get-buffer-window (current-buffer)) (point)) |
16409b0b | 4712 | (gnus-configure-windows 'article) |
56e96bed | 4713 | (gnus-run-hooks 'gnus-article-prepare-hook) |
eec82323 LMI |
4714 | t)))))) |
4715 | ||
16409b0b GM |
4716 | ;;;###autoload |
4717 | (defun gnus-article-prepare-display () | |
4718 | "Make the current buffer look like a nice article." | |
4719 | ;; Hooks for getting information from the article. | |
4720 | ;; This hook must be called before being narrowed. | |
4721 | (let ((gnus-article-buffer (current-buffer)) | |
23f87bed MB |
4722 | buffer-read-only |
4723 | (inhibit-read-only t)) | |
1b3b87df | 4724 | (unless (derived-mode-p 'gnus-article-mode) |
16409b0b GM |
4725 | (gnus-article-mode)) |
4726 | (setq buffer-read-only nil | |
23f87bed MB |
4727 | gnus-article-wash-types nil |
4728 | gnus-article-image-alist nil) | |
16409b0b GM |
4729 | (gnus-run-hooks 'gnus-tmp-internal-hook) |
4730 | (when gnus-display-mime-function | |
56e96bed | 4731 | (funcall gnus-display-mime-function)))) |
16409b0b | 4732 | |
01c52d31 MB |
4733 | ;;; |
4734 | ;;; Gnus Sticky Article Mode | |
4735 | ;;; | |
4736 | ||
4737 | (define-derived-mode gnus-sticky-article-mode gnus-article-mode "StickyArticle" | |
4738 | "Mode for sticky articles." | |
4739 | ;; Release bindings that won't work. | |
4740 | (substitute-key-definition 'gnus-article-read-summary-keys 'undefined | |
4741 | gnus-sticky-article-mode-map) | |
4742 | (substitute-key-definition 'gnus-article-refer-article 'undefined | |
4743 | gnus-sticky-article-mode-map) | |
4744 | (dolist (k '("e" "h" "s" "F" "R")) | |
4745 | (define-key gnus-sticky-article-mode-map k nil)) | |
4746 | (define-key gnus-sticky-article-mode-map "k" 'gnus-kill-sticky-article-buffer) | |
4747 | (define-key gnus-sticky-article-mode-map "q" 'bury-buffer) | |
4748 | (define-key gnus-sticky-article-mode-map "\C-hc" 'describe-key-briefly) | |
4749 | (define-key gnus-sticky-article-mode-map "\C-hk" 'describe-key)) | |
4750 | ||
4751 | (defun gnus-sticky-article (arg) | |
4752 | "Make the current article sticky. | |
4753 | If a prefix ARG is given, ask for a name for this sticky article buffer." | |
4754 | (interactive "P") | |
4755 | (gnus-summary-show-thread) | |
4756 | (gnus-summary-select-article nil nil 'pseudo) | |
4757 | (let (new-art-buf-name) | |
4758 | (gnus-eval-in-buffer-window gnus-article-buffer | |
4759 | (setq new-art-buf-name | |
4760 | (concat | |
4761 | "*Sticky Article: " | |
4762 | (if arg | |
4763 | (read-from-minibuffer "Sticky article buffer name: ") | |
4764 | (gnus-with-article-headers | |
4765 | (gnus-article-goto-header "subject") | |
4766 | (setq new-art-buf-name | |
4767 | (buffer-substring-no-properties | |
4768 | (line-beginning-position) (line-end-position))) | |
4769 | (goto-char (point-min)) | |
4770 | (gnus-article-goto-header "from") | |
4771 | (setq new-art-buf-name | |
4772 | (concat | |
4773 | new-art-buf-name ", " | |
4774 | (buffer-substring-no-properties | |
4775 | (line-beginning-position) (line-end-position)))) | |
4776 | (goto-char (point-min)) | |
4777 | (gnus-article-goto-header "date") | |
4778 | (setq new-art-buf-name | |
4779 | (concat | |
4780 | new-art-buf-name ", " | |
4781 | (buffer-substring-no-properties | |
4782 | (line-beginning-position) (line-end-position)))))) | |
4783 | "*")) | |
4784 | (if (and (gnus-buffer-live-p new-art-buf-name) | |
4785 | (with-current-buffer new-art-buf-name | |
1b3b87df | 4786 | (derived-mode-p 'gnus-sticky-article-mode))) |
01c52d31 MB |
4787 | (switch-to-buffer new-art-buf-name) |
4788 | (setq new-art-buf-name (rename-buffer new-art-buf-name t))) | |
4789 | (gnus-sticky-article-mode)) | |
4790 | (setq gnus-article-buffer new-art-buf-name)) | |
4791 | (gnus-summary-recenter) | |
4792 | (gnus-summary-position-point)) | |
4793 | ||
4794 | (defun gnus-kill-sticky-article-buffer (&optional buffer) | |
4795 | "Kill the given sticky article BUFFER. | |
4796 | If none is given, assume the current buffer and kill it if it has | |
4797 | `gnus-sticky-article-mode'." | |
4798 | (interactive) | |
4799 | (unless buffer | |
4800 | (setq buffer (current-buffer))) | |
4801 | (with-current-buffer buffer | |
1b3b87df | 4802 | (when (derived-mode-p 'gnus-sticky-article-mode) |
01c52d31 MB |
4803 | (gnus-kill-buffer buffer)))) |
4804 | ||
71f32295 JD |
4805 | (defun gnus-kill-sticky-article-buffers (arg) |
4806 | "Kill all sticky article buffers. | |
4807 | If a prefix ARG is given, ask for confirmation." | |
4808 | (interactive "P") | |
4809 | (dolist (buf (gnus-buffers)) | |
4810 | (with-current-buffer buf | |
1b3b87df SM |
4811 | (when (derived-mode-p 'gnus-sticky-article-mode) |
4812 | (if (not arg) | |
4813 | (gnus-kill-buffer buf) | |
4814 | (when (yes-or-no-p (concat "Kill buffer " (buffer-name buf) "? ")) | |
4815 | (gnus-kill-buffer buf))))))) | |
71f32295 | 4816 | |
16409b0b GM |
4817 | ;;; |
4818 | ;;; Gnus MIME viewing functions | |
4819 | ;;; | |
4820 | ||
4821 | (defvar gnus-mime-button-line-format "%{%([%p. %d%T]%)%}%e\n" | |
23f87bed MB |
4822 | "Format of the MIME buttons. |
4823 | ||
4824 | Valid specifiers include: | |
16409b0b GM |
4825 | %t The MIME type |
4826 | %T MIME type, along with additional info | |
4827 | %n The `name' parameter | |
4828 | %d The description, if any | |
4829 | %l The length of the encoded part | |
4830 | %p The part identifier number | |
23f87bed MB |
4831 | %e Dots if the part isn't displayed |
4832 | ||
4833 | General format specifiers can also be used. See Info node | |
4834 | `(gnus)Formatting Variables'.") | |
16409b0b GM |
4835 | |
4836 | (defvar gnus-mime-button-line-format-alist | |
4837 | '((?t gnus-tmp-type ?s) | |
4838 | (?T gnus-tmp-type-long ?s) | |
4839 | (?n gnus-tmp-name ?s) | |
4840 | (?d gnus-tmp-description ?s) | |
4841 | (?p gnus-tmp-id ?s) | |
4842 | (?l gnus-tmp-length ?d) | |
4843 | (?e gnus-tmp-dots ?s))) | |
4844 | ||
4845 | (defvar gnus-mime-button-commands | |
4846 | '((gnus-article-press-button "\r" "Toggle Display") | |
4847 | (gnus-mime-view-part "v" "View Interactively...") | |
4848 | (gnus-mime-view-part-as-type "t" "View As Type...") | |
23f87bed | 4849 | (gnus-mime-view-part-as-charset "C" "View As charset...") |
16409b0b | 4850 | (gnus-mime-save-part "o" "Save...") |
23f87bed | 4851 | (gnus-mime-save-part-and-strip "\C-o" "Save and Strip") |
01c52d31 | 4852 | (gnus-mime-replace-part "r" "Replace part") |
23f87bed | 4853 | (gnus-mime-delete-part "d" "Delete part") |
16409b0b GM |
4854 | (gnus-mime-copy-part "c" "View As Text, In Other Buffer") |
4855 | (gnus-mime-inline-part "i" "View As Text, In This Buffer") | |
01c52d31 | 4856 | (gnus-mime-view-part-internally "E" "View Internally") ;; Why `E'? |
23f87bed MB |
4857 | (gnus-mime-view-part-externally "e" "View Externally") |
4858 | (gnus-mime-print-part "p" "Print") | |
e0bad764 | 4859 | (gnus-mime-pipe-part "|" "Pipe To Command...") |
23f87bed | 4860 | (gnus-mime-action-on-part "." "Take action on the part..."))) |
16409b0b GM |
4861 | |
4862 | (defun gnus-article-mime-part-status () | |
4863 | (if gnus-article-mime-handle-alist-1 | |
23f87bed MB |
4864 | (if (eq 1 (length gnus-article-mime-handle-alist-1)) |
4865 | " (1 part)" | |
4866 | (format " (%d parts)" (length gnus-article-mime-handle-alist-1))) | |
16409b0b GM |
4867 | "")) |
4868 | ||
4869 | (defvar gnus-mime-button-map | |
4870 | (let ((map (make-sparse-keymap))) | |
16409b0b GM |
4871 | (define-key map gnus-mouse-2 'gnus-article-push-button) |
4872 | (define-key map gnus-down-mouse-3 'gnus-mime-button-menu) | |
4873 | (dolist (c gnus-mime-button-commands) | |
4874 | (define-key map (cadr c) (car c))) | |
4875 | map)) | |
4876 | ||
23f87bed MB |
4877 | (easy-menu-define |
4878 | gnus-mime-button-menu gnus-mime-button-map "MIME button menu." | |
4879 | `("MIME Part" | |
4880 | ,@(mapcar (lambda (c) | |
01c52d31 | 4881 | (vector (caddr c) (car c) :active t)) |
23f87bed MB |
4882 | gnus-mime-button-commands))) |
4883 | ||
7426b4f7 LMI |
4884 | (defvar gnus-url-button-commands |
4885 | '((gnus-article-copy-string "u" "Copy URL to kill ring"))) | |
4886 | ||
4887 | (defvar gnus-url-button-map | |
4888 | (let ((map (make-sparse-keymap))) | |
4889 | (dolist (c gnus-url-button-commands) | |
4890 | (define-key map (cadr c) (car c))) | |
4891 | map)) | |
4892 | ||
4893 | (easy-menu-define | |
4894 | gnus-url-button-menu gnus-url-button-map "URL button menu." | |
4895 | `("Url Button" | |
4896 | ,@(mapcar (lambda (c) | |
4897 | (vector (caddr c) (car c) :active t)) | |
4898 | gnus-url-button-commands))) | |
4899 | ||
b0b63450 MB |
4900 | (defmacro gnus-bind-safe-url-regexp (&rest body) |
4901 | "Bind `mm-w3m-safe-url-regexp' according to `gnus-safe-html-newsgroups'." | |
4902 | `(let ((mm-w3m-safe-url-regexp | |
1b3b87df | 4903 | (let ((group (if (and (derived-mode-p 'gnus-article-mode) |
b0b63450 MB |
4904 | (gnus-buffer-live-p |
4905 | gnus-article-current-summary)) | |
4906 | (with-current-buffer gnus-article-current-summary | |
4907 | gnus-newsgroup-name) | |
4908 | gnus-newsgroup-name))) | |
7cab80f9 KY |
4909 | (if (cond ((not group) |
4910 | ;; Maybe we're in a mml-preview buffer | |
4911 | ;; and no group is selected. | |
4912 | t) | |
4913 | ((stringp gnus-safe-html-newsgroups) | |
b0b63450 MB |
4914 | (string-match gnus-safe-html-newsgroups group)) |
4915 | ((consp gnus-safe-html-newsgroups) | |
4916 | (member group gnus-safe-html-newsgroups))) | |
4917 | nil | |
4918 | mm-w3m-safe-url-regexp)))) | |
4919 | ,@body)) | |
4920 | ||
23f87bed MB |
4921 | (defun gnus-mime-button-menu (event prefix) |
4922 | "Construct a context-sensitive menu of MIME commands." | |
4923 | (interactive "e\nP") | |
4924 | (save-window-excursion | |
4925 | (let ((pos (event-start event))) | |
4926 | (select-window (posn-window pos)) | |
4927 | (goto-char (posn-point pos)) | |
4928 | (gnus-article-check-buffer) | |
4929 | (popup-menu gnus-mime-button-menu nil prefix)))) | |
16409b0b GM |
4930 | |
4931 | (defun gnus-mime-view-all-parts (&optional handles) | |
4932 | "View all the MIME parts." | |
4933 | (interactive) | |
01c52d31 | 4934 | (with-current-buffer gnus-article-buffer |
16409b0b GM |
4935 | (let ((handles (or handles gnus-article-mime-handles)) |
4936 | (mail-parse-charset gnus-newsgroup-charset) | |
a1506d29 | 4937 | (mail-parse-ignored-charsets |
23f87bed MB |
4938 | (with-current-buffer gnus-summary-buffer |
4939 | gnus-newsgroup-ignored-charsets))) | |
4940 | (when handles | |
4941 | (mm-remove-parts handles) | |
4942 | (goto-char (point-min)) | |
4943 | (or (search-forward "\n\n") (goto-char (point-max))) | |
4944 | (let ((inhibit-read-only t)) | |
4945 | (delete-region (point) (point-max)) | |
b0b63450 | 4946 | (gnus-bind-safe-url-regexp (mm-display-parts handles))))))) |
23f87bed | 4947 | |
01c52d31 MB |
4948 | (defun gnus-article-jump-to-part (n) |
4949 | "Jump to MIME part N." | |
4950 | (interactive "P") | |
a87ee50b KY |
4951 | (let ((parts (with-current-buffer gnus-article-buffer |
4952 | (length gnus-article-mime-handle-alist)))) | |
4953 | (when (zerop parts) | |
4954 | (error "No such part")) | |
4955 | (pop-to-buffer gnus-article-buffer) | |
a87ee50b KY |
4956 | (or n |
4957 | (setq n (if (= parts 1) | |
4958 | 1 | |
4959 | (read-number (format "Jump to part (1..%s): " parts))))) | |
01c52d31 MB |
4960 | (unless (and (integerp n) (<= n parts) (>= n 1)) |
4961 | (setq n | |
4962 | (progn | |
4963 | (gnus-message 7 "Invalid part `%s', using %s instead." | |
4964 | n parts) | |
4965 | parts))) | |
4966 | (gnus-message 9 "Jumping to part %s." n) | |
4967 | (cond ((>= gnus-auto-select-part 1) | |
4968 | (while (and (<= n parts) | |
4969 | (not (gnus-article-goto-part n))) | |
4970 | (setq n (1+ n)))) | |
4971 | ((< gnus-auto-select-part 0) | |
4972 | (while (and (>= n 1) | |
4973 | (not (gnus-article-goto-part n))) | |
4974 | (setq n (1- n)))) | |
4975 | (t | |
4976 | (gnus-article-goto-part n))))) | |
4977 | ||
3e3ab3ab KY |
4978 | (defvar gnus-mime-buttonized-part-id nil |
4979 | "ID of a mime part that should be buttonized. | |
4980 | `gnus-mime-save-part-and-strip' and `gnus-mime-delete-part' bind it.") | |
4981 | ||
01c52d31 MB |
4982 | (eval-when-compile |
4983 | (defsubst gnus-article-edit-part (handles &optional current-id) | |
4984 | "Edit an article in order to delete a mime part. | |
4985 | This function is exclusively used by `gnus-mime-save-part-and-strip' | |
4986 | and `gnus-mime-delete-part', and not provided at run-time normally." | |
4987 | (gnus-article-edit-article | |
4988 | `(lambda () | |
4989 | (buffer-disable-undo) | |
4990 | (erase-buffer) | |
4991 | (let ((mail-parse-charset (or gnus-article-charset | |
4992 | ',gnus-newsgroup-charset)) | |
4993 | (mail-parse-ignored-charsets | |
4994 | (or gnus-article-ignored-charsets | |
4995 | ',gnus-newsgroup-ignored-charsets)) | |
4996 | (mbl mml-buffer-list)) | |
4997 | (setq mml-buffer-list nil) | |
4998 | (insert-buffer-substring gnus-original-article-buffer) | |
4999 | (mime-to-mml ',handles) | |
5000 | (setq gnus-article-mime-handles nil) | |
5001 | (let ((mbl1 mml-buffer-list)) | |
5002 | (setq mml-buffer-list mbl) | |
5003 | (set (make-local-variable 'mml-buffer-list) mbl1)) | |
5004 | (gnus-make-local-hook 'kill-buffer-hook) | |
5005 | (add-hook 'kill-buffer-hook 'mml-destroy-buffers t t))) | |
5006 | `(lambda (no-highlight) | |
5007 | (let ((mail-parse-charset (or gnus-article-charset | |
5008 | ',gnus-newsgroup-charset)) | |
5009 | (message-options message-options) | |
5010 | (message-options-set-recipient) | |
5011 | (mail-parse-ignored-charsets | |
5012 | (or gnus-article-ignored-charsets | |
5013 | ',gnus-newsgroup-ignored-charsets))) | |
5014 | (mml-to-mime) | |
5015 | (mml-destroy-buffers) | |
5016 | (remove-hook 'kill-buffer-hook | |
5017 | 'mml-destroy-buffers t) | |
5018 | (kill-local-variable 'mml-buffer-list)) | |
5019 | (gnus-summary-edit-article-done | |
5020 | ,(or (mail-header-references gnus-current-headers) "") | |
5021 | ,(gnus-group-read-only-p) | |
5022 | ,gnus-summary-buffer no-highlight)) | |
5023 | t) | |
3e3ab3ab KY |
5024 | ;; Force buttonizing this part. |
5025 | (let ((gnus-mime-buttonized-part-id current-id)) | |
5026 | (gnus-article-edit-done)) | |
54c72c31 | 5027 | (gnus-configure-windows 'article) |
01c52d31 | 5028 | (when (and current-id (integerp gnus-auto-select-part)) |
3e3ab3ab KY |
5029 | (gnus-article-jump-to-part |
5030 | (min (max (+ current-id gnus-auto-select-part) 1) | |
5031 | (with-current-buffer gnus-article-buffer | |
5032 | (length gnus-article-mime-handle-alist))))))) | |
01c52d31 MB |
5033 | |
5034 | (defun gnus-mime-replace-part (file) | |
5035 | "Replace MIME part under point with an external body." | |
5036 | ;; Useful if file has already been saved to disk | |
5037 | (interactive | |
5038 | (list | |
75eda25b SM |
5039 | (read-file-name "Replace MIME part with file: " |
5040 | (or mm-default-directory default-directory) | |
5041 | nil nil))) | |
01c52d31 MB |
5042 | (gnus-mime-save-part-and-strip file)) |
5043 | ||
5044 | (defun gnus-mime-save-part-and-strip (&optional file) | |
5045 | "Save the MIME part under point then replace it with an external body. | |
5046 | If FILE is given, use it for the external part." | |
23f87bed MB |
5047 | (interactive) |
5048 | (gnus-article-check-buffer) | |
5049 | (when (gnus-group-read-only-p) | |
5050 | (error "The current group does not support deleting of parts")) | |
5051 | (when (mm-complicated-handles gnus-article-mime-handles) | |
5052 | (error "\ | |
5053 | The current article has a complicated MIME structure, giving up...")) | |
01c52d31 MB |
5054 | (let* ((data (get-text-property (point) 'gnus-data)) |
5055 | (id (get-text-property (point) 'gnus-part)) | |
5056 | param | |
5057 | (handles gnus-article-mime-handles)) | |
5058 | (unless file | |
5059 | (setq file | |
5060 | (and data (mm-save-part data "Delete MIME part and save to: ")))) | |
5061 | (when file | |
5062 | (with-current-buffer (mm-handle-buffer data) | |
5063 | (erase-buffer) | |
5064 | (insert "Content-Type: " (mm-handle-media-type data)) | |
5065 | (mml-insert-parameter-string (cdr (mm-handle-type data)) | |
5066 | '(charset)) | |
5067 | ;; Add a filename for the sake of saving the part again. | |
5068 | (mml-insert-parameter | |
5069 | (mail-header-encode-parameter "name" (file-name-nondirectory file))) | |
5070 | (insert "\n") | |
5071 | (insert "Content-ID: " (message-make-message-id) "\n") | |
5072 | (insert "Content-Transfer-Encoding: binary\n") | |
5073 | (insert "\n")) | |
5074 | (setcdr data | |
5075 | (cdr (mm-make-handle nil | |
5076 | `("message/external-body" | |
5077 | (access-type . "LOCAL-FILE") | |
5078 | (name . ,file))))) | |
5079 | ;; (set-buffer gnus-summary-buffer) | |
5080 | (gnus-article-edit-part handles id)))) | |
5081 | ||
5082 | ;; A function like `gnus-summary-save-parts' (`X m', `<MIME> <Extract all | |
5083 | ;; parts...>') but with stripping would be nice. | |
23f87bed MB |
5084 | |
5085 | (defun gnus-mime-delete-part () | |
5086 | "Delete the MIME part under point. | |
5087 | Replace it with some information about the removed part." | |
5088 | (interactive) | |
5089 | (gnus-article-check-buffer) | |
5090 | (when (gnus-group-read-only-p) | |
5091 | (error "The current group does not support deleting of parts")) | |
5092 | (when (mm-complicated-handles gnus-article-mime-handles) | |
5093 | (error "\ | |
5094 | The current article has a complicated MIME structure, giving up...")) | |
01c52d31 MB |
5095 | (when (or gnus-expert-user |
5096 | (gnus-yes-or-no-p "\ | |
5097 | Deleting parts may malfunction or destroy the article; continue? ")) | |
23f87bed | 5098 | (let* ((data (get-text-property (point) 'gnus-data)) |
01c52d31 | 5099 | (id (get-text-property (point) 'gnus-part)) |
23f87bed | 5100 | (handles gnus-article-mime-handles) |
23f87bed | 5101 | (description |
bbbe940b MB |
5102 | (let ((desc (mm-handle-description data))) |
5103 | (when desc | |
5104 | (mail-decode-encoded-word-string desc)))) | |
88a7a941 | 5105 | (filename (or (mm-handle-filename data) "(none)")) |
23f87bed MB |
5106 | (type (mm-handle-media-type data))) |
5107 | (unless data | |
5108 | (error "No MIME part under point")) | |
5109 | (with-current-buffer (mm-handle-buffer data) | |
e5fa3899 | 5110 | (let ((bsize (buffer-size))) |
23f87bed MB |
5111 | (erase-buffer) |
5112 | (insert | |
5113 | (concat | |
5114 | ",----\n" | |
5115 | "| The following attachment has been deleted:\n" | |
5116 | "|\n" | |
5117 | "| Type: " type "\n" | |
5118 | "| Filename: " filename "\n" | |
e5fa3899 KY |
5119 | "| Size (encoded): " (format "%s byte%s\n" |
5120 | bsize (if (= bsize 1) | |
8ccbef23 G |
5121 | "" |
5122 | "s")) | |
bbbe940b MB |
5123 | (when description |
5124 | (concat "| Description: " description "\n")) | |
23f87bed MB |
5125 | "`----\n")) |
5126 | (setcdr data | |
5127 | (cdr (mm-make-handle | |
0cf681b6 | 5128 | nil `("text/plain" (charset . gnus-decoded)) nil nil |
23f87bed MB |
5129 | (list "attachment") |
5130 | (format "Deleted attachment (%s bytes)" bsize)))))) | |
01c52d31 MB |
5131 | ;; (set-buffer gnus-summary-buffer) |
5132 | (gnus-article-edit-part handles id)))) | |
16409b0b GM |
5133 | |
5134 | (defun gnus-mime-save-part () | |
5135 | "Save the MIME part under point." | |
5136 | (interactive) | |
5137 | (gnus-article-check-buffer) | |
5138 | (let ((data (get-text-property (point) 'gnus-data))) | |
23f87bed MB |
5139 | (when data |
5140 | (mm-save-part data)))) | |
16409b0b | 5141 | |
9581ba4d KY |
5142 | (defun gnus-mime-pipe-part (&optional cmd) |
5143 | "Pipe the MIME part under point to a process. | |
5144 | Use CMD as the process." | |
16409b0b GM |
5145 | (interactive) |
5146 | (gnus-article-check-buffer) | |
5147 | (let ((data (get-text-property (point) 'gnus-data))) | |
23f87bed | 5148 | (when data |
9581ba4d | 5149 | (mm-pipe-part data cmd)))) |
16409b0b GM |
5150 | |
5151 | (defun gnus-mime-view-part () | |
5152 | "Interactively choose a viewing method for the MIME part under point." | |
5153 | (interactive) | |
5154 | (gnus-article-check-buffer) | |
5155 | (let ((data (get-text-property (point) 'gnus-data))) | |
23f87bed MB |
5156 | (when data |
5157 | (setq gnus-article-mime-handles | |
5158 | (mm-merge-handles | |
5159 | gnus-article-mime-handles (setq data (copy-sequence data)))) | |
5160 | (mm-interactively-view-part data)))) | |
16409b0b GM |
5161 | |
5162 | (defun gnus-mime-view-part-as-type-internal () | |
5163 | (gnus-article-check-buffer) | |
54e573e6 MB |
5164 | (let* ((handle (get-text-property (point) 'gnus-data)) |
5165 | (name (or | |
5166 | ;; Content-Type: foo/bar; name=... | |
5167 | (mail-content-type-get (mm-handle-type handle) 'name) | |
5168 | ;; Content-Disposition: attachment; filename=... | |
5169 | (cdr (assq 'filename (cdr (mm-handle-disposition handle)))))) | |
16409b0b | 5170 | (def-type (and name (mm-default-file-encoding name)))) |
01c52d31 MB |
5171 | (or (and def-type (cons def-type 0)) |
5172 | (and handle | |
5173 | (equal (mm-handle-media-supertype handle) "text") | |
5174 | '("text/plain" . 0)) | |
5175 | '("application/octet-stream" . 0)))) | |
16409b0b | 5176 | |
54e573e6 MB |
5177 | (defun gnus-mime-view-part-as-type (&optional mime-type pred) |
5178 | "Choose a MIME media type, and view the part as such. | |
5179 | If non-nil, PRED is a predicate to use during completion to limit the | |
5180 | available media-types." | |
23f87bed MB |
5181 | (interactive) |
5182 | (unless mime-type | |
54e573e6 MB |
5183 | (setq mime-type |
5184 | (let ((default (gnus-mime-view-part-as-type-internal))) | |
229b59da G |
5185 | (gnus-completing-read |
5186 | "View as MIME type" | |
568f71a8 KY |
5187 | (if pred |
5188 | (gnus-remove-if-not pred (mailcap-mime-types)) | |
5189 | (mailcap-mime-types)) | |
229b59da | 5190 | nil nil nil |
54e573e6 | 5191 | (car default))))) |
16409b0b GM |
5192 | (gnus-article-check-buffer) |
5193 | (let ((handle (get-text-property (point) 'gnus-data))) | |
23f87bed | 5194 | (when handle |
531bedc3 MB |
5195 | (when (equal (mm-handle-media-type handle) "message/external-body") |
5196 | (unless (mm-handle-cache handle) | |
5197 | (mm-extern-cache-contents handle)) | |
5198 | (setq handle (mm-handle-cache handle))) | |
23f87bed MB |
5199 | (setq handle |
5200 | (mm-make-handle (mm-handle-buffer handle) | |
5201 | (cons mime-type (cdr (mm-handle-type handle))) | |
5202 | (mm-handle-encoding handle) | |
5203 | (mm-handle-undisplayer handle) | |
5204 | (mm-handle-disposition handle) | |
5205 | (mm-handle-description handle) | |
5206 | nil | |
5207 | (mm-handle-id handle))) | |
5208 | (setq gnus-article-mime-handles | |
5209 | (mm-merge-handles gnus-article-mime-handles handle)) | |
01c52d31 MB |
5210 | (when (mm-handle-displayed-p handle) |
5211 | (mm-remove-part handle)) | |
23f87bed MB |
5212 | (gnus-mm-display-part handle)))) |
5213 | ||
01c52d31 | 5214 | (defun gnus-mime-copy-part (&optional handle arg) |
23f87bed MB |
5215 | "Put the MIME part under point into a new buffer. |
5216 | If `auto-compression-mode' is enabled, compressed files like .gz and .bz2 | |
5217 | are decompressed." | |
01c52d31 | 5218 | (interactive (list nil current-prefix-arg)) |
16409b0b | 5219 | (gnus-article-check-buffer) |
01c52d31 MB |
5220 | (unless handle |
5221 | (setq handle (get-text-property (point) 'gnus-data))) | |
5222 | (when handle | |
247c22e1 | 5223 | (let ((filename (mm-handle-filename handle)) |
01c52d31 MB |
5224 | contents dont-decode charset coding-system) |
5225 | (mm-with-unibyte-buffer | |
5226 | (mm-insert-part handle) | |
5227 | (setq contents (or (condition-case nil | |
5228 | (mm-decompress-buffer filename nil 'sig) | |
5229 | (error | |
5230 | (setq dont-decode t) | |
5231 | nil)) | |
5232 | (buffer-string)))) | |
5233 | (setq filename (cond (filename (file-name-nondirectory filename)) | |
5234 | (dont-decode "*raw data*") | |
5235 | (t "*decoded*"))) | |
5236 | (cond | |
5237 | (dont-decode) | |
5238 | ((not arg) | |
5239 | (unless (setq charset (mail-content-type-get | |
5240 | (mm-handle-type handle) 'charset)) | |
5241 | (unless (setq coding-system (mm-with-unibyte-buffer | |
5242 | (insert contents) | |
5243 | (mm-find-buffer-file-coding-system))) | |
5244 | (setq charset gnus-newsgroup-charset)))) | |
5245 | ((numberp arg) | |
5246 | (setq charset (or (cdr (assq arg | |
5247 | gnus-summary-show-article-charset-alist)) | |
5248 | (mm-read-coding-system "Charset: "))))) | |
5249 | (switch-to-buffer (generate-new-buffer filename)) | |
5250 | (if (or coding-system | |
5251 | (and charset | |
07178229 KY |
5252 | (setq coding-system (mm-charset-to-coding-system |
5253 | charset nil t)) | |
a87ee50b | 5254 | (not (eq coding-system 'ascii)))) |
01c52d31 MB |
5255 | (progn |
5256 | (mm-enable-multibyte) | |
5257 | (insert (mm-decode-coding-string contents coding-system)) | |
5258 | (setq buffer-file-coding-system | |
5259 | (if (boundp 'last-coding-system-used) | |
5260 | (symbol-value 'last-coding-system-used) | |
5261 | coding-system))) | |
5262 | (mm-disable-multibyte) | |
5263 | (insert contents) | |
5264 | (setq buffer-file-coding-system mm-binary-coding-system)) | |
23f87bed MB |
5265 | ;; We do it this way to make `normal-mode' set the appropriate mode. |
5266 | (unwind-protect | |
5267 | (progn | |
01c52d31 | 5268 | (setq buffer-file-name (expand-file-name filename)) |
23f87bed MB |
5269 | (normal-mode)) |
5270 | (setq buffer-file-name nil)) | |
5271 | (goto-char (point-min))))) | |
5272 | ||
5273 | (defun gnus-mime-print-part (&optional handle filename) | |
5274 | "Print the MIME part under point." | |
5275 | (interactive (list nil (ps-print-preprint current-prefix-arg))) | |
5276 | (gnus-article-check-buffer) | |
5277 | (let* ((handle (or handle (get-text-property (point) 'gnus-data))) | |
5278 | (contents (and handle (mm-get-part handle))) | |
5279 | (file (mm-make-temp-file (expand-file-name "mm." mm-tmp-directory))) | |
5280 | (printer (mailcap-mime-info (mm-handle-media-type handle) "print"))) | |
5281 | (when contents | |
5282 | (if printer | |
5283 | (unwind-protect | |
5284 | (progn | |
5285 | (mm-save-part-to-file handle file) | |
5286 | (call-process shell-file-name nil | |
5287 | (generate-new-buffer " *mm*") | |
5288 | nil | |
5289 | shell-command-switch | |
5290 | (mm-mailcap-command | |
5291 | printer file (mm-handle-type handle)))) | |
5292 | (delete-file file)) | |
5293 | (with-temp-buffer | |
5294 | (insert contents) | |
5295 | (gnus-print-buffer)) | |
5296 | (ps-despool filename))))) | |
16409b0b | 5297 | |
e0bad764 | 5298 | (defun gnus-mime-inline-part (&optional handle arg) |
01c52d31 MB |
5299 | "Insert the MIME part under point into the current buffer. |
5300 | Compressed files like .gz and .bz2 are decompressed." | |
e0bad764 | 5301 | (interactive (list nil current-prefix-arg)) |
16409b0b | 5302 | (gnus-article-check-buffer) |
01c52d31 MB |
5303 | (unless handle |
5304 | (setq handle (get-text-property (point) 'gnus-data))) | |
5305 | (when handle | |
5306 | (let ((b (point)) | |
5307 | (inhibit-read-only t) | |
5308 | contents charset coding-system) | |
23f87bed MB |
5309 | (if (and (not arg) (mm-handle-undisplayer handle)) |
5310 | (mm-remove-part handle) | |
01c52d31 MB |
5311 | (mm-with-unibyte-buffer |
5312 | (mm-insert-part handle) | |
5313 | (setq contents | |
247c22e1 | 5314 | (or (mm-decompress-buffer (mm-handle-filename handle) nil t) |
01c52d31 | 5315 | (buffer-string)))) |
23f87bed MB |
5316 | (cond |
5317 | ((not arg) | |
01c52d31 MB |
5318 | (unless (setq charset (mail-content-type-get |
5319 | (mm-handle-type handle) 'charset)) | |
5320 | (unless (setq coding-system | |
5321 | (mm-with-unibyte-buffer | |
5322 | (insert contents) | |
5323 | (mm-find-buffer-file-coding-system))) | |
5324 | (setq charset gnus-newsgroup-charset)))) | |
23f87bed MB |
5325 | ((numberp arg) |
5326 | (if (mm-handle-undisplayer handle) | |
5327 | (mm-remove-part handle)) | |
5328 | (setq charset | |
5329 | (or (cdr (assq arg | |
5330 | gnus-summary-show-article-charset-alist)) | |
56c30d72 | 5331 | (mm-read-coding-system "Charset: ")))) |
89b163db G |
5332 | ((mm-handle-undisplayer handle) |
5333 | (mm-remove-part handle))) | |
23f87bed | 5334 | (forward-line 2) |
6e3165fb | 5335 | (mm-display-inline handle) |
23f87bed MB |
5336 | (goto-char b))))) |
5337 | ||
c0ccb0d6 KY |
5338 | (defun gnus-mime-set-charset-parameters (handle charset) |
5339 | "Set CHARSET to parameters in HANDLE. | |
5340 | CHARSET may either be a string or a symbol." | |
5341 | (unless (stringp charset) | |
5342 | (setq charset (symbol-name charset))) | |
6b554e88 | 5343 | (if (stringp (car handle)) |
c0ccb0d6 KY |
5344 | (dolist (h (cdr handle)) |
5345 | (gnus-mime-set-charset-parameters h charset)) | |
6b554e88 MB |
5346 | (let* ((type (mm-handle-type (if (equal (mm-handle-media-type handle) |
5347 | "message/external-body") | |
5348 | (progn | |
5349 | (unless (mm-handle-cache handle) | |
5350 | (mm-extern-cache-contents handle)) | |
5351 | (mm-handle-cache handle)) | |
5352 | handle))) | |
c0ccb0d6 KY |
5353 | (param (assq 'charset (cdr type)))) |
5354 | (if param | |
5355 | (setcdr param charset) | |
5356 | (setcdr type (cons (cons 'charset charset) (cdr type))))))) | |
6b554e88 | 5357 | |
23f87bed MB |
5358 | (defun gnus-mime-view-part-as-charset (&optional handle arg) |
5359 | "Insert the MIME part under point into the current buffer using the | |
5360 | specified charset." | |
5361 | (interactive (list nil current-prefix-arg)) | |
5362 | (gnus-article-check-buffer) | |
163cb72d MB |
5363 | (let ((handle (or handle (get-text-property (point) 'gnus-data))) |
5364 | (fun (get-text-property (point) 'gnus-callback)) | |
5365 | (gnus-newsgroup-ignored-charsets 'gnus-all) | |
c0ccb0d6 | 5366 | charset form preferred parts) |
23f87bed | 5367 | (when handle |
01c52d31 MB |
5368 | (when (prog1 |
5369 | (and fun | |
c0ccb0d6 | 5370 | (setq charset |
01c52d31 MB |
5371 | (or (cdr (assq |
5372 | arg | |
5373 | gnus-summary-show-article-charset-alist)) | |
5374 | (mm-read-coding-system "Charset: ")))) | |
5375 | (if (mm-handle-undisplayer handle) | |
5376 | (mm-remove-part handle))) | |
c0ccb0d6 | 5377 | (gnus-mime-set-charset-parameters handle charset) |
6b554e88 MB |
5378 | (when (and (consp (setq form (cdr-safe fun))) |
5379 | (setq form (ignore-errors | |
5380 | (assq 'gnus-mime-display-alternative form))) | |
5381 | (setq preferred (caddr form)) | |
5382 | (progn | |
5383 | (when (eq (car preferred) 'quote) | |
5384 | (setq preferred (cadr preferred))) | |
5385 | (not (equal preferred | |
5386 | (get-text-property (point) 'gnus-data)))) | |
5387 | (setq parts (get-text-property (point) 'gnus-part)) | |
5388 | (setq parts (cdr (assq parts | |
5389 | gnus-article-mime-handle-alist))) | |
5390 | (equal (mm-handle-media-type parts) "multipart/alternative") | |
5391 | (setq parts (reverse (cdr parts)))) | |
5392 | (setcar (cddr form) | |
5393 | (list 'quote (or (cadr (member preferred parts)) | |
5394 | (car parts))))) | |
163cb72d | 5395 | (funcall fun handle))))) |
23f87bed MB |
5396 | |
5397 | (defun gnus-mime-view-part-externally (&optional handle) | |
16409b0b GM |
5398 | "View the MIME part under point with an external viewer." |
5399 | (interactive) | |
5400 | (gnus-article-check-buffer) | |
5401 | (let* ((handle (or handle (get-text-property (point) 'gnus-data))) | |
5402 | (mm-user-display-methods nil) | |
5403 | (mm-inlined-types nil) | |
5404 | (mail-parse-charset gnus-newsgroup-charset) | |
a1506d29 | 5405 | (mail-parse-ignored-charsets |
54e573e6 MB |
5406 | (with-current-buffer gnus-summary-buffer |
5407 | gnus-newsgroup-ignored-charsets)) | |
5408 | (type (mm-handle-media-type handle)) | |
5409 | (method (mailcap-mime-info type)) | |
5410 | (mm-enable-external t)) | |
5411 | (if (not (stringp method)) | |
5412 | (gnus-mime-view-part-as-type | |
f7aa0b8f | 5413 | nil (lambda (type) (stringp (mailcap-mime-info type)))) |
54e573e6 | 5414 | (when handle |
a87ee50b | 5415 | (mm-display-part handle nil t))))) |
16409b0b | 5416 | |
23f87bed | 5417 | (defun gnus-mime-view-part-internally (&optional handle) |
16409b0b | 5418 | "View the MIME part under point with an internal viewer. |
23f87bed | 5419 | If no internal viewer is available, use an external viewer." |
16409b0b GM |
5420 | (interactive) |
5421 | (gnus-article-check-buffer) | |
5422 | (let* ((handle (or handle (get-text-property (point) 'gnus-data))) | |
5423 | (mm-inlined-types '(".*")) | |
5424 | (mm-inline-large-images t) | |
5425 | (mail-parse-charset gnus-newsgroup-charset) | |
a1506d29 | 5426 | (mail-parse-ignored-charsets |
54e573e6 MB |
5427 | (with-current-buffer gnus-summary-buffer |
5428 | gnus-newsgroup-ignored-charsets)) | |
23f87bed | 5429 | (inhibit-read-only t)) |
54e573e6 MB |
5430 | (if (not (mm-inlinable-p handle)) |
5431 | (gnus-mime-view-part-as-type | |
f7aa0b8f | 5432 | nil (lambda (type) (mm-inlinable-p handle type))) |
54e573e6 | 5433 | (when handle |
a87ee50b | 5434 | (gnus-bind-safe-url-regexp (mm-display-part handle)))))) |
16409b0b | 5435 | |
e0bad764 DL |
5436 | (defun gnus-mime-action-on-part (&optional action) |
5437 | "Do something with the MIME attachment at \(point\)." | |
5438 | (interactive | |
229b59da | 5439 | (list (gnus-completing-read "Action" (mapcar 'car gnus-mime-action-alist) t))) |
e0bad764 DL |
5440 | (gnus-article-check-buffer) |
5441 | (let ((action-pair (assoc action gnus-mime-action-alist))) | |
5442 | (if action-pair | |
5443 | (funcall (cdr action-pair))))) | |
5444 | ||
01c52d31 MB |
5445 | (defun gnus-article-part-wrapper (n function &optional no-handle interactive) |
5446 | "Call FUNCTION on MIME part N. | |
c7015153 JB |
5447 | Unless NO-HANDLE, call FUNCTION with N-th MIME handle as its only argument. |
5448 | If INTERACTIVE, call FUNCTION interactively." | |
01c52d31 MB |
5449 | (let (window frame) |
5450 | ;; Check whether the article is displayed. | |
5451 | (unless (and (gnus-buffer-live-p gnus-article-buffer) | |
5452 | (setq window (get-buffer-window gnus-article-buffer t)) | |
5453 | (frame-visible-p (setq frame (window-frame window)))) | |
5454 | (error "No article is displayed")) | |
5455 | (with-current-buffer gnus-article-buffer | |
5456 | ;; Check whether the article displays the right contents. | |
5457 | (unless (with-current-buffer gnus-summary-buffer | |
5458 | (eq gnus-current-article (gnus-summary-article-number))) | |
5459 | (error "You should select the right article first")) | |
5460 | (if n | |
5461 | (setq n (prefix-numeric-value n)) | |
5462 | (let ((pt (point))) | |
5463 | (setq n (or (get-text-property pt 'gnus-part) | |
5464 | (and (not (bobp)) | |
5465 | (get-text-property (1- pt) 'gnus-part)) | |
5466 | (get-text-property (prog2 | |
5467 | (forward-line 1) | |
5468 | (point) | |
5469 | (goto-char pt)) | |
5470 | 'gnus-part) | |
5471 | (get-text-property | |
5472 | (or (and (setq pt (previous-single-property-change | |
5473 | pt 'gnus-part)) | |
5474 | (1- pt)) | |
5475 | (next-single-property-change (point) 'gnus-part) | |
5476 | (point)) | |
5477 | 'gnus-part) | |
5478 | 1)))) | |
5479 | ;; Check whether the specified part exists. | |
5480 | (when (> n (length gnus-article-mime-handle-alist)) | |
5481 | (error "No such part"))) | |
5482 | (unless | |
5483 | (progn | |
5484 | ;; To select the window is needed so that the cursor | |
5485 | ;; might be visible on the MIME button. | |
5486 | (select-window (prog1 | |
5487 | window | |
5488 | (setq window (selected-window)) | |
5489 | ;; Article may be displayed in the other frame. | |
5490 | (gnus-select-frame-set-input-focus | |
5491 | (prog1 | |
5492 | frame | |
5493 | (setq frame (selected-frame)))))) | |
5494 | (when (gnus-article-goto-part n) | |
5495 | ;; We point the cursor and the arrow at the MIME button | |
5496 | ;; when the `function' prompt the user for something. | |
a87ee50b KY |
5497 | (unless (and (pos-visible-in-window-p) |
5498 | (> (count-lines (point) (window-end)) | |
5499 | (/ (1- (window-height)) 3))) | |
5500 | (recenter (/ (1- (window-height)) 3))) | |
01c52d31 MB |
5501 | (let ((cursor-in-non-selected-windows t) |
5502 | (overlay-arrow-string "=>") | |
5503 | (overlay-arrow-position (point-marker))) | |
5504 | (unwind-protect | |
5505 | (cond | |
5506 | ((and no-handle interactive) | |
5507 | (call-interactively function)) | |
5508 | (no-handle | |
5509 | (funcall function)) | |
5510 | (interactive | |
5511 | (call-interactively | |
a87ee50b | 5512 | function (get-text-property (point) 'gnus-data))) |
01c52d31 MB |
5513 | (t |
5514 | (funcall function | |
a87ee50b | 5515 | (get-text-property (point) 'gnus-data)))) |
01c52d31 MB |
5516 | (set-marker overlay-arrow-position nil) |
5517 | (unless gnus-auto-select-part | |
5518 | (gnus-select-frame-set-input-focus frame) | |
5519 | (select-window window)))) | |
5520 | t)) | |
5521 | (if gnus-inhibit-mime-unbuttonizing | |
5522 | ;; This is the default though the program shouldn't reach here. | |
5523 | (error "No such part") | |
5524 | ;; The part which doesn't have the MIME button is selected. | |
5525 | ;; So, we display all the buttons and redo it. | |
5526 | (let ((gnus-inhibit-mime-unbuttonizing t)) | |
5527 | (gnus-summary-show-article) | |
5528 | (gnus-article-part-wrapper n function no-handle)))))) | |
16409b0b GM |
5529 | |
5530 | (defun gnus-article-pipe-part (n) | |
5531 | "Pipe MIME part N, which is the numerical prefix." | |
01c52d31 | 5532 | (interactive "P") |
16409b0b GM |
5533 | (gnus-article-part-wrapper n 'mm-pipe-part)) |
5534 | ||
5535 | (defun gnus-article-save-part (n) | |
5536 | "Save MIME part N, which is the numerical prefix." | |
01c52d31 | 5537 | (interactive "P") |
16409b0b GM |
5538 | (gnus-article-part-wrapper n 'mm-save-part)) |
5539 | ||
5540 | (defun gnus-article-interactively-view-part (n) | |
5541 | "View MIME part N interactively, which is the numerical prefix." | |
01c52d31 | 5542 | (interactive "P") |
16409b0b GM |
5543 | (gnus-article-part-wrapper n 'mm-interactively-view-part)) |
5544 | ||
5545 | (defun gnus-article-copy-part (n) | |
5546 | "Copy MIME part N, which is the numerical prefix." | |
01c52d31 | 5547 | (interactive "P") |
16409b0b GM |
5548 | (gnus-article-part-wrapper n 'gnus-mime-copy-part)) |
5549 | ||
23f87bed MB |
5550 | (defun gnus-article-view-part-as-charset (n) |
5551 | "View MIME part N using a specified charset. | |
5552 | N is the numerical prefix." | |
01c52d31 | 5553 | (interactive "P") |
23f87bed MB |
5554 | (gnus-article-part-wrapper n 'gnus-mime-view-part-as-charset)) |
5555 | ||
5556 | (defun gnus-article-view-part-externally (n) | |
16409b0b | 5557 | "View MIME part N externally, which is the numerical prefix." |
01c52d31 | 5558 | (interactive "P") |
23f87bed | 5559 | (gnus-article-part-wrapper n 'gnus-mime-view-part-externally)) |
16409b0b GM |
5560 | |
5561 | (defun gnus-article-inline-part (n) | |
5562 | "Inline MIME part N, which is the numerical prefix." | |
01c52d31 | 5563 | (interactive "P") |
16409b0b GM |
5564 | (gnus-article-part-wrapper n 'gnus-mime-inline-part)) |
5565 | ||
01c52d31 MB |
5566 | (defun gnus-article-save-part-and-strip (n) |
5567 | "Save MIME part N and replace it with an external body. | |
5568 | N is the numerical prefix." | |
5569 | (interactive "P") | |
5570 | (gnus-article-part-wrapper n 'gnus-mime-save-part-and-strip t)) | |
5571 | ||
5572 | (defun gnus-article-replace-part (n) | |
5573 | "Replace MIME part N with an external body. | |
5574 | N is the numerical prefix." | |
5575 | (interactive "P") | |
5576 | (gnus-article-part-wrapper n 'gnus-mime-replace-part t t)) | |
5577 | ||
5578 | (defun gnus-article-delete-part (n) | |
5579 | "Delete MIME part N and add some information about the removed part. | |
5580 | N is the numerical prefix." | |
5581 | (interactive "P") | |
5582 | (gnus-article-part-wrapper n 'gnus-mime-delete-part t)) | |
5583 | ||
5584 | (defun gnus-article-view-part-as-type (n) | |
5585 | "Choose a MIME media type, and view part N as such. | |
5586 | N is the numerical prefix." | |
5587 | (interactive "P") | |
5588 | (gnus-article-part-wrapper n 'gnus-mime-view-part-as-type t)) | |
5589 | ||
16409b0b GM |
5590 | (defun gnus-article-mime-match-handle-first (condition) |
5591 | (if condition | |
01c52d31 MB |
5592 | (let (n) |
5593 | (dolist (ihandle gnus-article-mime-handle-alist) | |
a1506d29 | 5594 | (if (and (cond |
16409b0b GM |
5595 | ((functionp condition) |
5596 | (funcall condition (cdr ihandle))) | |
a1506d29 | 5597 | ((eq condition 'undisplayed) |
16409b0b GM |
5598 | (not (or (mm-handle-undisplayer (cdr ihandle)) |
5599 | (equal (mm-handle-media-type (cdr ihandle)) | |
5600 | "multipart/alternative")))) | |
5601 | ((eq condition 'undisplayed-alternative) | |
5602 | (not (mm-handle-undisplayer (cdr ihandle)))) | |
5603 | (t t)) | |
5604 | (gnus-article-goto-part (car ihandle)) | |
5605 | (or (not n) (< (car ihandle) n))) | |
5606 | (setq n (car ihandle)))) | |
5607 | (or n 1)) | |
5608 | 1)) | |
5609 | ||
5610 | (defun gnus-article-view-part (&optional n) | |
47fe149b KY |
5611 | "View MIME part N, which is the numerical prefix. |
5612 | If the part is already shown, hide the part. If N is nil, view | |
5613 | all parts." | |
16409b0b | 5614 | (interactive "P") |
01c52d31 | 5615 | (with-current-buffer gnus-article-buffer |
a1506d29 | 5616 | (or (numberp n) (setq n (gnus-article-mime-match-handle-first |
16409b0b GM |
5617 | gnus-article-mime-match-handle-function))) |
5618 | (when (> n (length gnus-article-mime-handle-alist)) | |
5619 | (error "No such part")) | |
5620 | (let ((handle (cdr (assq n gnus-article-mime-handle-alist)))) | |
5621 | (when (gnus-article-goto-part n) | |
5622 | (if (equal (car handle) "multipart/alternative") | |
71f56da2 KY |
5623 | (progn |
5624 | (beginning-of-line) ;; Make it toggle subparts | |
5625 | (gnus-article-press-button)) | |
16409b0b GM |
5626 | (when (eq (gnus-mm-display-part handle) 'internal) |
5627 | (gnus-set-window-start))))))) | |
5628 | ||
e0bad764 DL |
5629 | (defsubst gnus-article-mime-total-parts () |
5630 | (if (bufferp (car gnus-article-mime-handles)) | |
5631 | 1 ;; single part | |
5632 | (1- (length gnus-article-mime-handles)))) | |
5633 | ||
16409b0b GM |
5634 | (defun gnus-mm-display-part (handle) |
5635 | "Display HANDLE and fix MIME button." | |
5636 | (let ((id (get-text-property (point) 'gnus-part)) | |
5637 | (point (point)) | |
23f87bed | 5638 | (inhibit-read-only t)) |
16409b0b GM |
5639 | (forward-line 1) |
5640 | (prog1 | |
5641 | (let ((window (selected-window)) | |
5642 | (mail-parse-charset gnus-newsgroup-charset) | |
a1506d29 | 5643 | (mail-parse-ignored-charsets |
23f87bed | 5644 | (if (gnus-buffer-live-p gnus-summary-buffer) |
01c52d31 | 5645 | (with-current-buffer gnus-summary-buffer |
23f87bed MB |
5646 | gnus-newsgroup-ignored-charsets) |
5647 | nil))) | |
16409b0b GM |
5648 | (save-excursion |
5649 | (unwind-protect | |
23f87bed | 5650 | (let ((win (gnus-get-buffer-window (current-buffer) t)) |
16409b0b GM |
5651 | (beg (point))) |
5652 | (when win | |
5653 | (select-window win)) | |
5654 | (goto-char point) | |
5655 | (forward-line) | |
5656 | (if (mm-handle-displayed-p handle) | |
5657 | ;; This will remove the part. | |
5658 | (mm-display-part handle) | |
5659 | (save-restriction | |
23f87bed MB |
5660 | (narrow-to-region (point) |
5661 | (if (eobp) (point) (1+ (point)))) | |
b0b63450 | 5662 | (gnus-bind-safe-url-regexp (mm-display-part handle)) |
16409b0b GM |
5663 | ;; We narrow to the part itself and |
5664 | ;; then call the treatment functions. | |
5665 | (goto-char (point-min)) | |
5666 | (forward-line 1) | |
5667 | (narrow-to-region (point) (point-max)) | |
5668 | (gnus-treat-article | |
5669 | nil id | |
e0bad764 | 5670 | (gnus-article-mime-total-parts) |
16409b0b | 5671 | (mm-handle-media-type handle))))) |
23f87bed MB |
5672 | (if (window-live-p window) |
5673 | (select-window window))))) | |
16409b0b | 5674 | (goto-char point) |
23f87bed | 5675 | (gnus-delete-line) |
16409b0b GM |
5676 | (gnus-insert-mime-button |
5677 | handle id (list (mm-handle-displayed-p handle))) | |
5678 | (goto-char point)))) | |
5679 | ||
5680 | (defun gnus-article-goto-part (n) | |
5681 | "Go to MIME part N." | |
9efcd224 KY |
5682 | (when gnus-break-pages |
5683 | (widen)) | |
95de0327 KY |
5684 | (prog1 |
5685 | (let ((start (text-property-any (point-min) (point-max) 'gnus-part n)) | |
5686 | part handle end next handles) | |
5687 | (when start | |
5688 | (goto-char start) | |
5689 | (if (setq handle (get-text-property start 'gnus-data)) | |
5690 | start | |
5691 | ;; Go to the displayed subpart, assuming this is | |
5692 | ;; multipart/alternative. | |
5693 | (setq part start | |
5694 | end (point-at-eol)) | |
5695 | (while (and (not handle) | |
5696 | part | |
5697 | (< part end) | |
5698 | (setq next (text-property-not-all part end | |
5699 | 'gnus-data nil))) | |
5700 | (setq part next | |
5701 | handle (get-text-property part 'gnus-data)) | |
5702 | (push (cons handle part) handles) | |
5703 | (unless (mm-handle-displayed-p handle) | |
5704 | (setq handle nil | |
5705 | part (text-property-any part end 'gnus-data nil)))) | |
5706 | (unless handle | |
5707 | ;; No subpart is displayed, so we find preferred one. | |
5708 | (setq part | |
5709 | (cdr (assq (mm-preferred-alternative | |
5710 | (nreverse (mapcar 'car handles))) | |
5711 | handles)))) | |
5712 | (if part | |
5713 | (goto-char (1+ part)) | |
5714 | start)))) | |
5715 | (when gnus-break-pages | |
5716 | (gnus-narrow-to-page)))) | |
16409b0b GM |
5717 | |
5718 | (defun gnus-insert-mime-button (handle gnus-tmp-id &optional displayed) | |
5719 | (let ((gnus-tmp-name | |
247c22e1 | 5720 | (or (mm-handle-filename handle) |
23f87bed | 5721 | (mail-content-type-get (mm-handle-type handle) 'url) |
16409b0b GM |
5722 | "")) |
5723 | (gnus-tmp-type (mm-handle-media-type handle)) | |
4599d0ec | 5724 | (gnus-tmp-description (or (mm-handle-description handle) "")) |
16409b0b GM |
5725 | (gnus-tmp-dots |
5726 | (if (if displayed (car displayed) | |
5727 | (mm-handle-displayed-p handle)) | |
5728 | "" "...")) | |
5729 | (gnus-tmp-length (with-current-buffer (mm-handle-buffer handle) | |
5730 | (buffer-size))) | |
5731 | gnus-tmp-type-long b e) | |
5732 | (when (string-match ".*/" gnus-tmp-name) | |
5733 | (setq gnus-tmp-name (replace-match "" t t gnus-tmp-name))) | |
5734 | (setq gnus-tmp-type-long (concat gnus-tmp-type | |
5735 | (and (not (equal gnus-tmp-name "")) | |
5736 | (concat "; " gnus-tmp-name)))) | |
23f87bed MB |
5737 | (unless (equal gnus-tmp-description "") |
5738 | (setq gnus-tmp-type-long (concat " --- " gnus-tmp-type-long))) | |
16409b0b GM |
5739 | (unless (bolp) |
5740 | (insert "\n")) | |
5741 | (setq b (point)) | |
5742 | (gnus-eval-format | |
5743 | gnus-mime-button-line-format gnus-mime-button-line-format-alist | |
01c52d31 MB |
5744 | `(keymap ,gnus-mime-button-map |
5745 | gnus-callback gnus-mm-display-part | |
5746 | gnus-part ,gnus-tmp-id | |
5747 | article-type annotation | |
f0867027 KY |
5748 | gnus-data ,handle |
5749 | rear-nonsticky t)) | |
23f87bed MB |
5750 | (setq e (if (bolp) |
5751 | ;; Exclude a newline. | |
5752 | (1- (point)) | |
5753 | (point))) | |
01c52d31 MB |
5754 | (when gnus-article-button-face |
5755 | (gnus-overlay-put (gnus-make-overlay b e nil t) | |
5756 | 'face gnus-article-button-face)) | |
16409b0b GM |
5757 | (widget-convert-button |
5758 | 'link b e | |
5759 | :mime-handle handle | |
5760 | :action 'gnus-widget-press-button | |
5761 | :button-keymap gnus-mime-button-map | |
5762 | :help-echo | |
5843126b | 5763 | (lambda (widget) |
16409b0b GM |
5764 | ;; Needed to properly clear the message due to a bug in |
5765 | ;; wid-edit (XEmacs only). | |
5766 | (if (boundp 'help-echo-owns-message) | |
5767 | (setq help-echo-owns-message t)) | |
5768 | (format | |
5769 | "%S: %s the MIME part; %S: more options" | |
5770 | (aref gnus-mouse-2 0) | |
5843126b | 5771 | (if (mm-handle-displayed-p (widget-get widget :mime-handle)) |
16409b0b GM |
5772 | "hide" "show") |
5773 | (aref gnus-down-mouse-3 0)))))) | |
5774 | ||
5775 | (defun gnus-widget-press-button (elems el) | |
5776 | (goto-char (widget-get elems :from)) | |
5777 | (gnus-article-press-button)) | |
5778 | ||
5779 | (defvar gnus-displaying-mime nil) | |
5780 | ||
5781 | (defun gnus-display-mime (&optional ihandles) | |
5782 | "Display the MIME parts." | |
5783 | (save-excursion | |
5784 | (save-selected-window | |
5785 | (let ((window (get-buffer-window gnus-article-buffer)) | |
5786 | (point (point))) | |
5787 | (when window | |
5788 | (select-window window) | |
5789 | ;; We have to do this since selecting the window | |
5790 | ;; may change the point. So we set the window point. | |
5791 | (set-window-point window point))) | |
73043f7d MB |
5792 | (let ((handles ihandles) |
5793 | (inhibit-read-only t) | |
5794 | handle) | |
5795 | (cond (handles) | |
5796 | ((setq handles (mm-dissect-buffer nil gnus-article-loose-mime)) | |
5797 | (when gnus-article-emulate-mime | |
5798 | (mm-uu-dissect-text-parts handles))) | |
5799 | (gnus-article-emulate-mime | |
5800 | (setq handles (mm-uu-dissect)))) | |
16409b0b GM |
5801 | (when (and (not ihandles) |
5802 | (not gnus-displaying-mime)) | |
5803 | ;; Top-level call; we clean up. | |
5804 | (when gnus-article-mime-handles | |
5805 | (mm-destroy-parts gnus-article-mime-handles) | |
5806 | (setq gnus-article-mime-handle-alist nil));; A trick. | |
5807 | (setq gnus-article-mime-handles handles) | |
5808 | ;; We allow users to glean info from the handles. | |
5809 | (when gnus-article-mime-part-function | |
5810 | (gnus-mime-part-function handles))) | |
5811 | (if (and handles | |
5812 | (or (not (stringp (car handles))) | |
5813 | (cdr handles))) | |
5814 | (progn | |
5815 | (when (and (not ihandles) | |
5816 | (not gnus-displaying-mime)) | |
5817 | ;; Clean up for mime parts. | |
5818 | (article-goto-body) | |
5819 | (delete-region (point) (point-max))) | |
5820 | (let ((gnus-displaying-mime t)) | |
5821 | (gnus-mime-display-part handles))) | |
5822 | (save-restriction | |
5823 | (article-goto-body) | |
5824 | (narrow-to-region (point) (point-max)) | |
389b76fa | 5825 | (gnus-treat-article nil 1 1 "text/plain") |
16409b0b GM |
5826 | (widen))) |
5827 | (unless ihandles | |
5828 | ;; Highlight the headers. | |
5829 | (save-excursion | |
5830 | (save-restriction | |
5831 | (article-goto-body) | |
5832 | (narrow-to-region (point-min) (point)) | |
31640842 | 5833 | (gnus-article-save-original-date |
f362b760 MB |
5834 | (gnus-treat-article 'head))))))) |
5835 | ;; Cope with broken MIME messages. | |
5836 | (goto-char (point-max)) | |
5837 | (unless (bolp) | |
5838 | (insert "\n")))) | |
16409b0b | 5839 | |
23f87bed MB |
5840 | (defcustom gnus-mime-display-multipart-as-mixed nil |
5841 | "Display \"multipart\" parts as \"multipart/mixed\". | |
5842 | ||
5843 | If t, it overrides nil values of | |
5844 | `gnus-mime-display-multipart-alternative-as-mixed' and | |
5845 | `gnus-mime-display-multipart-related-as-mixed'." | |
5846 | :group 'gnus-article-mime | |
5847 | :type 'boolean) | |
5848 | ||
5849 | (defcustom gnus-mime-display-multipart-alternative-as-mixed nil | |
5850 | "Display \"multipart/alternative\" parts as \"multipart/mixed\"." | |
bf247b6e | 5851 | :version "22.1" |
23f87bed MB |
5852 | :group 'gnus-article-mime |
5853 | :type 'boolean) | |
5854 | ||
5855 | (defcustom gnus-mime-display-multipart-related-as-mixed nil | |
5856 | "Display \"multipart/related\" parts as \"multipart/mixed\". | |
5857 | ||
5858 | If displaying \"text/html\" is discouraged \(see | |
5859 | `mm-discouraged-alternatives'\) images or other material inside a | |
5860 | \"multipart/related\" part might be overlooked when this variable is nil." | |
bf247b6e | 5861 | :version "22.1" |
23f87bed MB |
5862 | :group 'gnus-article-mime |
5863 | :type 'boolean) | |
16409b0b GM |
5864 | |
5865 | (defun gnus-mime-display-part (handle) | |
5866 | (cond | |
430d3ed7 MB |
5867 | ;; Maybe a broken MIME message. |
5868 | ((null handle)) | |
16409b0b GM |
5869 | ;; Single part. |
5870 | ((not (stringp (car handle))) | |
5871 | (gnus-mime-display-single handle)) | |
5872 | ;; User-defined multipart | |
5873 | ((cdr (assoc (car handle) gnus-mime-multipart-functions)) | |
5874 | (funcall (cdr (assoc (car handle) gnus-mime-multipart-functions)) | |
5875 | handle)) | |
5876 | ;; multipart/alternative | |
5877 | ((and (equal (car handle) "multipart/alternative") | |
23f87bed MB |
5878 | (not (or gnus-mime-display-multipart-as-mixed |
5879 | gnus-mime-display-multipart-alternative-as-mixed))) | |
16409b0b GM |
5880 | (let ((id (1+ (length gnus-article-mime-handle-alist)))) |
5881 | (push (cons id handle) gnus-article-mime-handle-alist) | |
5882 | (gnus-mime-display-alternative (cdr handle) nil nil id))) | |
5883 | ;; multipart/related | |
5884 | ((and (equal (car handle) "multipart/related") | |
23f87bed MB |
5885 | (not (or gnus-mime-display-multipart-as-mixed |
5886 | gnus-mime-display-multipart-related-as-mixed))) | |
16409b0b GM |
5887 | ;;;!!!We should find the start part, but we just default |
5888 | ;;;!!!to the first part. | |
23f87bed MB |
5889 | ;;(gnus-mime-display-part (cadr handle)) |
5890 | ;;;!!! Most multipart/related is an HTML message plus images. | |
5891 | ;;;!!! Unfortunately we are unable to let W3 display those | |
5892 | ;;;!!! included images, so we just display it as a mixed multipart. | |
5893 | ;;(gnus-mime-display-mixed (cdr handle)) | |
5894 | ;;;!!! No, w3 can display everything just fine. | |
16409b0b | 5895 | (gnus-mime-display-part (cadr handle))) |
23f87bed MB |
5896 | ((equal (car handle) "multipart/signed") |
5897 | (gnus-add-wash-type 'signed) | |
5898 | (gnus-mime-display-security handle)) | |
5899 | ((equal (car handle) "multipart/encrypted") | |
5900 | (gnus-add-wash-type 'encrypted) | |
5901 | (gnus-mime-display-security handle)) | |
16409b0b GM |
5902 | ;; Other multiparts are handled like multipart/mixed. |
5903 | (t | |
5904 | (gnus-mime-display-mixed (cdr handle))))) | |
5905 | ||
5906 | (defun gnus-mime-part-function (handles) | |
5907 | (if (stringp (car handles)) | |
5908 | (mapcar 'gnus-mime-part-function (cdr handles)) | |
5909 | (funcall gnus-article-mime-part-function handles))) | |
5910 | ||
5911 | (defun gnus-mime-display-mixed (handles) | |
5912 | (mapcar 'gnus-mime-display-part handles)) | |
5913 | ||
5914 | (defun gnus-mime-display-single (handle) | |
5915 | (let ((type (mm-handle-media-type handle)) | |
5916 | (ignored gnus-ignored-mime-types) | |
5917 | (not-attachment t) | |
5918 | (move nil) | |
5919 | display text) | |
5920 | (catch 'ignored | |
5921 | (progn | |
5922 | (while ignored | |
5923 | (when (string-match (pop ignored) type) | |
5924 | (throw 'ignored nil))) | |
b59a9eef KY |
5925 | (if (and (not (and (if (gnus-buffer-live-p gnus-summary-buffer) |
5926 | (with-current-buffer gnus-summary-buffer | |
5927 | gnus-inhibit-images) | |
5928 | gnus-inhibit-images) | |
40de2c6d KY |
5929 | (string-match "\\`image/" type))) |
5930 | (setq not-attachment | |
16409b0b GM |
5931 | (and (not (mm-inline-override-p handle)) |
5932 | (or (not (mm-handle-disposition handle)) | |
5933 | (equal (car (mm-handle-disposition handle)) | |
5934 | "inline") | |
5935 | (mm-attachment-override-p handle)))) | |
5936 | (mm-automatic-display-p handle) | |
23f87bed MB |
5937 | (or (and |
5938 | (mm-inlinable-p handle) | |
5939 | (mm-inlined-p handle)) | |
16409b0b GM |
5940 | (mm-automatic-external-display-p type))) |
5941 | (setq display t) | |
5942 | (when (equal (mm-handle-media-supertype handle) "text") | |
5943 | (setq text t))) | |
e0bad764 DL |
5944 | (let ((id (1+ (length gnus-article-mime-handle-alist))) |
5945 | beg) | |
16409b0b | 5946 | (push (cons id handle) gnus-article-mime-handle-alist) |
531bedc3 MB |
5947 | (when (and display |
5948 | (equal (mm-handle-media-supertype handle) "message")) | |
5949 | (insert-char | |
5950 | ?\n | |
5951 | (cond ((not (bolp)) 2) | |
5952 | ((or (bobp) (eq (char-before (1- (point))) ?\n)) 0) | |
5953 | (t 1)))) | |
16409b0b | 5954 | (when (or (not display) |
3e3ab3ab KY |
5955 | (not (gnus-unbuttonized-mime-type-p type)) |
5956 | (eq id gnus-mime-buttonized-part-id)) | |
16409b0b GM |
5957 | (gnus-insert-mime-button |
5958 | handle id (list (or display (and not-attachment text)))) | |
5959 | (gnus-article-insert-newline) | |
23f87bed | 5960 | ;; Remember modify the number of forward lines. |
e0bad764 DL |
5961 | (setq move t)) |
5962 | (setq beg (point)) | |
16409b0b GM |
5963 | (cond |
5964 | (display | |
5965 | (when move | |
23f87bed | 5966 | (forward-line -1) |
16409b0b GM |
5967 | (setq beg (point))) |
5968 | (let ((mail-parse-charset gnus-newsgroup-charset) | |
a1506d29 | 5969 | (mail-parse-ignored-charsets |
16409b0b GM |
5970 | (save-excursion (condition-case () |
5971 | (set-buffer gnus-summary-buffer) | |
5972 | (error)) | |
5973 | gnus-newsgroup-ignored-charsets))) | |
b0b63450 | 5974 | (gnus-bind-safe-url-regexp (mm-display-part handle t))) |
16409b0b GM |
5975 | (goto-char (point-max))) |
5976 | ((and text not-attachment) | |
5977 | (when move | |
23f87bed | 5978 | (forward-line -1) |
16409b0b GM |
5979 | (setq beg (point))) |
5980 | (gnus-article-insert-newline) | |
f205c6e7 | 5981 | (mm-display-inline handle) |
16409b0b GM |
5982 | (goto-char (point-max)))) |
5983 | ;; Do highlighting. | |
5984 | (save-excursion | |
5985 | (save-restriction | |
5986 | (narrow-to-region beg (point)) | |
01c52d31 MB |
5987 | (if (eq handle gnus-article-mime-handles) |
5988 | ;; The format=flowed case. | |
5989 | (gnus-treat-article nil 1 1 (mm-handle-media-type handle)) | |
5990 | ;; Don't count signature parts that are never displayed. | |
5991 | ;; The part number should be re-calculated supposing this | |
5992 | ;; might be a message/rfc822 part. | |
5993 | (let (handles) | |
5994 | (dolist (part gnus-article-mime-handles) | |
5995 | (unless (or (stringp part) | |
5996 | (equal (car (mm-handle-type part)) | |
5997 | "application/pgp-signature")) | |
5998 | (push part handles))) | |
5999 | (gnus-treat-article | |
6000 | nil (length (memq handle handles)) (length handles) | |
6001 | (mm-handle-media-type handle))))))))))) | |
16409b0b GM |
6002 | |
6003 | (defun gnus-unbuttonized-mime-type-p (type) | |
6004 | "Say whether TYPE is to be unbuttonized." | |
6005 | (unless gnus-inhibit-mime-unbuttonizing | |
23f87bed MB |
6006 | (when (catch 'found |
6007 | (let ((types gnus-unbuttonized-mime-types)) | |
6008 | (while types | |
6009 | (when (string-match (pop types) type) | |
6010 | (throw 'found t))))) | |
6011 | (not (catch 'found | |
6012 | (let ((types gnus-buttonized-mime-types)) | |
6013 | (while types | |
6014 | (when (string-match (pop types) type) | |
6015 | (throw 'found t))))))))) | |
16409b0b GM |
6016 | |
6017 | (defun gnus-article-insert-newline () | |
6018 | "Insert a newline, but mark it as undeletable." | |
6019 | (gnus-put-text-property | |
6020 | (point) (progn (insert "\n") (point)) 'gnus-undeletable t)) | |
6021 | ||
6022 | (defun gnus-mime-display-alternative (handles &optional preferred ibegend id) | |
6023 | (let* ((preferred (or preferred (mm-preferred-alternative handles))) | |
6024 | (ihandles handles) | |
6025 | (point (point)) | |
23f87bed | 6026 | handle (inhibit-read-only t) from props begend not-pref) |
16409b0b GM |
6027 | (save-window-excursion |
6028 | (save-restriction | |
6029 | (when ibegend | |
6030 | (narrow-to-region (car ibegend) | |
6031 | (or (cdr ibegend) | |
6032 | (progn | |
6033 | (goto-char (car ibegend)) | |
6034 | (forward-line 2) | |
6035 | (point)))) | |
6036 | (delete-region (point-min) (point-max)) | |
6037 | (mm-remove-parts handles)) | |
6038 | (setq begend (list (point-marker))) | |
6039 | ;; Do the toggle. | |
6040 | (unless (setq not-pref (cadr (member preferred ihandles))) | |
6041 | (setq not-pref (car ihandles))) | |
6042 | (when (or ibegend | |
23f87bed | 6043 | (not preferred) |
16409b0b GM |
6044 | (not (gnus-unbuttonized-mime-type-p |
6045 | "multipart/alternative"))) | |
6046 | (gnus-add-text-properties | |
6047 | (setq from (point)) | |
6048 | (progn | |
6049 | (insert (format "%d. " id)) | |
6050 | (point)) | |
6051 | `(gnus-callback | |
6052 | (lambda (handles) | |
6053 | (unless ,(not ibegend) | |
6054 | (setq gnus-article-mime-handle-alist | |
6055 | ',gnus-article-mime-handle-alist)) | |
6056 | (gnus-mime-display-alternative | |
6057 | ',ihandles ',not-pref ',begend ,id)) | |
01c52d31 | 6058 | keymap ,gnus-mime-button-map |
16409b0b GM |
6059 | ,gnus-mouse-face-prop ,gnus-article-mouse-face |
6060 | face ,gnus-article-button-face | |
16409b0b | 6061 | gnus-part ,id |
f0867027 KY |
6062 | article-type multipart |
6063 | rear-nonsticky t)) | |
16409b0b GM |
6064 | (widget-convert-button 'link from (point) |
6065 | :action 'gnus-widget-press-button | |
6066 | :button-keymap gnus-widget-button-keymap) | |
6067 | ;; Do the handles | |
6068 | (while (setq handle (pop handles)) | |
6069 | (gnus-add-text-properties | |
6070 | (setq from (point)) | |
6071 | (progn | |
6072 | (insert (format "(%c) %-18s" | |
6073 | (if (equal handle preferred) ?* ? ) | |
6074 | (mm-handle-media-type handle))) | |
6075 | (point)) | |
6076 | `(gnus-callback | |
6077 | (lambda (handles) | |
6078 | (unless ,(not ibegend) | |
6079 | (setq gnus-article-mime-handle-alist | |
6080 | ',gnus-article-mime-handle-alist)) | |
6081 | (gnus-mime-display-alternative | |
6082 | ',ihandles ',handle ',begend ,id)) | |
01c52d31 | 6083 | keymap ,gnus-mime-button-map |
16409b0b GM |
6084 | ,gnus-mouse-face-prop ,gnus-article-mouse-face |
6085 | face ,gnus-article-button-face | |
16409b0b | 6086 | gnus-part ,id |
f0867027 KY |
6087 | gnus-data ,handle |
6088 | rear-nonsticky t)) | |
16409b0b GM |
6089 | (widget-convert-button 'link from (point) |
6090 | :action 'gnus-widget-press-button | |
6091 | :button-keymap gnus-widget-button-keymap) | |
6092 | (insert " ")) | |
6093 | (insert "\n\n")) | |
6094 | (when preferred | |
6095 | (if (stringp (car preferred)) | |
6096 | (gnus-display-mime preferred) | |
6097 | (let ((mail-parse-charset gnus-newsgroup-charset) | |
a1506d29 | 6098 | (mail-parse-ignored-charsets |
01c52d31 MB |
6099 | (with-current-buffer gnus-summary-buffer |
6100 | gnus-newsgroup-ignored-charsets))) | |
b0b63450 | 6101 | (gnus-bind-safe-url-regexp (mm-display-part preferred)) |
16409b0b GM |
6102 | ;; Do highlighting. |
6103 | (save-excursion | |
6104 | (save-restriction | |
6105 | (narrow-to-region (car begend) (point-max)) | |
6106 | (gnus-treat-article | |
6107 | nil (length gnus-article-mime-handle-alist) | |
e0bad764 | 6108 | (gnus-article-mime-total-parts) |
389b76fa | 6109 | (mm-handle-media-type preferred)))))) |
16409b0b GM |
6110 | (goto-char (point-max)) |
6111 | (setcdr begend (point-marker))))) | |
6112 | (when ibegend | |
6113 | (goto-char point)))) | |
6114 | ||
23f87bed MB |
6115 | (defconst gnus-article-wash-status-strings |
6116 | (let ((alist '((cite "c" "Possible hidden citation text" | |
6117 | " " "All citation text visible") | |
6118 | (headers "h" "Hidden headers" | |
6119 | " " "All headers visible.") | |
6120 | (pgp "p" "Encrypted or signed message status hidden" | |
6121 | " " "No hidden encryption nor digital signature status") | |
6122 | (signature "s" "Signature has been hidden" | |
6123 | " " "Signature is visible") | |
6124 | (overstrike "o" "Overstrike (^H) characters applied" | |
6125 | " " "No overstrike characters applied") | |
6126 | (emphasis "e" "/*_Emphasis_*/ characters applied" | |
6127 | " " "No /*_emphasis_*/ characters applied"))) | |
6128 | result) | |
6129 | (dolist (entry alist result) | |
6130 | (let ((key (nth 0 entry)) | |
6131 | (on (copy-sequence (nth 1 entry))) | |
6132 | (on-help (nth 2 entry)) | |
6133 | (off (copy-sequence (nth 3 entry))) | |
6134 | (off-help (nth 4 entry))) | |
6135 | (put-text-property 0 1 'help-echo on-help on) | |
6136 | (put-text-property 0 1 'help-echo off-help off) | |
6137 | (push (list key on off) result)))) | |
6138 | "Alist of strings describing wash status in the mode line. | |
6139 | Each entry has the form (KEY ON OF), where the KEY is a symbol | |
6140 | representing the particular washing function, ON is the string to use | |
6141 | in the article mode line when the washing function is active, and OFF | |
6142 | is the string to use when it is inactive.") | |
6143 | ||
6144 | (defun gnus-article-wash-status-entry (key value) | |
6145 | (let ((entry (assoc key gnus-article-wash-status-strings))) | |
6146 | (if value (nth 1 entry) (nth 2 entry)))) | |
6147 | ||
eec82323 LMI |
6148 | (defun gnus-article-wash-status () |
6149 | "Return a string which display status of article washing." | |
01c52d31 | 6150 | (with-current-buffer gnus-article-buffer |
16409b0b GM |
6151 | (let ((cite (memq 'cite gnus-article-wash-types)) |
6152 | (headers (memq 'headers gnus-article-wash-types)) | |
6153 | (boring (memq 'boring-headers gnus-article-wash-types)) | |
6154 | (pgp (memq 'pgp gnus-article-wash-types)) | |
6155 | (pem (memq 'pem gnus-article-wash-types)) | |
23f87bed MB |
6156 | (signed (memq 'signed gnus-article-wash-types)) |
6157 | (encrypted (memq 'encrypted gnus-article-wash-types)) | |
16409b0b GM |
6158 | (signature (memq 'signature gnus-article-wash-types)) |
6159 | (overstrike (memq 'overstrike gnus-article-wash-types)) | |
6160 | (emphasis (memq 'emphasis gnus-article-wash-types))) | |
23f87bed MB |
6161 | (concat |
6162 | (gnus-article-wash-status-entry 'cite cite) | |
6163 | (gnus-article-wash-status-entry 'headers (or headers boring)) | |
6164 | (gnus-article-wash-status-entry 'pgp (or pgp pem signed encrypted)) | |
6165 | (gnus-article-wash-status-entry 'signature signature) | |
6166 | (gnus-article-wash-status-entry 'overstrike overstrike) | |
6167 | (gnus-article-wash-status-entry 'emphasis emphasis))))) | |
6168 | ||
6169 | (defun gnus-add-wash-type (type) | |
6170 | "Add a washing of TYPE to the current status." | |
6171 | (add-to-list 'gnus-article-wash-types type)) | |
6172 | ||
6173 | (defun gnus-delete-wash-type (type) | |
6174 | "Add a washing of TYPE to the current status." | |
6175 | (setq gnus-article-wash-types (delq type gnus-article-wash-types))) | |
6176 | ||
6177 | (defun gnus-add-image (category image) | |
6178 | "Add IMAGE of CATEGORY to the list of displayed images." | |
6179 | (let ((entry (assq category gnus-article-image-alist))) | |
6180 | (unless entry | |
6181 | (setq entry (list category)) | |
6182 | (push entry gnus-article-image-alist)) | |
6183 | (nconc entry (list image)))) | |
6184 | ||
6185 | (defun gnus-delete-images (category) | |
6186 | "Delete all images in CATEGORY." | |
6187 | (let ((entry (assq category gnus-article-image-alist))) | |
6188 | (dolist (image (cdr entry)) | |
6189 | (gnus-remove-image image category)) | |
6190 | (setq gnus-article-image-alist (delq entry gnus-article-image-alist)) | |
6191 | (gnus-delete-wash-type category))) | |
eec82323 | 6192 | |
16409b0b | 6193 | (defalias 'gnus-article-hide-headers-if-wanted 'gnus-article-maybe-hide-headers) |
6748645f LMI |
6194 | |
6195 | (defun gnus-article-maybe-hide-headers () | |
eec82323 LMI |
6196 | "Hide unwanted headers if `gnus-have-all-headers' is nil. |
6197 | Provided for backwards compatibility." | |
16409b0b | 6198 | (when (and (or (not (gnus-buffer-live-p gnus-summary-buffer)) |
01c52d31 MB |
6199 | (not (with-current-buffer gnus-summary-buffer |
6200 | gnus-have-all-headers))) | |
16409b0b GM |
6201 | (not gnus-inhibit-hiding)) |
6202 | (gnus-article-hide-headers))) | |
eec82323 | 6203 | |
89b163db | 6204 | (declare-function shr-put-image "shr" (data alt &optional flags)) |
b9bdaf74 | 6205 | |
89b163db | 6206 | (defun gnus-shr-put-image (data alt &optional flags) |
b9bdaf74 | 6207 | "Put image DATA with a string ALT. Enable image to be deleted." |
abd2f2a4 KY |
6208 | (let ((image (if flags |
6209 | (shr-put-image data (propertize (or alt "*") | |
6210 | 'gnus-image-category 'shr) | |
6211 | flags) | |
6212 | ;; Old `shr-put-image' doesn't take the optional `flags' | |
6213 | ;; argument. | |
6214 | (shr-put-image data (propertize (or alt "*") | |
6215 | 'gnus-image-category 'shr))))) | |
b9bdaf74 KY |
6216 | (when image |
6217 | (gnus-add-image 'shr image)))) | |
6218 | ||
eec82323 LMI |
6219 | ;;; Article savers. |
6220 | ||
6221 | (defun gnus-output-to-file (file-name) | |
26c9afc3 MB |
6222 | "Append the current article to a file named FILE-NAME. |
6223 | If `gnus-article-save-coding-system' is non-nil, it is used to encode | |
6224 | text and used as the value of the coding cookie which is added to the | |
6225 | top of a file. Otherwise, this function saves a raw article without | |
6226 | the coding cookie." | |
6227 | (let* ((artbuf (current-buffer)) | |
6228 | (file-name-coding-system nnmail-pathname-coding-system) | |
6229 | (coding gnus-article-save-coding-system) | |
6230 | (coding-system-for-read (if coding | |
6231 | nil ;; Rely on the coding cookie. | |
6232 | mm-text-coding-system)) | |
6233 | (coding-system-for-write (or coding | |
6234 | mm-text-coding-system-for-write | |
6235 | mm-text-coding-system)) | |
6236 | (exists (file-exists-p file-name))) | |
16409b0b | 6237 | (with-temp-buffer |
26c9afc3 MB |
6238 | (when exists |
6239 | (insert-file-contents file-name) | |
6240 | (goto-char (point-min)) | |
6241 | ;; Remove the existing coding cookie. | |
6242 | (when (looking-at "X-Gnus-Coding-System: .+\n\n") | |
6243 | (delete-region (match-beginning 0) (match-end 0)))) | |
6244 | (goto-char (point-max)) | |
eec82323 LMI |
6245 | (insert-buffer-substring artbuf) |
6246 | ;; Append newline at end of the buffer as separator, and then | |
6247 | ;; save it to file. | |
6248 | (goto-char (point-max)) | |
6249 | (insert "\n") | |
26c9afc3 MB |
6250 | (when coding |
6251 | ;; If the coding system is not suitable to encode the text, | |
6252 | ;; ask a user for a proper one. | |
6253 | (when (fboundp 'select-safe-coding-system) | |
6254 | (setq coding (coding-system-base | |
6255 | (save-window-excursion | |
6256 | (select-safe-coding-system (point-min) (point-max) | |
6257 | coding)))) | |
6258 | (setq coding-system-for-write | |
6259 | (or (cdr (assq coding '((mule-utf-8 . utf-8)))) | |
6260 | coding))) | |
6261 | (goto-char (point-min)) | |
6262 | ;; Add the coding cookie. | |
6263 | (insert (format "X-Gnus-Coding-System: -*- coding: %s; -*-\n\n" | |
6264 | coding-system-for-write))) | |
6265 | (if exists | |
6266 | (progn | |
6267 | (write-region (point-min) (point-max) file-name nil 'no-message) | |
6268 | (message "Appended to %s" file-name)) | |
6269 | (write-region (point-min) (point-max) file-name)))) | |
6270 | t) | |
eec82323 LMI |
6271 | |
6272 | (defun gnus-narrow-to-page (&optional arg) | |
6273 | "Narrow the article buffer to a page. | |
6274 | If given a numerical ARG, move forward ARG pages." | |
6275 | (interactive "P") | |
6276 | (setq arg (if arg (prefix-numeric-value arg) 0)) | |
80de1778 | 6277 | (with-current-buffer gnus-article-buffer |
eec82323 LMI |
6278 | (widen) |
6279 | ;; Remove any old next/prev buttons. | |
6280 | (when (gnus-visual-p 'page-marker) | |
4e7d0221 | 6281 | (let ((inhibit-read-only t)) |
eec82323 LMI |
6282 | (gnus-remove-text-with-property 'gnus-prev) |
6283 | (gnus-remove-text-with-property 'gnus-next))) | |
8f7abae3 MB |
6284 | (let (st nd pt) |
6285 | (when (save-excursion | |
6286 | (cond ((< arg 0) | |
6287 | (if (re-search-backward page-delimiter nil 'move (abs arg)) | |
6288 | (prog1 | |
6289 | (setq nd (match-beginning 0) | |
6290 | pt nd) | |
6291 | (when (re-search-backward page-delimiter nil t) | |
6292 | (setq st (match-end 0)))) | |
6293 | (when (re-search-forward page-delimiter nil t) | |
6294 | (setq nd (match-beginning 0) | |
6295 | pt (point-min))))) | |
6296 | ((> arg 0) | |
6297 | (if (re-search-forward page-delimiter nil 'move arg) | |
6298 | (prog1 | |
6299 | (setq st (match-end 0) | |
6300 | pt st) | |
6301 | (when (re-search-forward page-delimiter nil t) | |
6302 | (setq nd (match-beginning 0)))) | |
6303 | (when (re-search-backward page-delimiter nil t) | |
6304 | (setq st (match-end 0) | |
6305 | pt (point-max))))) | |
6306 | (t | |
6307 | (when (re-search-backward page-delimiter nil t) | |
6308 | (goto-char (setq st (match-end 0)))) | |
6309 | (when (re-search-forward page-delimiter nil t) | |
6310 | (setq nd (match-beginning 0))) | |
6311 | (or st nd)))) | |
6312 | (setq gnus-page-broken t) | |
6313 | (when pt (goto-char pt)) | |
6314 | (narrow-to-region (or st (point-min)) (or nd (point-max))) | |
6315 | (when (gnus-visual-p 'page-marker) | |
6316 | (save-excursion | |
6317 | (when nd | |
6318 | (goto-char nd) | |
6319 | (gnus-insert-next-page-button)) | |
6320 | (when st | |
6321 | (goto-char st) | |
6322 | (gnus-insert-prev-page-button)))))))) | |
eec82323 LMI |
6323 | |
6324 | ;; Article mode commands | |
6325 | ||
6326 | (defun gnus-article-goto-next-page () | |
6327 | "Show the next page of the article." | |
6328 | (interactive) | |
6329 | (when (gnus-article-next-page) | |
6330 | (goto-char (point-min)) | |
6331 | (gnus-article-read-summary-keys nil (gnus-character-to-event ?n)))) | |
6332 | ||
23f87bed | 6333 | |
eec82323 | 6334 | (defun gnus-article-goto-prev-page () |
23f87bed | 6335 | "Show the previous page of the article." |
eec82323 | 6336 | (interactive) |
8f7abae3 | 6337 | (if (save-restriction (widen) (bobp)) ;; Real beginning-of-buffer? |
23f87bed | 6338 | (gnus-article-read-summary-keys nil (gnus-character-to-event ?p)) |
eec82323 LMI |
6339 | (gnus-article-prev-page nil))) |
6340 | ||
23f87bed MB |
6341 | ;; This is cleaner but currently breaks `gnus-pick-mode': |
6342 | ;; | |
6343 | ;; (defun gnus-article-goto-next-page () | |
6344 | ;; "Show the next page of the article." | |
6345 | ;; (interactive) | |
6346 | ;; (gnus-eval-in-buffer-window gnus-summary-buffer | |
6347 | ;; (gnus-summary-next-page))) | |
6348 | ;; | |
6349 | ;; (defun gnus-article-goto-prev-page () | |
6350 | ;; "Show the next page of the article." | |
6351 | ;; (interactive) | |
6352 | ;; (gnus-eval-in-buffer-window gnus-summary-buffer | |
6353 | ;; (gnus-summary-prev-page))) | |
6354 | ||
eec82323 LMI |
6355 | (defun gnus-article-next-page (&optional lines) |
6356 | "Show the next page of the current article. | |
6357 | If end of article, return non-nil. Otherwise return nil. | |
6358 | Argument LINES specifies lines to be scrolled up." | |
6359 | (interactive "p") | |
9153f10d | 6360 | (move-to-window-line (if (featurep 'xemacs) -1 (- -1 scroll-margin))) |
60ece9b0 MB |
6361 | (if (and (not (and gnus-article-over-scroll |
6362 | (> (count-lines (window-start) (point-max)) | |
9153f10d MB |
6363 | (if (featurep 'xemacs) |
6364 | (or lines (1- (window-height))) | |
6365 | (+ (or lines (1- (window-height))) scroll-margin))))) | |
60ece9b0 MB |
6366 | (save-excursion |
6367 | (end-of-line) | |
6368 | (and (pos-visible-in-window-p) ;Not continuation line. | |
647559c2 | 6369 | (>= (point) (point-max))))) |
eec82323 LMI |
6370 | ;; Nothing in this page. |
6371 | (if (or (not gnus-page-broken) | |
6372 | (save-excursion | |
6373 | (save-restriction | |
23f87bed MB |
6374 | (widen) |
6375 | (forward-line) | |
6376 | (eobp)))) ;Real end-of-buffer? | |
6377 | (progn | |
6378 | (when gnus-article-over-scroll | |
6379 | (gnus-article-next-page-1 lines)) | |
6380 | t) ;Nothing more. | |
eec82323 LMI |
6381 | (gnus-narrow-to-page 1) ;Go to next page. |
6382 | nil) | |
6383 | ;; More in this page. | |
23f87bed | 6384 | (gnus-article-next-page-1 lines) |
eec82323 LMI |
6385 | nil)) |
6386 | ||
b1992461 | 6387 | (defun gnus-article-beginning-of-window () |
d8a88581 MB |
6388 | "Move point to the beginning of the window. |
6389 | In Emacs, the point is placed at the line number which `scroll-margin' | |
6390 | specifies." | |
6391 | (if (featurep 'xemacs) | |
b1992461 KY |
6392 | (move-to-window-line 0) |
6393 | ;; There is an obscure bug in Emacs that makes it impossible to | |
6394 | ;; scroll past big pictures in the article buffer. Try to fix | |
6395 | ;; this by adding a sanity check by counting the lines visible. | |
6396 | (when (> (count-lines (window-start) (window-end)) 30) | |
6397 | (move-to-window-line | |
6398 | (min (max 0 scroll-margin) | |
6399 | (max 1 (- (window-height) | |
6400 | (if mode-line-format 1 0) | |
6401 | (if header-line-format 1 0) | |
6402 | 2))))))) | |
d8a88581 | 6403 | |
23f87bed | 6404 | (defun gnus-article-next-page-1 (lines) |
4b91459a | 6405 | (condition-case () |
01baa1e6 G |
6406 | (let ((scroll-in-place nil) |
6407 | (auto-window-vscroll nil)) | |
4b91459a MB |
6408 | (scroll-up lines)) |
6409 | (end-of-buffer | |
6410 | ;; Long lines may cause an end-of-buffer error. | |
6411 | (goto-char (point-max)))) | |
6412 | (gnus-article-beginning-of-window)) | |
23f87bed | 6413 | |
eec82323 LMI |
6414 | (defun gnus-article-prev-page (&optional lines) |
6415 | "Show previous page of current article. | |
6416 | Argument LINES specifies lines to be scrolled down." | |
6417 | (interactive "p") | |
d8a88581 | 6418 | (move-to-window-line 0) |
eec82323 LMI |
6419 | (if (and gnus-page-broken |
6420 | (bobp) | |
6421 | (not (save-restriction (widen) (bobp)))) ;Real beginning-of-buffer? | |
6422 | (progn | |
6423 | (gnus-narrow-to-page -1) ;Go to previous page. | |
6424 | (goto-char (point-max)) | |
60ece9b0 MB |
6425 | (recenter (if gnus-article-over-scroll |
6426 | (if lines | |
9153f10d MB |
6427 | (max (if (featurep 'xemacs) |
6428 | lines | |
6429 | (+ lines scroll-margin)) | |
60ece9b0 MB |
6430 | 3) |
6431 | (- (window-height) 2)) | |
6432 | -1))) | |
c03ac728 MB |
6433 | (prog1 |
6434 | (condition-case () | |
6435 | (let ((scroll-in-place nil)) | |
6436 | (scroll-down lines)) | |
6437 | (beginning-of-buffer | |
6438 | (goto-char (point-min)))) | |
6439 | (gnus-article-beginning-of-window)))) | |
eec82323 | 6440 | |
23f87bed MB |
6441 | (defun gnus-article-only-boring-p () |
6442 | "Decide whether there is only boring text remaining in the article. | |
6443 | Something \"interesting\" is a word of at least two letters that does | |
6444 | not have a face in `gnus-article-boring-faces'." | |
6445 | (when (and gnus-article-skip-boring | |
6446 | (boundp 'gnus-article-boring-faces) | |
6447 | (symbol-value 'gnus-article-boring-faces)) | |
6448 | (save-excursion | |
531bedc3 MB |
6449 | (let ((inhibit-point-motion-hooks t)) |
6450 | (catch 'only-boring | |
6451 | (while (re-search-forward "\\b\\w\\w" nil t) | |
6452 | (forward-char -1) | |
6453 | (when (not (gnus-intersection | |
6454 | (gnus-faces-at (point)) | |
6455 | (symbol-value 'gnus-article-boring-faces))) | |
6456 | (throw 'only-boring nil))) | |
6457 | (throw 'only-boring t)))))) | |
23f87bed | 6458 | |
eec82323 LMI |
6459 | (defun gnus-article-refer-article () |
6460 | "Read article specified by message-id around point." | |
6461 | (interactive) | |
23f87bed | 6462 | (save-excursion |
01c52d31 MB |
6463 | (re-search-backward "[ \t]\\|^" (point-at-bol) t) |
6464 | (re-search-forward "<?news:<?\\|<" (point-at-eol) t) | |
6465 | (if (re-search-forward "[^@ ]+@[^ \t>]+" (point-at-eol) t) | |
23f87bed | 6466 | (let ((msg-id (concat "<" (match-string 0) ">"))) |
eec82323 | 6467 | (set-buffer gnus-summary-buffer) |
23f87bed | 6468 | (gnus-summary-refer-article msg-id)) |
eec82323 LMI |
6469 | (error "No references around point")))) |
6470 | ||
6471 | (defun gnus-article-show-summary () | |
6472 | "Reconfigure windows to show summary buffer." | |
6473 | (interactive) | |
6474 | (if (not (gnus-buffer-live-p gnus-summary-buffer)) | |
6475 | (error "There is no summary buffer for this article buffer") | |
a8151ef7 | 6476 | (gnus-article-set-globals) |
eec82323 | 6477 | (gnus-configure-windows 'article) |
6748645f LMI |
6478 | (gnus-summary-goto-subject gnus-current-article) |
6479 | (gnus-summary-position-point))) | |
eec82323 LMI |
6480 | |
6481 | (defun gnus-article-describe-briefly () | |
6482 | "Describe article mode commands briefly." | |
6483 | (interactive) | |
bdaa75c7 | 6484 | (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"))) |
eec82323 | 6485 | |
16409b0b GM |
6486 | (defun gnus-article-check-buffer () |
6487 | "Beep if not in an article buffer." | |
1b3b87df | 6488 | (unless (derived-mode-p 'gnus-article-mode) |
16409b0b GM |
6489 | (error "Command invoked outside of a Gnus article buffer"))) |
6490 | ||
eec82323 LMI |
6491 | (defun gnus-article-read-summary-keys (&optional arg key not-restore-window) |
6492 | "Read a summary buffer key sequence and execute it from the article buffer." | |
6493 | (interactive "P") | |
16409b0b | 6494 | (gnus-article-check-buffer) |
eec82323 | 6495 | (let ((nosaves |
23f87bed MB |
6496 | '("q" "Q" "c" "r" "\C-c\C-f" "m" "a" "f" |
6497 | "Zc" "ZC" "ZE" "ZQ" "ZZ" "Zn" "ZR" "ZG" "ZN" "ZP" | |
6498 | "=" "^" "\M-^" "|")) | |
6499 | (nosave-but-article | |
0b6799c3 MB |
6500 | '("A " "A<" "A>" "AM" "AP" "AR" "AT" "A\C-?" "A\M-\r" "A\r" "Ab" "Ae" |
6501 | "An" "Ap" [?A (meta return)] [?A delete])) | |
23f87bed | 6502 | (nosave-in-article |
0b6799c3 | 6503 | '("AS" "\C-d")) |
23f87bed MB |
6504 | (up-to-top |
6505 | '("n" "Gn" "p" "Gp")) | |
6506 | keys new-sum-point) | |
80de1778 | 6507 | (with-current-buffer gnus-article-current-summary |
eec82323 | 6508 | (let (gnus-pick-mode) |
95838435 MB |
6509 | (setq unread-command-events (nconc unread-command-events |
6510 | (list (or key last-command-event))) | |
6511 | keys (if (featurep 'xemacs) | |
6512 | (events-to-keys (read-key-sequence nil t)) | |
6513 | (read-key-sequence nil t))))) | |
a1506d29 | 6514 | |
eec82323 LMI |
6515 | (message "") |
6516 | ||
01c52d31 MB |
6517 | (cond |
6518 | ((eq (aref keys (1- (length keys))) ?\C-h) | |
0b6799c3 | 6519 | (gnus-article-describe-bindings (substring keys 0 -1))) |
01c52d31 MB |
6520 | ((or (member keys nosaves) |
6521 | (member keys nosave-but-article) | |
6522 | (member keys nosave-in-article)) | |
6523 | (let (func) | |
6524 | (save-window-excursion | |
6525 | (pop-to-buffer gnus-article-current-summary) | |
6526 | ;; We disable the pick minor mode commands. | |
6527 | (let (gnus-pick-mode) | |
6ab2c7a8 | 6528 | (setq func (key-binding keys t)))) |
01c52d31 MB |
6529 | (if (or (not func) |
6530 | (numberp func)) | |
6531 | (ding) | |
6532 | (unless (member keys nosave-in-article) | |
6533 | (set-buffer gnus-article-current-summary)) | |
89b163db G |
6534 | (when (and (symbolp func) |
6535 | (get func 'disabled)) | |
cb51ba08 | 6536 | (error "Function %s disabled" func)) |
01c52d31 MB |
6537 | (call-interactively func) |
6538 | (setq new-sum-point (point))) | |
6539 | (when (member keys nosave-but-article) | |
6540 | (pop-to-buffer gnus-article-buffer)))) | |
6541 | (t | |
eec82323 LMI |
6542 | ;; These commands should restore window configuration. |
6543 | (let ((obuf (current-buffer)) | |
23f87bed | 6544 | (owin (current-window-configuration)) |
01c52d31 | 6545 | win func in-buffer selected new-sum-start new-sum-hscroll err) |
23f87bed | 6546 | (cond (not-restore-window |
01c52d31 MB |
6547 | (pop-to-buffer gnus-article-current-summary) |
6548 | (setq win (selected-window))) | |
23f87bed MB |
6549 | ((setq win (get-buffer-window gnus-article-current-summary)) |
6550 | (select-window win)) | |
6551 | (t | |
01c52d31 MB |
6552 | (let ((summary-buffer gnus-article-current-summary)) |
6553 | (gnus-configure-windows 'article) | |
6554 | (unless (setq win (get-buffer-window summary-buffer 'visible)) | |
6555 | (let ((gnus-buffer-configuration | |
de0bdfe7 KY |
6556 | '((article ((vertical 1.0 |
6557 | (summary 0.25 point) | |
6558 | (article 1.0))))))) | |
01c52d31 MB |
6559 | (gnus-configure-windows 'article)) |
6560 | (setq win (get-buffer-window summary-buffer 'visible))) | |
6561 | (gnus-select-frame-set-input-focus (window-frame win)) | |
6562 | (select-window win)))) | |
23f87bed MB |
6563 | (setq in-buffer (current-buffer)) |
6564 | ;; We disable the pick minor mode commands. | |
cb51ba08 LI |
6565 | (setq func (let (gnus-pick-mode) |
6566 | (key-binding keys t))) | |
6567 | (when (get func 'disabled) | |
6568 | (error "Function %s disabled" func)) | |
6569 | (if (and func | |
01c52d31 MB |
6570 | (functionp func) |
6571 | (condition-case code | |
6572 | (progn | |
6573 | (call-interactively func) | |
6574 | t) | |
6575 | (error | |
6576 | (setq err code) | |
6577 | nil))) | |
23f87bed | 6578 | (progn |
23f87bed MB |
6579 | (when (eq win (selected-window)) |
6580 | (setq new-sum-point (point) | |
6581 | new-sum-start (window-start win) | |
9a89f5b0 | 6582 | new-sum-hscroll (window-hscroll win))) |
01c52d31 MB |
6583 | (when (or (eq in-buffer (current-buffer)) |
6584 | (when (eq obuf (current-buffer)) | |
6585 | (set-buffer in-buffer) | |
6586 | t)) | |
520aa572 SZ |
6587 | (setq selected (gnus-summary-select-article)) |
6588 | (set-buffer obuf) | |
6589 | (unless not-restore-window | |
6590 | (set-window-configuration owin)) | |
01c52d31 MB |
6591 | (when (and (eq selected 'old) |
6592 | new-sum-point) | |
520aa572 SZ |
6593 | (set-window-start (get-buffer-window (current-buffer)) |
6594 | 1) | |
6595 | (set-window-point (get-buffer-window (current-buffer)) | |
01c52d31 MB |
6596 | (if (article-goto-body) |
6597 | (1- (point)) | |
6598 | (point)))) | |
23f87bed | 6599 | (when (and (not not-restore-window) |
01c52d31 | 6600 | new-sum-point |
4520e527 | 6601 | (window-live-p win) |
01c52d31 | 6602 | (with-current-buffer (window-buffer win) |
1b3b87df | 6603 | (derived-mode-p 'gnus-summary-mode))) |
23f87bed MB |
6604 | (set-window-point win new-sum-point) |
6605 | (set-window-start win new-sum-start) | |
9a89f5b0 | 6606 | (set-window-hscroll win new-sum-hscroll)))) |
23f87bed | 6607 | (set-window-configuration owin) |
01c52d31 MB |
6608 | (if err |
6609 | (signal (car err) (cdr err)) | |
6610 | (ding)))))))) | |
520aa572 | 6611 | |
95838435 MB |
6612 | (defun gnus-article-read-summary-send-keys () |
6613 | (interactive) | |
0b6799c3 | 6614 | (let ((unread-command-events (list (gnus-character-to-event ?S)))) |
95838435 MB |
6615 | (gnus-article-read-summary-keys))) |
6616 | ||
520aa572 | 6617 | (defun gnus-article-describe-key (key) |
95838435 MB |
6618 | "Display documentation of the function invoked by KEY. |
6619 | KEY is a string or a vector." | |
6620 | (interactive (list (let ((cursor-in-echo-area t)) ;; better for XEmacs. | |
6621 | (read-key-sequence "Describe key: ")))) | |
520aa572 | 6622 | (gnus-article-check-buffer) |
95838435 MB |
6623 | (if (memq (key-binding key t) '(gnus-article-read-summary-keys |
6624 | gnus-article-read-summary-send-keys)) | |
80de1778 | 6625 | (with-current-buffer gnus-article-current-summary |
95838435 MB |
6626 | (setq unread-command-events |
6627 | (if (featurep 'xemacs) | |
6628 | (append key nil) | |
6629 | (mapcar (lambda (x) (if (and (integerp x) (>= x 128)) | |
6630 | (list 'meta (- x 128)) | |
6631 | x)) | |
6632 | key))) | |
6633 | (let ((cursor-in-echo-area t) | |
6634 | gnus-pick-mode) | |
6635 | (describe-key (read-key-sequence nil t)))) | |
520aa572 SZ |
6636 | (describe-key key))) |
6637 | ||
6638 | (defun gnus-article-describe-key-briefly (key &optional insert) | |
95838435 MB |
6639 | "Display documentation of the function invoked by KEY. |
6640 | KEY is a string or a vector." | |
6641 | (interactive (list (let ((cursor-in-echo-area t)) ;; better for XEmacs. | |
6642 | (read-key-sequence "Describe key: ")) | |
6643 | current-prefix-arg)) | |
520aa572 | 6644 | (gnus-article-check-buffer) |
95838435 MB |
6645 | (if (memq (key-binding key t) '(gnus-article-read-summary-keys |
6646 | gnus-article-read-summary-send-keys)) | |
80de1778 | 6647 | (with-current-buffer gnus-article-current-summary |
95838435 MB |
6648 | (setq unread-command-events |
6649 | (if (featurep 'xemacs) | |
6650 | (append key nil) | |
6651 | (mapcar (lambda (x) (if (and (integerp x) (>= x 128)) | |
6652 | (list 'meta (- x 128)) | |
6653 | x)) | |
6654 | key))) | |
6655 | (let ((cursor-in-echo-area t) | |
6656 | gnus-pick-mode) | |
6657 | (describe-key-briefly (read-key-sequence nil t) insert))) | |
520aa572 | 6658 | (describe-key-briefly key insert))) |
eec82323 | 6659 | |
0b6799c3 MB |
6660 | ;;`gnus-agent-mode' in gnus-agent.el will define it. |
6661 | (defvar gnus-agent-summary-mode) | |
e9198520 | 6662 | (defvar gnus-draft-mode) |
12ea3d65 | 6663 | (defvar help-xref-stack-item) |
0b6799c3 MB |
6664 | |
6665 | (defun gnus-article-describe-bindings (&optional prefix) | |
6666 | "Show a list of all defined keys, and their definitions. | |
6667 | The optional argument PREFIX, if non-nil, should be a key sequence; | |
6668 | then we display only bindings that start with that prefix." | |
6669 | (interactive) | |
6670 | (gnus-article-check-buffer) | |
6671 | (let ((keymap (copy-keymap gnus-article-mode-map)) | |
6672 | (map (copy-keymap gnus-article-send-map)) | |
6673 | (sumkeys (where-is-internal 'gnus-article-read-summary-keys)) | |
8a908224 | 6674 | parent agent draft) |
0b6799c3 MB |
6675 | (define-key keymap "S" map) |
6676 | (define-key map [t] nil) | |
6677 | (with-current-buffer gnus-article-current-summary | |
8a908224 KY |
6678 | (set-keymap-parent |
6679 | keymap | |
6680 | (if (setq parent (keymap-parent gnus-article-mode-map)) | |
6681 | (prog1 | |
6682 | (setq parent (copy-keymap parent)) | |
6683 | (set-keymap-parent parent (current-local-map))) | |
6684 | (current-local-map))) | |
0b6799c3 | 6685 | (set-keymap-parent map (key-binding "S")) |
8f7abae3 MB |
6686 | (let (key def gnus-pick-mode) |
6687 | (while sumkeys | |
6688 | (setq key (pop sumkeys)) | |
6689 | (cond ((and (vectorp key) (= (length key) 1) | |
6690 | (consp (setq def (aref key 0))) | |
6691 | (numberp (car def)) (numberp (cdr def))) | |
6692 | (when (< (max (car def) (cdr def)) 128) | |
6693 | (setq sumkeys | |
6694 | (append (mapcar | |
6695 | #'vector | |
6696 | (nreverse (gnus-uncompress-range def))) | |
6697 | sumkeys)))) | |
6698 | ((setq def (key-binding key)) | |
6699 | (unless (eq def 'undefined) | |
6700 | (define-key keymap key def)))))) | |
0b6799c3 | 6701 | (when (boundp 'gnus-agent-summary-mode) |
e9198520 MB |
6702 | (setq agent gnus-agent-summary-mode)) |
6703 | (when (boundp 'gnus-draft-mode) | |
6704 | (setq draft gnus-draft-mode))) | |
0b6799c3 MB |
6705 | (with-temp-buffer |
6706 | (use-local-map keymap) | |
6707 | (set (make-local-variable 'gnus-agent-summary-mode) agent) | |
e9198520 | 6708 | (set (make-local-variable 'gnus-draft-mode) draft) |
0b6799c3 MB |
6709 | (describe-bindings prefix)) |
6710 | (let ((item `((lambda (prefix) | |
80de1778 | 6711 | (with-current-buffer ,(current-buffer) |
0b6799c3 MB |
6712 | (gnus-article-describe-bindings prefix))) |
6713 | ,prefix))) | |
269db053 KY |
6714 | ;; Loading `help-mode' here is necessary if `describe-bindings' |
6715 | ;; is replaced with something, e.g. `helm-descbinds'. | |
af69a478 | 6716 | (require 'help-mode) |
5843126b | 6717 | (with-current-buffer (let (help-xref-following) (help-buffer)) |
0b6799c3 MB |
6718 | (setq help-xref-stack-item item))))) |
6719 | ||
23f87bed MB |
6720 | (defun gnus-article-reply-with-original (&optional wide) |
6721 | "Start composing a reply mail to the current message. | |
6722 | The text in the region will be yanked. If the region isn't active, | |
6723 | the entire article will be yanked." | |
95838435 | 6724 | (interactive) |
23f87bed MB |
6725 | (let ((article (cdr gnus-article-current)) |
6726 | contents) | |
1d0df8af | 6727 | (if (not (gnus-region-active-p)) |
23f87bed MB |
6728 | (with-current-buffer gnus-summary-buffer |
6729 | (gnus-summary-reply (list (list article)) wide)) | |
6730 | (setq contents (buffer-substring (point) (mark t))) | |
6731 | ;; Deactivate active regions. | |
6732 | (when (and (boundp 'transient-mark-mode) | |
6733 | transient-mark-mode) | |
6734 | (setq mark-active nil)) | |
6735 | (with-current-buffer gnus-summary-buffer | |
6736 | (gnus-summary-reply | |
6737 | (list (list article contents)) wide))))) | |
6738 | ||
95838435 MB |
6739 | (defun gnus-article-wide-reply-with-original () |
6740 | "Start composing a wide reply mail to the current message. | |
6741 | The text in the region will be yanked. If the region isn't active, | |
6742 | the entire article will be yanked." | |
6743 | (interactive) | |
6744 | (gnus-article-reply-with-original t)) | |
6745 | ||
23f87bed MB |
6746 | (defun gnus-article-followup-with-original () |
6747 | "Compose a followup to the current article. | |
6748 | The text in the region will be yanked. If the region isn't active, | |
6749 | the entire article will be yanked." | |
6750 | (interactive) | |
6751 | (let ((article (cdr gnus-article-current)) | |
6752 | contents) | |
1d0df8af | 6753 | (if (not (gnus-region-active-p)) |
23f87bed MB |
6754 | (with-current-buffer gnus-summary-buffer |
6755 | (gnus-summary-followup (list (list article)))) | |
6756 | (setq contents (buffer-substring (point) (mark t))) | |
6757 | ;; Deactivate active regions. | |
6758 | (when (and (boundp 'transient-mark-mode) | |
6759 | transient-mark-mode) | |
6760 | (setq mark-active nil)) | |
6761 | (with-current-buffer gnus-summary-buffer | |
6762 | (gnus-summary-followup | |
6763 | (list (list article contents))))))) | |
6764 | ||
eec82323 LMI |
6765 | (defun gnus-article-hide (&optional arg force) |
6766 | "Hide all the gruft in the current article. | |
23f87bed MB |
6767 | This means that signatures, cited text and (some) headers will be |
6768 | hidden. | |
eec82323 | 6769 | If given a prefix, show the hidden text instead." |
6748645f | 6770 | (interactive (append (gnus-article-hidden-arg) (list 'force))) |
eec82323 | 6771 | (gnus-article-hide-headers arg) |
16409b0b | 6772 | (gnus-article-hide-list-identifiers arg) |
eec82323 LMI |
6773 | (gnus-article-hide-citation-maybe arg force) |
6774 | (gnus-article-hide-signature arg)) | |
6775 | ||
6748645f LMI |
6776 | (defun gnus-check-group-server () |
6777 | ;; Make sure the connection to the server is alive. | |
6778 | (unless (gnus-server-opened | |
6779 | (gnus-find-method-for-group gnus-newsgroup-name)) | |
6780 | (gnus-check-server (gnus-find-method-for-group gnus-newsgroup-name)) | |
6781 | (gnus-request-group gnus-newsgroup-name t))) | |
6782 | ||
23f87bed MB |
6783 | (eval-when-compile |
6784 | (autoload 'nneething-get-file-name "nneething")) | |
6785 | ||
eec82323 LMI |
6786 | (defun gnus-request-article-this-buffer (article group) |
6787 | "Get an article and insert it into this buffer." | |
6748645f | 6788 | (let (do-update-line sparse-header) |
eec82323 LMI |
6789 | (prog1 |
6790 | (save-excursion | |
6791 | (erase-buffer) | |
6792 | (gnus-kill-all-overlays) | |
6793 | (setq group (or group gnus-newsgroup-name)) | |
6794 | ||
eec82323 LMI |
6795 | ;; Using `gnus-request-article' directly will insert the article into |
6796 | ;; `nntp-server-buffer' - so we'll save some time by not having to | |
6797 | ;; copy it from the server buffer into the article buffer. | |
6798 | ||
6799 | ;; We only request an article by message-id when we do not have the | |
6800 | ;; headers for it, so we'll have to get those. | |
6801 | (when (stringp article) | |
16409b0b | 6802 | (gnus-read-header article)) |
eec82323 LMI |
6803 | |
6804 | ;; If the article number is negative, that means that this article | |
6805 | ;; doesn't belong in this newsgroup (possibly), so we find its | |
6806 | ;; message-id and request it by id instead of number. | |
6807 | (when (and (numberp article) | |
6808 | gnus-summary-buffer | |
6809 | (get-buffer gnus-summary-buffer) | |
6748645f | 6810 | (gnus-buffer-exists-p gnus-summary-buffer)) |
80de1778 | 6811 | (with-current-buffer gnus-summary-buffer |
eec82323 LMI |
6812 | (let ((header (gnus-summary-article-header article))) |
6813 | (when (< article 0) | |
6814 | (cond | |
6815 | ((memq article gnus-newsgroup-sparse) | |
6816 | ;; This is a sparse gap article. | |
6817 | (setq do-update-line article) | |
6818 | (setq article (mail-header-id header)) | |
16409b0b | 6819 | (setq sparse-header (gnus-read-header article)) |
eec82323 LMI |
6820 | (setq gnus-newsgroup-sparse |
6821 | (delq article gnus-newsgroup-sparse))) | |
6822 | ((vectorp header) | |
6823 | ;; It's a real article. | |
6824 | (setq article (mail-header-id header))) | |
6825 | (t | |
6826 | ;; It is an extracted pseudo-article. | |
6827 | (setq article 'pseudo) | |
6828 | (gnus-request-pseudo-article header)))) | |
6829 | ||
6830 | (let ((method (gnus-find-method-for-group | |
6831 | gnus-newsgroup-name))) | |
6748645f LMI |
6832 | (when (and (eq (car method) 'nneething) |
6833 | (vectorp header)) | |
23f87bed MB |
6834 | (let ((dir (nneething-get-file-name |
6835 | (mail-header-id header)))) | |
6836 | (when (and (stringp dir) | |
6837 | (file-directory-p dir)) | |
eec82323 LMI |
6838 | (setq article 'nneething) |
6839 | (gnus-group-enter-directory dir)))))))) | |
6840 | ||
6841 | (cond | |
6842 | ;; Refuse to select canceled articles. | |
6843 | ((and (numberp article) | |
6844 | gnus-summary-buffer | |
6845 | (get-buffer gnus-summary-buffer) | |
6748645f | 6846 | (gnus-buffer-exists-p gnus-summary-buffer) |
01c52d31 | 6847 | (eq (cdr (with-current-buffer gnus-summary-buffer |
eec82323 LMI |
6848 | (assq article gnus-newsgroup-reads))) |
6849 | gnus-canceled-mark)) | |
6850 | nil) | |
6851 | ;; We first check `gnus-original-article-buffer'. | |
6852 | ((and (get-buffer gnus-original-article-buffer) | |
6853 | (numberp article) | |
01c52d31 | 6854 | (with-current-buffer gnus-original-article-buffer |
eec82323 LMI |
6855 | (and (equal (car gnus-original-article) group) |
6856 | (eq (cdr gnus-original-article) article)))) | |
75eda25b SM |
6857 | ;; `insert-buffer-substring' would incorrectly use the |
6858 | ;; equivalent of string-make-multibyte which amount to decoding | |
6859 | ;; with locale-coding-system, causing failure of | |
6860 | ;; subsequent decoding. | |
6861 | (insert (mm-string-to-multibyte | |
6862 | (with-current-buffer gnus-original-article-buffer | |
6863 | (buffer-substring (point-min) (point-max))))) | |
eec82323 LMI |
6864 | 'article) |
6865 | ;; Check the backlog. | |
6866 | ((and gnus-keep-backlog | |
6867 | (gnus-backlog-request-article group article (current-buffer))) | |
6868 | 'article) | |
6869 | ;; Check asynchronous pre-fetch. | |
6870 | ((gnus-async-request-fetched-article group article (current-buffer)) | |
6871 | (gnus-async-prefetch-next group article gnus-summary-buffer) | |
6748645f LMI |
6872 | (when (and (numberp article) gnus-keep-backlog) |
6873 | (gnus-backlog-enter-article group article (current-buffer))) | |
eec82323 LMI |
6874 | 'article) |
6875 | ;; Check the cache. | |
6876 | ((and gnus-use-cache | |
6877 | (numberp article) | |
6878 | (gnus-cache-request-article article group)) | |
6879 | 'article) | |
23f87bed MB |
6880 | ;; Check the agent cache. |
6881 | ((gnus-agent-request-article article group) | |
6882 | 'article) | |
eec82323 | 6883 | ;; Get the article and put into the article buffer. |
16409b0b GM |
6884 | ((or (stringp article) |
6885 | (numberp article)) | |
6886 | (let ((gnus-override-method gnus-override-method) | |
a1506d29 | 6887 | (methods (and (stringp article) |
936d08bb G |
6888 | (with-current-buffer gnus-summary-buffer |
6889 | (gnus-refer-article-methods)))) | |
23f87bed MB |
6890 | (backend (car (gnus-find-method-for-group |
6891 | gnus-newsgroup-name))) | |
16409b0b | 6892 | result |
4e7d0221 | 6893 | (inhibit-read-only t)) |
16409b0b GM |
6894 | (when (and (null gnus-override-method) |
6895 | methods) | |
6896 | (setq gnus-override-method (pop methods))) | |
6897 | (while (not result) | |
16409b0b GM |
6898 | (erase-buffer) |
6899 | (gnus-kill-all-overlays) | |
6900 | (let ((gnus-newsgroup-name group)) | |
6901 | (gnus-check-group-server)) | |
23f87bed MB |
6902 | (cond |
6903 | ((gnus-request-article article group (current-buffer)) | |
16409b0b | 6904 | (when (numberp article) |
a1506d29 | 6905 | (gnus-async-prefetch-next group article |
16409b0b GM |
6906 | gnus-summary-buffer) |
6907 | (when gnus-keep-backlog | |
6908 | (gnus-backlog-enter-article | |
f3b146e9 LMI |
6909 | group article (current-buffer))) |
6910 | (when (and gnus-agent | |
6911 | (gnus-agent-group-covered-p group)) | |
6912 | (gnus-agent-store-article article group))) | |
16409b0b | 6913 | (setq result 'article)) |
23f87bed MB |
6914 | (methods |
6915 | (setq gnus-override-method (pop methods))) | |
6916 | ((not (string-match "^400 " | |
6917 | (nnheader-get-report backend))) | |
6918 | ;; If we get 400 server disconnect, reconnect and | |
6919 | ;; retry; otherwise, assume the article has expired. | |
6920 | (setq result 'done)))) | |
16409b0b | 6921 | (and (eq result 'article) 'article))) |
eec82323 LMI |
6922 | ;; It was a pseudo. |
6923 | (t article))) | |
6924 | ||
6748645f LMI |
6925 | ;; Associate this article with the current summary buffer. |
6926 | (setq gnus-article-current-summary gnus-summary-buffer) | |
6927 | ||
eec82323 LMI |
6928 | ;; Take the article from the original article buffer |
6929 | ;; and place it in the buffer it's supposed to be in. | |
6930 | (when (and (get-buffer gnus-article-buffer) | |
eec82323 LMI |
6931 | (equal (buffer-name (current-buffer)) |
6932 | (buffer-name (get-buffer gnus-article-buffer)))) | |
6933 | (save-excursion | |
6934 | (if (get-buffer gnus-original-article-buffer) | |
6748645f LMI |
6935 | (set-buffer gnus-original-article-buffer) |
6936 | (set-buffer (gnus-get-buffer-create gnus-original-article-buffer)) | |
16409b0b | 6937 | (buffer-disable-undo) |
eec82323 | 6938 | (setq major-mode 'gnus-original-article-mode) |
6748645f | 6939 | (setq buffer-read-only t)) |
23f87bed | 6940 | (let ((inhibit-read-only t)) |
eec82323 LMI |
6941 | (erase-buffer) |
6942 | (insert-buffer-substring gnus-article-buffer)) | |
16409b0b GM |
6943 | (setq gnus-original-article (cons group article))) |
6944 | ||
6945 | ;; Decode charsets. | |
6946 | (run-hooks 'gnus-article-decode-hook) | |
6947 | ;; Mark article as decoded or not. | |
6948 | (setq gnus-article-decoded-p gnus-article-decode-hook)) | |
eec82323 LMI |
6949 | |
6950 | ;; Update sparse articles. | |
6951 | (when (and do-update-line | |
6952 | (or (numberp article) | |
6953 | (stringp article))) | |
6954 | (let ((buf (current-buffer))) | |
6955 | (set-buffer gnus-summary-buffer) | |
6748645f | 6956 | (gnus-summary-update-article do-update-line sparse-header) |
eec82323 | 6957 | (gnus-summary-goto-subject do-update-line nil t) |
23f87bed | 6958 | (set-window-point (gnus-get-buffer-window (current-buffer) t) |
eec82323 LMI |
6959 | (point)) |
6960 | (set-buffer buf)))))) | |
6961 | ||
2526f423 | 6962 | (defun gnus-block-private-groups (group) |
6ed7a66a G |
6963 | (if (or (gnus-news-group-p group) |
6964 | (gnus-member-of-valid 'global group)) | |
2526f423 G |
6965 | ;; Block nothing in news groups. |
6966 | nil | |
6967 | ;; Block everything anywhere else. | |
6968 | ".")) | |
6969 | ||
6970 | (defun gnus-blocked-images () | |
6971 | (if (functionp gnus-blocked-images) | |
6972 | (funcall gnus-blocked-images gnus-newsgroup-name) | |
6973 | gnus-blocked-images)) | |
6974 | ||
eec82323 LMI |
6975 | ;;; |
6976 | ;;; Article editing | |
6977 | ;;; | |
6978 | ||
6979 | (defcustom gnus-article-edit-mode-hook nil | |
6980 | "Hook run in article edit mode buffers." | |
6981 | :group 'gnus-article-various | |
6982 | :type 'hook) | |
6983 | ||
6984 | (defvar gnus-article-edit-done-function nil) | |
6985 | ||
6986 | (defvar gnus-article-edit-mode-map nil) | |
6987 | ||
16409b0b | 6988 | ;; Should we be using derived.el for this? |
eec82323 | 6989 | (unless gnus-article-edit-mode-map |
23f87bed | 6990 | (setq gnus-article-edit-mode-map (make-keymap)) |
16409b0b | 6991 | (set-keymap-parent gnus-article-edit-mode-map text-mode-map) |
eec82323 LMI |
6992 | |
6993 | (gnus-define-keys gnus-article-edit-mode-map | |
23f87bed | 6994 | "\C-c?" describe-mode |
eec82323 | 6995 | "\C-c\C-c" gnus-article-edit-done |
23f87bed MB |
6996 | "\C-c\C-k" gnus-article-edit-exit |
6997 | "\C-c\C-f\C-t" message-goto-to | |
6998 | "\C-c\C-f\C-o" message-goto-from | |
6999 | "\C-c\C-f\C-b" message-goto-bcc | |
7000 | ;;"\C-c\C-f\C-w" message-goto-fcc | |
7001 | "\C-c\C-f\C-c" message-goto-cc | |
7002 | "\C-c\C-f\C-s" message-goto-subject | |
7003 | "\C-c\C-f\C-r" message-goto-reply-to | |
7004 | "\C-c\C-f\C-n" message-goto-newsgroups | |
7005 | "\C-c\C-f\C-d" message-goto-distribution | |
7006 | "\C-c\C-f\C-f" message-goto-followup-to | |
7007 | "\C-c\C-f\C-m" message-goto-mail-followup-to | |
7008 | "\C-c\C-f\C-k" message-goto-keywords | |
7009 | "\C-c\C-f\C-u" message-goto-summary | |
7010 | "\C-c\C-f\C-i" message-insert-or-toggle-importance | |
7011 | "\C-c\C-f\C-a" message-generate-unsubscribed-mail-followup-to | |
7012 | "\C-c\C-b" message-goto-body | |
7013 | "\C-c\C-i" message-goto-signature | |
7014 | ||
7015 | "\C-c\C-t" message-insert-to | |
7016 | "\C-c\C-n" message-insert-newsgroups | |
7017 | "\C-c\C-o" message-sort-headers | |
7018 | "\C-c\C-e" message-elide-region | |
7019 | "\C-c\C-v" message-delete-not-region | |
7020 | "\C-c\C-z" message-kill-to-signature | |
7021 | "\M-\r" message-newline-and-reformat | |
7022 | "\C-c\C-a" mml-attach-file | |
7023 | "\C-a" message-beginning-of-line | |
7024 | "\t" message-tab | |
7025 | "\M-;" comment-region) | |
eec82323 LMI |
7026 | |
7027 | (gnus-define-keys (gnus-article-edit-wash-map | |
7028 | "\C-c\C-w" gnus-article-edit-mode-map) | |
7029 | "f" gnus-article-edit-full-stops)) | |
7030 | ||
23f87bed MB |
7031 | (easy-menu-define |
7032 | gnus-article-edit-mode-field-menu gnus-article-edit-mode-map "" | |
7033 | '("Field" | |
7034 | ["Fetch To" message-insert-to t] | |
7035 | ["Fetch Newsgroups" message-insert-newsgroups t] | |
7036 | "----" | |
7037 | ["To" message-goto-to t] | |
7038 | ["From" message-goto-from t] | |
7039 | ["Subject" message-goto-subject t] | |
7040 | ["Cc" message-goto-cc t] | |
7041 | ["Reply-To" message-goto-reply-to t] | |
7042 | ["Summary" message-goto-summary t] | |
7043 | ["Keywords" message-goto-keywords t] | |
7044 | ["Newsgroups" message-goto-newsgroups t] | |
7045 | ["Followup-To" message-goto-followup-to t] | |
7046 | ["Mail-Followup-To" message-goto-mail-followup-to t] | |
7047 | ["Distribution" message-goto-distribution t] | |
7048 | ["Body" message-goto-body t] | |
7049 | ["Signature" message-goto-signature t])) | |
7050 | ||
4e7d0221 | 7051 | (define-derived-mode gnus-article-edit-mode message-mode "Article Edit" |
eec82323 LMI |
7052 | "Major mode for editing articles. |
7053 | This is an extended text-mode. | |
7054 | ||
7055 | \\{gnus-article-edit-mode-map}" | |
eec82323 LMI |
7056 | (make-local-variable 'gnus-article-edit-done-function) |
7057 | (make-local-variable 'gnus-prev-winconf) | |
80b47379 SZ |
7058 | (set (make-local-variable 'font-lock-defaults) |
7059 | '(message-font-lock-keywords t)) | |
23f87bed MB |
7060 | (set (make-local-variable 'mail-header-separator) "") |
7061 | (set (make-local-variable 'gnus-article-edit-mode) t) | |
7062 | (easy-menu-add message-mode-field-menu message-mode-map) | |
7063 | (mml-mode) | |
eec82323 LMI |
7064 | (setq buffer-read-only nil) |
7065 | (buffer-enable-undo) | |
80b47379 | 7066 | (widen)) |
eec82323 LMI |
7067 | |
7068 | (defun gnus-article-edit (&optional force) | |
7069 | "Edit the current article. | |
7070 | This will have permanent effect only in mail groups. | |
7071 | If FORCE is non-nil, allow editing of articles even in read-only | |
7072 | groups." | |
7073 | (interactive "P") | |
7074 | (when (and (not force) | |
7075 | (gnus-group-read-only-p)) | |
a8151ef7 | 7076 | (error "The current newsgroup does not support article editing")) |
6748645f | 7077 | (gnus-article-date-original) |
eec82323 | 7078 | (gnus-article-edit-article |
16409b0b | 7079 | 'ignore |
6748645f | 7080 | `(lambda (no-highlight) |
16409b0b | 7081 | 'ignore |
eec82323 LMI |
7082 | (gnus-summary-edit-article-done |
7083 | ,(or (mail-header-references gnus-current-headers) "") | |
6748645f | 7084 | ,(gnus-group-read-only-p) ,gnus-summary-buffer no-highlight)))) |
eec82323 | 7085 | |
01c52d31 | 7086 | (defun gnus-article-edit-article (start-func exit-func &optional quiet) |
eec82323 LMI |
7087 | "Start editing the contents of the current article buffer." |
7088 | (let ((winconf (current-window-configuration))) | |
7089 | (set-buffer gnus-article-buffer) | |
0683d241 MB |
7090 | (let ((message-auto-save-directory |
7091 | ;; Don't associate the article buffer with a draft file. | |
7092 | nil)) | |
7093 | (gnus-article-edit-mode)) | |
16409b0b | 7094 | (funcall start-func) |
23f87bed | 7095 | (set-buffer-modified-p nil) |
eec82323 LMI |
7096 | (gnus-configure-windows 'edit-article) |
7097 | (setq gnus-article-edit-done-function exit-func) | |
7098 | (setq gnus-prev-winconf winconf) | |
01c52d31 MB |
7099 | (unless quiet |
7100 | (gnus-message 6 "C-c C-c to end edits")))) | |
eec82323 | 7101 | |
6748645f | 7102 | (defun gnus-article-edit-done (&optional arg) |
eec82323 | 7103 | "Update the article edits and exit." |
6748645f | 7104 | (interactive "P") |
eec82323 LMI |
7105 | (let ((func gnus-article-edit-done-function) |
7106 | (buf (current-buffer)) | |
23f87bed MB |
7107 | (start (window-start)) |
7108 | (p (point)) | |
7109 | (winconf gnus-prev-winconf)) | |
7110 | (widen) ;; Widen it in case that users narrowed the buffer. | |
7111 | (funcall func arg) | |
7112 | (set-buffer buf) | |
7113 | ;; The cache and backlog have to be flushed somewhat. | |
7114 | (when gnus-keep-backlog | |
7115 | (gnus-backlog-remove-article | |
7116 | (car gnus-article-current) (cdr gnus-article-current))) | |
7117 | ;; Flush original article as well. | |
8ccbef23 | 7118 | (gnus-flush-original-article-buffer) |
23f87bed MB |
7119 | (when gnus-use-cache |
7120 | (gnus-cache-update-article | |
7121 | (car gnus-article-current) (cdr gnus-article-current))) | |
7122 | ;; We remove all text props from the article buffer. | |
7123 | (kill-all-local-variables) | |
01c52d31 | 7124 | (set-text-properties (point-min) (point-max) nil) |
23f87bed MB |
7125 | (gnus-article-mode) |
7126 | (set-window-configuration winconf) | |
eec82323 LMI |
7127 | (set-buffer buf) |
7128 | (set-window-start (get-buffer-window buf) start) | |
23f87bed MB |
7129 | (set-window-point (get-buffer-window buf) (point))) |
7130 | (gnus-summary-show-article)) | |
eec82323 | 7131 | |
8ccbef23 G |
7132 | (defun gnus-flush-original-article-buffer () |
7133 | (when (get-buffer gnus-original-article-buffer) | |
7134 | (with-current-buffer gnus-original-article-buffer | |
7135 | (setq gnus-original-article nil)))) | |
7136 | ||
eec82323 LMI |
7137 | (defun gnus-article-edit-exit () |
7138 | "Exit the article editing without updating." | |
7139 | (interactive) | |
23f87bed MB |
7140 | (when (or (not (buffer-modified-p)) |
7141 | (yes-or-no-p "Article modified; kill anyway? ")) | |
7142 | (let ((curbuf (current-buffer)) | |
7143 | (p (point)) | |
7144 | (window-start (window-start))) | |
7145 | (erase-buffer) | |
7146 | (if (gnus-buffer-live-p gnus-original-article-buffer) | |
d8a88581 | 7147 | (insert-buffer-substring gnus-original-article-buffer)) |
23f87bed MB |
7148 | (let ((winconf gnus-prev-winconf)) |
7149 | (kill-all-local-variables) | |
7150 | (gnus-article-mode) | |
7151 | (set-window-configuration winconf) | |
7152 | ;; Tippy-toe some to make sure that point remains where it was. | |
7153 | (save-current-buffer | |
7154 | (set-buffer curbuf) | |
7155 | (set-window-start (get-buffer-window (current-buffer)) window-start) | |
7156 | (goto-char p)))) | |
7157 | (gnus-summary-show-article))) | |
eec82323 LMI |
7158 | |
7159 | (defun gnus-article-edit-full-stops () | |
7160 | "Interactively repair spacing at end of sentences." | |
7161 | (interactive) | |
7162 | (save-excursion | |
7163 | (goto-char (point-min)) | |
7164 | (search-forward-regexp "^$" nil t) | |
7165 | (let ((case-fold-search nil)) | |
7166 | (query-replace-regexp "\\([.!?][])}]* \\)\\([[({A-Z]\\)" "\\1 \\2")))) | |
7167 | ||
7168 | ;;; | |
7169 | ;;; Article highlights | |
7170 | ;;; | |
7171 | ||
7172 | ;; Written by Per Abrahamsen <abraham@iesd.auc.dk>. | |
7173 | ||
7174 | ;;; Internal Variables: | |
7175 | ||
a1506d29 | 7176 | (defcustom gnus-button-url-regexp |
01c52d31 MB |
7177 | (concat |
7178 | "\\b\\(\\(www\\.\\|\\(s?https?\\|ftp\\|file\\|gopher\\|" | |
7179 | "nntp\\|news\\|telnet\\|wais\\|mailto\\|info\\):\\)" | |
7180 | "\\(//[-a-z0-9_.]+:[0-9]*\\)?" | |
7181 | (if (string-match "[[:digit:]]" "1") ;; Support POSIX? | |
7182 | (let ((chars "-a-z0-9_=#$@~%&*+\\/[:word:]") | |
7183 | (punct "!?:;.,")) | |
7184 | (concat | |
7185 | "\\(?:" | |
7186 | ;; Match paired parentheses, e.g. in Wikipedia URLs: | |
9b3ebcb6 | 7187 | ;; http://thread.gmane.org/47B4E3B2.3050402@gmail.com |
02e2beb9 AS |
7188 | "[" chars punct "]+" "(" "[" chars punct "]+" "[" chars "]*)" |
7189 | "\\(?:" "[" chars punct "]+" "[" chars "]" "\\)?" | |
01c52d31 | 7190 | "\\|" |
02e2beb9 | 7191 | "[" chars punct "]+" "[" chars "]" |
01c52d31 MB |
7192 | "\\)")) |
7193 | (concat ;; XEmacs 21.4 doesn't support POSIX. | |
7194 | "\\([-a-z0-9_=!?#$@~%&*+\\/:;.,]\\|\\w\\)+" | |
7195 | "\\([-a-z0-9_=#$@~%&*+\\/]\\|\\w\\)")) | |
7196 | "\\)") | |
eec82323 | 7197 | "Regular expression that matches URLs." |
02e2beb9 | 7198 | :version "24.4" |
eec82323 LMI |
7199 | :group 'gnus-article-buttons |
7200 | :type 'regexp) | |
7201 | ||
23f87bed MB |
7202 | (defcustom gnus-button-valid-fqdn-regexp |
7203 | message-valid-fqdn-regexp | |
7204 | "Regular expression that matches a valid FQDN." | |
bf247b6e | 7205 | :version "22.1" |
23f87bed MB |
7206 | :group 'gnus-article-buttons |
7207 | :type 'regexp) | |
7208 | ||
97f78c9b MB |
7209 | ;; Regexp suggested by Felix Wiemann in <87oeuomcz9.fsf@news2.ososo.de> |
7210 | (defcustom gnus-button-valid-localpart-regexp | |
14e6dc54 | 7211 | "[a-z0-9$%(*-=?[_][^<>\")!;:,{}\n\t @]*" |
97f78c9b MB |
7212 | "Regular expression that matches a localpart of mail addresses or MIDs." |
7213 | :version "22.1" | |
7214 | :group 'gnus-article-buttons | |
7215 | :type 'regexp) | |
7216 | ||
23f87bed MB |
7217 | (defcustom gnus-button-man-handler 'manual-entry |
7218 | "Function to use for displaying man pages. | |
7219 | The function must take at least one argument with a string naming the | |
7220 | man page." | |
bf247b6e | 7221 | :version "22.1" |
23f87bed MB |
7222 | :type '(choice (function-item :tag "Man" manual-entry) |
7223 | (function-item :tag "Woman" woman) | |
7224 | (function :tag "Other")) | |
7225 | :group 'gnus-article-buttons) | |
7226 | ||
23f87bed | 7227 | (defcustom gnus-button-mid-or-mail-regexp |
97f78c9b | 7228 | (concat "\\b\\(<?" gnus-button-valid-localpart-regexp "@" |
23f87bed MB |
7229 | gnus-button-valid-fqdn-regexp |
7230 | ">?\\)\\b") | |
7231 | "Regular expression that matches a message ID or a mail address." | |
bf247b6e | 7232 | :version "22.1" |
23f87bed MB |
7233 | :group 'gnus-article-buttons |
7234 | :type 'regexp) | |
7235 | ||
7236 | (defcustom gnus-button-prefer-mid-or-mail 'gnus-button-mid-or-mail-heuristic | |
7237 | "What to do when the button on a string as \"foo123@bar.invalid\" is pushed. | |
7238 | Strings like this can be either a message ID or a mail address. If it is one | |
7239 | of the symbols `mid' or `mail', Gnus will always assume that the string is a | |
7240 | message ID or a mail address, respectively. If this variable is set to the | |
7241 | symbol `ask', always query the user what do do. If it is a function, this | |
aa819354 | 7242 | function will be called with the string as its only argument. The function |
23f87bed | 7243 | must return `mid', `mail', `invalid' or `ask'." |
bf247b6e | 7244 | :version "22.1" |
23f87bed MB |
7245 | :group 'gnus-article-buttons |
7246 | :type '(choice (function-item :tag "Heuristic function" | |
7247 | gnus-button-mid-or-mail-heuristic) | |
7248 | (const ask) | |
7249 | (const mid) | |
7250 | (const mail))) | |
7251 | ||
7252 | (defcustom gnus-button-mid-or-mail-heuristic-alist | |
7253 | '((-10.0 . ".+\\$.+@") | |
7254 | (-10.0 . "#") | |
7255 | (-10.0 . "\\*") | |
7256 | (-5.0 . "\\+[^+]*\\+.*@") ;; # two plus signs | |
7257 | (-5.0 . "@[Nn][Ee][Ww][Ss]") ;; /\@news/i | |
7258 | (-5.0 . "@.*[Dd][Ii][Aa][Ll][Uu][Pp]") ;; /\@.*dialup/i; | |
7259 | (-1.0 . "^[^a-z]+@") | |
7260 | ;; | |
7261 | (-5.0 . "\\.[0-9][0-9]+.*@") ;; "\.[0-9]{2,}.*\@" | |
7262 | (-5.0 . "[a-z].*[A-Z].*[a-z].*[A-Z].*@") ;; "([a-z].*[A-Z].*){2,}\@" | |
7263 | (-3.0 . "[A-Z][A-Z][a-z][a-z].*@") | |
7264 | (-5.0 . "\\...?.?@") ;; (-5.0 . "\..{1,3}\@") | |
7265 | ;; | |
7266 | (-2.0 . "^[0-9]") | |
7267 | (-1.0 . "^[0-9][0-9]") | |
7268 | ;; | |
7269 | ;; -3.0 /^[0-9][0-9a-fA-F]{2,2}/; | |
7270 | (-3.0 . "^[0-9][0-9a-fA-F][0-9a-fA-F][^0-9a-fA-F]") | |
7271 | ;; -5.0 /^[0-9][0-9a-fA-F]{3,3}/; | |
7272 | (-5.0 . "^[0-9][0-9a-fA-F][0-9a-fA-F][0-9a-fA-F][^0-9a-fA-F]") | |
7273 | ;; | |
7274 | (-3.0 . "[0-9][0-9][0-9][0-9][0-9][^0-9].*@") ;; "[0-9]{5,}.*\@" | |
7275 | (-3.0 . "[0-9][0-9][0-9][0-9][0-9][0-9][0-9][0-9][^0-9].*@") | |
7276 | ;; "[0-9]{8,}.*\@" | |
7277 | (-3.0 | |
7278 | . "[0-9][0-9][0-9][0-9][0-9][0-9][0-9][0-9][0-9][0-9][0-9][0-9].*@") | |
7279 | ;; "[0-9]{12,}.*\@" | |
7280 | ;; compensation for TDMA dated mail addresses: | |
7281 | (25.0 . "-dated-[0-9][0-9][0-9][0-9][0-9][0-9][0-9][0-9]+.*@") | |
7282 | ;; | |
7283 | (-20.0 . "\\.fsf@") ;; Gnus | |
7284 | (-20.0 . "^slrn") | |
7285 | (-20.0 . "^Pine") | |
437ce4be | 7286 | (-20.0 . "^alpine\\.") |
23f87bed MB |
7287 | (-20.0 . "_-_") ;; Subject change in thread |
7288 | ;; | |
7289 | (-20.0 . "\\.ln@") ;; leafnode | |
7290 | (-30.0 . "@ID-[0-9]+\\.[a-zA-Z]+\\.dfncis\\.de") | |
7291 | (-30.0 . "@4[Aa][Xx]\\.com") ;; Forte Agent | |
7292 | ;; | |
7293 | ;; (5.0 . "") ;; $local_part_len <= 7 | |
7294 | (10.0 . "^[^0-9]+@") | |
7295 | (3.0 . "^[^0-9]+[0-9][0-9]?[0-9]?@") | |
7296 | ;; ^[^0-9]+[0-9]{1,3}\@ digits only at end of local part | |
7297 | (3.0 . "\@stud") | |
7298 | ;; | |
7299 | (2.0 . "[a-z][a-z][._-][A-Z][a-z].*@") | |
7300 | ;; | |
7301 | (0.5 . "^[A-Z][a-z]") | |
7302 | (0.5 . "^[A-Z][a-z][a-z]") | |
7303 | (1.5 . "^[A-Z][a-z][A-Z][a-z][^a-z]") ;; ^[A-Z][a-z]{3,3} | |
7304 | (2.0 . "^[A-Z][a-z][A-Z][a-z][a-z][^a-z]")) ;; ^[A-Z][a-z]{4,4} | |
7305 | "An alist of \(RATE . REGEXP\) pairs for `gnus-button-mid-or-mail-heuristic'. | |
7306 | ||
7307 | A negative RATE indicates a message IDs, whereas a positive indicates a mail | |
7308 | address. The REGEXP is processed with `case-fold-search' set to nil." | |
bf247b6e | 7309 | :version "22.1" |
23f87bed MB |
7310 | :group 'gnus-article-buttons |
7311 | :type '(repeat (cons (number :tag "Rate") | |
7312 | (regexp :tag "Regexp")))) | |
7313 | ||
7314 | (defun gnus-button-mid-or-mail-heuristic (mid-or-mail) | |
7315 | "Guess whether MID-OR-MAIL is a message ID or a mail address. | |
7316 | Returns `mid' if MID-OR-MAIL is a message IDs, `mail' if it's a mail | |
7317 | address, `ask' if unsure and `invalid' if the string is invalid." | |
7318 | (let ((case-fold-search nil) | |
7319 | (list gnus-button-mid-or-mail-heuristic-alist) | |
7320 | (result 0) rate regexp lpartlen elem) | |
7321 | (setq lpartlen | |
7322 | (length (gnus-replace-in-string mid-or-mail "^\\(.*\\)@.*$" "\\1"))) | |
7323 | (gnus-message 8 "`%s', length of local part=`%s'." mid-or-mail lpartlen) | |
7324 | ;; Certain special cases... | |
7325 | (when (string-match | |
7326 | (concat | |
7327 | "^0[0-9]+-[0-9][0-9][0-9][0-9]@t-online\\.de$\\|" | |
7328 | "^[0-9]+\\.[0-9]+@compuserve\\|" | |
7329 | "@public\\.gmane\\.org") | |
7330 | mid-or-mail) | |
7331 | (gnus-message 8 "`%s' is a known mail address." mid-or-mail) | |
7332 | (setq result 'mail)) | |
7333 | (when (string-match "@.*@\\| " mid-or-mail) | |
7334 | (gnus-message 8 "`%s' is invalid." mid-or-mail) | |
7335 | (setq result 'invalid)) | |
7336 | ;; Nothing more to do, if result is not a number here... | |
7337 | (when (numberp result) | |
7338 | (while list | |
7339 | (setq elem (car list) | |
7340 | rate (car elem) | |
7341 | regexp (cdr elem) | |
7342 | list (cdr list)) | |
7343 | (when (string-match regexp mid-or-mail) | |
7344 | (setq result (+ result rate)) | |
7345 | (gnus-message | |
7346 | 9 "`%s' matched `%s', rate `%s', result `%s'." | |
7347 | mid-or-mail regexp rate result))) | |
7348 | (when (<= lpartlen 7) | |
7349 | (setq result (+ result 5.0)) | |
7350 | (gnus-message 9 "`%s' matched (<= lpartlen 7), result `%s'." | |
7351 | mid-or-mail result)) | |
7352 | (when (>= lpartlen 12) | |
7353 | (gnus-message 9 "`%s' matched (>= lpartlen 12)" mid-or-mail) | |
7354 | (cond | |
7355 | ((string-match "[0-9][^0-9]+[0-9].*@" mid-or-mail) | |
7356 | ;; Long local part should contain realname if e-mail address, | |
7357 | ;; too many digits: message-id. | |
7358 | ;; $score -= 5.0 + 0.1 * $local_part_len; | |
7359 | (setq rate (* -1.0 (+ 5.0 (* 0.1 lpartlen)))) | |
7360 | (setq result (+ result rate)) | |
7361 | (gnus-message | |
7362 | 9 "Many digits in `%s', rate `%s', result `%s'." | |
7363 | mid-or-mail rate result)) | |
7364 | ((string-match "[^aeiouy][^aeiouy][^aeiouy][^aeiouy]+.*\@" | |
7365 | mid-or-mail) | |
7366 | ;; Too few vowels [^aeiouy]{4,}.*\@ | |
7367 | (setq result (+ result -5.0)) | |
7368 | (gnus-message | |
7369 | 9 "Few vowels in `%s', rate `%s', result `%s'." | |
7370 | mid-or-mail -5.0 result)) | |
7371 | (t | |
7372 | (setq result (+ result 5.0)) | |
7373 | (gnus-message | |
7374 | 9 "`%s', rate `%s', result `%s'." mid-or-mail 5.0 result))))) | |
7375 | (gnus-message 8 "`%s': Final rate is `%s'." mid-or-mail result) | |
7376 | ;; Maybe we should make this a customizable alist: (condition . 'result) | |
7377 | (cond | |
7378 | ((symbolp result) result) | |
7379 | ;; Now convert number into proper results: | |
7380 | ((< result -10.0) 'mid) | |
7381 | ((> result 10.0) 'mail) | |
7382 | (t 'ask)))) | |
7383 | ||
7384 | (defun gnus-button-handle-mid-or-mail (mid-or-mail) | |
7385 | (let* ((pref gnus-button-prefer-mid-or-mail) guessed | |
7386 | (url-mid (concat "news" ":" mid-or-mail)) | |
7387 | (url-mailto (concat "mailto" ":" mid-or-mail))) | |
7388 | (gnus-message 9 "mid-or-mail=%s" mid-or-mail) | |
7389 | (when (fboundp pref) | |
7390 | (setq guessed | |
7391 | ;; get rid of surrounding angles... | |
7392 | (funcall pref | |
7393 | (gnus-replace-in-string mid-or-mail "^<\\|>$" ""))) | |
7394 | (if (or (eq 'mid guessed) (eq 'mail guessed)) | |
7395 | (setq pref guessed) | |
7396 | (setq pref 'ask))) | |
7397 | (if (eq pref 'ask) | |
7398 | (save-window-excursion | |
7399 | (if (y-or-n-p (concat "Is <" mid-or-mail "> a mail address? ")) | |
7400 | (setq pref 'mail) | |
7401 | (setq pref 'mid)))) | |
7402 | (cond ((eq pref 'mid) | |
7403 | (gnus-message 8 "calling `gnus-button-handle-news' %s" url-mid) | |
7404 | (gnus-button-handle-news url-mid)) | |
7405 | ((eq pref 'mail) | |
7406 | (gnus-message 8 "calling `gnus-url-mailto' %s" url-mailto) | |
7407 | (gnus-url-mailto url-mailto)) | |
7408 | (t (gnus-message 3 "Invalid string."))))) | |
7409 | ||
01c52d31 MB |
7410 | (defun gnus-button-handle-custom (fun arg) |
7411 | "Call function FUN on argument ARG. | |
7412 | Both FUN and ARG are supposed to be strings. ARG will be passed | |
7413 | as a symbol to FUN." | |
7414 | (funcall (intern fun) | |
7415 | (if (string-match "^customize-apropos" fun) | |
7416 | arg | |
7417 | (intern arg)))) | |
23f87bed MB |
7418 | |
7419 | (defvar gnus-button-handle-describe-prefix "^\\(C-h\\|<?[Ff]1>?\\)") | |
7420 | ||
23f87bed MB |
7421 | (defun gnus-button-handle-describe-function (url) |
7422 | "Call `describe-function' when pushing the corresponding URL button." | |
7423 | (describe-function | |
7424 | (intern | |
7425 | (gnus-replace-in-string url gnus-button-handle-describe-prefix "")))) | |
7426 | ||
7427 | (defun gnus-button-handle-describe-variable (url) | |
7428 | "Call `describe-variable' when pushing the corresponding URL button." | |
7429 | (describe-variable | |
7430 | (intern | |
7431 | (gnus-replace-in-string url gnus-button-handle-describe-prefix "")))) | |
7432 | ||
7433 | (defun gnus-button-handle-symbol (url) | |
7434 | "Display help on variable or function. | |
7435 | Calls `describe-variable' or `describe-function'." | |
7436 | (let ((sym (intern url))) | |
7437 | (cond | |
7438 | ((fboundp sym) (describe-function sym)) | |
7439 | ((boundp sym) (describe-variable sym)) | |
7440 | (t (gnus-message 3 "`%s' is not a known function of variable." url))))) | |
7441 | ||
7442 | (defun gnus-button-handle-describe-key (url) | |
7443 | "Call `describe-key' when pushing the corresponding URL button." | |
7444 | (let* ((key-string | |
7445 | (gnus-replace-in-string url gnus-button-handle-describe-prefix "")) | |
7446 | (keys (ignore-errors (eval `(kbd ,key-string))))) | |
7447 | (if keys | |
7448 | (describe-key keys) | |
7449 | (gnus-message 3 "Invalid key sequence in button: %s" key-string)))) | |
7450 | ||
7451 | (defun gnus-button-handle-apropos (url) | |
7452 | "Call `apropos' when pushing the corresponding URL button." | |
7453 | (apropos (gnus-replace-in-string url gnus-button-handle-describe-prefix ""))) | |
7454 | ||
7455 | (defun gnus-button-handle-apropos-command (url) | |
7456 | "Call `apropos' when pushing the corresponding URL button." | |
7457 | (apropos-command | |
7458 | (gnus-replace-in-string url gnus-button-handle-describe-prefix ""))) | |
7459 | ||
7460 | (defun gnus-button-handle-apropos-variable (url) | |
7461 | "Call `apropos' when pushing the corresponding URL button." | |
7462 | (funcall | |
7463 | (if (fboundp 'apropos-variable) 'apropos-variable 'apropos) | |
7464 | (gnus-replace-in-string url gnus-button-handle-describe-prefix ""))) | |
7465 | ||
7466 | (defun gnus-button-handle-apropos-documentation (url) | |
7467 | "Call `apropos' when pushing the corresponding URL button." | |
7468 | (funcall | |
7469 | (if (fboundp 'apropos-documentation) 'apropos-documentation 'apropos) | |
7470 | (gnus-replace-in-string url gnus-button-handle-describe-prefix ""))) | |
7471 | ||
7472 | (defun gnus-button-handle-library (url) | |
7473 | "Call `locate-library' when pushing the corresponding URL button." | |
7474 | (gnus-message 9 "url=`%s'" url) | |
7475 | (let* ((lib (locate-library url)) | |
7476 | (file (gnus-replace-in-string (or lib "") "\.elc" ".el"))) | |
7477 | (if (not lib) | |
7478 | (gnus-message 1 "Cannot locale library `%s'." url) | |
7479 | (find-file-read-only file)))) | |
7480 | ||
23f87bed MB |
7481 | (defcustom gnus-button-man-level 5 |
7482 | "*Integer that says how many man-related buttons Gnus will show. | |
7483 | The higher the number, the more buttons will appear and the more false | |
7484 | positives are possible. Note that you can set this variable local to | |
7485 | specific groups. Setting it higher in Unix groups is probably a good idea. | |
7486 | See Info node `(gnus)Group Parameters' and the variable `gnus-parameters' on | |
7487 | how to set variables in specific groups." | |
bf247b6e | 7488 | :version "22.1" |
23f87bed MB |
7489 | :group 'gnus-article-buttons |
7490 | :link '(custom-manual "(gnus)Group Parameters") | |
7491 | :type 'integer) | |
7492 | ||
7493 | (defcustom gnus-button-emacs-level 5 | |
7494 | "*Integer that says how many emacs-related buttons Gnus will show. | |
7495 | The higher the number, the more buttons will appear and the more false | |
7496 | positives are possible. Note that you can set this variable local to | |
7497 | specific groups. Setting it higher in Emacs or Gnus related groups is | |
7498 | probably a good idea. See Info node `(gnus)Group Parameters' and the variable | |
7499 | `gnus-parameters' on how to set variables in specific groups." | |
bf247b6e | 7500 | :version "22.1" |
23f87bed MB |
7501 | :group 'gnus-article-buttons |
7502 | :link '(custom-manual "(gnus)Group Parameters") | |
7503 | :type 'integer) | |
7504 | ||
7505 | (defcustom gnus-button-message-level 5 | |
7506 | "*Integer that says how many buttons for news or mail messages will appear. | |
7507 | The higher the number, the more buttons will appear and the more false | |
7508 | positives are possible." | |
7509 | ;; mail addresses, MIDs, URLs for news, ... | |
bf247b6e | 7510 | :version "22.1" |
23f87bed MB |
7511 | :group 'gnus-article-buttons |
7512 | :type 'integer) | |
7513 | ||
7514 | (defcustom gnus-button-browse-level 5 | |
7515 | "*Integer that says how many buttons for browsing will appear. | |
7516 | The higher the number, the more buttons will appear and the more false | |
7517 | positives are possible." | |
7518 | ;; stuff handled by `browse-url' or `gnus-button-embedded-url' | |
bf247b6e | 7519 | :version "22.1" |
23f87bed MB |
7520 | :group 'gnus-article-buttons |
7521 | :type 'integer) | |
7522 | ||
eec82323 | 7523 | (defcustom gnus-button-alist |
23f87bed MB |
7524 | '(("<\\(url:[>\n\t ]*?\\)?\\(nntp\\|news\\):[>\n\t ]*\\([^>\n\t ]*@[^>\n\t ]*\\)>" |
7525 | 0 (>= gnus-button-message-level 0) gnus-button-handle-news 3) | |
97f78c9b MB |
7526 | ((concat "\\b\\(nntp\\|news\\):\\(" |
7527 | gnus-button-valid-localpart-regexp "@[a-z0-9.-]+[a-z]\\)") | |
7528 | 0 t gnus-button-handle-news 2) | |
23f87bed MB |
7529 | ("\\(\\b<\\(url:[>\n\t ]*\\)?\\(nntp\\|news\\):[>\n\t ]*\\(//\\)?\\([^>\n\t ]*\\)>\\)" |
7530 | 1 (>= gnus-button-message-level 0) gnus-button-fetch-group 5) | |
7531 | ("\\b\\(nntp\\|news\\):\\(//\\)?\\([^'\">\n\t ]+\\)" | |
7532 | 0 (>= gnus-button-message-level 0) gnus-button-fetch-group 3) | |
7533 | ;; RFC 2392 (Don't allow `/' in domain part --> CID) | |
7534 | ("\\bmid:\\(//\\)?\\([^'\">\n\t ]+@[^'\">\n\t /]+\\)" | |
7535 | 0 (>= gnus-button-message-level 0) gnus-button-message-id 2) | |
7536 | ("\\bin\\( +article\\| +message\\)? +\\(<\\([^\n @<>]+@[^\n @<>]+\\)>\\)" | |
7537 | 2 (>= gnus-button-message-level 0) gnus-button-message-id 3) | |
01c52d31 MB |
7538 | ("\\b\\(mid\\|message-id\\):? +\\(<\\([^\n @<>]+@[^\n @<>]+\\)>\\)" |
7539 | 2 (>= gnus-button-message-level 0) gnus-button-message-id 3) | |
23f87bed MB |
7540 | ("\\(<URL: *\\)mailto: *\\([^> \n\t]+\\)>" |
7541 | 0 (>= gnus-button-message-level 0) gnus-url-mailto 2) | |
7542 | ;; RFC 2368 (The mailto URL scheme) | |
531e5812 | 7543 | ("\\bmailto:\\([-a-z.@_+0-9%=?&/]+\\)" |
23f87bed MB |
7544 | 0 (>= gnus-button-message-level 0) gnus-url-mailto 1) |
7545 | ("\\bmailto:\\([^ \n\t]+\\)" | |
7546 | 0 (>= gnus-button-message-level 0) gnus-url-mailto 1) | |
9eb59592 MB |
7547 | ;; Info Konqueror style <info:/foo/bar baz>. |
7548 | ;; Must come before " Gnus home-grown style". | |
7549 | ("\\binfo://?\\([^'\">\n\t]+\\)" | |
7550 | 0 (>= gnus-button-emacs-level 1) gnus-button-handle-info-url 1) | |
7551 | ;; Info, Gnus home-grown style (deprecated) <info://foo/bar+baz> | |
23f87bed MB |
7552 | ("\\binfo://\\([^'\">\n\t ]+\\)" |
7553 | 0 (>= gnus-button-emacs-level 1) gnus-button-handle-info-url 1) | |
7554 | ;; Info GNOME style <info:foo#bar_baz> | |
7555 | ("\\binfo:\\([^('\n\t\r \"><][^'\n\t\r \"><]*\\)" | |
7556 | 0 (>= gnus-button-emacs-level 1) gnus-button-handle-info-url-gnome 1) | |
7557 | ;; Info KDE style <info:(foo)bar baz> | |
7558 | ("<\\(info:\\(([^)]+)[^>\n\r]*\\)\\)>" | |
7559 | 1 (>= gnus-button-emacs-level 1) gnus-button-handle-info-url-kde 2) | |
7560 | ("\\((Info-goto-node\\|(info\\)[ \t\n]*\\(\"[^\"]*\"\\))" 0 | |
7561 | (>= gnus-button-emacs-level 1) gnus-button-handle-info-url 2) | |
9b3ebcb6 MB |
7562 | ("\\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,]*\\)\\)?" |
7563 | ;; Info links like `C-h i d m Gnus RET' or `C-h i d m Gnus RET i partial RET' | |
7564 | 0 (>= gnus-button-emacs-level 1) gnus-button-handle-info-keystrokes 0) | |
23f87bed | 7565 | ;; This is custom |
e425f18b | 7566 | ("M-x[ \t\n]\\(customize-[^ ]+\\)[ \t\n]RET[ \t\n]\\([^ ]+\\)[ \t\n]RET\\>" 0 |
01c52d31 | 7567 | (>= gnus-button-emacs-level 1) gnus-button-handle-custom 1 2) |
23f87bed | 7568 | ;; Emacs help commands |
e425f18b | 7569 | ("M-x[ \t\n]+apropos[ \t\n]+RET[ \t\n]+\\([^ \t\n]+\\)[ \t\n]+RET\\>" |
23f87bed MB |
7570 | ;; regexp doesn't match arguments containing ` '. |
7571 | 0 (>= gnus-button-emacs-level 1) gnus-button-handle-apropos 1) | |
e425f18b | 7572 | ("M-x[ \t\n]+apropos-command[ \t\n]+RET[ \t\n]+\\([^ \t\n]+\\)[ \t\n]+RET\\>" |
23f87bed | 7573 | 0 (>= gnus-button-emacs-level 1) gnus-button-handle-apropos-command 1) |
e425f18b | 7574 | ("M-x[ \t\n]+apropos-variable[ \t\n]+RET[ \t\n]+\\([^ \t\n]+\\)[ \t\n]+RET\\>" |
23f87bed | 7575 | 0 (>= gnus-button-emacs-level 1) gnus-button-handle-apropos-variable 1) |
e425f18b | 7576 | ("M-x[ \t\n]+apropos-documentation[ \t\n]+RET[ \t\n]+\\([^ \t\n]+\\)[ \t\n]+RET\\>" |
23f87bed MB |
7577 | 0 (>= gnus-button-emacs-level 1) gnus-button-handle-apropos-documentation 1) |
7578 | ;; The following entries may lead to many false positives so don't enable | |
531e5812 MB |
7579 | ;; them by default (use a high button level). |
7580 | ("/\\([a-z][-a-z0-9]+\\.el\\)\\>[^.?]" | |
7581 | ;; Exclude [.?] for URLs in gmane.emacs.cvs | |
23f87bed MB |
7582 | 1 (>= gnus-button-emacs-level 8) gnus-button-handle-library 1) |
7583 | ("`\\([a-z][-a-z0-9]+\\.el\\)'" | |
7584 | 1 (>= gnus-button-emacs-level 8) gnus-button-handle-library 1) | |
01c52d31 | 7585 | ("`\\([a-z][a-z0-9]+-[a-z0-9]+-[-a-z0-9]*[a-z]\\|\\(gnus\\|message\\)-[-a-z]+\\)'" |
23f87bed MB |
7586 | 0 (>= gnus-button-emacs-level 8) gnus-button-handle-symbol 1) |
7587 | ("`\\([a-z][a-z0-9]+-[a-z]+\\)'" | |
7588 | 0 (>= gnus-button-emacs-level 9) gnus-button-handle-symbol 1) | |
7589 | ("(setq[ \t\n]+\\([a-z][a-z0-9]+-[-a-z0-9]+\\)[ \t\n]+.+)" | |
7590 | 1 (>= gnus-button-emacs-level 7) gnus-button-handle-describe-variable 1) | |
e425f18b | 7591 | ("\\bM-x[ \t\n]+\\([^ \t\n]+\\)[ \t\n]+RET\\>" |
23f87bed | 7592 | 1 (>= gnus-button-emacs-level 7) gnus-button-handle-describe-function 1) |
e425f18b | 7593 | ("\\b\\(C-h\\|<?[Ff]1>?\\)[ \t\n]+f[ \t\n]+\\([^ \t\n]+\\)[ \t\n]+RET\\>" |
23f87bed | 7594 | 0 (>= gnus-button-emacs-level 1) gnus-button-handle-describe-function 2) |
e425f18b | 7595 | ("\\b\\(C-h\\|<?[Ff]1>?\\)[ \t\n]+v[ \t\n]+\\([^ \t\n]+\\)[ \t\n]+RET\\>" |
23f87bed | 7596 | 0 (>= gnus-button-emacs-level 1) gnus-button-handle-describe-variable 2) |
87ba2830 | 7597 | ("`\\(\\(C-h\\|<?[Ff]1>?\\)[ \t\n]+k[ \t\n]+\\([^']+\\)\\)'" |
23f87bed MB |
7598 | ;; Unlike the other regexps we really have to require quoting |
7599 | ;; here to determine where it ends. | |
7600 | 1 (>= gnus-button-emacs-level 1) gnus-button-handle-describe-key 3) | |
7601 | ;; This is how URLs _should_ be embedded in text (RFC 1738, RFC 2396)... | |
01c52d31 | 7602 | ("<URL: *\\([^\n<>]*\\)>" |
23f87bed MB |
7603 | 1 (>= gnus-button-browse-level 0) gnus-button-embedded-url 1) |
7604 | ;; RFC 2396 (2.4.3., delims) ... | |
01c52d31 | 7605 | ("\"URL: *\\([^\n\"]*\\)\"" |
23f87bed | 7606 | 1 (>= gnus-button-browse-level 0) gnus-button-embedded-url 1) |
eec82323 | 7607 | ;; Raw URLs. |
23f87bed MB |
7608 | (gnus-button-url-regexp |
7609 | 0 (>= gnus-button-browse-level 0) browse-url 0) | |
7610 | ;; man pages | |
531e5812 | 7611 | ("\\b\\([a-z][a-z]+([1-9])\\)\\W" |
23f87bed MB |
7612 | 0 (and (>= gnus-button-man-level 1) (< gnus-button-man-level 3)) |
7613 | gnus-button-handle-man 1) | |
7614 | ;; more man pages: resolv.conf(5), iso_8859-1(7), xterm(1x) | |
531e5812 | 7615 | ("\\b\\([a-z][-_.a-z0-9]+([1-9])\\)\\W" |
23f87bed MB |
7616 | 0 (and (>= gnus-button-man-level 3) (< gnus-button-man-level 5)) |
7617 | gnus-button-handle-man 1) | |
7618 | ;; even more: Apache::PerlRun(3pm), PDL::IO::FastRaw(3pm), | |
7619 | ;; SoWWWAnchor(3iv), XSelectInput(3X11), X(1), X(7) | |
531e5812 | 7620 | ("\\b\\(\\(?:[a-z][-+_.:a-z0-9]+([1-9][X1a-z]*)\\)\\|\\b\\(?:X([1-9])\\)\\)\\W" |
23f87bed | 7621 | 0 (>= gnus-button-man-level 5) gnus-button-handle-man 1) |
01c52d31 MB |
7622 | ;; Recognizing patches to .el files. This is somewhat obscure, |
7623 | ;; but considering the percentage of Gnus users who hack Emacs | |
7624 | ;; Lisp files... | |
7625 | ("^--- \\([^ .]+\\.el\\).*\n.*\n@@ -?\\([0-9]+\\)" 1 | |
7626 | (>= gnus-button-message-level 4) gnus-button-patch 1 2) | |
7627 | ("^\\*\\*\\* \\([^ .]+\\.el\\).*\n.*\n\\*+\n\\*\\*\\* \\([0-9]+\\)" 1 | |
7628 | (>= gnus-button-message-level 4) gnus-button-patch 1 2) | |
23f87bed MB |
7629 | ;; MID or mail: To avoid too many false positives we don't try to catch |
7630 | ;; all kind of allowed MIDs or mail addresses. Domain part must contain | |
7631 | ;; at least one dot. TLD must contain two or three chars or be a know TLD | |
7632 | ;; (info|name|...). Put this entry near the _end_ of `gnus-button-alist' | |
7633 | ;; so that non-ambiguous entries (see above) match first. | |
7634 | (gnus-button-mid-or-mail-regexp | |
7635 | 0 (>= gnus-button-message-level 5) gnus-button-handle-mid-or-mail 1)) | |
6748645f | 7636 | "*Alist of regexps matching buttons in article bodies. |
eec82323 LMI |
7637 | |
7638 | Each entry has the form (REGEXP BUTTON FORM CALLBACK PAR...), where | |
23f87bed MB |
7639 | REGEXP: is the string (case insensitive) matching text around the button (can |
7640 | also be Lisp expression evaluating to a string), | |
eec82323 | 7641 | BUTTON: is the number of the regexp grouping actually matching the button, |
4e7d0221 | 7642 | FORM: is a Lisp expression which must eval to true for the button to |
eec82323 LMI |
7643 | be added, |
7644 | CALLBACK: is the function to call when the user push this button, and each | |
7645 | PAR: is a number of a regexp grouping whose text will be passed to CALLBACK. | |
7646 | ||
7647 | CALLBACK can also be a variable, in that case the value of that | |
7648 | variable it the real callback function." | |
7649 | :group 'gnus-article-buttons | |
23f87bed | 7650 | :type '(repeat (list (choice regexp variable sexp) |
eec82323 LMI |
7651 | (integer :tag "Button") |
7652 | (sexp :tag "Form") | |
7653 | (function :tag "Callback") | |
7654 | (repeat :tag "Par" | |
7655 | :inline t | |
7656 | (integer :tag "Regexp group"))))) | |
60ece9b0 | 7657 | (put 'gnus-button-alist 'risky-local-variable t) |
eec82323 LMI |
7658 | |
7659 | (defcustom gnus-header-button-alist | |
23f87bed MB |
7660 | '(("^\\(References\\|Message-I[Dd]\\|^In-Reply-To\\):" "<[^<>]+>" |
7661 | 0 (>= gnus-button-message-level 0) gnus-button-message-id 0) | |
7662 | ("^\\(From\\|Reply-To\\):" ": *\\(.+\\)$" | |
7663 | 1 (>= gnus-button-message-level 0) gnus-button-reply 1) | |
eec82323 | 7664 | ("^\\(Cc\\|To\\):" "[^ \t\n<>,()\"]+@[^ \t\n<>,()\"]+" |
fa9a04e1 | 7665 | 0 (>= gnus-button-message-level 0) gnus-msg-mail 0) |
23f87bed MB |
7666 | ("^X-[Uu][Rr][Ll]:" gnus-button-url-regexp |
7667 | 0 (>= gnus-button-browse-level 0) browse-url 0) | |
7668 | ("^Subject:" gnus-button-url-regexp | |
7669 | 0 (>= gnus-button-browse-level 0) browse-url 0) | |
7670 | ("^[^:]+:" gnus-button-url-regexp | |
7671 | 0 (>= gnus-button-browse-level 0) browse-url 0) | |
01c52d31 MB |
7672 | ("^OpenPGP:.*url=" gnus-button-url-regexp |
7673 | 0 (>= gnus-button-browse-level 0) gnus-button-openpgp 0) | |
531e5812 | 7674 | ("^[^:]+:" "\\bmailto:\\([-a-z.@_+0-9%=?&/]+\\)" |
23f87bed MB |
7675 | 0 (>= gnus-button-message-level 0) gnus-url-mailto 1) |
7676 | ("^[^:]+:" "\\(<\\(url: \\)?\\(nntp\\|news\\):\\([^>\n ]*\\)>\\)" | |
7677 | 1 (>= gnus-button-message-level 0) gnus-button-message-id 4)) | |
6748645f | 7678 | "*Alist of headers and regexps to match buttons in article heads. |
eec82323 LMI |
7679 | |
7680 | This alist is very similar to `gnus-button-alist', except that each | |
7681 | alist has an additional HEADER element first in each entry: | |
7682 | ||
7683 | \(HEADER REGEXP BUTTON FORM CALLBACK PAR) | |
7684 | ||
7685 | HEADER is a regexp to match a header. For a fuller explanation, see | |
7686 | `gnus-button-alist'." | |
7687 | :group 'gnus-article-buttons | |
7688 | :group 'gnus-article-headers | |
7689 | :type '(repeat (list (regexp :tag "Header") | |
23f87bed | 7690 | (choice regexp variable) |
eec82323 LMI |
7691 | (integer :tag "Button") |
7692 | (sexp :tag "Form") | |
7693 | (function :tag "Callback") | |
7694 | (repeat :tag "Par" | |
7695 | :inline t | |
7696 | (integer :tag "Regexp group"))))) | |
60ece9b0 | 7697 | (put 'gnus-header-button-alist 'risky-local-variable t) |
eec82323 | 7698 | |
eec82323 LMI |
7699 | ;;; Commands: |
7700 | ||
7701 | (defun gnus-article-push-button (event) | |
7702 | "Check text under the mouse pointer for a callback function. | |
7703 | If the text under the mouse pointer has a `gnus-callback' property, | |
7704 | call it with the value of the `gnus-data' text property." | |
7705 | (interactive "e") | |
7706 | (set-buffer (window-buffer (posn-window (event-start event)))) | |
7707 | (let* ((pos (posn-point (event-start event))) | |
23f87bed | 7708 | (data (get-text-property pos 'gnus-data)) |
eec82323 | 7709 | (fun (get-text-property pos 'gnus-callback))) |
6748645f | 7710 | (goto-char pos) |
eec82323 LMI |
7711 | (when fun |
7712 | (funcall fun data)))) | |
7713 | ||
7714 | (defun gnus-article-press-button () | |
7715 | "Check text at point for a callback function. | |
7716 | If the text at point has a `gnus-callback' property, | |
7717 | call it with the value of the `gnus-data' text property." | |
7718 | (interactive) | |
23f87bed MB |
7719 | (let ((data (get-text-property (point) 'gnus-data)) |
7720 | (fun (get-text-property (point) 'gnus-callback))) | |
eec82323 LMI |
7721 | (when fun |
7722 | (funcall fun data)))) | |
7723 | ||
eec82323 LMI |
7724 | (defun gnus-article-highlight (&optional force) |
7725 | "Highlight current article. | |
7726 | This function calls `gnus-article-highlight-headers', | |
7727 | `gnus-article-highlight-citation', | |
7728 | `gnus-article-highlight-signature', and `gnus-article-add-buttons' to | |
7729 | do the highlighting. See the documentation for those functions." | |
7730 | (interactive (list 'force)) | |
7731 | (gnus-article-highlight-headers) | |
7732 | (gnus-article-highlight-citation force) | |
7733 | (gnus-article-highlight-signature) | |
a2e3ac99 | 7734 | (gnus-article-add-buttons) |
eec82323 LMI |
7735 | (gnus-article-add-buttons-to-head)) |
7736 | ||
7737 | (defun gnus-article-highlight-some (&optional force) | |
7738 | "Highlight current article. | |
7739 | This function calls `gnus-article-highlight-headers', | |
7740 | `gnus-article-highlight-signature', and `gnus-article-add-buttons' to | |
7741 | do the highlighting. See the documentation for those functions." | |
7742 | (interactive (list 'force)) | |
7743 | (gnus-article-highlight-headers) | |
7744 | (gnus-article-highlight-signature) | |
7745 | (gnus-article-add-buttons)) | |
7746 | ||
7747 | (defun gnus-article-highlight-headers () | |
7748 | "Highlight article headers as specified by `gnus-header-face-alist'." | |
7749 | (interactive) | |
01c52d31 MB |
7750 | (gnus-with-article-headers |
7751 | (let (regexp header-face field-face from hpoints fpoints) | |
7752 | (dolist (entry gnus-header-face-alist) | |
7753 | (goto-char (point-min)) | |
7754 | (setq regexp (concat "^\\(" | |
7755 | (if (string-equal "" (nth 0 entry)) | |
7756 | "[^\t ]" | |
7757 | (nth 0 entry)) | |
7758 | "\\)") | |
7759 | header-face (nth 1 entry) | |
7760 | field-face (nth 2 entry)) | |
7761 | (while (and (re-search-forward regexp nil t) | |
7762 | (not (eobp))) | |
7763 | (beginning-of-line) | |
7764 | (setq from (point)) | |
7765 | (unless (search-forward ":" nil t) | |
7766 | (forward-char 1)) | |
7767 | (when (and header-face | |
7768 | (not (memq (point) hpoints))) | |
7769 | (push (point) hpoints) | |
7770 | (gnus-put-text-property from (point) 'face header-face)) | |
7771 | (when (and field-face | |
7772 | (not (memq (setq from (point)) fpoints))) | |
7773 | (push from fpoints) | |
7774 | (if (re-search-forward "^[^ \t]" nil t) | |
7775 | (forward-char -2) | |
7776 | (goto-char (point-max))) | |
7777 | (gnus-put-text-property from (point) 'face field-face))))))) | |
eec82323 LMI |
7778 | |
7779 | (defun gnus-article-highlight-signature () | |
7780 | "Highlight the signature in an article. | |
7781 | It does this by highlighting everything after | |
0f49874b | 7782 | `gnus-signature-separator' using the face `gnus-signature'." |
eec82323 | 7783 | (interactive) |
01c52d31 MB |
7784 | (gnus-with-article-buffer |
7785 | (let ((inhibit-point-motion-hooks t)) | |
eec82323 LMI |
7786 | (save-restriction |
7787 | (when (and gnus-signature-face | |
7788 | (gnus-article-narrow-to-signature)) | |
01c52d31 | 7789 | (gnus-overlay-put (gnus-make-overlay (point-min) (point-max) nil t) |
eec82323 LMI |
7790 | 'face gnus-signature-face) |
7791 | (widen) | |
7792 | (gnus-article-search-signature) | |
7793 | (let ((start (match-beginning 0)) | |
7794 | (end (set-marker (make-marker) (1+ (match-end 0))))) | |
7795 | (gnus-article-add-button start (1- end) 'gnus-signature-toggle | |
7796 | end))))))) | |
7797 | ||
7798 | (defun gnus-button-in-region-p (b e prop) | |
7799 | "Say whether PROP exists in the region." | |
7800 | (text-property-not-all b e prop nil)) | |
7801 | ||
672022e7 | 7802 | (defun gnus-article-add-buttons () |
eec82323 LMI |
7803 | "Find external references in the article and make buttons of them. |
7804 | \"External references\" are things like Message-IDs and URLs, as | |
7805 | specified by `gnus-button-alist'." | |
672022e7 | 7806 | (interactive) |
01c52d31 MB |
7807 | (gnus-with-article-buffer |
7808 | (let ((inhibit-point-motion-hooks t) | |
eec82323 LMI |
7809 | (case-fold-search t) |
7810 | (alist gnus-button-alist) | |
7811 | beg entry regexp) | |
eec82323 | 7812 | ;; We skip the headers. |
16409b0b | 7813 | (article-goto-body) |
eec82323 LMI |
7814 | (setq beg (point)) |
7815 | (while (setq entry (pop alist)) | |
23f87bed | 7816 | (setq regexp (eval (car entry))) |
eec82323 LMI |
7817 | (goto-char beg) |
7818 | (while (re-search-forward regexp nil t) | |
01c52d31 MB |
7819 | (let ((start (match-beginning (nth 1 entry))) |
7820 | (end (match-end (nth 1 entry))) | |
7821 | (from (match-beginning 0))) | |
672022e7 | 7822 | (when (and (eval (nth 2 entry)) |
eec82323 LMI |
7823 | (not (gnus-button-in-region-p |
7824 | start end 'gnus-callback))) | |
7825 | ;; That optional form returned non-nil, so we add the | |
7826 | ;; button. | |
01c52d31 | 7827 | (setq from (set-marker (make-marker) from)) |
01c52d31 MB |
7828 | (unless (and (eq (car entry) 'gnus-button-url-regexp) |
7829 | (gnus-article-extend-url-button from start end)) | |
7830 | (gnus-article-add-button start end | |
672022e7 | 7831 | 'gnus-button-push (list from entry)) |
7426b4f7 LMI |
7832 | (gnus-put-text-property |
7833 | start end | |
10e91ca9 LMI |
7834 | 'gnus-string (buffer-substring-no-properties |
7835 | start end)))))))))) | |
01c52d31 MB |
7836 | |
7837 | (defun gnus-article-extend-url-button (beg start end) | |
7838 | "Extend url button if url is folded into two or more lines. | |
7839 | Return non-nil if button is extended. BEG is a marker that points to | |
7840 | the beginning position of a text containing url. START and END are | |
7841 | the endpoints of a url button before it is extended. The concatenated | |
7842 | url is put as the `gnus-button-url' overlay property on the button." | |
7843 | (let ((opoint (point)) | |
7844 | (points (list start end)) | |
7845 | url delim regexp) | |
7846 | (prog1 | |
7847 | (when (and (progn | |
7848 | (goto-char end) | |
7849 | (not (looking-at "[\t ]*[\">]"))) | |
7850 | (progn | |
7851 | (goto-char start) | |
7852 | (string-match | |
7853 | "\\(?:\"\\|\\(<\\)\\)[\t ]*\\(?:url[\t ]*:[\t ]*\\)?\\'" | |
7854 | (buffer-substring (point-at-bol) start))) | |
7855 | (progn | |
7856 | (setq url (list (buffer-substring start end)) | |
7857 | delim (if (match-beginning 1) ">" "\"")) | |
7858 | (beginning-of-line) | |
7859 | (setq regexp (concat | |
7860 | (when (and (looking-at | |
7861 | message-cite-prefix-regexp) | |
7862 | (< (match-end 0) start)) | |
7863 | (regexp-quote (match-string 0))) | |
7864 | "\ | |
7865 | \[\t ]*\\(?:\\([^\t\n \">]+\\)[\t ]*$\\|\\([^\t\n \">]*\\)[\t ]*" | |
7866 | delim "\\)")) | |
7867 | (while (progn | |
7868 | (forward-line 1) | |
7869 | (and (looking-at regexp) | |
7870 | (prog1 | |
7871 | (match-beginning 1) | |
7872 | (push (or (match-string 2) | |
7873 | (match-string 1)) | |
7874 | url) | |
7875 | (push (setq end (or (match-end 2) | |
7876 | (match-end 1))) | |
7877 | points) | |
7878 | (push (or (match-beginning 2) | |
7879 | (match-beginning 1)) | |
7880 | points))))) | |
7881 | (match-beginning 2))) | |
7882 | (let (gnus-article-mouse-face widget-mouse-face) | |
7883 | (while points | |
7884 | (gnus-article-add-button (pop points) (pop points) | |
dbca79f8 KY |
7885 | 'gnus-button-push |
7886 | (list beg (assq 'gnus-button-url-regexp | |
7887 | gnus-button-alist))))) | |
01c52d31 MB |
7888 | (let ((overlay (gnus-make-overlay start end))) |
7889 | (gnus-overlay-put overlay 'evaporate t) | |
7890 | (gnus-overlay-put overlay 'gnus-button-url | |
7891 | (list (mapconcat 'identity (nreverse url) ""))) | |
7892 | (when gnus-article-mouse-face | |
7893 | (gnus-overlay-put overlay 'mouse-face gnus-article-mouse-face))) | |
7894 | t) | |
7895 | (goto-char opoint)))) | |
eec82323 LMI |
7896 | |
7897 | ;; Add buttons to the head of an article. | |
7898 | (defun gnus-article-add-buttons-to-head () | |
7899 | "Add buttons to the head of the article." | |
7900 | (interactive) | |
01c52d31 MB |
7901 | (gnus-with-article-headers |
7902 | (let (beg end) | |
7903 | (dolist (entry gnus-header-button-alist) | |
7904 | ;; Each alist entry. | |
7905 | (goto-char (point-min)) | |
7906 | (while (re-search-forward (car entry) nil t) | |
7907 | ;; Each header matching the entry. | |
7908 | (setq beg (match-beginning 0)) | |
7909 | (setq end (or (and (re-search-forward "^[^ \t]" nil t) | |
7910 | (match-beginning 0)) | |
7911 | (point-max))) | |
7912 | (goto-char beg) | |
7913 | (while (re-search-forward (eval (nth 1 entry)) end t) | |
7914 | ;; Each match within a header. | |
7915 | (let* ((entry (cdr entry)) | |
7916 | (start (match-beginning (nth 1 entry))) | |
7917 | (end (match-end (nth 1 entry))) | |
7918 | (form (nth 2 entry))) | |
7919 | (goto-char (match-end 0)) | |
7920 | (when (eval form) | |
7921 | (gnus-article-add-button | |
7922 | start end (nth 3 entry) | |
7923 | (buffer-substring (match-beginning (nth 4 entry)) | |
7924 | (match-end (nth 4 entry))))))) | |
7925 | (goto-char end)))))) | |
eec82323 LMI |
7926 | |
7927 | ;;; External functions: | |
7928 | ||
b1992461 | 7929 | (defun gnus-article-add-button (from to fun &optional data text) |
eec82323 LMI |
7930 | "Create a button between FROM and TO with callback FUN and data DATA." |
7931 | (when gnus-article-button-face | |
01c52d31 | 7932 | (gnus-overlay-put (gnus-make-overlay from to nil t) |
eec82323 LMI |
7933 | 'face gnus-article-button-face)) |
7934 | (gnus-add-text-properties | |
7935 | from to | |
7936 | (nconc (and gnus-article-mouse-face | |
7937 | (list gnus-mouse-face-prop gnus-article-mouse-face)) | |
7938 | (list 'gnus-callback fun) | |
16409b0b GM |
7939 | (and data (list 'gnus-data data)))) |
7940 | (widget-convert-button 'link from to :action 'gnus-widget-press-button | |
b1992461 | 7941 | :help-echo (or text "Follow the link") |
7426b4f7 | 7942 | :keymap gnus-url-button-map |
16409b0b | 7943 | :button-keymap gnus-widget-button-keymap)) |
eec82323 | 7944 | |
7426b4f7 LMI |
7945 | (defun gnus-article-copy-string () |
7946 | "Copy the string in the button to the kill ring." | |
7947 | (interactive) | |
7948 | (gnus-article-check-buffer) | |
10e91ca9 | 7949 | (let ((data (get-text-property (point) 'gnus-string))) |
7426b4f7 LMI |
7950 | (when data |
7951 | (with-temp-buffer | |
7952 | (insert data) | |
c25d60ab LMI |
7953 | (copy-region-as-kill (point-min) (point-max)) |
7954 | (message "Copied %s" data))))) | |
7426b4f7 | 7955 | |
eec82323 LMI |
7956 | ;;; Internal functions: |
7957 | ||
a8151ef7 | 7958 | (defun gnus-article-set-globals () |
01c52d31 | 7959 | (with-current-buffer gnus-summary-buffer |
a8151ef7 LMI |
7960 | (gnus-set-global-variables))) |
7961 | ||
eec82323 | 7962 | (defun gnus-signature-toggle (end) |
01c52d31 MB |
7963 | (gnus-with-article-buffer |
7964 | (let ((inhibit-point-motion-hooks t)) | |
520aa572 | 7965 | (if (text-property-any end (point-max) 'article-type 'signature) |
23f87bed MB |
7966 | (progn |
7967 | (gnus-delete-wash-type 'signature) | |
7968 | (gnus-remove-text-properties-when | |
7969 | 'article-type 'signature end (point-max) | |
7970 | (cons 'article-type (cons 'signature | |
7971 | gnus-hidden-properties)))) | |
7972 | (gnus-add-wash-type 'signature) | |
520aa572 SZ |
7973 | (gnus-add-text-properties-when |
7974 | 'article-type nil end (point-max) | |
7975 | (cons 'article-type (cons 'signature | |
23f87bed MB |
7976 | gnus-hidden-properties))))) |
7977 | (let ((gnus-article-mime-handle-alist-1 gnus-article-mime-handle-alist)) | |
7978 | (gnus-set-mode-line 'article)))) | |
eec82323 | 7979 | |
672022e7 | 7980 | (defun gnus-button-push (marker-and-entry) |
eec82323 LMI |
7981 | ;; Push button starting at MARKER. |
7982 | (save-excursion | |
672022e7 G |
7983 | (let* ((marker (car marker-and-entry)) |
7984 | (entry (cadr marker-and-entry)) | |
7985 | (regexp (car entry)) | |
7986 | (inhibit-point-motion-hooks t)) | |
7987 | (goto-char marker) | |
7988 | ;; This is obviously true, or something bad is happening :) | |
7989 | ;; But we need it to have the match-data | |
7990 | (when (looking-at (or (if (symbolp regexp) | |
7991 | (symbol-value regexp) | |
7992 | regexp))) | |
7993 | (let ((fun (nth 3 entry)) | |
7994 | (args (or (and (eq (car entry) 'gnus-button-url-regexp) | |
7995 | (get-char-property marker 'gnus-button-url)) | |
7996 | (mapcar (lambda (group) | |
7997 | (let ((string (match-string group))) | |
7998 | (set-text-properties | |
7999 | 0 (length string) nil string) | |
8000 | string)) | |
8001 | (nthcdr 4 entry))))) | |
8002 | ||
8003 | (cond | |
8004 | ((fboundp fun) | |
8005 | (apply fun args)) | |
8006 | ((and (boundp fun) | |
8007 | (fboundp (symbol-value fun))) | |
8008 | (apply (symbol-value fun) args)) | |
8009 | (t | |
8010 | (gnus-message 1 "You must define `%S' to use this button" | |
8011 | (cons fun args))))))))) | |
eec82323 | 8012 | |
23f87bed | 8013 | (defun gnus-parse-news-url (url) |
82a8ad04 | 8014 | (let (scheme server port group message-id articles) |
23f87bed MB |
8015 | (with-temp-buffer |
8016 | (insert url) | |
8017 | (goto-char (point-min)) | |
8018 | (when (looking-at "\\([A-Za-z]+\\):") | |
8019 | (setq scheme (match-string 1)) | |
8020 | (goto-char (match-end 0))) | |
82a8ad04 | 8021 | (when (looking-at "//\\([^:/]+\\)\\(:?\\)\\([0-9]+\\)?/") |
23f87bed | 8022 | (setq server (match-string 1)) |
82a8ad04 MB |
8023 | (setq port (if (stringp (match-string 3)) |
8024 | (string-to-number (match-string 3)) | |
8025 | (match-string 3))) | |
23f87bed MB |
8026 | (goto-char (match-end 0))) |
8027 | ||
8028 | (cond | |
8029 | ((looking-at "\\(.*@.*\\)") | |
8030 | (setq message-id (match-string 1))) | |
8031 | ((looking-at "\\([^/]+\\)/\\([-0-9]+\\)") | |
8032 | (setq group (match-string 1) | |
8033 | articles (split-string (match-string 2) "-"))) | |
8034 | ((looking-at "\\([^/]+\\)/?") | |
8035 | (setq group (match-string 1))) | |
8036 | (t | |
8037 | (error "Unknown news URL syntax")))) | |
82a8ad04 | 8038 | (list scheme server port group message-id articles))) |
23f87bed MB |
8039 | |
8040 | (defun gnus-button-handle-news (url) | |
8041 | "Fetch a news URL." | |
82a8ad04 | 8042 | (destructuring-bind (scheme server port group message-id articles) |
23f87bed MB |
8043 | (gnus-parse-news-url url) |
8044 | (cond | |
8045 | (message-id | |
80de1778 | 8046 | (with-current-buffer gnus-summary-buffer |
23f87bed | 8047 | (if server |
ff4d3926 MB |
8048 | (let ((gnus-refer-article-method |
8049 | (nconc (list (list 'nntp server)) | |
8050 | gnus-refer-article-method)) | |
82a8ad04 | 8051 | (nntp-port-number (or port "nntp"))) |
ff4d3926 MB |
8052 | (gnus-message 7 "Fetching %s with %s" |
8053 | message-id gnus-refer-article-method) | |
23f87bed MB |
8054 | (gnus-summary-refer-article message-id)) |
8055 | (gnus-summary-refer-article message-id)))) | |
8056 | (group | |
8057 | (gnus-button-fetch-group url))))) | |
8058 | ||
01c52d31 MB |
8059 | (defun gnus-button-patch (library line) |
8060 | "Visit an Emacs Lisp library LIBRARY on line LINE." | |
8061 | (interactive) | |
8062 | (let ((file (locate-library (file-name-nondirectory library)))) | |
8063 | (unless file | |
8064 | (error "Couldn't find library %s" library)) | |
8065 | (find-file file) | |
5dcc825f GM |
8066 | (goto-char (point-min)) |
8067 | (forward-line (1- (string-to-number line))))) | |
01c52d31 | 8068 | |
23f87bed MB |
8069 | (defun gnus-button-handle-man (url) |
8070 | "Fetch a man page." | |
531e5812 MB |
8071 | (gnus-message 9 "`%s' `%s'" gnus-button-man-handler url) |
8072 | (when (eq gnus-button-man-handler 'woman) | |
8073 | (setq url (gnus-replace-in-string url "([1-9][X1a-z]*).*\\'" ""))) | |
8074 | (gnus-message 9 "`%s' `%s'" gnus-button-man-handler url) | |
23f87bed MB |
8075 | (funcall gnus-button-man-handler url)) |
8076 | ||
8077 | (defun gnus-button-handle-info-url (url) | |
8078 | "Fetch an info URL." | |
8079 | (setq url (mm-subst-char-in-string ?+ ?\ url)) | |
8080 | (cond | |
8081 | ((string-match "^\\([^:/]+\\)?/\\(.*\\)" url) | |
8082 | (gnus-info-find-node | |
8083 | (concat "(" (or (gnus-url-unhex-string (match-string 1 url)) | |
8084 | "Gnus") | |
8085 | ")" (gnus-url-unhex-string (match-string 2 url))))) | |
8086 | ((string-match "([^)\"]+)[^\"]+" url) | |
8087 | (setq url | |
8088 | (gnus-replace-in-string | |
8089 | (gnus-replace-in-string url "[\n\t ]+" " ") "\"" "")) | |
8090 | (gnus-info-find-node url)) | |
8091 | (t (error "Can't parse %s" url)))) | |
8092 | ||
8093 | (defun gnus-button-handle-info-url-gnome (url) | |
8094 | "Fetch GNOME style info URL." | |
8095 | (setq url (mm-subst-char-in-string ?_ ?\ url)) | |
8096 | (if (string-match "\\([^#]+\\)#?\\(.*\\)" url) | |
8097 | (gnus-info-find-node | |
8098 | (concat "(" | |
bf247b6e | 8099 | (gnus-url-unhex-string |
23f87bed MB |
8100 | (match-string 1 url)) |
8101 | ")" | |
bf247b6e | 8102 | (or (gnus-url-unhex-string |
23f87bed MB |
8103 | (match-string 2 url)) |
8104 | "Top"))) | |
8105 | (error "Can't parse %s" url))) | |
8106 | ||
8107 | (defun gnus-button-handle-info-url-kde (url) | |
8108 | "Fetch KDE style info URL." | |
8109 | (gnus-info-find-node (gnus-url-unhex-string url))) | |
8110 | ||
9640c3bc GM |
8111 | ;; (info) will autoload info.el |
8112 | (declare-function Info-menu "info" (menu-item &optional fork)) | |
9b3ebcb6 | 8113 | (declare-function Info-index-next "info" (num)) |
9640c3bc | 8114 | |
23f87bed MB |
8115 | (defun gnus-button-handle-info-keystrokes (url) |
8116 | "Call `info' when pushing the corresponding URL button." | |
9b3ebcb6 MB |
8117 | ;; For links like `C-h i d m gnus RET part RET , ,', `C-h i d m CC Mode RET'. |
8118 | (let (node indx comma) | |
8119 | (if (string-match | |
8120 | (concat "\\b\\(C-h\\|<?[Ff]1>?\\)[ \t\n]+i[ \t\n]+d?[ \t\n]?m[ \t\n]+" | |
8121 | "\\([^ ]+ ?[^ ]+\\)[ \t\n]+RET" | |
e425f18b | 8122 | "\\([ \t\n]+i[ \t\n]+[^ ]+ ?[^ ]+[ \t\n]+RET\\>" |
9b3ebcb6 MB |
8123 | "\\(?:[ \t\n,]*\\)\\)?") |
8124 | url) | |
8125 | (setq node (match-string 2 url) | |
8126 | indx (match-string 3 url)) | |
8127 | (error "Can't parse %s" url)) | |
8128 | (info) | |
8129 | (Info-directory) | |
8130 | (Info-menu node) | |
8131 | (when (> (length indx) 0) | |
e425f18b | 8132 | (string-match (concat "[ \t\n]+i[ \t\n]+\\([^ ]+ ?[^ ]+\\)[ \t\n]+RET\\>" |
9b3ebcb6 MB |
8133 | "\\([ \t\n,]*\\)") |
8134 | indx) | |
8135 | (setq comma (match-string 2 indx)) | |
8136 | (setq indx (match-string 1 indx)) | |
8137 | (Info-index indx) | |
8138 | (when comma | |
8139 | (dotimes (i (with-temp-buffer | |
8140 | (insert comma) | |
8141 | ;; Note: the XEmacs version of `how-many' takes | |
8142 | ;; no optional argument. | |
8143 | (goto-char (point-min)) | |
8144 | (how-many ","))) | |
8145 | (Info-index-next 1))) | |
8146 | nil))) | |
1888e568 | 8147 | |
9d9cfd53 | 8148 | (autoload 'pgg-snarf-keys-region "pgg") |
1888e568 GM |
8149 | ;; Called after pgg-snarf-keys-region, which autoloads pgg.el. |
8150 | (declare-function pgg-display-output-buffer "pgg" (start end status)) | |
23f87bed | 8151 | |
01c52d31 MB |
8152 | (defun gnus-button-openpgp (url) |
8153 | "Retrieve and add an OpenPGP key given URL from an OpenPGP header." | |
8154 | (with-temp-buffer | |
8155 | (mm-url-insert-file-contents-external url) | |
8156 | (pgg-snarf-keys-region (point-min) (point-max)) | |
8157 | (pgg-display-output-buffer nil nil nil))) | |
8158 | ||
eec82323 LMI |
8159 | (defun gnus-button-message-id (message-id) |
8160 | "Fetch MESSAGE-ID." | |
01c52d31 | 8161 | (with-current-buffer gnus-summary-buffer |
eec82323 LMI |
8162 | (gnus-summary-refer-article message-id))) |
8163 | ||
01c52d31 | 8164 | (defun gnus-button-fetch-group (address &rest ignore) |
eec82323 | 8165 | "Fetch GROUP specified by ADDRESS." |
01c52d31 MB |
8166 | (when (string-match "\\`\\(nntp\\|news\\):\\(//\\)?\\(.*\\)\\'" |
8167 | address) | |
8168 | ;; Allow to use `gnus-button-fetch-group' in `browse-url-browser-function' | |
8169 | ;; for nntp:// and news:// | |
8170 | (setq address (match-string 3 address))) | |
eec82323 LMI |
8171 | (if (not (string-match "[:/]" address)) |
8172 | ;; This is just a simple group url. | |
8173 | (gnus-group-read-ephemeral-group address gnus-select-method) | |
23f87bed MB |
8174 | (if (not |
8175 | (string-match | |
8176 | "^\\([^:/]+\\)\\(:\\([^/]+\\)\\)?/\\([^/]+\\)\\(/\\([0-9]+\\)\\)?" | |
8177 | address)) | |
eec82323 LMI |
8178 | (error "Can't parse %s" address) |
8179 | (gnus-group-read-ephemeral-group | |
8180 | (match-string 4 address) | |
8181 | `(nntp ,(match-string 1 address) | |
8182 | (nntp-address ,(match-string 1 address)) | |
8183 | (nntp-port-number ,(if (match-end 3) | |
8184 | (match-string 3 address) | |
23f87bed MB |
8185 | "nntp"))) |
8186 | nil nil nil | |
e9bd5782 | 8187 | (and (match-end 6) (list (string-to-number (match-string 6 address)))))))) |
eec82323 | 8188 | |
eec82323 LMI |
8189 | (defun gnus-url-parse-query-string (query &optional downcase) |
8190 | (let (retval pairs cur key val) | |
16409b0b | 8191 | (setq pairs (split-string query "&")) |
eec82323 LMI |
8192 | (while pairs |
8193 | (setq cur (car pairs) | |
23f87bed | 8194 | pairs (cdr pairs)) |
eec82323 | 8195 | (if (not (string-match "=" cur)) |
23f87bed MB |
8196 | nil ; Grace |
8197 | (setq key (gnus-url-unhex-string (substring cur 0 (match-beginning 0))) | |
8198 | val (gnus-url-unhex-string (substring cur (match-end 0) nil) t)) | |
8199 | (if downcase | |
8200 | (setq key (downcase key))) | |
8201 | (setq cur (assoc key retval)) | |
8202 | (if cur | |
8203 | (setcdr cur (cons val (cdr cur))) | |
8204 | (setq retval (cons (list key val) retval))))) | |
eec82323 LMI |
8205 | retval)) |
8206 | ||
eec82323 LMI |
8207 | (defun gnus-url-mailto (url) |
8208 | ;; Send mail to someone | |
1e91d0eb | 8209 | (setq url (replace-regexp-in-string "\n" " " url)) |
eec82323 LMI |
8210 | (when (string-match "mailto:/*\\(.*\\)" url) |
8211 | (setq url (substring url (match-beginning 1) nil))) | |
6748645f | 8212 | (let (to args subject func) |
23f87bed MB |
8213 | (setq args (gnus-url-parse-query-string |
8214 | (if (string-match "^\\?" url) | |
8215 | (substring url 1) | |
8216 | (if (string-match "^\\([^?]+\\)\\?\\(.*\\)" url) | |
8217 | (concat "to=" (match-string 1 url) "&" | |
8218 | (match-string 2 url)) | |
440b1345 | 8219 | (concat "to=" url)))) |
23f87bed MB |
8220 | subject (cdr-safe (assoc "subject" args))) |
8221 | (gnus-msg-mail) | |
eec82323 LMI |
8222 | (while args |
8223 | (setq func (intern-soft (concat "message-goto-" (downcase (caar args))))) | |
8224 | (if (fboundp func) | |
23f87bed MB |
8225 | (funcall func) |
8226 | (message-position-on-field (caar args))) | |
8227 | (insert (gnus-replace-in-string | |
8228 | (mapconcat 'identity (reverse (cdar args)) ", ") | |
8229 | "\r\n" "\n" t)) | |
eec82323 LMI |
8230 | (setq args (cdr args))) |
8231 | (if subject | |
23f87bed | 8232 | (message-goto-body) |
eec82323 LMI |
8233 | (message-goto-subject)))) |
8234 | ||
eec82323 | 8235 | (defun gnus-button-embedded-url (address) |
e0bad764 | 8236 | "Activate ADDRESS with `browse-url'." |
1b978bfc | 8237 | (browse-url (gnus-strip-whitespace address))) |
eec82323 LMI |
8238 | |
8239 | ;;; Next/prev buttons in the article buffer. | |
8240 | ||
8241 | (defvar gnus-next-page-line-format "%{%(Next page...%)%}\n") | |
8242 | (defvar gnus-prev-page-line-format "%{%(Previous page...%)%}\n") | |
8243 | ||
23f87bed MB |
8244 | (defvar gnus-prev-page-map |
8245 | (let ((map (make-sparse-keymap))) | |
23f87bed MB |
8246 | (define-key map gnus-mouse-2 'gnus-button-prev-page) |
8247 | (define-key map "\r" 'gnus-button-prev-page) | |
8248 | map)) | |
8249 | ||
8250 | (defvar gnus-next-page-map | |
8251 | (let ((map (make-sparse-keymap))) | |
23f87bed MB |
8252 | (define-key map gnus-mouse-2 'gnus-button-next-page) |
8253 | (define-key map "\r" 'gnus-button-next-page) | |
8254 | map)) | |
eec82323 LMI |
8255 | |
8256 | (defun gnus-insert-prev-page-button () | |
01c52d31 | 8257 | (let ((b (point)) e |
23f87bed | 8258 | (inhibit-read-only t)) |
eec82323 LMI |
8259 | (gnus-eval-format |
8260 | gnus-prev-page-line-format nil | |
01c52d31 MB |
8261 | `(keymap ,gnus-prev-page-map |
8262 | gnus-prev t | |
8263 | gnus-callback gnus-article-button-prev-page | |
8264 | article-type annotation)) | |
8265 | (setq e (if (bolp) | |
8266 | ;; Exclude a newline. | |
8267 | (1- (point)) | |
8268 | (point))) | |
8269 | (when gnus-article-button-face | |
8270 | (gnus-overlay-put (gnus-make-overlay b e nil t) | |
8271 | 'face gnus-article-button-face)) | |
23f87bed | 8272 | (widget-convert-button |
01c52d31 | 8273 | 'link b e |
23f87bed MB |
8274 | :action 'gnus-button-prev-page |
8275 | :button-keymap gnus-prev-page-map))) | |
8276 | ||
8277 | (defun gnus-button-next-page (&optional args more-args) | |
eec82323 LMI |
8278 | "Go to the next page." |
8279 | (interactive) | |
8280 | (let ((win (selected-window))) | |
23f87bed | 8281 | (select-window (gnus-get-buffer-window gnus-article-buffer t)) |
eec82323 LMI |
8282 | (gnus-article-next-page) |
8283 | (select-window win))) | |
8284 | ||
23f87bed | 8285 | (defun gnus-button-prev-page (&optional args more-args) |
eec82323 LMI |
8286 | "Go to the prev page." |
8287 | (interactive) | |
8288 | (let ((win (selected-window))) | |
23f87bed | 8289 | (select-window (gnus-get-buffer-window gnus-article-buffer t)) |
eec82323 LMI |
8290 | (gnus-article-prev-page) |
8291 | (select-window win))) | |
8292 | ||
8293 | (defun gnus-insert-next-page-button () | |
01c52d31 | 8294 | (let ((b (point)) e |
23f87bed | 8295 | (inhibit-read-only t)) |
eec82323 | 8296 | (gnus-eval-format gnus-next-page-line-format nil |
01c52d31 MB |
8297 | `(keymap ,gnus-next-page-map |
8298 | gnus-next t | |
8299 | gnus-callback gnus-article-button-next-page | |
8300 | article-type annotation)) | |
8301 | (setq e (if (bolp) | |
8302 | ;; Exclude a newline. | |
8303 | (1- (point)) | |
8304 | (point))) | |
8305 | (when gnus-article-button-face | |
8306 | (gnus-overlay-put (gnus-make-overlay b e nil t) | |
8307 | 'face gnus-article-button-face)) | |
23f87bed | 8308 | (widget-convert-button |
01c52d31 | 8309 | 'link b e |
23f87bed MB |
8310 | :action 'gnus-button-next-page |
8311 | :button-keymap gnus-next-page-map))) | |
eec82323 LMI |
8312 | |
8313 | (defun gnus-article-button-next-page (arg) | |
8314 | "Go to the next page." | |
8315 | (interactive "P") | |
8316 | (let ((win (selected-window))) | |
23f87bed | 8317 | (select-window (gnus-get-buffer-window gnus-article-buffer t)) |
eec82323 LMI |
8318 | (gnus-article-next-page) |
8319 | (select-window win))) | |
8320 | ||
8321 | (defun gnus-article-button-prev-page (arg) | |
8322 | "Go to the prev page." | |
8323 | (interactive "P") | |
8324 | (let ((win (selected-window))) | |
23f87bed | 8325 | (select-window (gnus-get-buffer-window gnus-article-buffer t)) |
eec82323 LMI |
8326 | (gnus-article-prev-page) |
8327 | (select-window win))) | |
8328 | ||
16409b0b GM |
8329 | (defvar gnus-decode-header-methods |
8330 | '(mail-decode-encoded-word-region) | |
8331 | "List of methods used to decode headers. | |
8332 | ||
8333 | This variable is a list of FUNCTION or (REGEXP . FUNCTION). If item | |
4e7d0221 | 8334 | is FUNCTION, FUNCTION will be applied to all newsgroups. If item is a |
23f87bed | 8335 | \(REGEXP . FUNCTION), FUNCTION will be only apply to the newsgroups |
16409b0b GM |
8336 | whose names match REGEXP. |
8337 | ||
8338 | For example: | |
8f688cb0 | 8339 | \((\"chinese\" . gnus-decode-encoded-word-region-by-guess) |
16409b0b GM |
8340 | mail-decode-encoded-word-region |
8341 | (\"chinese\" . rfc1843-decode-region)) | |
8342 | ") | |
8343 | ||
8344 | (defvar gnus-decode-header-methods-cache nil) | |
8345 | ||
8346 | (defun gnus-multi-decode-header (start end) | |
8347 | "Apply the functions from `gnus-encoded-word-methods' that match." | |
8348 | (unless (and gnus-decode-header-methods-cache | |
8349 | (eq gnus-newsgroup-name | |
8350 | (car gnus-decode-header-methods-cache))) | |
8351 | (setq gnus-decode-header-methods-cache (list gnus-newsgroup-name)) | |
01c52d31 MB |
8352 | (dolist (x gnus-decode-header-methods) |
8353 | (if (symbolp x) | |
8354 | (nconc gnus-decode-header-methods-cache (list x)) | |
8355 | (if (and gnus-newsgroup-name | |
8356 | (string-match (car x) gnus-newsgroup-name)) | |
8357 | (nconc gnus-decode-header-methods-cache | |
8358 | (list (cdr x))))))) | |
16409b0b GM |
8359 | (let ((xlist gnus-decode-header-methods-cache)) |
8360 | (pop xlist) | |
8361 | (save-restriction | |
8362 | (narrow-to-region start end) | |
8363 | (while xlist | |
8364 | (funcall (pop xlist) (point-min) (point-max)))))) | |
8365 | ||
8366 | ;;; | |
8367 | ;;; Treatment top-level handling. | |
8368 | ;;; | |
8369 | ||
389b76fa G |
8370 | (defvar gnus-inhibit-article-treatments nil) |
8371 | ||
c497474b GM |
8372 | (defun gnus-treat-article (gnus-treat-condition |
8373 | &optional part-number total-parts gnus-treat-type) | |
8374 | (let ((gnus-treat-length (- (point-max) (point-min))) | |
16409b0b GM |
8375 | (alist gnus-treatment-function-alist) |
8376 | (article-goto-body-goes-to-point-min-p t) | |
8377 | (treated-type | |
c497474b | 8378 | (or (not gnus-treat-type) |
16409b0b GM |
8379 | (catch 'found |
8380 | (let ((list gnus-article-treat-types)) | |
8381 | (while list | |
c497474b | 8382 | (when (string-match (pop list) gnus-treat-type) |
16409b0b GM |
8383 | (throw 'found t))))))) |
8384 | (highlightp (gnus-visual-p 'article-highlight 'highlight)) | |
8385 | val elem) | |
8386 | (gnus-run-hooks 'gnus-part-display-hook) | |
23f87bed | 8387 | (dolist (elem alist) |
16409b0b GM |
8388 | (setq val |
8389 | (save-excursion | |
23f87bed MB |
8390 | (when (gnus-buffer-live-p gnus-summary-buffer) |
8391 | (set-buffer gnus-summary-buffer)) | |
16409b0b GM |
8392 | (symbol-value (car elem)))) |
8393 | (when (and (or (consp val) | |
8394 | treated-type) | |
389b76fa | 8395 | (or (not gnus-inhibit-article-treatments) |
c497474b | 8396 | (eq gnus-treat-condition 'head)) |
16409b0b GM |
8397 | (gnus-treat-predicate val) |
8398 | (or (not (get (car elem) 'highlight)) | |
8399 | highlightp)) | |
8400 | (save-restriction | |
8401 | (funcall (cadr elem))))))) | |
8402 | ||
8403 | ;; Dynamic variables. | |
9efa445f DN |
8404 | (defvar part-number) |
8405 | (defvar total-parts) | |
c497474b GM |
8406 | (defvar gnus-treat-type) |
8407 | (defvar gnus-treat-condition) | |
8408 | (defvar gnus-treat-length) | |
e0bad764 | 8409 | |
16409b0b GM |
8410 | (defun gnus-treat-predicate (val) |
8411 | (cond | |
8412 | ((null val) | |
8413 | nil) | |
c497474b GM |
8414 | (gnus-treat-condition |
8415 | (eq gnus-treat-condition val)) | |
16409b0b GM |
8416 | ((and (listp val) |
8417 | (stringp (car val))) | |
8418 | (apply 'gnus-or (mapcar `(lambda (s) | |
8419 | (string-match s ,(or gnus-newsgroup-name ""))) | |
8420 | val))) | |
8421 | ((listp val) | |
8422 | (let ((pred (pop val))) | |
8423 | (cond | |
8424 | ((eq pred 'or) | |
8425 | (apply 'gnus-or (mapcar 'gnus-treat-predicate val))) | |
8426 | ((eq pred 'and) | |
8427 | (apply 'gnus-and (mapcar 'gnus-treat-predicate val))) | |
8428 | ((eq pred 'not) | |
8429 | (not (gnus-treat-predicate (car val)))) | |
8430 | ((eq pred 'typep) | |
c497474b | 8431 | (equal (car val) gnus-treat-type)) |
47cc1156 G |
8432 | ((functionp pred) |
8433 | (funcall pred)) | |
16409b0b GM |
8434 | (t |
8435 | (error "%S is not a valid predicate" pred))))) | |
16409b0b GM |
8436 | ((eq val t) |
8437 | t) | |
8438 | ((eq val 'head) | |
8439 | nil) | |
01c52d31 MB |
8440 | ((eq val 'first) |
8441 | (eq part-number 1)) | |
16409b0b GM |
8442 | ((eq val 'last) |
8443 | (eq part-number total-parts)) | |
8444 | ((numberp val) | |
c497474b | 8445 | (< gnus-treat-length val)) |
16409b0b GM |
8446 | (t |
8447 | (error "%S is not a valid value" val)))) | |
8448 | ||
23f87bed MB |
8449 | (defun gnus-article-encrypt-body (protocol &optional n) |
8450 | "Encrypt the article body." | |
8451 | (interactive | |
8452 | (list | |
8453 | (or gnus-article-encrypt-protocol | |
229b59da G |
8454 | (gnus-completing-read "Encrypt protocol" |
8455 | (mapcar 'car gnus-article-encrypt-protocol-alist) | |
8456 | t)) | |
23f87bed | 8457 | current-prefix-arg)) |
bbbe940b MB |
8458 | ;; User might hit `K E' instead of `K e', so prompt once. |
8459 | (when (and gnus-article-encrypt-protocol | |
8460 | gnus-novice-user) | |
8461 | (unless (gnus-y-or-n-p "Really encrypt article(s)? ") | |
d93ec753 | 8462 | (error "Encrypt aborted"))) |
23f87bed MB |
8463 | (let ((func (cdr (assoc protocol gnus-article-encrypt-protocol-alist)))) |
8464 | (unless func | |
998a5a95 | 8465 | (error "Can't find the encrypt protocol %s" protocol)) |
23f87bed MB |
8466 | (if (member gnus-newsgroup-name '("nndraft:delayed" |
8467 | "nndraft:drafts" | |
8468 | "nndraft:queue")) | |
8469 | (error "Can't encrypt the article in group %s" | |
8470 | gnus-newsgroup-name)) | |
8471 | (gnus-summary-iterate n | |
80de1778 | 8472 | (with-current-buffer gnus-summary-buffer |
23f87bed MB |
8473 | (let ((mail-parse-charset gnus-newsgroup-charset) |
8474 | (mail-parse-ignored-charsets gnus-newsgroup-ignored-charsets) | |
8475 | (summary-buffer gnus-summary-buffer) | |
8476 | references point) | |
8477 | (gnus-set-global-variables) | |
8478 | (when (gnus-group-read-only-p) | |
8479 | (error "The current newsgroup does not support article encrypt")) | |
8480 | (gnus-summary-show-article t) | |
8481 | (setq references | |
8482 | (or (mail-header-references gnus-current-headers) "")) | |
8483 | (set-buffer gnus-article-buffer) | |
8484 | (let* ((inhibit-read-only t) | |
8485 | (headers | |
8486 | (mapcar (lambda (field) | |
8487 | (and (save-restriction | |
8488 | (message-narrow-to-head) | |
8489 | (goto-char (point-min)) | |
8490 | (search-forward field nil t)) | |
8491 | (prog2 | |
8492 | (message-narrow-to-field) | |
8493 | (buffer-string) | |
8494 | (delete-region (point-min) (point-max)) | |
8495 | (widen)))) | |
8496 | '("Content-Type:" "Content-Transfer-Encoding:" | |
8497 | "Content-Disposition:")))) | |
8498 | (message-narrow-to-head) | |
8499 | (message-remove-header "MIME-Version") | |
8500 | (goto-char (point-max)) | |
8501 | (setq point (point)) | |
8502 | (insert (apply 'concat headers)) | |
8503 | (widen) | |
8504 | (narrow-to-region point (point-max)) | |
8505 | (let ((message-options message-options)) | |
8506 | (message-options-set 'message-sender user-mail-address) | |
8507 | (message-options-set 'message-recipients user-mail-address) | |
8508 | (message-options-set 'message-sign-encrypt 'not) | |
8509 | (funcall func)) | |
8510 | (goto-char (point-min)) | |
8511 | (insert "MIME-Version: 1.0\n") | |
8512 | (widen) | |
8513 | (gnus-summary-edit-article-done | |
8514 | references nil summary-buffer t)) | |
8515 | (when gnus-keep-backlog | |
8516 | (gnus-backlog-remove-article | |
8517 | (car gnus-article-current) (cdr gnus-article-current))) | |
8ccbef23 | 8518 | (gnus-flush-original-article-buffer) |
23f87bed MB |
8519 | (when gnus-use-cache |
8520 | (gnus-cache-update-article | |
8521 | (car gnus-article-current) (cdr gnus-article-current)))))))) | |
8522 | ||
8523 | (defvar gnus-mime-security-button-line-format "%{%([[%t:%i]%D]%)%}\n" | |
8524 | "The following specs can be used: | |
8525 | %t The security MIME type | |
8526 | %i Additional info | |
8527 | %d Details | |
8528 | %D Details if button is pressed") | |
8529 | ||
8530 | (defvar gnus-mime-security-button-end-line-format "%{%([[End of %t]%D]%)%}\n" | |
8531 | "The following specs can be used: | |
8532 | %t The security MIME type | |
8533 | %i Additional info | |
8534 | %d Details | |
8535 | %D Details if button is pressed") | |
8536 | ||
8537 | (defvar gnus-mime-security-button-line-format-alist | |
8538 | '((?t gnus-tmp-type ?s) | |
8539 | (?i gnus-tmp-info ?s) | |
8540 | (?d gnus-tmp-details ?s) | |
8541 | (?D gnus-tmp-pressed-details ?s))) | |
8542 | ||
01c52d31 MB |
8543 | (defvar gnus-mime-security-button-commands |
8544 | '((gnus-article-press-button "\r" "Show Detail") | |
8545 | (undefined "v") | |
8546 | (undefined "t") | |
8547 | (undefined "C") | |
8548 | (gnus-mime-security-save-part "o" "Save...") | |
8549 | (undefined "\C-o") | |
8550 | (undefined "r") | |
8551 | (undefined "d") | |
8552 | (undefined "c") | |
8553 | (undefined "i") | |
8554 | (undefined "E") | |
8555 | (undefined "e") | |
8556 | (undefined "p") | |
8557 | (gnus-mime-security-pipe-part "|" "Pipe To Command...") | |
8558 | (undefined "."))) | |
8559 | ||
23f87bed MB |
8560 | (defvar gnus-mime-security-button-map |
8561 | (let ((map (make-sparse-keymap))) | |
23f87bed | 8562 | (define-key map gnus-mouse-2 'gnus-article-push-button) |
01c52d31 MB |
8563 | (define-key map gnus-down-mouse-3 'gnus-mime-security-button-menu) |
8564 | (dolist (c gnus-mime-security-button-commands) | |
8565 | (define-key map (cadr c) (car c))) | |
23f87bed MB |
8566 | map)) |
8567 | ||
01c52d31 MB |
8568 | (easy-menu-define |
8569 | gnus-mime-security-button-menu gnus-mime-security-button-map | |
8570 | "Security button menu." | |
8571 | `("Security Part" | |
8572 | ,@(delq nil | |
8573 | (mapcar (lambda (c) | |
8574 | (unless (eq (car c) 'undefined) | |
8575 | (vector (caddr c) (car c) :active t))) | |
8576 | gnus-mime-security-button-commands)))) | |
8577 | ||
8578 | (defun gnus-mime-security-button-menu (event prefix) | |
8579 | "Construct a context-sensitive menu of security commands." | |
8580 | (interactive "e\nP") | |
8581 | (save-window-excursion | |
8582 | (let ((pos (event-start event))) | |
8583 | (select-window (posn-window pos)) | |
8584 | (goto-char (posn-point pos)) | |
8585 | (gnus-article-check-buffer) | |
8586 | (popup-menu gnus-mime-security-button-menu nil prefix)))) | |
8587 | ||
23f87bed MB |
8588 | (defvar gnus-mime-security-details-buffer nil) |
8589 | ||
8590 | (defvar gnus-mime-security-button-pressed nil) | |
8591 | ||
8592 | (defvar gnus-mime-security-show-details-inline t | |
8593 | "If non-nil, show details in the article buffer.") | |
8594 | ||
8595 | (defun gnus-mime-security-verify-or-decrypt (handle) | |
8596 | (mm-remove-parts (cdr handle)) | |
8597 | (let ((region (mm-handle-multipart-ctl-parameter handle 'gnus-region)) | |
8598 | point (inhibit-read-only t)) | |
8599 | (if region | |
8600 | (goto-char (car region))) | |
01c52d31 MB |
8601 | (setq point (point)) |
8602 | (with-current-buffer (mm-handle-multipart-original-buffer handle) | |
8603 | (let* ((mm-verify-option 'known) | |
8604 | (mm-decrypt-option 'known) | |
8605 | (nparts (mm-possibly-verify-or-decrypt (cdr handle) handle))) | |
8606 | (unless (eq nparts (cdr handle)) | |
8607 | (mm-destroy-parts (cdr handle)) | |
8608 | (setcdr handle nparts)))) | |
8609 | (gnus-mime-display-security handle) | |
23f87bed MB |
8610 | (when region |
8611 | (delete-region (point) (cdr region)) | |
8612 | (set-marker (car region) nil) | |
8613 | (set-marker (cdr region) nil)) | |
8614 | (goto-char point))) | |
8615 | ||
8616 | (defun gnus-mime-security-show-details (handle) | |
8617 | (let ((details (mm-handle-multipart-ctl-parameter handle 'gnus-details))) | |
8618 | (if (not details) | |
8619 | (gnus-message 5 "No details.") | |
8620 | (if gnus-mime-security-show-details-inline | |
8621 | (let ((gnus-mime-security-button-pressed | |
8622 | (not (get-text-property (point) 'gnus-mime-details))) | |
8623 | (gnus-mime-security-button-line-format | |
8624 | (get-text-property (point) 'gnus-line-format)) | |
8625 | (inhibit-read-only t)) | |
8626 | (forward-char -1) | |
8627 | (while (eq (get-text-property (point) 'gnus-line-format) | |
8628 | gnus-mime-security-button-line-format) | |
8629 | (forward-char -1)) | |
8630 | (forward-char) | |
8631 | (save-restriction | |
8632 | (narrow-to-region (point) (point)) | |
8633 | (gnus-insert-mime-security-button handle)) | |
8634 | (delete-region (point) | |
8635 | (or (text-property-not-all | |
8636 | (point) (point-max) | |
8637 | 'gnus-line-format | |
8638 | gnus-mime-security-button-line-format) | |
8639 | (point-max)))) | |
8640 | ;; Not inlined. | |
8641 | (if (gnus-buffer-live-p gnus-mime-security-details-buffer) | |
8642 | (with-current-buffer gnus-mime-security-details-buffer | |
8643 | (erase-buffer) | |
8644 | t) | |
8645 | (setq gnus-mime-security-details-buffer | |
8646 | (gnus-get-buffer-create "*MIME Security Details*"))) | |
8647 | (with-current-buffer gnus-mime-security-details-buffer | |
8648 | (insert details) | |
8649 | (goto-char (point-min))) | |
8650 | (pop-to-buffer gnus-mime-security-details-buffer))))) | |
8651 | ||
8652 | (defun gnus-mime-security-press-button (handle) | |
8653 | (save-excursion | |
8654 | (if (mm-handle-multipart-ctl-parameter handle 'gnus-info) | |
8655 | (gnus-mime-security-show-details handle) | |
8656 | (gnus-mime-security-verify-or-decrypt handle)))) | |
8657 | ||
8658 | (defun gnus-insert-mime-security-button (handle &optional displayed) | |
8659 | (let* ((protocol (mm-handle-multipart-ctl-parameter handle 'protocol)) | |
8660 | (gnus-tmp-type | |
8661 | (concat | |
8662 | (or (nth 2 (assoc protocol mm-verify-function-alist)) | |
8663 | (nth 2 (assoc protocol mm-decrypt-function-alist)) | |
8664 | "Unknown") | |
8665 | (if (equal (car handle) "multipart/signed") | |
8666 | " Signed" " Encrypted") | |
8667 | " Part")) | |
8668 | (gnus-tmp-info | |
8669 | (or (mm-handle-multipart-ctl-parameter handle 'gnus-info) | |
8670 | "Undecided")) | |
8671 | (gnus-tmp-details | |
8672 | (mm-handle-multipart-ctl-parameter handle 'gnus-details)) | |
8673 | gnus-tmp-pressed-details | |
8674 | b e) | |
8675 | (setq gnus-tmp-details | |
8676 | (if gnus-tmp-details | |
8677 | (concat "\n" gnus-tmp-details) | |
8678 | "")) | |
8679 | (setq gnus-tmp-pressed-details | |
8680 | (if gnus-mime-security-button-pressed gnus-tmp-details "")) | |
8681 | (unless (bolp) | |
8682 | (insert "\n")) | |
8683 | (setq b (point)) | |
8684 | (gnus-eval-format | |
8685 | gnus-mime-security-button-line-format | |
8686 | gnus-mime-security-button-line-format-alist | |
01c52d31 | 8687 | `(keymap ,gnus-mime-security-button-map |
23f87bed MB |
8688 | gnus-callback gnus-mime-security-press-button |
8689 | gnus-line-format ,gnus-mime-security-button-line-format | |
8690 | gnus-mime-details ,gnus-mime-security-button-pressed | |
8691 | article-type annotation | |
8692 | gnus-data ,handle)) | |
8693 | (setq e (if (bolp) | |
8694 | ;; Exclude a newline. | |
8695 | (1- (point)) | |
8696 | (point))) | |
01c52d31 MB |
8697 | (when gnus-article-button-face |
8698 | (gnus-overlay-put (gnus-make-overlay b e nil t) | |
8699 | 'face gnus-article-button-face)) | |
23f87bed MB |
8700 | (widget-convert-button |
8701 | 'link b e | |
8702 | :mime-handle handle | |
8703 | :action 'gnus-widget-press-button | |
8704 | :button-keymap gnus-mime-security-button-map | |
8705 | :help-echo | |
5843126b | 8706 | (lambda (widget) |
23f87bed MB |
8707 | ;; Needed to properly clear the message due to a bug in |
8708 | ;; wid-edit (XEmacs only). | |
8709 | (when (boundp 'help-echo-owns-message) | |
8710 | (setq help-echo-owns-message t)) | |
8711 | (format | |
01c52d31 MB |
8712 | "%S: show detail; %S: more options" |
8713 | (aref gnus-mouse-2 0) | |
8714 | (aref gnus-down-mouse-3 0)))))) | |
23f87bed MB |
8715 | |
8716 | (defun gnus-mime-display-security (handle) | |
8717 | (save-restriction | |
8718 | (narrow-to-region (point) (point)) | |
8719 | (unless (gnus-unbuttonized-mime-type-p (car handle)) | |
8720 | (gnus-insert-mime-security-button handle)) | |
01c52d31 | 8721 | (gnus-mime-display-part (cadr handle)) |
23f87bed MB |
8722 | (unless (bolp) |
8723 | (insert "\n")) | |
8724 | (unless (gnus-unbuttonized-mime-type-p (car handle)) | |
8725 | (let ((gnus-mime-security-button-line-format | |
8726 | gnus-mime-security-button-end-line-format)) | |
8727 | (gnus-insert-mime-security-button handle))) | |
8728 | (mm-set-handle-multipart-parameter | |
30818a23 | 8729 | handle 'gnus-region (cons (point-min-marker) (point-max-marker))) |
01c52d31 MB |
8730 | (goto-char (point-max)))) |
8731 | ||
8732 | (defun gnus-mime-security-run-function (function) | |
8733 | "Run FUNCTION with the security part under point." | |
8734 | (gnus-article-check-buffer) | |
8735 | (let ((data (get-text-property (point) 'gnus-data)) | |
8736 | buffer handle) | |
8737 | (when (and (stringp (car-safe data)) | |
8738 | (setq buffer (mm-handle-multipart-original-buffer data)) | |
8739 | (setq handle (cadr data))) | |
8740 | (if (bufferp (mm-handle-buffer handle)) | |
8741 | (progn | |
8742 | (setq handle (cons buffer (copy-sequence (cdr handle)))) | |
8743 | (mm-handle-set-undisplayer handle nil)) | |
8744 | (setq handle (mm-make-handle | |
8745 | buffer | |
8746 | (mm-handle-multipart-ctl-parameter handle 'protocol) | |
8747 | nil nil nil nil nil nil))) | |
8748 | (funcall function handle)))) | |
8749 | ||
8750 | (defun gnus-mime-security-save-part () | |
8751 | "Save the security part under point." | |
8752 | (interactive) | |
8753 | (gnus-mime-security-run-function 'mm-save-part)) | |
8754 | ||
8755 | (defun gnus-mime-security-pipe-part () | |
8756 | "Pipe the security part under point to a process." | |
8757 | (interactive) | |
8758 | (gnus-mime-security-run-function 'mm-pipe-part)) | |
23f87bed | 8759 | |
eec82323 LMI |
8760 | (gnus-ems-redefine) |
8761 | ||
8762 | (provide 'gnus-art) | |
8763 | ||
8764 | (run-hooks 'gnus-art-load-hook) | |
8765 | ||
8766 | ;;; gnus-art.el ends here |