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