Mercurial > emacs
comparison lisp/gnus/gnus-uu.el @ 17493:e6935c08cf0b
Initial revision
author | Lars Magne Ingebrigtsen <larsi@gnus.org> |
---|---|
date | Wed, 16 Apr 1997 22:13:18 +0000 |
parents | |
children | 118761d47324 |
comparison
equal
deleted
inserted
replaced
17492:59dc7e0fc186 | 17493:e6935c08cf0b |
---|---|
1 ;;; gnus-uu.el --- extract (uu)encoded files in Gnus | |
2 ;; Copyright (C) 1985,86,87,93,94,95,96,97 Free Software Foundation, Inc. | |
3 | |
4 ;; Author: Lars Magne Ingebrigtsen <larsi@ifi.uio.no> | |
5 ;; Created: 2 Oct 1993 | |
6 ;; Keyword: news | |
7 | |
8 ;; This file is part of GNU Emacs. | |
9 | |
10 ;; GNU Emacs is free software; you can redistribute it and/or modify | |
11 ;; it under the terms of the GNU General Public License as published by | |
12 ;; the Free Software Foundation; either version 2, or (at your option) | |
13 ;; any later version. | |
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 | |
17 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
18 ;; GNU General Public License for more details. | |
19 | |
20 ;; You should have received a copy of the GNU General Public License | |
21 ;; along with GNU Emacs; see the file COPYING. If not, write to the | |
22 ;; Free Software Foundation, Inc., 59 Temple Place - Suite 330, | |
23 ;; Boston, MA 02111-1307, USA. | |
24 | |
25 ;;; Commentary: | |
26 | |
27 ;;; Code: | |
28 | |
29 (require 'gnus) | |
30 (require 'gnus-art) | |
31 (require 'message) | |
32 (require 'gnus-msg) | |
33 | |
34 (defgroup gnus-extract nil | |
35 "Extracting encoded files." | |
36 :prefix "gnus-uu-" | |
37 :group 'gnus) | |
38 | |
39 (defgroup gnus-extract-view nil | |
40 "Viewwing extracted files." | |
41 :group 'gnus-extract) | |
42 | |
43 (defgroup gnus-extract-archive nil | |
44 "Extracting encoded archives." | |
45 :group 'gnus-extract) | |
46 | |
47 (defgroup gnus-extract-post nil | |
48 "Extracting encoded archives." | |
49 :prefix "gnus-uu-post" | |
50 :group 'gnus-extract) | |
51 | |
52 ;; Default viewing action rules | |
53 | |
54 (defcustom gnus-uu-default-view-rules | |
55 '(("\\.te?xt$\\|\\.doc$\\|read.*me\\|\\.c?$\\|\\.h$\\|\\.bat$\\|\\.asm$\\|makefile" "cat %s | sed s/\r//g") | |
56 ("\\.pas$" "cat %s | sed s/\r//g") | |
57 ("\\.[1-9]$" "groff -mandoc -Tascii %s | sed s/\b.//g") | |
58 ("\\.\\(jpe?g\\|gif\\|tiff?\\|p[pgb]m\\|xwd\\|xbm\\|pcx\\)$" "xv") | |
59 ("\\.tga$" "tgatoppm %s | xv -") | |
60 ("\\.\\(wav\\|aiff\\|hcom\\|u[blw]\\|s[bfw]\\|voc\\|smp\\)$" | |
61 "sox -v .5 %s -t .au -u - > /dev/audio") | |
62 ("\\.au$" "cat %s > /dev/audio") | |
63 ("\\.midi?$" "playmidi -f") | |
64 ("\\.mod$" "str32") | |
65 ("\\.ps$" "ghostview") | |
66 ("\\.dvi$" "xdvi") | |
67 ("\\.html$" "xmosaic") | |
68 ("\\.mpe?g$" "mpeg_play") | |
69 ("\\.\\(flc\\|fli\\|rle\\|iff\\|pfx\\|avi\\|sme\\|rpza\\|dl\\|qt\\|rsrc\\|mov\\)$" "xanim") | |
70 ("\\.\\(tar\\|arj\\|zip\\|zoo\\|arc\\|gz\\|Z\\|lzh\\|ar\\|lha\\)$" | |
71 "gnus-uu-archive")) | |
72 "Default actions to be taken when the user asks to view a file. | |
73 To change the behaviour, you can either edit this variable or set | |
74 `gnus-uu-user-view-rules' to something useful. | |
75 | |
76 For example: | |
77 | |
78 To make gnus-uu use 'xli' to display JPEG and GIF files, put the | |
79 following in your .emacs file: | |
80 | |
81 (setq gnus-uu-user-view-rules '((\"jpg$\\\\|gif$\" \"xli\"))) | |
82 | |
83 Both these variables are lists of lists with two string elements. The | |
84 first string is a regular expression. If the file name matches this | |
85 regular expression, the command in the second string is executed with | |
86 the file as an argument. | |
87 | |
88 If the command string contains \"%s\", the file name will be inserted | |
89 at that point in the command string. If there's no \"%s\" in the | |
90 command string, the file name will be appended to the command string | |
91 before executing. | |
92 | |
93 There are several user variables to tailor the behaviour of gnus-uu to | |
94 your needs. First we have `gnus-uu-user-view-rules', which is the | |
95 variable gnus-uu first consults when trying to decide how to view a | |
96 file. If this variable contains no matches, gnus-uu examines the | |
97 default rule variable provided in this package. If gnus-uu finds no | |
98 match here, it uses `gnus-uu-user-view-rules-end' to try to make a | |
99 match." | |
100 :group 'gnus-extract-view | |
101 :type '(repeat (group regexp (string :tag "Command")))) | |
102 | |
103 (defcustom gnus-uu-user-view-rules nil | |
104 "What actions are to be taken to view a file. | |
105 See the documentation on the `gnus-uu-default-view-rules' variable for | |
106 details." | |
107 :group 'gnus-extract-view | |
108 :type '(repeat (group regexp (string :tag "Command")))) | |
109 | |
110 (defcustom gnus-uu-user-view-rules-end | |
111 '(("" "file")) | |
112 "What actions are to be taken if no rule matched the file name. | |
113 See the documentation on the `gnus-uu-default-view-rules' variable for | |
114 details." | |
115 :group 'gnus-extract-view | |
116 :type '(repeat (group regexp (string :tag "Command")))) | |
117 | |
118 ;; Default unpacking commands | |
119 | |
120 (defcustom gnus-uu-default-archive-rules | |
121 '(("\\.tar$" "tar xf") | |
122 ("\\.zip$" "unzip -o") | |
123 ("\\.ar$" "ar x") | |
124 ("\\.arj$" "unarj x") | |
125 ("\\.zoo$" "zoo -e") | |
126 ("\\.\\(lzh\\|lha\\)$" "lha x") | |
127 ("\\.Z$" "uncompress") | |
128 ("\\.gz$" "gunzip") | |
129 ("\\.arc$" "arc -x")) | |
130 "See `gnus-uu-user-archive-rules'." | |
131 :group 'gnus-extract-archive | |
132 :type '(repeat (group regexp (string :tag "Command")))) | |
133 | |
134 (defvar gnus-uu-destructive-archivers | |
135 (list "uncompress" "gunzip")) | |
136 | |
137 (defcustom gnus-uu-user-archive-rules nil | |
138 "A list that can be set to override the default archive unpacking commands. | |
139 To use, for instance, 'untar' to unpack tar files and 'zip -x' to | |
140 unpack zip files, say the following: | |
141 (setq gnus-uu-user-archive-rules | |
142 '((\"\\\\.tar$\" \"untar\") | |
143 (\"\\\\.zip$\" \"zip -x\")))" | |
144 :group 'gnus-extract-archive | |
145 :type '(repeat (group regexp (string :tag "Command")))) | |
146 | |
147 (defcustom gnus-uu-ignore-files-by-name nil | |
148 "*A regular expression saying what files should not be viewed based on name. | |
149 If, for instance, you want gnus-uu to ignore all .au and .wav files, | |
150 you could say something like | |
151 | |
152 (setq gnus-uu-ignore-files-by-name \"\\\\.au$\\\\|\\\\.wav$\") | |
153 | |
154 Note that this variable can be used in conjunction with the | |
155 `gnus-uu-ignore-files-by-type' variable." | |
156 :group 'gnus-extract | |
157 :type '(choice (const :tag "off" nil) | |
158 (regexp :format "%v"))) | |
159 | |
160 (defcustom gnus-uu-ignore-files-by-type nil | |
161 "*A regular expression saying what files that shouldn't be viewed, based on MIME file type. | |
162 If, for instance, you want gnus-uu to ignore all audio files and all mpegs, | |
163 you could say something like | |
164 | |
165 (setq gnus-uu-ignore-files-by-type \"audio/\\\\|video/mpeg\") | |
166 | |
167 Note that this variable can be used in conjunction with the | |
168 `gnus-uu-ignore-files-by-name' variable." | |
169 :group 'gnus-extract | |
170 :type '(choice (const :tag "off" nil) | |
171 (regexp :format "%v"))) | |
172 | |
173 ;; Pseudo-MIME support | |
174 | |
175 (defconst gnus-uu-ext-to-mime-list | |
176 '(("\\.gif$" "image/gif") | |
177 ("\\.jpe?g$" "image/jpeg") | |
178 ("\\.tiff?$" "image/tiff") | |
179 ("\\.xwd$" "image/xwd") | |
180 ("\\.pbm$" "image/pbm") | |
181 ("\\.pgm$" "image/pgm") | |
182 ("\\.ppm$" "image/ppm") | |
183 ("\\.xbm$" "image/xbm") | |
184 ("\\.pcx$" "image/pcx") | |
185 ("\\.tga$" "image/tga") | |
186 ("\\.ps$" "image/postscript") | |
187 ("\\.fli$" "video/fli") | |
188 ("\\.wav$" "audio/wav") | |
189 ("\\.aiff$" "audio/aiff") | |
190 ("\\.hcom$" "audio/hcom") | |
191 ("\\.voc$" "audio/voc") | |
192 ("\\.smp$" "audio/smp") | |
193 ("\\.mod$" "audio/mod") | |
194 ("\\.dvi$" "image/dvi") | |
195 ("\\.mpe?g$" "video/mpeg") | |
196 ("\\.au$" "audio/basic") | |
197 ("\\.\\(te?xt\\|doc\\|c\\|h\\)$" "text/plain") | |
198 ("\\.\\(c\\|h\\)$" "text/source") | |
199 ("read.*me" "text/plain") | |
200 ("\\.html$" "text/html") | |
201 ("\\.bat$" "text/bat") | |
202 ("\\.[1-6]$" "text/man") | |
203 ("\\.flc$" "video/flc") | |
204 ("\\.rle$" "video/rle") | |
205 ("\\.pfx$" "video/pfx") | |
206 ("\\.avi$" "video/avi") | |
207 ("\\.sme$" "video/sme") | |
208 ("\\.rpza$" "video/prza") | |
209 ("\\.dl$" "video/dl") | |
210 ("\\.qt$" "video/qt") | |
211 ("\\.rsrc$" "video/rsrc") | |
212 ("\\..*$" "unknown/unknown"))) | |
213 | |
214 ;; Various variables users may set | |
215 | |
216 (defcustom gnus-uu-tmp-dir "/tmp/" | |
217 "*Variable saying where gnus-uu is to do its work. | |
218 Default is \"/tmp/\"." | |
219 :group 'gnus-extract | |
220 :type 'directory) | |
221 | |
222 (defcustom gnus-uu-do-not-unpack-archives nil | |
223 "*Non-nil means that gnus-uu won't peek inside archives looking for files to display. | |
224 Default is nil." | |
225 :group 'gnus-extract-archive | |
226 :type 'boolean) | |
227 | |
228 (defcustom gnus-uu-ignore-default-view-rules nil | |
229 "*Non-nil means that gnus-uu will ignore the default viewing rules. | |
230 Only the user viewing rules will be consulted. Default is nil." | |
231 :group 'gnus-extract-view | |
232 :type 'boolean) | |
233 | |
234 (defcustom gnus-uu-grabbed-file-functions nil | |
235 "Functions run on each file after successful decoding. | |
236 They will be called with the name of the file as the argument. | |
237 Likely functions you can use in this list are `gnus-uu-grab-view' | |
238 and `gnus-uu-grab-move'." | |
239 :group 'gnus-extract | |
240 :options '(gnus-uu-grab-view gnus-uu-grab-move) | |
241 :type 'hook) | |
242 | |
243 (defcustom gnus-uu-ignore-default-archive-rules nil | |
244 "*Non-nil means that gnus-uu will ignore the default archive unpacking commands. | |
245 Only the user unpacking commands will be consulted. Default is nil." | |
246 :group 'gnus-extract-archive | |
247 :type 'boolean) | |
248 | |
249 (defcustom gnus-uu-kill-carriage-return t | |
250 "*Non-nil means that gnus-uu will strip all carriage returns from articles. | |
251 Default is t." | |
252 :group 'gnus-extract | |
253 :type 'boolean) | |
254 | |
255 (defcustom gnus-uu-view-with-metamail nil | |
256 "*Non-nil means that files will be viewed with metamail. | |
257 The gnus-uu viewing functions will be ignored and gnus-uu will try | |
258 to guess at a content-type based on file name suffixes. Default | |
259 it nil." | |
260 :group 'gnus-extract | |
261 :type 'boolean) | |
262 | |
263 (defcustom gnus-uu-unmark-articles-not-decoded nil | |
264 "*Non-nil means that gnus-uu will mark articles that were unsuccessfully decoded as unread. | |
265 Default is nil." | |
266 :group 'gnus-extract | |
267 :type 'boolean) | |
268 | |
269 (defcustom gnus-uu-correct-stripped-uucode nil | |
270 "*Non-nil means that gnus-uu will *try* to fix uuencoded files that have had trailing spaces deleted. | |
271 Default is nil." | |
272 :group 'gnus-extract | |
273 :type 'boolean) | |
274 | |
275 (defcustom gnus-uu-save-in-digest nil | |
276 "*Non-nil means that gnus-uu, when asked to save without decoding, will save in digests. | |
277 If this variable is nil, gnus-uu will just save everything in a | |
278 file without any embellishments. The digesting almost conforms to RFC1153 - | |
279 no easy way to specify any meaningful volume and issue numbers were found, | |
280 so I simply dropped them." | |
281 :group 'gnus-extract | |
282 :type 'boolean) | |
283 | |
284 (defcustom gnus-uu-digest-headers | |
285 '("^Date:" "^From:" "^To:" "^Cc:" "^Subject:" "^Message-ID:" "^Keywords:" | |
286 "^Summary:" "^References:") | |
287 "List of regexps to match headers included in digested messages. | |
288 The headers will be included in the sequence they are matched." | |
289 :group 'gnus-extract | |
290 :type '(repeat regexp)) | |
291 | |
292 (defcustom gnus-uu-save-separate-articles nil | |
293 "*Non-nil means that gnus-uu will save articles in separate files." | |
294 :group 'gnus-extract | |
295 :type 'boolean) | |
296 | |
297 (defcustom gnus-uu-be-dangerous 'ask | |
298 "*Specifies what to do if unusual situations arise during decoding. | |
299 If nil, be as conservative as possible. If t, ignore things that | |
300 didn't work, and overwrite existing files. Otherwise, ask each time." | |
301 :group 'gnus-extract | |
302 :type '(choice (const :tag "conservative" nil) | |
303 (const :tag "ask" ask) | |
304 (const :tag "liberal" t))) | |
305 | |
306 ;; Internal variables | |
307 | |
308 (defvar gnus-uu-saved-article-name nil) | |
309 | |
310 (defconst gnus-uu-begin-string "^begin[ \t]+[0-7][0-7][0-7][ \t]+\\(.*\\)$") | |
311 (defconst gnus-uu-end-string "^end[ \t]*$") | |
312 | |
313 (defconst gnus-uu-body-line "^M") | |
314 (let ((i 61)) | |
315 (while (> (setq i (1- i)) 0) | |
316 (setq gnus-uu-body-line (concat gnus-uu-body-line "[^a-z]"))) | |
317 (setq gnus-uu-body-line (concat gnus-uu-body-line ".?$"))) | |
318 | |
319 ;"^M.............................................................?$" | |
320 | |
321 (defconst gnus-uu-shar-begin-string "^#! */bin/sh") | |
322 | |
323 (defvar gnus-uu-shar-file-name nil) | |
324 (defconst gnus-uu-shar-name-marker "begin [0-7][0-7][0-7][ \t]+\\(\\(\\w\\|\\.\\)*\\b\\)") | |
325 | |
326 (defconst gnus-uu-postscript-begin-string "^%!PS-") | |
327 (defconst gnus-uu-postscript-end-string "^%%EOF$") | |
328 | |
329 (defvar gnus-uu-file-name nil) | |
330 (defconst gnus-uu-uudecode-process nil) | |
331 (defvar gnus-uu-binhex-article-name nil) | |
332 | |
333 (defvar gnus-uu-work-dir nil) | |
334 | |
335 (defconst gnus-uu-output-buffer-name " *Gnus UU Output*") | |
336 | |
337 (defvar gnus-uu-default-dir gnus-article-save-directory) | |
338 (defvar gnus-uu-digest-from-subject nil) | |
339 | |
340 ;; Keymaps | |
341 | |
342 (gnus-define-keys (gnus-uu-mark-map "P" gnus-summary-mark-map) | |
343 "p" gnus-summary-mark-as-processable | |
344 "u" gnus-summary-unmark-as-processable | |
345 "U" gnus-summary-unmark-all-processable | |
346 "v" gnus-uu-mark-over | |
347 "s" gnus-uu-mark-series | |
348 "r" gnus-uu-mark-region | |
349 "R" gnus-uu-mark-by-regexp | |
350 "t" gnus-uu-mark-thread | |
351 "T" gnus-uu-unmark-thread | |
352 "a" gnus-uu-mark-all | |
353 "b" gnus-uu-mark-buffer | |
354 "S" gnus-uu-mark-sparse | |
355 "k" gnus-summary-kill-process-mark | |
356 "y" gnus-summary-yank-process-mark | |
357 "w" gnus-summary-save-process-mark | |
358 "i" gnus-uu-invert-processable) | |
359 | |
360 (gnus-define-keys (gnus-uu-extract-map "X" gnus-summary-mode-map) | |
361 ;;"x" gnus-uu-extract-any | |
362 ;;"m" gnus-uu-extract-mime | |
363 "u" gnus-uu-decode-uu | |
364 "U" gnus-uu-decode-uu-and-save | |
365 "s" gnus-uu-decode-unshar | |
366 "S" gnus-uu-decode-unshar-and-save | |
367 "o" gnus-uu-decode-save | |
368 "O" gnus-uu-decode-save | |
369 "b" gnus-uu-decode-binhex | |
370 "B" gnus-uu-decode-binhex | |
371 "p" gnus-uu-decode-postscript | |
372 "P" gnus-uu-decode-postscript-and-save) | |
373 | |
374 (gnus-define-keys | |
375 (gnus-uu-extract-view-map "v" gnus-uu-extract-map) | |
376 "u" gnus-uu-decode-uu-view | |
377 "U" gnus-uu-decode-uu-and-save-view | |
378 "s" gnus-uu-decode-unshar-view | |
379 "S" gnus-uu-decode-unshar-and-save-view | |
380 "o" gnus-uu-decode-save-view | |
381 "O" gnus-uu-decode-save-view | |
382 "b" gnus-uu-decode-binhex-view | |
383 "B" gnus-uu-decode-binhex-view | |
384 "p" gnus-uu-decode-postscript-view | |
385 "P" gnus-uu-decode-postscript-and-save-view) | |
386 | |
387 | |
388 ;; Commands. | |
389 | |
390 (defun gnus-uu-decode-uu (&optional n) | |
391 "Uudecodes the current article." | |
392 (interactive "P") | |
393 (gnus-uu-decode-with-method 'gnus-uu-uustrip-article n)) | |
394 | |
395 (defun gnus-uu-decode-uu-and-save (n dir) | |
396 "Decodes and saves the resulting file." | |
397 (interactive | |
398 (list current-prefix-arg | |
399 (file-name-as-directory | |
400 (read-file-name "Uudecode and save in dir: " | |
401 gnus-uu-default-dir | |
402 gnus-uu-default-dir t)))) | |
403 (gnus-uu-decode-with-method 'gnus-uu-uustrip-article n dir nil nil t)) | |
404 | |
405 (defun gnus-uu-decode-unshar (&optional n) | |
406 "Unshars the current article." | |
407 (interactive "P") | |
408 (gnus-uu-decode-with-method 'gnus-uu-unshar-article n nil nil 'scan t)) | |
409 | |
410 (defun gnus-uu-decode-unshar-and-save (n dir) | |
411 "Unshars and saves the current article." | |
412 (interactive | |
413 (list current-prefix-arg | |
414 (file-name-as-directory | |
415 (read-file-name "Unshar and save in dir: " | |
416 gnus-uu-default-dir | |
417 gnus-uu-default-dir t)))) | |
418 (gnus-uu-decode-with-method 'gnus-uu-unshar-article n dir nil 'scan t)) | |
419 | |
420 (defun gnus-uu-decode-save (n file) | |
421 "Saves the current article." | |
422 (interactive | |
423 (list current-prefix-arg | |
424 (read-file-name | |
425 (if gnus-uu-save-separate-articles | |
426 "Save articles is dir: " | |
427 "Save articles in file: ") | |
428 gnus-uu-default-dir | |
429 gnus-uu-default-dir))) | |
430 (setq gnus-uu-saved-article-name file) | |
431 (gnus-uu-decode-with-method 'gnus-uu-save-article n nil t)) | |
432 | |
433 (defun gnus-uu-decode-binhex (n dir) | |
434 "Unbinhexes the current article." | |
435 (interactive | |
436 (list current-prefix-arg | |
437 (file-name-as-directory | |
438 (read-file-name "Unbinhex and save in dir: " | |
439 gnus-uu-default-dir | |
440 gnus-uu-default-dir)))) | |
441 (setq gnus-uu-binhex-article-name | |
442 (make-temp-name (concat gnus-uu-work-dir "binhex"))) | |
443 (gnus-uu-decode-with-method 'gnus-uu-binhex-article n dir)) | |
444 | |
445 (defun gnus-uu-decode-uu-view (&optional n) | |
446 "Uudecodes and views the current article." | |
447 (interactive "P") | |
448 (let ((gnus-view-pseudos (or gnus-view-pseudos 'automatic))) | |
449 (gnus-uu-decode-uu n))) | |
450 | |
451 (defun gnus-uu-decode-uu-and-save-view (n dir) | |
452 "Decodes, views and saves the resulting file." | |
453 (interactive | |
454 (list current-prefix-arg | |
455 (read-file-name "Uudecode, view and save in dir: " | |
456 gnus-uu-default-dir | |
457 gnus-uu-default-dir t))) | |
458 (let ((gnus-view-pseudos (or gnus-view-pseudos 'automatic))) | |
459 (gnus-uu-decode-uu-and-save n dir))) | |
460 | |
461 (defun gnus-uu-decode-unshar-view (&optional n) | |
462 "Unshars and views the current article." | |
463 (interactive "P") | |
464 (let ((gnus-view-pseudos (or gnus-view-pseudos 'automatic))) | |
465 (gnus-uu-decode-unshar n))) | |
466 | |
467 (defun gnus-uu-decode-unshar-and-save-view (n dir) | |
468 "Unshars and saves the current article." | |
469 (interactive | |
470 (list current-prefix-arg | |
471 (read-file-name "Unshar, view and save in dir: " | |
472 gnus-uu-default-dir | |
473 gnus-uu-default-dir t))) | |
474 (let ((gnus-view-pseudos (or gnus-view-pseudos 'automatic))) | |
475 (gnus-uu-decode-unshar-and-save n dir))) | |
476 | |
477 (defun gnus-uu-decode-save-view (n file) | |
478 "Saves and views the current article." | |
479 (interactive | |
480 (list current-prefix-arg | |
481 (read-file-name (if gnus-uu-save-separate-articles | |
482 "Save articles is dir: " | |
483 "Save articles in file: ") | |
484 gnus-uu-default-dir gnus-uu-default-dir))) | |
485 (let ((gnus-view-pseudos (or gnus-view-pseudos 'automatic))) | |
486 (gnus-uu-decode-save n file))) | |
487 | |
488 (defun gnus-uu-decode-binhex-view (n file) | |
489 "Unbinhexes and views the current article." | |
490 (interactive | |
491 (list current-prefix-arg | |
492 (read-file-name "Unbinhex, view and save in dir: " | |
493 gnus-uu-default-dir gnus-uu-default-dir))) | |
494 (setq gnus-uu-binhex-article-name | |
495 (make-temp-name (concat gnus-uu-work-dir "binhex"))) | |
496 (let ((gnus-view-pseudos (or gnus-view-pseudos 'automatic))) | |
497 (gnus-uu-decode-binhex n file))) | |
498 | |
499 | |
500 ;; Digest and forward articles | |
501 | |
502 (defun gnus-uu-digest-mail-forward (&optional n post) | |
503 "Digests and forwards all articles in this series." | |
504 (interactive "P") | |
505 (let ((gnus-uu-save-in-digest t) | |
506 (file (make-temp-name (nnheader-concat gnus-uu-tmp-dir "forward"))) | |
507 buf subject from newsgroups) | |
508 (gnus-setup-message 'forward | |
509 (setq gnus-uu-digest-from-subject nil) | |
510 (gnus-uu-decode-save n file) | |
511 (setq buf (switch-to-buffer (get-buffer-create " *gnus-uu-forward*"))) | |
512 (gnus-add-current-to-buffer-list) | |
513 (erase-buffer) | |
514 (insert-file file) | |
515 (let ((fs gnus-uu-digest-from-subject)) | |
516 (when fs | |
517 (setq from (caar fs) | |
518 subject (gnus-simplify-subject-fuzzy (cdar fs)) | |
519 fs (cdr fs)) | |
520 (while (and fs (or from subject)) | |
521 (when from | |
522 (unless (string= from (caar fs)) | |
523 (setq from nil))) | |
524 (when subject | |
525 (unless (string= (gnus-simplify-subject-fuzzy (cdar fs)) | |
526 subject) | |
527 (setq subject nil))) | |
528 (setq fs (cdr fs)))) | |
529 (unless subject | |
530 (setq subject "Digested Articles")) | |
531 (unless from | |
532 (setq from | |
533 (if (gnus-news-group-p gnus-newsgroup-name) | |
534 gnus-newsgroup-name | |
535 "Various")))) | |
536 (goto-char (point-min)) | |
537 (when (re-search-forward "^Subject: ") | |
538 (delete-region (point) (gnus-point-at-eol)) | |
539 (insert subject)) | |
540 (goto-char (point-min)) | |
541 (when (re-search-forward "^From: ") | |
542 (delete-region (point) (gnus-point-at-eol)) | |
543 (insert from)) | |
544 (message-forward post)) | |
545 (delete-file file) | |
546 (kill-buffer buf) | |
547 (setq gnus-uu-digest-from-subject nil))) | |
548 | |
549 (defun gnus-uu-digest-post-forward (&optional n) | |
550 "Digest and forward to a newsgroup." | |
551 (interactive "P") | |
552 (gnus-uu-digest-mail-forward n t)) | |
553 | |
554 ;; Process marking. | |
555 | |
556 (defun gnus-uu-mark-by-regexp (regexp &optional unmark) | |
557 "Ask for a regular expression and set the process mark on all articles that match." | |
558 (interactive (list (read-from-minibuffer "Mark (regexp): "))) | |
559 (gnus-set-global-variables) | |
560 (let ((articles (gnus-uu-find-articles-matching regexp))) | |
561 (while articles | |
562 (if unmark | |
563 (gnus-summary-remove-process-mark (pop articles)) | |
564 (gnus-summary-set-process-mark (pop articles)))) | |
565 (message "")) | |
566 (gnus-summary-position-point)) | |
567 | |
568 (defun gnus-uu-unmark-by-regexp (regexp &optional unmark) | |
569 "Ask for a regular expression and remove the process mark on all articles that match." | |
570 (interactive (list (read-from-minibuffer "Mark (regexp): "))) | |
571 (gnus-uu-mark-by-regexp regexp t)) | |
572 | |
573 (defun gnus-uu-mark-series () | |
574 "Mark the current series with the process mark." | |
575 (interactive) | |
576 (gnus-set-global-variables) | |
577 (let ((articles (gnus-uu-find-articles-matching))) | |
578 (while articles | |
579 (gnus-summary-set-process-mark (car articles)) | |
580 (setq articles (cdr articles))) | |
581 (message "")) | |
582 (gnus-summary-position-point)) | |
583 | |
584 (defun gnus-uu-mark-region (beg end &optional unmark) | |
585 "Set the process mark on all articles between point and mark." | |
586 (interactive "r") | |
587 (gnus-set-global-variables) | |
588 (save-excursion | |
589 (goto-char beg) | |
590 (while (< (point) end) | |
591 (if unmark | |
592 (gnus-summary-remove-process-mark (gnus-summary-article-number)) | |
593 (gnus-summary-set-process-mark (gnus-summary-article-number))) | |
594 (forward-line 1))) | |
595 (gnus-summary-position-point)) | |
596 | |
597 (defun gnus-uu-unmark-region (beg end) | |
598 "Remove the process mark from all articles between point and mark." | |
599 (interactive "r") | |
600 (gnus-uu-mark-region beg end t)) | |
601 | |
602 (defun gnus-uu-mark-buffer () | |
603 "Set the process mark on all articles in the buffer." | |
604 (interactive) | |
605 (gnus-uu-mark-region (point-min) (point-max))) | |
606 | |
607 (defun gnus-uu-unmark-buffer () | |
608 "Remove the process mark on all articles in the buffer." | |
609 (interactive) | |
610 (gnus-uu-mark-region (point-min) (point-max) t)) | |
611 | |
612 (defun gnus-uu-mark-thread () | |
613 "Marks all articles downwards in this thread." | |
614 (interactive) | |
615 (gnus-set-global-variables) | |
616 (let ((level (gnus-summary-thread-level))) | |
617 (while (and (gnus-summary-set-process-mark (gnus-summary-article-number)) | |
618 (zerop (gnus-summary-next-subject 1)) | |
619 (> (gnus-summary-thread-level) level)))) | |
620 (gnus-summary-position-point)) | |
621 | |
622 (defun gnus-uu-unmark-thread () | |
623 "Unmarks all articles downwards in this thread." | |
624 (interactive) | |
625 (gnus-set-global-variables) | |
626 (let ((level (gnus-summary-thread-level))) | |
627 (while (and (gnus-summary-remove-process-mark | |
628 (gnus-summary-article-number)) | |
629 (zerop (gnus-summary-next-subject 1)) | |
630 (> (gnus-summary-thread-level) level)))) | |
631 (gnus-summary-position-point)) | |
632 | |
633 (defun gnus-uu-invert-processable () | |
634 "Invert the list of process-marked articles." | |
635 (let ((data gnus-newsgroup-data) | |
636 d number) | |
637 (save-excursion | |
638 (while data | |
639 (if (memq (setq number (gnus-data-number (pop data))) | |
640 gnus-newsgroup-processable) | |
641 (gnus-summary-remove-process-mark number) | |
642 (gnus-summary-set-process-mark number))))) | |
643 (gnus-summary-position-point)) | |
644 | |
645 (defun gnus-uu-mark-over (&optional score) | |
646 "Mark all articles with a score over SCORE (the prefix.)" | |
647 (interactive "P") | |
648 (let ((score (gnus-score-default score)) | |
649 (data gnus-newsgroup-data)) | |
650 (save-excursion | |
651 (while data | |
652 (when (> (or (cdr (assq (gnus-data-number (car data)) | |
653 gnus-newsgroup-scored)) | |
654 gnus-summary-default-score 0) | |
655 score) | |
656 (gnus-summary-set-process-mark (caar data))) | |
657 (setq data (cdr data)))) | |
658 (gnus-summary-position-point))) | |
659 | |
660 (defun gnus-uu-mark-sparse () | |
661 "Mark all series that have some articles marked." | |
662 (interactive) | |
663 (gnus-set-global-variables) | |
664 (let ((marked (nreverse gnus-newsgroup-processable)) | |
665 subject articles total headers) | |
666 (unless marked | |
667 (error "No articles marked with the process mark")) | |
668 (setq gnus-newsgroup-processable nil) | |
669 (save-excursion | |
670 (while marked | |
671 (and (vectorp (setq headers | |
672 (gnus-summary-article-header (car marked)))) | |
673 (setq subject (mail-header-subject headers) | |
674 articles (gnus-uu-find-articles-matching | |
675 (gnus-uu-reginize-string subject)) | |
676 total (nconc total articles))) | |
677 (while articles | |
678 (gnus-summary-set-process-mark (car articles)) | |
679 (setcdr marked (delq (car articles) (cdr marked))) | |
680 (setq articles (cdr articles))) | |
681 (setq marked (cdr marked))) | |
682 (setq gnus-newsgroup-processable (nreverse total))) | |
683 (gnus-summary-position-point))) | |
684 | |
685 (defun gnus-uu-mark-all () | |
686 "Mark all articles in \"series\" order." | |
687 (interactive) | |
688 (gnus-set-global-variables) | |
689 (setq gnus-newsgroup-processable nil) | |
690 (save-excursion | |
691 (let ((data gnus-newsgroup-data) | |
692 number) | |
693 (while data | |
694 (when (and (not (memq (setq number (gnus-data-number (car data))) | |
695 gnus-newsgroup-processable)) | |
696 (vectorp (gnus-data-header (car data)))) | |
697 (gnus-summary-goto-subject number) | |
698 (gnus-uu-mark-series)) | |
699 (setq data (cdr data))))) | |
700 (gnus-summary-position-point)) | |
701 | |
702 ;; All PostScript functions written by Erik Selberg <speed@cs.washington.edu>. | |
703 | |
704 (defun gnus-uu-decode-postscript (&optional n) | |
705 "Gets postscript of the current article." | |
706 (interactive "P") | |
707 (gnus-uu-decode-with-method 'gnus-uu-decode-postscript-article n)) | |
708 | |
709 (defun gnus-uu-decode-postscript-view (&optional n) | |
710 "Gets and views the current article." | |
711 (interactive "P") | |
712 (let ((gnus-view-pseudos (or gnus-view-pseudos 'automatic))) | |
713 (gnus-uu-decode-postscript n))) | |
714 | |
715 (defun gnus-uu-decode-postscript-and-save (n dir) | |
716 "Extracts postscript and saves the current article." | |
717 (interactive | |
718 (list current-prefix-arg | |
719 (file-name-as-directory | |
720 (read-file-name "Save in dir: " | |
721 gnus-uu-default-dir | |
722 gnus-uu-default-dir t)))) | |
723 (gnus-uu-decode-with-method 'gnus-uu-decode-postscript-article | |
724 n dir nil nil t)) | |
725 | |
726 (defun gnus-uu-decode-postscript-and-save-view (n dir) | |
727 "Decodes, views and saves the resulting file." | |
728 (interactive | |
729 (list current-prefix-arg | |
730 (read-file-name "Where do you want to save the file(s)? " | |
731 gnus-uu-default-dir | |
732 gnus-uu-default-dir t))) | |
733 (let ((gnus-view-pseudos (or gnus-view-pseudos 'automatic))) | |
734 (gnus-uu-decode-postscript-and-save n dir))) | |
735 | |
736 | |
737 ;; Internal functions. | |
738 | |
739 (defun gnus-uu-decode-with-method (method n &optional save not-insert | |
740 scan cdir) | |
741 (gnus-uu-initialize scan) | |
742 (when save | |
743 (setq gnus-uu-default-dir save)) | |
744 ;; Create the directory we save to. | |
745 (when (and scan cdir save | |
746 (not (file-exists-p save))) | |
747 (make-directory save t)) | |
748 (let ((articles (gnus-uu-get-list-of-articles n)) | |
749 files) | |
750 (setq files (gnus-uu-grab-articles articles method t)) | |
751 (let ((gnus-current-article (car articles))) | |
752 (when scan | |
753 (setq files (gnus-uu-scan-directory gnus-uu-work-dir)))) | |
754 (when save | |
755 (gnus-uu-save-files files save)) | |
756 (when (eq gnus-uu-do-not-unpack-archives nil) | |
757 (setq files (gnus-uu-unpack-files files))) | |
758 (setq files (nreverse (gnus-uu-get-actions files))) | |
759 (or not-insert (not gnus-insert-pseudo-articles) | |
760 (gnus-summary-insert-pseudos files save)))) | |
761 | |
762 (defun gnus-uu-scan-directory (dir &optional rec) | |
763 "Return a list of all files under DIR." | |
764 (let ((files (directory-files dir t)) | |
765 out file) | |
766 (while (setq file (pop files)) | |
767 (unless (member (file-name-nondirectory file) '("." "..")) | |
768 (push (list (cons 'name file) | |
769 (cons 'article gnus-current-article)) | |
770 out) | |
771 (when (file-directory-p file) | |
772 (setq out (nconc (gnus-uu-scan-directory file t) out))))) | |
773 (if rec | |
774 out | |
775 (nreverse out)))) | |
776 | |
777 (defun gnus-uu-save-files (files dir) | |
778 "Save FILES in DIR." | |
779 (let ((len (length files)) | |
780 (reg (concat "^" (regexp-quote gnus-uu-work-dir))) | |
781 to-file file fromdir) | |
782 (while (setq file (cdr (assq 'name (pop files)))) | |
783 (when (file-exists-p file) | |
784 (string-match reg file) | |
785 (setq fromdir (substring file (match-end 0))) | |
786 (if (file-directory-p file) | |
787 (gnus-make-directory (concat dir fromdir)) | |
788 (setq to-file (concat dir fromdir)) | |
789 (when (or (not (file-exists-p to-file)) | |
790 (eq gnus-uu-be-dangerous t) | |
791 (and gnus-uu-be-dangerous | |
792 (gnus-y-or-n-p (format "%s exists; overwrite? " | |
793 to-file)))) | |
794 (copy-file file to-file t t))))) | |
795 (gnus-message 5 "Saved %d file%s" len (if (= len 1) "" "s")))) | |
796 | |
797 ;; Functions for saving and possibly digesting articles without | |
798 ;; any decoding. | |
799 | |
800 ;; Function called by gnus-uu-grab-articles to treat each article. | |
801 (defun gnus-uu-save-article (buffer in-state) | |
802 (cond | |
803 (gnus-uu-save-separate-articles | |
804 (save-excursion | |
805 (set-buffer buffer) | |
806 (gnus-write-buffer | |
807 (concat gnus-uu-saved-article-name gnus-current-article)) | |
808 (cond ((eq in-state 'first) (list gnus-uu-saved-article-name 'begin)) | |
809 ((eq in-state 'first-and-last) (list gnus-uu-saved-article-name | |
810 'begin 'end)) | |
811 ((eq in-state 'last) (list 'end)) | |
812 (t (list 'middle))))) | |
813 ((not gnus-uu-save-in-digest) | |
814 (save-excursion | |
815 (set-buffer buffer) | |
816 (write-region (point-min) (point-max) gnus-uu-saved-article-name t) | |
817 (cond ((eq in-state 'first) (list gnus-uu-saved-article-name 'begin)) | |
818 ((eq in-state 'first-and-last) (list gnus-uu-saved-article-name | |
819 'begin 'end)) | |
820 ((eq in-state 'last) (list 'end)) | |
821 (t (list 'middle))))) | |
822 (t | |
823 (let ((header (gnus-summary-article-header))) | |
824 (push (cons (mail-header-from header) | |
825 (mail-header-subject header)) | |
826 gnus-uu-digest-from-subject)) | |
827 (let ((name (file-name-nondirectory gnus-uu-saved-article-name)) | |
828 (delim (concat "^" (make-string 30 ?-) "$")) | |
829 beg subj headers headline sorthead body end-string state) | |
830 (if (or (eq in-state 'first) | |
831 (eq in-state 'first-and-last)) | |
832 (progn | |
833 (setq state (list 'begin)) | |
834 (save-excursion (set-buffer (get-buffer-create "*gnus-uu-body*")) | |
835 (erase-buffer)) | |
836 (save-excursion | |
837 (set-buffer (get-buffer-create "*gnus-uu-pre*")) | |
838 (erase-buffer) | |
839 (insert (format | |
840 "Date: %s\nFrom: %s\nSubject: %s Digest\n\nTopics:\n" | |
841 (current-time-string) name name)))) | |
842 (when (not (eq in-state 'end)) | |
843 (setq state (list 'middle)))) | |
844 (save-excursion | |
845 (set-buffer (get-buffer "*gnus-uu-body*")) | |
846 (goto-char (setq beg (point-max))) | |
847 (save-excursion | |
848 (save-restriction | |
849 (set-buffer buffer) | |
850 (let (buffer-read-only) | |
851 (gnus-set-text-properties (point-min) (point-max) nil) | |
852 ;; These two are necessary for XEmacs 19.12 fascism. | |
853 (put-text-property (point-min) (point-max) 'invisible nil) | |
854 (put-text-property (point-min) (point-max) 'intangible nil)) | |
855 (goto-char (point-min)) | |
856 (re-search-forward "\n\n") | |
857 ;; Quote all 30-dash lines. | |
858 (save-excursion | |
859 (while (re-search-forward delim nil t) | |
860 (beginning-of-line) | |
861 (delete-char 1) | |
862 (insert " "))) | |
863 (setq body (buffer-substring (1- (point)) (point-max))) | |
864 (narrow-to-region (point-min) (point)) | |
865 (if (not (setq headers gnus-uu-digest-headers)) | |
866 (setq sorthead (buffer-substring (point-min) (point-max))) | |
867 (while headers | |
868 (setq headline (car headers)) | |
869 (setq headers (cdr headers)) | |
870 (goto-char (point-min)) | |
871 (while (re-search-forward headline nil t) | |
872 (setq sorthead | |
873 (concat sorthead | |
874 (buffer-substring | |
875 (match-beginning 0) | |
876 (or (and (re-search-forward "^[^ \t]" nil t) | |
877 (1- (point))) | |
878 (progn (forward-line 1) (point))))))))) | |
879 (widen))) | |
880 (insert sorthead) (goto-char (point-max)) | |
881 (insert body) (goto-char (point-max)) | |
882 (insert (concat "\n" (make-string 30 ?-) "\n\n")) | |
883 (goto-char beg) | |
884 (when (re-search-forward "^Subject: \\(.*\\)$" nil t) | |
885 (setq subj (buffer-substring (match-beginning 1) (match-end 1))) | |
886 (save-excursion | |
887 (set-buffer (get-buffer "*gnus-uu-pre*")) | |
888 (insert (format " %s\n" subj))))) | |
889 (when (or (eq in-state 'last) | |
890 (eq in-state 'first-and-last)) | |
891 (save-excursion | |
892 (set-buffer (get-buffer "*gnus-uu-pre*")) | |
893 (insert (format "\n\n%s\n\n" (make-string 70 ?-))) | |
894 (gnus-write-buffer gnus-uu-saved-article-name)) | |
895 (save-excursion | |
896 (set-buffer (get-buffer "*gnus-uu-body*")) | |
897 (goto-char (point-max)) | |
898 (insert | |
899 (concat (setq end-string (format "End of %s Digest" name)) | |
900 "\n")) | |
901 (insert (concat (make-string (length end-string) ?*) "\n")) | |
902 (write-region | |
903 (point-min) (point-max) gnus-uu-saved-article-name t)) | |
904 (kill-buffer (get-buffer "*gnus-uu-pre*")) | |
905 (kill-buffer (get-buffer "*gnus-uu-body*")) | |
906 (push 'end state)) | |
907 (if (memq 'begin state) | |
908 (cons gnus-uu-saved-article-name state) | |
909 state))))) | |
910 | |
911 ;; Binhex treatment - not very advanced. | |
912 | |
913 (defconst gnus-uu-binhex-body-line | |
914 "^[^:]...............................................................$") | |
915 (defconst gnus-uu-binhex-begin-line | |
916 "^:...............................................................$") | |
917 (defconst gnus-uu-binhex-end-line | |
918 ":$") | |
919 | |
920 (defun gnus-uu-binhex-article (buffer in-state) | |
921 (let (state start-char) | |
922 (save-excursion | |
923 (set-buffer buffer) | |
924 (widen) | |
925 (goto-char (point-min)) | |
926 (when (not (re-search-forward gnus-uu-binhex-begin-line nil t)) | |
927 (when (not (re-search-forward gnus-uu-binhex-body-line nil t)) | |
928 (setq state (list 'wrong-type)))) | |
929 | |
930 (if (memq 'wrong-type state) | |
931 () | |
932 (beginning-of-line) | |
933 (setq start-char (point)) | |
934 (if (looking-at gnus-uu-binhex-begin-line) | |
935 (progn | |
936 (setq state (list 'begin)) | |
937 (write-region 1 1 gnus-uu-binhex-article-name)) | |
938 (setq state (list 'middle))) | |
939 (goto-char (point-max)) | |
940 (re-search-backward (concat gnus-uu-binhex-body-line "\\|" | |
941 gnus-uu-binhex-end-line) | |
942 nil t) | |
943 (when (looking-at gnus-uu-binhex-end-line) | |
944 (setq state (if (memq 'begin state) | |
945 (cons 'end state) | |
946 (list 'end)))) | |
947 (beginning-of-line) | |
948 (forward-line 1) | |
949 (when (file-exists-p gnus-uu-binhex-article-name) | |
950 (append-to-file start-char (point) gnus-uu-binhex-article-name)))) | |
951 (if (memq 'begin state) | |
952 (cons gnus-uu-binhex-article-name state) | |
953 state))) | |
954 | |
955 ;; PostScript | |
956 | |
957 (defun gnus-uu-decode-postscript-article (process-buffer in-state) | |
958 (let ((state (list 'ok)) | |
959 start-char end-char file-name) | |
960 (save-excursion | |
961 (set-buffer process-buffer) | |
962 (goto-char (point-min)) | |
963 (if (not (re-search-forward gnus-uu-postscript-begin-string nil t)) | |
964 (setq state (list 'wrong-type)) | |
965 (beginning-of-line) | |
966 (setq start-char (point)) | |
967 (if (not (re-search-forward gnus-uu-postscript-end-string nil t)) | |
968 (setq state (list 'wrong-type)) | |
969 (setq end-char (point)) | |
970 (set-buffer (get-buffer-create gnus-uu-output-buffer-name)) | |
971 (insert-buffer-substring process-buffer start-char end-char) | |
972 (setq file-name (concat gnus-uu-work-dir | |
973 (cdr gnus-article-current) ".ps")) | |
974 (write-region (point-min) (point-max) file-name) | |
975 (setq state (list file-name 'begin 'end))))) | |
976 state)) | |
977 | |
978 | |
979 ;; Find actions. | |
980 | |
981 (defun gnus-uu-get-actions (files) | |
982 (let ((ofiles files) | |
983 action name) | |
984 (while files | |
985 (setq name (cdr (assq 'name (car files)))) | |
986 (and | |
987 (setq action (gnus-uu-get-action name)) | |
988 (setcar files (nconc (list (if (string= action "gnus-uu-archive") | |
989 (cons 'action "file") | |
990 (cons 'action action)) | |
991 (cons 'execute (gnus-uu-command | |
992 action name))) | |
993 (car files)))) | |
994 (setq files (cdr files))) | |
995 ofiles)) | |
996 | |
997 (defun gnus-uu-get-action (file-name) | |
998 (let (action) | |
999 (setq action | |
1000 (gnus-uu-choose-action | |
1001 file-name | |
1002 (append | |
1003 gnus-uu-user-view-rules | |
1004 (if gnus-uu-ignore-default-view-rules | |
1005 nil | |
1006 gnus-uu-default-view-rules) | |
1007 gnus-uu-user-view-rules-end))) | |
1008 (when (and (not (string= (or action "") "gnus-uu-archive")) | |
1009 gnus-uu-view-with-metamail) | |
1010 (when (setq action | |
1011 (gnus-uu-choose-action file-name gnus-uu-ext-to-mime-list)) | |
1012 (setq action (format "metamail -d -b -c \"%s\"" action)))) | |
1013 action)) | |
1014 | |
1015 | |
1016 ;; Functions for treating subjects and collecting series. | |
1017 | |
1018 (defun gnus-uu-reginize-string (string) | |
1019 ;; Takes a string and puts a \ in front of every special character; | |
1020 ;; ignores any leading "version numbers" thingies that they use in | |
1021 ;; the comp.binaries groups, and either replaces anything that looks | |
1022 ;; like "2/3" with "[0-9]+/[0-9]+" or, if it can't find something | |
1023 ;; like that, replaces the last two numbers with "[0-9]+". This, in | |
1024 ;; my experience, should get most postings of a series. | |
1025 (let ((count 2) | |
1026 (vernum "v[0-9]+[a-z][0-9]+:") | |
1027 beg) | |
1028 (save-excursion | |
1029 (set-buffer (get-buffer-create gnus-uu-output-buffer-name)) | |
1030 (buffer-disable-undo (current-buffer)) | |
1031 (erase-buffer) | |
1032 (insert (regexp-quote string)) | |
1033 (setq beg 1) | |
1034 | |
1035 (setq case-fold-search nil) | |
1036 (goto-char (point-min)) | |
1037 (when (looking-at vernum) | |
1038 (replace-match vernum t t) | |
1039 (setq beg (length vernum))) | |
1040 | |
1041 (goto-char beg) | |
1042 (if (re-search-forward "[ \t]*[0-9]+/[0-9]+" nil t) | |
1043 (replace-match " [0-9]+/[0-9]+") | |
1044 | |
1045 (goto-char beg) | |
1046 (if (re-search-forward "[0-9]+[ \t]*of[ \t]*[0-9]+" nil t) | |
1047 (replace-match "[0-9]+ of [0-9]+") | |
1048 | |
1049 (end-of-line) | |
1050 (if (re-search-backward "\\([^0-9]\\)[0-9]+\\([^0-9]+\\)[0-9]+" | |
1051 nil t) | |
1052 (replace-match "\\1[0-9]+\\2[0-9]+" t nil nil nil)))) | |
1053 | |
1054 (goto-char beg) | |
1055 (while (re-search-forward "[ \t]+" nil t) | |
1056 (replace-match "[ \t]*" t t)) | |
1057 | |
1058 (buffer-substring 1 (point-max))))) | |
1059 | |
1060 (defun gnus-uu-get-list-of-articles (n) | |
1061 ;; If N is non-nil, the article numbers of the N next articles | |
1062 ;; will be returned. | |
1063 ;; If any articles have been marked as processable, they will be | |
1064 ;; returned. | |
1065 ;; Failing that, articles that have subjects that are part of the | |
1066 ;; same "series" as the current will be returned. | |
1067 (let (articles) | |
1068 (cond | |
1069 (n | |
1070 (setq n (prefix-numeric-value n)) | |
1071 (let ((backward (< n 0)) | |
1072 (n (abs n))) | |
1073 (save-excursion | |
1074 (while (and (> n 0) | |
1075 (push (gnus-summary-article-number) | |
1076 articles) | |
1077 (gnus-summary-search-forward nil nil backward)) | |
1078 (setq n (1- n)))) | |
1079 (nreverse articles))) | |
1080 (gnus-newsgroup-processable | |
1081 (reverse gnus-newsgroup-processable)) | |
1082 (t | |
1083 (gnus-uu-find-articles-matching))))) | |
1084 | |
1085 (defun gnus-uu-string< (l1 l2) | |
1086 (string< (car l1) (car l2))) | |
1087 | |
1088 (defun gnus-uu-find-articles-matching | |
1089 (&optional subject only-unread do-not-translate) | |
1090 ;; Finds all articles that matches the regexp SUBJECT. If it is | |
1091 ;; nil, the current article name will be used. If ONLY-UNREAD is | |
1092 ;; non-nil, only unread articles are chosen. If DO-NOT-TRANSLATE is | |
1093 ;; non-nil, article names are not equalized before sorting. | |
1094 (let ((subject (or subject | |
1095 (gnus-uu-reginize-string (gnus-summary-article-subject)))) | |
1096 list-of-subjects) | |
1097 (save-excursion | |
1098 (if (not subject) | |
1099 () | |
1100 ;; Collect all subjects matching subject. | |
1101 (let ((case-fold-search t) | |
1102 (data gnus-newsgroup-data) | |
1103 subj mark d) | |
1104 (while data | |
1105 (setq d (pop data)) | |
1106 (and (not (gnus-data-pseudo-p d)) | |
1107 (or (not only-unread) | |
1108 (= (setq mark (gnus-data-mark d)) | |
1109 gnus-unread-mark) | |
1110 (= mark gnus-ticked-mark) | |
1111 (= mark gnus-dormant-mark)) | |
1112 (setq subj (mail-header-subject (gnus-data-header d))) | |
1113 (string-match subject subj) | |
1114 (push (cons subj (gnus-data-number d)) | |
1115 list-of-subjects)))) | |
1116 | |
1117 ;; Expand numbers, sort, and return the list of article | |
1118 ;; numbers. | |
1119 (mapcar (lambda (sub) (cdr sub)) | |
1120 (sort (gnus-uu-expand-numbers | |
1121 list-of-subjects | |
1122 (not do-not-translate)) | |
1123 'gnus-uu-string<)))))) | |
1124 | |
1125 (defun gnus-uu-expand-numbers (string-list &optional translate) | |
1126 ;; Takes a list of strings and "expands" all numbers in all the | |
1127 ;; strings. That is, this function makes all numbers equal length by | |
1128 ;; prepending lots of zeroes before each number. This is to ease later | |
1129 ;; sorting to find out what sequence the articles are supposed to be | |
1130 ;; decoded in. Returns the list of expanded strings. | |
1131 (let ((out-list string-list) | |
1132 string) | |
1133 (save-excursion | |
1134 (set-buffer (get-buffer-create gnus-uu-output-buffer-name)) | |
1135 (buffer-disable-undo (current-buffer)) | |
1136 (while string-list | |
1137 (erase-buffer) | |
1138 (insert (caar string-list)) | |
1139 ;; Translate multiple spaces to one space. | |
1140 (goto-char (point-min)) | |
1141 (while (re-search-forward "[ \t]+" nil t) | |
1142 (replace-match " ")) | |
1143 ;; Translate all characters to "a". | |
1144 (goto-char (point-min)) | |
1145 (when translate | |
1146 (while (re-search-forward "[A-Za-z]" nil t) | |
1147 (replace-match "a" t t))) | |
1148 ;; Expand numbers. | |
1149 (goto-char (point-min)) | |
1150 (while (re-search-forward "[0-9]+" nil t) | |
1151 (replace-match | |
1152 (format "%06d" | |
1153 (string-to-int (buffer-substring | |
1154 (match-beginning 0) (match-end 0)))))) | |
1155 (setq string (buffer-substring 1 (point-max))) | |
1156 (setcar (car string-list) string) | |
1157 (setq string-list (cdr string-list)))) | |
1158 out-list)) | |
1159 | |
1160 | |
1161 ;; `gnus-uu-grab-articles' is the general multi-article treatment | |
1162 ;; function. It takes a list of articles to be grabbed and a function | |
1163 ;; to apply to each article. | |
1164 ;; | |
1165 ;; The function to be called should take two parameters. The first | |
1166 ;; parameter is the article buffer. The function should leave the | |
1167 ;; result, if any, in this buffer. Most treatment functions will just | |
1168 ;; generate files... | |
1169 ;; | |
1170 ;; The second parameter is the state of the list of articles, and can | |
1171 ;; have four values: `first', `middle', `last' and `first-and-last'. | |
1172 ;; | |
1173 ;; The function should return a list. The list may contain the | |
1174 ;; following symbols: | |
1175 ;; `error' if an error occurred | |
1176 ;; `begin' if the beginning of an encoded file has been received | |
1177 ;; If the list returned contains a `begin', the first element of | |
1178 ;; the list *must* be a string with the file name of the decoded | |
1179 ;; file. | |
1180 ;; `end' if the end of an encoded file has been received | |
1181 ;; `middle' if the article was a body part of an encoded file | |
1182 ;; `wrong-type' if the article was not a part of an encoded file | |
1183 ;; `ok', which can be used everything is ok | |
1184 | |
1185 (defvar gnus-uu-has-been-grabbed nil) | |
1186 | |
1187 (defun gnus-uu-unmark-list-of-grabbed (&optional dont-unmark-last-article) | |
1188 (let (art) | |
1189 (if (not (and gnus-uu-has-been-grabbed | |
1190 gnus-uu-unmark-articles-not-decoded)) | |
1191 () | |
1192 (when dont-unmark-last-article | |
1193 (setq art (car gnus-uu-has-been-grabbed)) | |
1194 (setq gnus-uu-has-been-grabbed (cdr gnus-uu-has-been-grabbed))) | |
1195 (while gnus-uu-has-been-grabbed | |
1196 (gnus-summary-tick-article (car gnus-uu-has-been-grabbed) t) | |
1197 (setq gnus-uu-has-been-grabbed (cdr gnus-uu-has-been-grabbed))) | |
1198 (when dont-unmark-last-article | |
1199 (setq gnus-uu-has-been-grabbed (list art)))))) | |
1200 | |
1201 ;; This function takes a list of articles and a function to apply to | |
1202 ;; each article grabbed. | |
1203 ;; | |
1204 ;; This function returns a list of files decoded if the grabbing and | |
1205 ;; the process-function has been successful and nil otherwise. | |
1206 (defun gnus-uu-grab-articles (articles process-function | |
1207 &optional sloppy limit no-errors) | |
1208 (let ((state 'first) | |
1209 has-been-begin article result-file result-files process-state | |
1210 gnus-summary-display-article-function | |
1211 gnus-article-display-hook gnus-article-prepare-hook | |
1212 article-series files) | |
1213 | |
1214 (while (and articles | |
1215 (not (memq 'error process-state)) | |
1216 (or sloppy | |
1217 (not (memq 'end process-state)))) | |
1218 | |
1219 (setq article (pop articles)) | |
1220 (push article article-series) | |
1221 | |
1222 (unless articles | |
1223 (if (eq state 'first) | |
1224 (setq state 'first-and-last) | |
1225 (setq state 'last))) | |
1226 | |
1227 (let ((part (gnus-uu-part-number article))) | |
1228 (gnus-message 6 "Getting article %d%s..." | |
1229 article (if (string= part "") "" (concat ", " part)))) | |
1230 (gnus-summary-display-article article) | |
1231 | |
1232 ;; Push the article to the processing function. | |
1233 (save-excursion | |
1234 (set-buffer gnus-original-article-buffer) | |
1235 (let ((buffer-read-only nil)) | |
1236 (save-excursion | |
1237 (set-buffer gnus-summary-buffer) | |
1238 (setq process-state | |
1239 (funcall process-function | |
1240 gnus-original-article-buffer state))))) | |
1241 | |
1242 (gnus-summary-remove-process-mark article) | |
1243 | |
1244 ;; If this is the beginning of a decoded file, we push it | |
1245 ;; on to a list. | |
1246 (when (or (memq 'begin process-state) | |
1247 (and (or (eq state 'first) | |
1248 (eq state 'first-and-last)) | |
1249 (memq 'ok process-state))) | |
1250 (when has-been-begin | |
1251 ;; If there is a `result-file' here, that means that the | |
1252 ;; file was unsuccessfully decoded, so we delete it. | |
1253 (when (and result-file | |
1254 (file-exists-p result-file) | |
1255 (not gnus-uu-be-dangerous) | |
1256 (or (eq gnus-uu-be-dangerous t) | |
1257 (gnus-y-or-n-p | |
1258 (format "Delete unsuccessfully decoded file %s" | |
1259 result-file)))) | |
1260 (delete-file result-file))) | |
1261 (when (memq 'begin process-state) | |
1262 (setq result-file (car process-state))) | |
1263 (setq has-been-begin t)) | |
1264 | |
1265 ;; Check whether we have decoded one complete file. | |
1266 (when (memq 'end process-state) | |
1267 (setq article-series nil) | |
1268 (setq has-been-begin nil) | |
1269 (if (stringp result-file) | |
1270 (setq files (list result-file)) | |
1271 (setq files result-file)) | |
1272 (setq result-file (car files)) | |
1273 (while files | |
1274 (push (list (cons 'name (pop files)) | |
1275 (cons 'article article)) | |
1276 result-files)) | |
1277 ;; Allow user-defined functions to be run on this file. | |
1278 (when gnus-uu-grabbed-file-functions | |
1279 (let ((funcs gnus-uu-grabbed-file-functions)) | |
1280 (unless (listp funcs) | |
1281 (setq funcs (list funcs))) | |
1282 (while funcs | |
1283 (funcall (pop funcs) result-file)))) | |
1284 (setq result-file nil) | |
1285 ;; Check whether we have decoded enough articles. | |
1286 (and limit (= (length result-files) limit) | |
1287 (setq articles nil))) | |
1288 | |
1289 ;; If this is the last article to be decoded, and | |
1290 ;; we still haven't reached the end, then we delete | |
1291 ;; the partially decoded file. | |
1292 (and (or (eq state 'last) (eq state 'first-and-last)) | |
1293 (not (memq 'end process-state)) | |
1294 result-file | |
1295 (file-exists-p result-file) | |
1296 (not gnus-uu-be-dangerous) | |
1297 (or (eq gnus-uu-be-dangerous t) | |
1298 (gnus-y-or-n-p (format "Delete incomplete file %s? " result-file))) | |
1299 (delete-file result-file)) | |
1300 | |
1301 ;; If this was a file of the wrong sort, then | |
1302 (when (and (or (memq 'wrong-type process-state) | |
1303 (memq 'error process-state)) | |
1304 gnus-uu-unmark-articles-not-decoded) | |
1305 (gnus-summary-tick-article article t)) | |
1306 | |
1307 ;; Set the new series state. | |
1308 (if (and (not has-been-begin) | |
1309 (not sloppy) | |
1310 (or (memq 'end process-state) | |
1311 (memq 'middle process-state))) | |
1312 (progn | |
1313 (setq process-state (list 'error)) | |
1314 (gnus-message 2 "No begin part at the beginning") | |
1315 (sleep-for 2)) | |
1316 (setq state 'middle))) | |
1317 | |
1318 ;; When there are no result-files, then something must be wrong. | |
1319 (if result-files | |
1320 (message "") | |
1321 (cond | |
1322 ((not has-been-begin) | |
1323 (gnus-message 2 "Wrong type file")) | |
1324 ((memq 'error process-state) | |
1325 (gnus-message 2 "An error occurred during decoding")) | |
1326 ((not (or (memq 'ok process-state) | |
1327 (memq 'end process-state))) | |
1328 (gnus-message 2 "End of articles reached before end of file"))) | |
1329 ;; Make unsuccessfully decoded articles unread. | |
1330 (when gnus-uu-unmark-articles-not-decoded | |
1331 (while article-series | |
1332 (gnus-summary-tick-article (pop article-series) t)))) | |
1333 | |
1334 result-files)) | |
1335 | |
1336 (defun gnus-uu-grab-view (file) | |
1337 "View FILE using the gnus-uu methods." | |
1338 (let ((action (gnus-uu-get-action file))) | |
1339 (gnus-execute-command | |
1340 (if (string-match "%" action) | |
1341 (format action file) | |
1342 (concat action " " file)) | |
1343 (eq gnus-view-pseudos 'not-confirm)))) | |
1344 | |
1345 (defun gnus-uu-grab-move (file) | |
1346 "Move FILE to somewhere." | |
1347 (when gnus-uu-default-dir | |
1348 (let ((to-file (concat (file-name-as-directory gnus-uu-default-dir) | |
1349 (file-name-nondirectory file)))) | |
1350 (rename-file file to-file) | |
1351 (unless (file-exists-p file) | |
1352 (make-symbolic-link to-file file))))) | |
1353 | |
1354 (defun gnus-uu-part-number (article) | |
1355 (let* ((header (gnus-summary-article-header article)) | |
1356 (subject (and header (mail-header-subject header)))) | |
1357 (if (and subject | |
1358 (string-match "[0-9]+ */[0-9]+\\|[0-9]+ * of *[0-9]+" subject)) | |
1359 (match-string 0 subject) | |
1360 ""))) | |
1361 | |
1362 (defun gnus-uu-uudecode-sentinel (process event) | |
1363 (delete-process (get-process process))) | |
1364 | |
1365 (defun gnus-uu-uustrip-article (process-buffer in-state) | |
1366 ;; Uudecodes a file asynchronously. | |
1367 (save-excursion | |
1368 (set-buffer process-buffer) | |
1369 (let ((state (list 'wrong-type)) | |
1370 process-connection-type case-fold-search buffer-read-only | |
1371 files start-char) | |
1372 (goto-char (point-min)) | |
1373 | |
1374 ;; Deal with ^M at the end of the lines. | |
1375 (when gnus-uu-kill-carriage-return | |
1376 (save-excursion | |
1377 (while (search-forward "\r" nil t) | |
1378 (delete-backward-char 1)))) | |
1379 | |
1380 (while (or (re-search-forward gnus-uu-begin-string nil t) | |
1381 (re-search-forward gnus-uu-body-line nil t)) | |
1382 (setq state (list 'ok)) | |
1383 ;; Ok, we are at the first uucoded line. | |
1384 (beginning-of-line) | |
1385 (setq start-char (point)) | |
1386 | |
1387 (if (not (looking-at gnus-uu-begin-string)) | |
1388 (setq state (list 'middle)) | |
1389 ;; This is the beginning of an uuencoded article. | |
1390 ;; We replace certain characters that could make things messy. | |
1391 (setq gnus-uu-file-name | |
1392 (let ((nnheader-file-name-translation-alist | |
1393 '((?/ . ?,) (? . ?_) (?* . ?_) (?$ . ?_)))) | |
1394 (nnheader-translate-file-chars (match-string 1)))) | |
1395 (replace-match (concat "begin 644 " gnus-uu-file-name) t t) | |
1396 | |
1397 ;; Remove any non gnus-uu-body-line right after start. | |
1398 (forward-line 1) | |
1399 (while (and (not (eobp)) | |
1400 (not (looking-at gnus-uu-body-line))) | |
1401 (gnus-delete-line)) | |
1402 | |
1403 ;; If a process is running, we kill it. | |
1404 (when (and gnus-uu-uudecode-process | |
1405 (memq (process-status gnus-uu-uudecode-process) | |
1406 '(run stop))) | |
1407 (delete-process gnus-uu-uudecode-process) | |
1408 (gnus-uu-unmark-list-of-grabbed t)) | |
1409 | |
1410 ;; Start a new uudecoding process. | |
1411 (let ((cdir default-directory)) | |
1412 (unwind-protect | |
1413 (progn | |
1414 (cd gnus-uu-work-dir) | |
1415 (setq gnus-uu-uudecode-process | |
1416 (start-process | |
1417 "*uudecode*" | |
1418 (get-buffer-create gnus-uu-output-buffer-name) | |
1419 shell-file-name shell-command-switch | |
1420 (format "cd %s %s uudecode" gnus-uu-work-dir | |
1421 gnus-shell-command-separator)))) | |
1422 (cd cdir))) | |
1423 (set-process-sentinel | |
1424 gnus-uu-uudecode-process 'gnus-uu-uudecode-sentinel) | |
1425 (setq state (list 'begin)) | |
1426 (push (concat gnus-uu-work-dir gnus-uu-file-name) files)) | |
1427 | |
1428 ;; We look for the end of the thing to be decoded. | |
1429 (if (re-search-forward gnus-uu-end-string nil t) | |
1430 (push 'end state) | |
1431 (goto-char (point-max)) | |
1432 (re-search-backward gnus-uu-body-line nil t)) | |
1433 | |
1434 (forward-line 1) | |
1435 | |
1436 (when gnus-uu-uudecode-process | |
1437 (when (memq (process-status gnus-uu-uudecode-process) '(run stop)) | |
1438 ;; Try to correct mishandled uucode. | |
1439 (when gnus-uu-correct-stripped-uucode | |
1440 (gnus-uu-check-correct-stripped-uucode start-char (point))) | |
1441 | |
1442 ;; Send the text to the process. | |
1443 (condition-case nil | |
1444 (process-send-region | |
1445 gnus-uu-uudecode-process start-char (point)) | |
1446 (error | |
1447 (progn | |
1448 (delete-process gnus-uu-uudecode-process) | |
1449 (gnus-message 2 "gnus-uu: Couldn't uudecode") | |
1450 (setq state (list 'wrong-type))))) | |
1451 | |
1452 (if (memq 'end state) | |
1453 (progn | |
1454 ;; Send an EOF, just in case. | |
1455 (ignore-errors | |
1456 (process-send-eof gnus-uu-uudecode-process)) | |
1457 (while (memq (process-status gnus-uu-uudecode-process) | |
1458 '(open run)) | |
1459 (accept-process-output gnus-uu-uudecode-process 1))) | |
1460 (when (or (not gnus-uu-uudecode-process) | |
1461 (not (memq (process-status gnus-uu-uudecode-process) | |
1462 '(run stop)))) | |
1463 (setq state (list 'wrong-type))))))) | |
1464 | |
1465 (if (memq 'begin state) | |
1466 (cons (if (= (length files) 1) (car files) files) state) | |
1467 state)))) | |
1468 | |
1469 ;; This function is used by `gnus-uu-grab-articles' to treat | |
1470 ;; a shared article. | |
1471 (defun gnus-uu-unshar-article (process-buffer in-state) | |
1472 (let ((state (list 'ok)) | |
1473 start-char) | |
1474 (save-excursion | |
1475 (set-buffer process-buffer) | |
1476 (goto-char (point-min)) | |
1477 (if (not (re-search-forward gnus-uu-shar-begin-string nil t)) | |
1478 (setq state (list 'wrong-type)) | |
1479 (beginning-of-line) | |
1480 (setq start-char (point)) | |
1481 (call-process-region | |
1482 start-char (point-max) shell-file-name nil | |
1483 (get-buffer-create gnus-uu-output-buffer-name) nil | |
1484 shell-command-switch | |
1485 (concat "cd " gnus-uu-work-dir " " | |
1486 gnus-shell-command-separator " sh")))) | |
1487 state)) | |
1488 | |
1489 ;; Returns the name of what the shar file is going to unpack. | |
1490 (defun gnus-uu-find-name-in-shar () | |
1491 (let ((oldpoint (point)) | |
1492 res) | |
1493 (goto-char (point-min)) | |
1494 (when (re-search-forward gnus-uu-shar-name-marker nil t) | |
1495 (setq res (buffer-substring (match-beginning 1) (match-end 1)))) | |
1496 (goto-char oldpoint) | |
1497 res)) | |
1498 | |
1499 ;; `gnus-uu-choose-action' chooses what action to perform given the name | |
1500 ;; and `gnus-uu-file-action-list'. Returns either nil if no action is | |
1501 ;; found, or the name of the command to run if such a rule is found. | |
1502 (defun gnus-uu-choose-action (file-name file-action-list &optional no-ignore) | |
1503 (let ((action-list (copy-sequence file-action-list)) | |
1504 (case-fold-search t) | |
1505 rule action) | |
1506 (and | |
1507 (unless no-ignore | |
1508 (and (not | |
1509 (and gnus-uu-ignore-files-by-name | |
1510 (string-match gnus-uu-ignore-files-by-name file-name))) | |
1511 (not | |
1512 (and gnus-uu-ignore-files-by-type | |
1513 (string-match gnus-uu-ignore-files-by-type | |
1514 (or (gnus-uu-choose-action | |
1515 file-name gnus-uu-ext-to-mime-list t) | |
1516 "")))))) | |
1517 (while (not (or (eq action-list ()) action)) | |
1518 (setq rule (car action-list)) | |
1519 (setq action-list (cdr action-list)) | |
1520 (when (string-match (car rule) file-name) | |
1521 (setq action (cadr rule))))) | |
1522 action)) | |
1523 | |
1524 (defun gnus-uu-treat-archive (file-path) | |
1525 ;; Unpacks an archive. Returns t if unpacking is successful. | |
1526 (let ((did-unpack t) | |
1527 action command dir) | |
1528 (setq action (gnus-uu-choose-action | |
1529 file-path (append gnus-uu-user-archive-rules | |
1530 (if gnus-uu-ignore-default-archive-rules | |
1531 nil | |
1532 gnus-uu-default-archive-rules)))) | |
1533 | |
1534 (when (not action) | |
1535 (error "No unpackers for the file %s" file-path)) | |
1536 | |
1537 (string-match "/[^/]*$" file-path) | |
1538 (setq dir (substring file-path 0 (match-beginning 0))) | |
1539 | |
1540 (when (member action gnus-uu-destructive-archivers) | |
1541 (copy-file file-path (concat file-path "~") t)) | |
1542 | |
1543 (setq command (format "cd %s ; %s" dir (gnus-uu-command action file-path))) | |
1544 | |
1545 (save-excursion | |
1546 (set-buffer (get-buffer-create gnus-uu-output-buffer-name)) | |
1547 (erase-buffer)) | |
1548 | |
1549 (gnus-message 5 "Unpacking: %s..." (gnus-uu-command action file-path)) | |
1550 | |
1551 (if (= 0 (call-process shell-file-name nil | |
1552 (get-buffer-create gnus-uu-output-buffer-name) | |
1553 nil shell-command-switch command)) | |
1554 (message "") | |
1555 (gnus-message 2 "Error during unpacking of archive") | |
1556 (setq did-unpack nil)) | |
1557 | |
1558 (when (member action gnus-uu-destructive-archivers) | |
1559 (rename-file (concat file-path "~") file-path t)) | |
1560 | |
1561 did-unpack)) | |
1562 | |
1563 (defun gnus-uu-dir-files (dir) | |
1564 (let ((dirs (directory-files dir t "[^/][^\\.][^\\.]?$")) | |
1565 files file) | |
1566 (while dirs | |
1567 (if (file-directory-p (setq file (car dirs))) | |
1568 (setq files (append files (gnus-uu-dir-files file))) | |
1569 (push file files)) | |
1570 (setq dirs (cdr dirs))) | |
1571 files)) | |
1572 | |
1573 (defun gnus-uu-unpack-files (files &optional ignore) | |
1574 ;; Go through FILES and look for files to unpack. | |
1575 (let* ((totfiles (gnus-uu-ls-r gnus-uu-work-dir)) | |
1576 (ofiles files) | |
1577 file did-unpack) | |
1578 (while files | |
1579 (setq file (cdr (assq 'name (car files)))) | |
1580 (when (and (not (member file ignore)) | |
1581 (equal (gnus-uu-get-action (file-name-nondirectory file)) | |
1582 "gnus-uu-archive")) | |
1583 (push file did-unpack) | |
1584 (unless (gnus-uu-treat-archive file) | |
1585 (gnus-message 2 "Error during unpacking of %s" file)) | |
1586 (let* ((newfiles (gnus-uu-ls-r gnus-uu-work-dir)) | |
1587 (nfiles newfiles)) | |
1588 (while nfiles | |
1589 (unless (member (car nfiles) totfiles) | |
1590 (push (list (cons 'name (car nfiles)) | |
1591 (cons 'original file)) | |
1592 ofiles)) | |
1593 (setq nfiles (cdr nfiles))) | |
1594 (setq totfiles newfiles))) | |
1595 (setq files (cdr files))) | |
1596 (if did-unpack | |
1597 (gnus-uu-unpack-files ofiles (append did-unpack ignore)) | |
1598 ofiles))) | |
1599 | |
1600 (defun gnus-uu-ls-r (dir) | |
1601 (let* ((files (gnus-uu-directory-files dir t)) | |
1602 (ofiles files)) | |
1603 (while files | |
1604 (when (file-directory-p (car files)) | |
1605 (setq ofiles (delete (car files) ofiles)) | |
1606 (setq ofiles (append ofiles (gnus-uu-ls-r (car files))))) | |
1607 (setq files (cdr files))) | |
1608 ofiles)) | |
1609 | |
1610 ;; Various stuff | |
1611 | |
1612 (defun gnus-uu-directory-files (dir &optional full) | |
1613 (let (files out file) | |
1614 (setq files (directory-files dir full)) | |
1615 (while files | |
1616 (setq file (car files)) | |
1617 (setq files (cdr files)) | |
1618 (unless (member (file-name-nondirectory file) '("." "..")) | |
1619 (push file out))) | |
1620 (setq out (nreverse out)) | |
1621 out)) | |
1622 | |
1623 (defun gnus-uu-check-correct-stripped-uucode (start end) | |
1624 (save-excursion | |
1625 (let (found beg length) | |
1626 (if (not gnus-uu-correct-stripped-uucode) | |
1627 () | |
1628 (goto-char start) | |
1629 | |
1630 (if (re-search-forward " \\|`" end t) | |
1631 (progn | |
1632 (goto-char start) | |
1633 (while (not (eobp)) | |
1634 (progn | |
1635 (when (looking-at "\n") | |
1636 (replace-match "")) | |
1637 (forward-line 1)))) | |
1638 | |
1639 (while (not (eobp)) | |
1640 (if (looking-at (concat gnus-uu-begin-string "\\|" | |
1641 gnus-uu-end-string)) | |
1642 () | |
1643 (when (not found) | |
1644 (beginning-of-line) | |
1645 (setq beg (point)) | |
1646 (end-of-line) | |
1647 (setq length (- (point) beg))) | |
1648 (setq found t) | |
1649 (beginning-of-line) | |
1650 (setq beg (point)) | |
1651 (end-of-line) | |
1652 (when (not (= length (- (point) beg))) | |
1653 (insert (make-string (- length (- (point) beg)) ? )))) | |
1654 (forward-line 1))))))) | |
1655 | |
1656 (defvar gnus-uu-tmp-alist nil) | |
1657 | |
1658 (defun gnus-uu-initialize (&optional scan) | |
1659 (let (entry) | |
1660 (if (and (not scan) | |
1661 (when (setq entry (assoc gnus-newsgroup-name gnus-uu-tmp-alist)) | |
1662 (if (file-exists-p (cdr entry)) | |
1663 (setq gnus-uu-work-dir (cdr entry)) | |
1664 (setq gnus-uu-tmp-alist (delq entry gnus-uu-tmp-alist)) | |
1665 nil))) | |
1666 t | |
1667 (setq gnus-uu-tmp-dir (file-name-as-directory | |
1668 (expand-file-name gnus-uu-tmp-dir))) | |
1669 (if (not (file-directory-p gnus-uu-tmp-dir)) | |
1670 (error "Temp directory %s doesn't exist" gnus-uu-tmp-dir) | |
1671 (when (not (file-writable-p gnus-uu-tmp-dir)) | |
1672 (error "Temp directory %s can't be written to" | |
1673 gnus-uu-tmp-dir))) | |
1674 | |
1675 (setq gnus-uu-work-dir | |
1676 (make-temp-name (concat gnus-uu-tmp-dir "gnus"))) | |
1677 (gnus-make-directory gnus-uu-work-dir) | |
1678 (set-file-modes gnus-uu-work-dir 448) | |
1679 (setq gnus-uu-work-dir (file-name-as-directory gnus-uu-work-dir)) | |
1680 (push (cons gnus-newsgroup-name gnus-uu-work-dir) | |
1681 gnus-uu-tmp-alist)))) | |
1682 | |
1683 | |
1684 ;; Kills the temporary uu buffers, kills any processes, etc. | |
1685 (defun gnus-uu-clean-up () | |
1686 (let (buf) | |
1687 (and gnus-uu-uudecode-process | |
1688 (memq (process-status (or gnus-uu-uudecode-process "nevair")) | |
1689 '(stop run)) | |
1690 (delete-process gnus-uu-uudecode-process)) | |
1691 (when (setq buf (get-buffer gnus-uu-output-buffer-name)) | |
1692 (kill-buffer buf)))) | |
1693 | |
1694 (defun gnus-quote-arg-for-sh-or-csh (arg) | |
1695 (let ((pos 0) new-pos accum) | |
1696 ;; *** bug: we don't handle newline characters properly | |
1697 (while (setq new-pos (string-match "[!`\"$\\& \t{}]" arg pos)) | |
1698 (push (substring arg pos new-pos) accum) | |
1699 (push "\\" accum) | |
1700 (push (list (aref arg new-pos)) accum) | |
1701 (setq pos (1+ new-pos))) | |
1702 (if (= pos 0) | |
1703 arg | |
1704 (apply 'concat (nconc (nreverse accum) (list (substring arg pos))))))) | |
1705 | |
1706 ;; Inputs an action and a filename and returns a full command, making sure | |
1707 ;; that the filename will be treated as a single argument when the shell | |
1708 ;; executes the command. | |
1709 (defun gnus-uu-command (action file) | |
1710 (let ((quoted-file (gnus-quote-arg-for-sh-or-csh file))) | |
1711 (if (string-match "%s" action) | |
1712 (format action quoted-file) | |
1713 (concat action " " quoted-file)))) | |
1714 | |
1715 (defun gnus-uu-delete-work-dir (&optional dir) | |
1716 "Delete recursively all files and directories under `gnus-uu-work-dir'." | |
1717 (if dir | |
1718 (gnus-message 7 "Deleting directory %s..." dir) | |
1719 (setq dir gnus-uu-work-dir)) | |
1720 (when (and dir | |
1721 (file-exists-p dir)) | |
1722 (let ((files (directory-files dir t nil t)) | |
1723 file) | |
1724 (while (setq file (pop files)) | |
1725 (unless (member (file-name-nondirectory file) '("." "..")) | |
1726 (if (file-directory-p file) | |
1727 (gnus-uu-delete-work-dir file) | |
1728 (gnus-message 9 "Deleting file %s..." file) | |
1729 (delete-file file)))) | |
1730 (delete-directory dir))) | |
1731 (gnus-message 7 "")) | |
1732 | |
1733 ;; Initializing | |
1734 | |
1735 (add-hook 'gnus-exit-group-hook 'gnus-uu-clean-up) | |
1736 (add-hook 'gnus-exit-group-hook 'gnus-uu-delete-work-dir) | |
1737 | |
1738 | |
1739 | |
1740 ;;; | |
1741 ;;; uuencoded posting | |
1742 ;;; | |
1743 | |
1744 ;; Any function that is to be used as and encoding method will take two | |
1745 ;; parameters: PATH-NAME and FILE-NAME. (E.g. "/home/gaga/spiral.jpg" | |
1746 ;; and "spiral.jpg", respectively.) The function should return nil if | |
1747 ;; the encoding wasn't successful. | |
1748 (defcustom gnus-uu-post-encode-method 'gnus-uu-post-encode-uuencode | |
1749 "Function used for encoding binary files. | |
1750 There are three functions supplied with gnus-uu for encoding files: | |
1751 `gnus-uu-post-encode-uuencode', which does straight uuencoding; | |
1752 `gnus-uu-post-encode-mime', which encodes with base64 and adds MIME | |
1753 headers; and `gnus-uu-post-encode-mime-uuencode', which encodes with | |
1754 uuencode and adds MIME headers." | |
1755 :group 'gnus-extract-post | |
1756 :type '(radio (function-item gnus-uu-post-encode-uuencode) | |
1757 (function-item gnus-uu-post-encode-mime) | |
1758 (function-item gnus-uu-post-encode-mime-uuencode) | |
1759 (function :tag "Other"))) | |
1760 | |
1761 (defcustom gnus-uu-post-include-before-composing nil | |
1762 "Non-nil means that gnus-uu will ask for a file to encode before you compose the article. | |
1763 If this variable is t, you can either include an encoded file with | |
1764 \\[gnus-uu-post-insert-binary-in-article] or have one included for you when you post the article." | |
1765 :group 'gnus-extract-post | |
1766 :type 'boolean) | |
1767 | |
1768 (defcustom gnus-uu-post-length 990 | |
1769 "Maximum length of an article. | |
1770 The encoded file will be split into how many articles it takes to | |
1771 post the entire file." | |
1772 :group 'gnus-extract-post | |
1773 :type 'integer) | |
1774 | |
1775 (defcustom gnus-uu-post-threaded nil | |
1776 "Non-nil means that gnus-uu will post the encoded file in a thread. | |
1777 This may not be smart, as no other decoder I have seen are able to | |
1778 follow threads when collecting uuencoded articles. (Well, I have seen | |
1779 one package that does that - gnus-uu, but somehow, I don't think that | |
1780 counts...) Default is nil." | |
1781 :group 'gnus-extract-post | |
1782 :type 'boolean) | |
1783 | |
1784 (defcustom gnus-uu-post-separate-description t | |
1785 "Non-nil means that the description will be posted in a separate article. | |
1786 The first article will typically be numbered (0/x). If this variable | |
1787 is nil, the description the user enters will be included at the | |
1788 beginning of the first article, which will be numbered (1/x). Default | |
1789 is t." | |
1790 :group 'gnus-extract-post | |
1791 :type 'boolean) | |
1792 | |
1793 (defvar gnus-uu-post-binary-separator "--binary follows this line--") | |
1794 (defvar gnus-uu-post-message-id nil) | |
1795 (defvar gnus-uu-post-inserted-file-name nil) | |
1796 (defvar gnus-uu-winconf-post-news nil) | |
1797 | |
1798 (defun gnus-uu-post-news () | |
1799 "Compose an article and post an encoded file." | |
1800 (interactive) | |
1801 (setq gnus-uu-post-inserted-file-name nil) | |
1802 (setq gnus-uu-winconf-post-news (current-window-configuration)) | |
1803 | |
1804 (gnus-summary-post-news) | |
1805 | |
1806 (use-local-map (copy-keymap (current-local-map))) | |
1807 (local-set-key "\C-c\C-c" 'gnus-summary-edit-article-done) | |
1808 (local-set-key "\C-c\C-c" 'gnus-uu-post-news-inews) | |
1809 (local-set-key "\C-c\C-s" 'gnus-uu-post-news-inews) | |
1810 (local-set-key "\C-c\C-i" 'gnus-uu-post-insert-binary-in-article) | |
1811 | |
1812 (when gnus-uu-post-include-before-composing | |
1813 (save-excursion (setq gnus-uu-post-inserted-file-name | |
1814 (gnus-uu-post-insert-binary))))) | |
1815 | |
1816 (defun gnus-uu-post-insert-binary-in-article () | |
1817 "Inserts an encoded file in the buffer. | |
1818 The user will be asked for a file name." | |
1819 (interactive) | |
1820 (save-excursion | |
1821 (setq gnus-uu-post-inserted-file-name (gnus-uu-post-insert-binary)))) | |
1822 | |
1823 ;; Encodes with uuencode and substitutes all spaces with backticks. | |
1824 (defun gnus-uu-post-encode-uuencode (path file-name) | |
1825 (when (gnus-uu-post-encode-file "uuencode" path file-name) | |
1826 (goto-char (point-min)) | |
1827 (forward-line 1) | |
1828 (while (re-search-forward " " nil t) | |
1829 (replace-match "`")) | |
1830 t)) | |
1831 | |
1832 ;; Encodes with uuencode and adds MIME headers. | |
1833 (defun gnus-uu-post-encode-mime-uuencode (path file-name) | |
1834 (when (gnus-uu-post-encode-uuencode path file-name) | |
1835 (gnus-uu-post-make-mime file-name "x-uue") | |
1836 t)) | |
1837 | |
1838 ;; Encodes with base64 and adds MIME headers | |
1839 (defun gnus-uu-post-encode-mime (path file-name) | |
1840 (when (gnus-uu-post-encode-file "mmencode" path file-name) | |
1841 (gnus-uu-post-make-mime file-name "base64") | |
1842 t)) | |
1843 | |
1844 ;; Adds MIME headers. | |
1845 (defun gnus-uu-post-make-mime (file-name encoding) | |
1846 (goto-char (point-min)) | |
1847 (insert (format "Content-Type: %s; name=\"%s\"\n" | |
1848 (gnus-uu-choose-action file-name gnus-uu-ext-to-mime-list) | |
1849 file-name)) | |
1850 (insert (format "Content-Transfer-Encoding: %s\n\n" encoding)) | |
1851 (save-restriction | |
1852 (set-buffer gnus-message-buffer) | |
1853 (goto-char (point-min)) | |
1854 (re-search-forward (concat "^" (regexp-quote mail-header-separator) "$")) | |
1855 (forward-line -1) | |
1856 (narrow-to-region 1 (point)) | |
1857 (unless (mail-fetch-field "mime-version") | |
1858 (widen) | |
1859 (insert "MIME-Version: 1.0\n")) | |
1860 (widen))) | |
1861 | |
1862 ;; Encodes a file PATH with COMMAND, leaving the result in the | |
1863 ;; current buffer. | |
1864 (defun gnus-uu-post-encode-file (command path file-name) | |
1865 (= 0 (call-process shell-file-name nil t nil shell-command-switch | |
1866 (format "%s %s %s" command path file-name)))) | |
1867 | |
1868 (defun gnus-uu-post-news-inews () | |
1869 "Posts the composed news article and encoded file. | |
1870 If no file has been included, the user will be asked for a file." | |
1871 (interactive) | |
1872 | |
1873 (let (file-name) | |
1874 | |
1875 (if gnus-uu-post-inserted-file-name | |
1876 (setq file-name gnus-uu-post-inserted-file-name) | |
1877 (setq file-name (gnus-uu-post-insert-binary))) | |
1878 | |
1879 (if gnus-uu-post-threaded | |
1880 (let ((message-required-news-headers | |
1881 (if (memq 'Message-ID message-required-news-headers) | |
1882 message-required-news-headers | |
1883 (cons 'Message-ID message-required-news-headers))) | |
1884 gnus-inews-article-hook) | |
1885 | |
1886 (setq gnus-inews-article-hook (if (listp gnus-inews-article-hook) | |
1887 gnus-inews-article-hook | |
1888 (list gnus-inews-article-hook))) | |
1889 (push | |
1890 '(lambda () | |
1891 (save-excursion | |
1892 (goto-char (point-min)) | |
1893 (if (re-search-forward "^Message-ID: \\(.*\\)$" nil t) | |
1894 (setq gnus-uu-post-message-id | |
1895 (buffer-substring | |
1896 (match-beginning 1) (match-end 1))) | |
1897 (setq gnus-uu-post-message-id nil)))) | |
1898 gnus-inews-article-hook) | |
1899 (gnus-uu-post-encoded file-name t)) | |
1900 (gnus-uu-post-encoded file-name nil))) | |
1901 (setq gnus-uu-post-inserted-file-name nil) | |
1902 (when gnus-uu-winconf-post-news | |
1903 (set-window-configuration gnus-uu-winconf-post-news))) | |
1904 | |
1905 ;; Asks for a file to encode, encodes it and inserts the result in | |
1906 ;; the current buffer. Returns the file name the user gave. | |
1907 (defun gnus-uu-post-insert-binary () | |
1908 (let ((uuencode-buffer-name "*uuencode buffer*") | |
1909 file-path uubuf file-name) | |
1910 | |
1911 (setq file-path (read-file-name | |
1912 "What file do you want to encode? ")) | |
1913 (when (not (file-exists-p file-path)) | |
1914 (error "%s: No such file" file-path)) | |
1915 | |
1916 (goto-char (point-max)) | |
1917 (insert (format "\n%s\n" gnus-uu-post-binary-separator)) | |
1918 | |
1919 (when (string-match "^~/" file-path) | |
1920 (setq file-path (concat "$HOME" (substring file-path 1)))) | |
1921 (if (string-match "/[^/]*$" file-path) | |
1922 (setq file-name (substring file-path (1+ (match-beginning 0)))) | |
1923 (setq file-name file-path)) | |
1924 | |
1925 (unwind-protect | |
1926 (if (save-excursion | |
1927 (set-buffer (setq uubuf | |
1928 (get-buffer-create uuencode-buffer-name))) | |
1929 (erase-buffer) | |
1930 (funcall gnus-uu-post-encode-method file-path file-name)) | |
1931 (insert-buffer-substring uubuf) | |
1932 (error "Encoding unsuccessful")) | |
1933 (kill-buffer uubuf)) | |
1934 file-name)) | |
1935 | |
1936 ;; Posts the article and all of the encoded file. | |
1937 (defun gnus-uu-post-encoded (file-name &optional threaded) | |
1938 (let ((send-buffer-name "*uuencode send buffer*") | |
1939 (encoded-buffer-name "*encoded buffer*") | |
1940 (top-string "[ cut here %s (%s %d/%d) %s gnus-uu ]") | |
1941 (separator (concat mail-header-separator "\n\n")) | |
1942 uubuf length parts header i end beg | |
1943 beg-line minlen buf post-buf whole-len beg-binary end-binary) | |
1944 | |
1945 (setq post-buf (current-buffer)) | |
1946 | |
1947 (goto-char (point-min)) | |
1948 (when (not (re-search-forward | |
1949 (if gnus-uu-post-separate-description | |
1950 (concat "^" (regexp-quote gnus-uu-post-binary-separator) | |
1951 "$") | |
1952 (concat "^" (regexp-quote mail-header-separator) "$")) | |
1953 nil t)) | |
1954 (error "Internal error: No binary/header separator")) | |
1955 (beginning-of-line) | |
1956 (forward-line 1) | |
1957 (setq beg-binary (point)) | |
1958 (setq end-binary (point-max)) | |
1959 | |
1960 (save-excursion | |
1961 (set-buffer (setq uubuf (get-buffer-create encoded-buffer-name))) | |
1962 (erase-buffer) | |
1963 (insert-buffer-substring post-buf beg-binary end-binary) | |
1964 (goto-char (point-min)) | |
1965 (setq length (count-lines 1 (point-max))) | |
1966 (setq parts (/ length gnus-uu-post-length)) | |
1967 (when (not (< (% length gnus-uu-post-length) 4)) | |
1968 (setq parts (1+ parts)))) | |
1969 | |
1970 (when gnus-uu-post-separate-description | |
1971 (forward-line -1)) | |
1972 (kill-region (point) (point-max)) | |
1973 | |
1974 (goto-char (point-min)) | |
1975 (re-search-forward | |
1976 (concat "^" (regexp-quote mail-header-separator) "$") nil t) | |
1977 (beginning-of-line) | |
1978 (setq header (buffer-substring 1 (point))) | |
1979 | |
1980 (goto-char (point-min)) | |
1981 (if (not gnus-uu-post-separate-description) | |
1982 () | |
1983 (when (and (not threaded) (re-search-forward "^Subject: " nil t)) | |
1984 (end-of-line) | |
1985 (insert (format " (0/%d)" parts))) | |
1986 (message-send)) | |
1987 | |
1988 (save-excursion | |
1989 (setq i 1) | |
1990 (setq beg 1) | |
1991 (while (not (> i parts)) | |
1992 (set-buffer (get-buffer-create send-buffer-name)) | |
1993 (erase-buffer) | |
1994 (insert header) | |
1995 (when (and threaded gnus-uu-post-message-id) | |
1996 (insert (format "References: %s\n" gnus-uu-post-message-id))) | |
1997 (insert separator) | |
1998 (setq whole-len | |
1999 (- 62 (length (format top-string "" file-name i parts "")))) | |
2000 (when (> 1 (setq minlen (/ whole-len 2))) | |
2001 (setq minlen 1)) | |
2002 (setq | |
2003 beg-line | |
2004 (format top-string | |
2005 (make-string minlen ?-) | |
2006 file-name i parts | |
2007 (make-string | |
2008 (if (= 0 (% whole-len 2)) (1- minlen) minlen) ?-))) | |
2009 | |
2010 (goto-char (point-min)) | |
2011 (if (not (re-search-forward "^Subject: " nil t)) | |
2012 () | |
2013 (if (not threaded) | |
2014 (progn | |
2015 (end-of-line) | |
2016 (insert (format " (%d/%d)" i parts))) | |
2017 (when (or (and (= i 2) gnus-uu-post-separate-description) | |
2018 (and (= i 1) (not gnus-uu-post-separate-description))) | |
2019 (replace-match "Subject: Re: ")))) | |
2020 | |
2021 (goto-char (point-max)) | |
2022 (save-excursion | |
2023 (set-buffer uubuf) | |
2024 (goto-char beg) | |
2025 (if (= i parts) | |
2026 (goto-char (point-max)) | |
2027 (forward-line gnus-uu-post-length)) | |
2028 (when (and (= (1+ i) parts) (< (count-lines (point) (point-max)) 4)) | |
2029 (forward-line -4)) | |
2030 (setq end (point))) | |
2031 (insert-buffer-substring uubuf beg end) | |
2032 (insert beg-line) | |
2033 (insert "\n") | |
2034 (setq beg end) | |
2035 (setq i (1+ i)) | |
2036 (goto-char (point-min)) | |
2037 (re-search-forward | |
2038 (concat "^" (regexp-quote mail-header-separator) "$") nil t) | |
2039 (beginning-of-line) | |
2040 (forward-line 2) | |
2041 (when (re-search-forward | |
2042 (concat "^" (regexp-quote gnus-uu-post-binary-separator) "$") | |
2043 nil t) | |
2044 (replace-match "") | |
2045 (forward-line 1)) | |
2046 (insert beg-line) | |
2047 (insert "\n") | |
2048 (let (message-sent-message-via) | |
2049 (message-send)))) | |
2050 | |
2051 (when (setq buf (get-buffer send-buffer-name)) | |
2052 (kill-buffer buf)) | |
2053 (when (setq buf (get-buffer encoded-buffer-name)) | |
2054 (kill-buffer buf)) | |
2055 | |
2056 (when (not gnus-uu-post-separate-description) | |
2057 (set-buffer-modified-p nil) | |
2058 (when (fboundp 'bury-buffer) | |
2059 (bury-buffer))))) | |
2060 | |
2061 (provide 'gnus-uu) | |
2062 | |
2063 ;; gnus-uu.el ends here |