1 ;;; gnus-uu.el --- extract (uu)encoded files in Gnus
2 ;; Copyright (C) 1985,86,87,93,94,95 Free Software Foundation, Inc.
4 ;; Author: Lars Magne Ingebrigtsen <larsi@ifi.uio.no>
9 ;; This file is part of GNU Emacs.
11 ;; GNU Emacs is free software; you can redistribute it and/or modify
12 ;; it under the terms of the GNU General Public License as published by
13 ;; the Free Software Foundation; either version 2, or (at your option)
16 ;; GNU Emacs is distributed in the hope that it will be useful,
17 ;; but WITHOUT ANY WARRANTY; without even the implied warranty of
18 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19 ;; GNU General Public License for more details.
21 ;; You should have received a copy of the GNU General Public License
22 ;; along with GNU Emacs; see the file COPYING. If not, write to
23 ;; the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA.
32 ;; Default viewing action rules
34 (defvar gnus-uu-default-view-rules
35 '(("\\.te?xt$\\|\\.doc$\\|read.*me\\|\\.c?$\\|\\.h$\\|\\.bat$\\|\\.asm$\\|makefile" "cat %s | sed s/\r//g")
36 ("\\.pas$" "cat %s | sed s/\r//g")
37 ("\\.[1-9]$" "groff -mandoc -Tascii %s | sed s/\b.//g")
38 ("\\.\\(jpe?g\\|gif\\|tiff?\\|p[pgb]m\\|xwd\\|xbm\\|pcx\\)$" "xv")
39 ("\\.tga$" "tgatoppm %s | xv -")
40 ("\\.\\(wav\\|aiff\\|hcom\\|u[blw]\\|s[bfw]\\|voc\\|smp\\)$"
41 "sox -v .5 %s -t .au -u - > /dev/audio")
42 ("\\.au$" "cat %s > /dev/audio")
44 ("\\.ps$" "ghostview")
46 ("\\.html$" "xmosaic")
47 ("\\.mpe?g$" "mpeg_play")
48 ("\\.\\(flc\\|fli\\|rle\\|iff\\|pfx\\|avi\\|sme\\|rpza\\|dl\\|qt\\|rsrc\\|mov\\)$" "xanim")
49 ("\\.\\(tar\\|arj\\|zip\\|zoo\\|arc\\|gz\\|Z\\|lzh\\|ar\\|lha\\)$"
51 "*Default actions to be taken when the user asks to view a file.
52 To change the behaviour, you can either edit this variable or set
53 `gnus-uu-user-view-rules' to something useful.
57 To make gnus-uu use 'xli' to display JPEG and GIF files, put the
58 following in your .emacs file:
60 (setq gnus-uu-user-view-rules '((\"jpg$\\\\|gif$\" \"xli\")))
62 Both these variables are lists of lists with two string elements. The
63 first string is a regular expression. If the file name matches this
64 regular expression, the command in the second string is executed with
65 the file as an argument.
67 If the command string contains \"%s\", the file name will be inserted
68 at that point in the command string. If there's no \"%s\" in the
69 command string, the file name will be appended to the command string
72 There are several user variables to tailor the behaviour of gnus-uu to
73 your needs. First we have `gnus-uu-user-view-rules', which is the
74 variable gnus-uu first consults when trying to decide how to view a
75 file. If this variable contains no matches, gnus-uu examines the
76 default rule variable provided in this package. If gnus-uu finds no
77 match here, it uses `gnus-uu-user-view-rules-end' to try to make a
80 (defvar gnus-uu-user-view-rules nil
81 "*Variable detailing what actions are to be taken to view a file.
82 See the documentation on the `gnus-uu-default-view-rules' variable for
85 (defvar gnus-uu-user-view-rules-end
87 "*Variable saying what actions are to be taken if no rule matched the file name.
88 See the documentation on the `gnus-uu-default-view-rules' variable for
91 ;; Default unpacking commands
93 (defvar gnus-uu-default-archive-rules
94 '(("\\.tar$" "tar xf")
95 ("\\.zip$" "unzip -o")
99 ("\\.\\(lzh\\|lha\\)$" "lha x")
100 ("\\.Z$" "uncompress")
102 ("\\.arc$" "arc -x")))
104 (defvar gnus-uu-destructive-archivers
105 (list "uncompress" "gunzip"))
107 (defvar gnus-uu-user-archive-rules nil
108 "*A list that can be set to override the default archive unpacking commands.
109 To use, for instance, 'untar' to unpack tar files and 'zip -x' to
110 unpack zip files, say the following:
111 (setq gnus-uu-user-archive-rules
112 '((\"\\\\.tar$\" \"untar\")
113 (\"\\\\.zip$\" \"zip -x\")))")
115 (defvar gnus-uu-ignore-files-by-name nil
116 "*A regular expression saying what files should not be viewed based on name.
117 If, for instance, you want gnus-uu to ignore all .au and .wav files,
118 you could say something like
120 (setq gnus-uu-ignore-files-by-name \"\\\\.au$\\\\|\\\\.wav$\")
122 Note that this variable can be used in conjunction with the
123 `gnus-uu-ignore-files-by-type' variable.")
125 (defvar gnus-uu-ignore-files-by-type nil
126 "*A regular expression saying what files that shouldn't be viewed, based on MIME file type.
127 If, for instance, you want gnus-uu to ignore all audio files and all mpegs,
128 you could say something like
130 (setq gnus-uu-ignore-files-by-type \"audio/\\\\|video/mpeg\")
132 Note that this variable can be used in conjunction with the
133 `gnus-uu-ignore-files-by-name' variable.")
135 ;; Pseudo-MIME support
137 (defconst gnus-uu-ext-to-mime-list
138 '(("\\.gif$" "image/gif")
139 ("\\.jpe?g$" "image/jpeg")
140 ("\\.tiff?$" "image/tiff")
141 ("\\.xwd$" "image/xwd")
142 ("\\.pbm$" "image/pbm")
143 ("\\.pgm$" "image/pgm")
144 ("\\.ppm$" "image/ppm")
145 ("\\.xbm$" "image/xbm")
146 ("\\.pcx$" "image/pcx")
147 ("\\.tga$" "image/tga")
148 ("\\.ps$" "image/postscript")
149 ("\\.fli$" "video/fli")
150 ("\\.wav$" "audio/wav")
151 ("\\.aiff$" "audio/aiff")
152 ("\\.hcom$" "audio/hcom")
153 ("\\.voc$" "audio/voc")
154 ("\\.smp$" "audio/smp")
155 ("\\.mod$" "audio/mod")
156 ("\\.dvi$" "image/dvi")
157 ("\\.mpe?g$" "video/mpeg")
158 ("\\.au$" "audio/basic")
159 ("\\.\\(te?xt\\|doc\\|c\\|h\\)$" "text/plain")
160 ("\\.\\(c\\|h\\)$" "text/source")
161 ("read.*me" "text/plain")
162 ("\\.html$" "text/html")
163 ("\\.bat$" "text/bat")
164 ("\\.[1-6]$" "text/man")
165 ("\\.flc$" "video/flc")
166 ("\\.rle$" "video/rle")
167 ("\\.pfx$" "video/pfx")
168 ("\\.avi$" "video/avi")
169 ("\\.sme$" "video/sme")
170 ("\\.rpza$" "video/prza")
171 ("\\.dl$" "video/dl")
172 ("\\.qt$" "video/qt")
173 ("\\.rsrc$" "video/rsrc")
174 ("\\..*$" "unknown/unknown")))
176 ;; Various variables users may set
178 (defvar gnus-uu-tmp-dir "/tmp/"
179 "*Variable saying where gnus-uu is to do its work.
180 Default is \"/tmp/\".")
182 (defvar gnus-uu-do-not-unpack-archives nil
183 "*Non-nil means that gnus-uu won't peek inside archives looking for files to dispay.
186 (defvar gnus-uu-view-and-save nil
187 "*Non-nil means that the user will always be asked to save a file after viewing it.
188 If the variable is nil, the user will only be asked to save if the
189 viewing is unsuccessful. Default is nil.")
191 (defvar gnus-uu-ignore-default-view-rules nil
192 "*Non-nil means that gnus-uu will ignore the default viewing rules.
193 Only the user viewing rules will be consulted. Default is nil.")
195 (defvar gnus-uu-ignore-default-archive-rules nil
196 "*Non-nil means that gnus-uu will ignore the default archive unpacking commands.
197 Only the user unpacking commands will be consulted. Default is nil.")
199 (defvar gnus-uu-kill-carriage-return t
200 "*Non-nil means that gnus-uu will strip all carriage returns from articles.
203 (defvar gnus-uu-view-with-metamail nil
204 "*Non-nil means that files will be viewed with metamail.
205 The gnus-uu viewing functions will be ignored and gnus-uu will try
206 to guess at a content-type based on file name suffixes. Default
209 (defvar gnus-uu-unmark-articles-not-decoded nil
210 "*Non-nil means that gnus-uu will mark articles that were unsuccessfully decoded as unread.
213 (defvar gnus-uu-correct-stripped-uucode nil
214 "*Non-nil means that gnus-uu will *try* to fix uuencoded files that have had trailing spaces deleted.
217 (defvar gnus-uu-save-in-digest nil
218 "*Non-nil means that gnus-uu, when asked to save without decoding, will save in digests.
219 If this variable is nil, gnus-uu will just save everything in a
220 file without any embellishments. The digesting almost conforms to RFC1153 -
221 no easy way to specify any meaningful volume and issue numbers were found,
222 so I simply dropped them.")
224 (defvar gnus-uu-digest-headers
225 '("^Date:" "^From:" "^To:" "^Cc:" "^Subject:" "^Message-ID:" "^Keywords:"
226 "^Summary:" "^References:")
227 "*List of regexps to match headers included in digested messages.
228 The headers will be included in the sequence they are matched.")
230 (defvar gnus-uu-save-separate-articles nil
231 "*Non-nil means that gnus-uu will save articles in separate files.")
233 ;; Internal variables
235 (defvar gnus-uu-saved-article-name nil)
237 (defconst gnus-uu-begin-string "^begin[ \t]+[0-7][0-7][0-7][ \t]+\\(.*\\)$")
238 (defconst gnus-uu-end-string "^end[ \t]*$")
240 (defconst gnus-uu-body-line "^M")
242 (while (> (setq i (1- i)) 0)
243 (setq gnus-uu-body-line (concat gnus-uu-body-line "[^a-z]")))
244 (setq gnus-uu-body-line (concat gnus-uu-body-line ".?$")))
246 ;"^M.............................................................?$"
248 (defconst gnus-uu-shar-begin-string "^#! */bin/sh")
250 (defvar gnus-uu-shar-file-name nil)
251 (defconst gnus-uu-shar-name-marker "begin [0-7][0-7][0-7][ \t]+\\(\\(\\w\\|\\.\\)*\\b\\)")
253 (defconst gnus-uu-postscript-begin-string "^%!PS-")
254 (defconst gnus-uu-postscript-end-string "^%%EOF$")
256 (defvar gnus-uu-file-name nil)
257 (defconst gnus-uu-uudecode-process nil)
259 (defvar gnus-uu-generated-file-list nil)
260 (defvar gnus-uu-work-dir nil)
262 (defconst gnus-uu-output-buffer-name "*Gnus UU Output*")
264 (defconst gnus-uu-highest-article-number 1)
265 (defvar gnus-uu-default-dir default-directory)
269 (defvar gnus-uu-extract-map nil)
270 (defvar gnus-uu-extract-view-map nil)
271 (defvar gnus-uu-mark-map nil)
273 (define-prefix-command 'gnus-uu-mark-map)
274 (define-key gnus-summary-mark-map "p" 'gnus-uu-mark-map)
275 (define-key gnus-uu-mark-map "p" 'gnus-summary-mark-as-processable)
276 (define-key gnus-uu-mark-map "u" 'gnus-summary-unmark-as-processable)
277 (define-key gnus-uu-mark-map "U" 'gnus-summary-unmark-all-processable)
278 (define-key gnus-uu-mark-map "s" 'gnus-uu-mark-series)
279 (define-key gnus-uu-mark-map "r" 'gnus-uu-mark-region)
280 (define-key gnus-uu-mark-map "R" 'gnus-uu-mark-by-regexp)
281 (define-key gnus-uu-mark-map "t" 'gnus-uu-mark-thread)
282 (define-key gnus-uu-mark-map "a" 'gnus-uu-mark-all)
283 (define-key gnus-uu-mark-map "S" 'gnus-uu-mark-sparse)
285 (define-prefix-command 'gnus-uu-extract-map)
286 (define-key gnus-summary-mode-map "X" 'gnus-uu-extract-map)
287 ;;(define-key gnus-uu-extract-map "x" 'gnus-uu-extract-any)
288 ;;(define-key gnus-uu-extract-map "m" 'gnus-uu-extract-mime)
289 (define-key gnus-uu-extract-map "u" 'gnus-uu-decode-uu)
290 (define-key gnus-uu-extract-map "U" 'gnus-uu-decode-uu-and-save)
291 (define-key gnus-uu-extract-map "s" 'gnus-uu-decode-unshar)
292 (define-key gnus-uu-extract-map "S" 'gnus-uu-decode-unshar-and-save)
293 (define-key gnus-uu-extract-map "o" 'gnus-uu-decode-save)
294 (define-key gnus-uu-extract-map "O" 'gnus-uu-decode-save)
295 (define-key gnus-uu-extract-map "b" 'gnus-uu-decode-binhex)
296 (define-key gnus-uu-extract-map "B" 'gnus-uu-decode-binhex)
297 (define-key gnus-uu-extract-map "p" 'gnus-uu-decode-postscript)
298 (define-key gnus-uu-extract-map "P" 'gnus-uu-decode-postscript-and-save)
300 (define-prefix-command 'gnus-uu-extract-view-map)
301 (define-key gnus-uu-extract-map "v" 'gnus-uu-extract-view-map)
302 (define-key gnus-uu-extract-view-map "u" 'gnus-uu-decode-uu-view)
303 (define-key gnus-uu-extract-view-map "U" 'gnus-uu-decode-uu-and-save-view)
304 (define-key gnus-uu-extract-view-map "s" 'gnus-uu-decode-unshar-view)
305 (define-key gnus-uu-extract-view-map "S" 'gnus-uu-decode-unshar-and-save-view)
306 (define-key gnus-uu-extract-view-map "o" 'gnus-uu-decode-save-view)
307 (define-key gnus-uu-extract-view-map "O" 'gnus-uu-decode-save-view)
308 (define-key gnus-uu-extract-view-map "b" 'gnus-uu-decode-binhex-view)
309 (define-key gnus-uu-extract-view-map "B" 'gnus-uu-decode-binhex-view)
310 (define-key gnus-uu-extract-view-map "p" 'gnus-uu-decode-postscript-view)
311 (define-key gnus-uu-extract-view-map "P" 'gnus-uu-decode-postscript-and-save-view)
317 (defun gnus-uu-decode-uu (n)
318 "Uudecodes the current article."
320 (gnus-uu-decode-with-method 'gnus-uu-uustrip-article n))
322 (defun gnus-uu-decode-uu-and-save (n dir)
323 "Decodes and saves the resulting file."
325 (list current-prefix-arg
326 (read-file-name "Uudecode and save in dir: "
328 gnus-uu-default-dir t)))
329 (gnus-uu-decode-with-method 'gnus-uu-uustrip-article n dir))
331 (defun gnus-uu-decode-unshar (n)
332 "Unshars the current article."
334 (gnus-uu-decode-with-method 'gnus-uu-unshar-article n nil nil 'scan))
336 (defun gnus-uu-decode-unshar-and-save (n dir)
337 "Unshars and saves the current article."
339 (list current-prefix-arg
340 (read-file-name "Unshar and save in dir: "
342 gnus-uu-default-dir t)))
343 (gnus-uu-decode-with-method 'gnus-uu-unshar-article n dir nil 'scan))
345 (defun gnus-uu-decode-save (n file)
346 "Saves the current article."
348 (list current-prefix-arg
350 (if gnus-uu-save-separate-articles
351 "Save articles is dir: "
352 "Save articles in file: ")
354 gnus-uu-default-dir)))
355 (setq gnus-uu-saved-article-name file)
356 (gnus-uu-decode-with-method 'gnus-uu-save-article n nil t)
357 (setq gnus-uu-generated-file-list
358 (delete file gnus-uu-generated-file-list)))
360 (defun gnus-uu-decode-binhex (n dir)
361 "Unbinhexes the current article."
363 (list current-prefix-arg
364 (read-file-name "Unbinhex and save in dir: "
366 gnus-uu-default-dir t)))
367 (gnus-uu-decode-with-method 'gnus-uu-binhex-article n dir))
369 (defun gnus-uu-decode-uu-view (n)
370 "Uudecodes and views the current article."
372 (let ((gnus-view-pseudos (or gnus-view-pseudos 'automatic)))
373 (gnus-uu-decode-uu n)))
375 (defun gnus-uu-decode-uu-and-save-view (n dir)
376 "Decodes, views and saves the resulting file."
378 (list current-prefix-arg
379 (read-file-name "Uudecode, view and save in dir: "
381 gnus-uu-default-dir t)))
382 (let ((gnus-view-pseudos (or gnus-view-pseudos 'automatic)))
383 (gnus-uu-decode-uu-and-save n dir)))
385 (defun gnus-uu-decode-unshar-view (n)
386 "Unshars and views the current article."
388 (let ((gnus-view-pseudos (or gnus-view-pseudos 'automatic)))
389 (gnus-uu-decode-unshar n)))
391 (defun gnus-uu-decode-unshar-and-save-view (n dir)
392 "Unshars and saves the current article."
394 (list current-prefix-arg
395 (read-file-name "Unshar, view and save in dir: "
397 gnus-uu-default-dir t)))
398 (let ((gnus-view-pseudos (or gnus-view-pseudos 'automatic)))
399 (gnus-uu-decode-unshar-and-save n dir)))
401 (defun gnus-uu-decode-save-view (n file)
402 "Saves and views the current article."
404 (list current-prefix-arg
405 (read-file-name (if gnus-uu-save-separate-articles
406 "Save articles is dir: "
407 "Save articles in file: ")
408 gnus-uu-default-dir gnus-uu-default-dir)))
409 (let ((gnus-view-pseudos (or gnus-view-pseudos 'automatic)))
410 (gnus-uu-decode-save n file)))
412 (defun gnus-uu-decode-binhex-view (n file)
413 "Unbinhexes and views the current article."
415 (list current-prefix-arg
416 (read-file-name "Unbinhex, view and save in dir: "
417 gnus-uu-default-dir gnus-uu-default-dir)))
418 (let ((gnus-view-pseudos (or gnus-view-pseudos 'automatic)))
419 (gnus-uu-decode-binhex n file)))
422 ;; Digest and forward articles
424 (defun gnus-uu-digest-mail-forward (n &optional post)
425 "Digests and forwards all articles in this series."
428 (let ((gnus-uu-save-in-digest t)
429 (file (concat gnus-uu-work-dir (make-temp-name "forward")))
430 (winconf (current-window-configuration))
432 (gnus-uu-decode-save n file)
433 (gnus-uu-add-file file)
434 (setq buf (switch-to-buffer (get-buffer-create " *gnus-uu-forward*")))
435 (gnus-add-current-to-buffer-list)
437 (delete-other-windows)
439 (goto-char (point-min))
440 (and (re-search-forward "^Subject: ")
442 (delete-region (point) (gnus-point-at-eol))
443 (insert "Digested Articles")))
444 (goto-char (point-min))
445 (and (re-search-forward "^From: ")
447 (delete-region (point) (gnus-point-at-eol))
450 (gnus-forward-using-post)
451 (funcall gnus-mail-forward-method))
454 (defun gnus-uu-digest-post-forward (n)
455 "Digest and forward to a newsgroup."
457 (gnus-uu-digest-mail-forward n t))
461 (defun gnus-uu-mark-by-regexp (regexp)
462 "Ask for a regular expression and set the process mark on all articles that match."
463 (interactive (list (read-from-minibuffer "Mark (regexp): ")))
464 (gnus-set-global-variables)
465 (let ((articles (gnus-uu-find-articles-matching regexp)))
467 (gnus-summary-set-process-mark (car articles))
468 (setq articles (cdr articles)))
470 (gnus-summary-position-cursor))
472 (defun gnus-uu-mark-series ()
473 "Mark the current series with the process mark."
475 (gnus-set-global-variables)
476 (let ((articles (gnus-uu-find-articles-matching)))
478 (gnus-summary-set-process-mark (car articles))
479 (setq articles (cdr articles)))
481 (gnus-summary-position-cursor))
483 (defun gnus-uu-mark-region (beg end)
484 "Marks all articles between point and mark."
486 (gnus-set-global-variables)
489 (while (< (point) end)
490 (gnus-summary-set-process-mark (gnus-summary-article-number))
492 (gnus-summary-position-cursor))
494 (defun gnus-uu-mark-thread ()
495 "Marks all articles downwards in this thread."
497 (gnus-set-global-variables)
499 (let ((level (gnus-summary-thread-level)))
500 (while (and (gnus-summary-set-process-mark (gnus-summary-article-number))
501 (zerop (gnus-summary-next-subject 1))
502 (> (gnus-summary-thread-level) level)))))
503 (gnus-summary-position-cursor))
505 (defun gnus-uu-mark-sparse ()
506 "Mark all series that have some articles marked."
508 (gnus-set-global-variables)
509 (let ((marked (nreverse gnus-newsgroup-processable))
510 subject articles total headers)
511 (or marked (error "No articles marked with the process mark"))
512 (setq gnus-newsgroup-processable nil)
515 (and (setq headers (gnus-get-header-by-number (car marked)))
516 (setq subject (header-subject headers)
517 articles (gnus-uu-find-articles-matching
518 (gnus-uu-reginize-string subject))
519 total (nconc total articles)))
521 (gnus-summary-set-process-mark (car articles))
522 (setcdr marked (delq (car articles) (cdr marked)))
523 (setq articles (cdr articles)))
524 (setq marked (cdr marked)))
525 (setq gnus-newsgroup-processable (nreverse total)))
526 (gnus-summary-position-cursor)))
528 (defun gnus-uu-mark-all ()
529 "Mark all articles in \"series\" order."
531 (gnus-set-global-variables)
532 (setq gnus-newsgroup-processable nil)
534 (goto-char (point-min))
536 (while (and (not (eobp))
537 (setq number (gnus-summary-article-number)))
538 (if (not (memq number gnus-newsgroup-processable))
539 (save-excursion (gnus-uu-mark-series)))
541 (gnus-summary-position-cursor))
543 ;; All PostScript functions written by Erik Selberg <speed@cs.washington.edu>.
545 (defun gnus-uu-decode-postscript (n)
546 "Gets postscript of the current article."
548 (gnus-uu-decode-with-method 'gnus-uu-decode-postscript-article n))
550 (defun gnus-uu-decode-postscript-view (n)
551 "Gets and views the current article."
553 (let ((gnus-view-pseudos (or gnus-view-pseudos 'automatic)))
554 (gnus-uu-decode-postscript n)))
556 (defun gnus-uu-decode-postscript-and-save (n dir)
557 "Extracts postscript and saves the current article."
559 (list current-prefix-arg
560 (read-file-name "Where do you want to save the file(s)? "
562 gnus-uu-default-dir t)))
563 (gnus-uu-decode-with-method 'gnus-uu-decode-postscript-article n dir))
566 (defun gnus-uu-decode-postscript-and-save-view (n dir)
567 "Decodes, views and saves the resulting file."
569 (list current-prefix-arg
570 (read-file-name "Where do you want to save the file(s)? "
572 gnus-uu-default-dir t)))
573 (let ((gnus-view-pseudos (or gnus-view-pseudos 'automatic)))
574 (gnus-uu-decode-postscript-and-save n dir)))
577 ;; Internal functions.
579 (defun gnus-uu-decode-with-method (method n &optional save not-insert scan)
581 (if save (setq gnus-uu-default-dir save))
582 (let ((articles (gnus-uu-get-list-of-articles n))
584 (setq files (gnus-uu-grab-articles articles method t))
585 (let ((gnus-current-article (car articles)))
586 (and scan (setq files (gnus-uu-scan-directory gnus-uu-work-dir))))
587 (and save (gnus-uu-save-files files save))
588 (setq files (gnus-uu-unpack-files files))
589 (gnus-uu-add-file (mapcar (lambda (file) (cdr (assq 'name file))) files))
590 (setq files (nreverse (gnus-uu-get-actions files)))
591 (or not-insert (gnus-summary-insert-pseudos files))))
593 ;; Return a list of files in dir.
594 (defun gnus-uu-scan-directory (dir)
595 (let ((files (directory-files dir t))
598 (cond ((string-match "/\\.\\.?$" (car files)))
599 ((file-directory-p (car files))
600 (setq dirs (cons (car files) dirs)))
601 (t (setq out (cons (list (cons 'name (car files))
602 (cons 'article gnus-current-article))
604 (setq files (cdr files)))
605 (apply 'nconc out (mapcar (lambda (d) (gnus-uu-scan-directory d))
608 (defun gnus-uu-save-files (files dir)
609 (let ((len (length files))
612 (setq file (cdr (assq 'name (car files))))
613 (and (file-exists-p file)
615 (setq to-file (if (file-directory-p dir)
616 (concat dir (file-name-nondirectory file))
618 (and (or (not (file-exists-p to-file))
619 (gnus-y-or-n-p (format "%s exists; overwrite? "
621 (copy-file file to-file 1 t))))
622 (setq files (cdr files)))
623 (message "Saved %d file%s" len (if (> len 1) "s" ""))))
625 ;; Functions for saving and possibly digesting articles without
628 ;; Function called by gnus-uu-grab-articles to treat each article.
629 (defun gnus-uu-save-article (buffer in-state)
631 (gnus-uu-save-separate-articles
634 (write-region 1 (point-max) (concat gnus-uu-saved-article-name
635 gnus-current-article))
636 (cond ((eq in-state 'first) (list gnus-uu-saved-article-name 'begin))
637 ((eq in-state 'first-and-last) (list gnus-uu-saved-article-name
639 ((eq in-state 'last) (list 'end))
640 (t (list 'middle)))))
641 ((not gnus-uu-save-in-digest)
644 (write-region 1 (point-max) gnus-uu-saved-article-name t)
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
648 ((eq in-state 'last) (list 'end))
649 (t (list 'middle)))))
651 (let ((name (file-name-nondirectory gnus-uu-saved-article-name))
652 beg subj headers headline sorthead body end-string state)
653 (if (or (eq in-state 'first)
654 (eq in-state 'first-and-last))
656 (setq state (list 'begin))
657 (save-excursion (set-buffer (get-buffer-create "*gnus-uu-body*"))
660 (set-buffer (get-buffer-create "*gnus-uu-pre*"))
663 "Date: %s\nFrom: %s\nSubject: %s Digest\n\nTopics:\n"
664 (current-time-string) name name))))
665 (if (not (eq in-state 'end))
666 (setq state (list 'middle))))
668 (set-buffer (get-buffer "*gnus-uu-body*"))
669 (goto-char (setq beg (point-max)))
673 (goto-char (point-min))
674 (re-search-forward "\n\n")
675 (setq body (buffer-substring (1- (point)) (point-max)))
676 (narrow-to-region 1 (point))
677 (setq headers gnus-uu-digest-headers)
679 (setq headline (car headers))
680 (setq headers (cdr headers))
681 (goto-char (point-min))
682 (if (re-search-forward headline nil t)
687 (or (and (re-search-forward "^[^ \t]" nil t)
689 (progn (forward-line 1) (point))))))))
691 (insert sorthead)(goto-char (point-max))
692 (insert body)(goto-char (point-max))
693 (insert (concat "\n" (make-string 30 ?-) "\n\n"))
695 (if (re-search-forward "^Subject: \\(.*\\)$" nil t)
697 (setq subj (buffer-substring (match-beginning 1) (match-end 1)))
699 (set-buffer (get-buffer "*gnus-uu-pre*"))
700 (insert (format " %s\n" subj))))))
701 (if (or (eq in-state 'last)
702 (eq in-state 'first-and-last))
705 (set-buffer (get-buffer "*gnus-uu-pre*"))
706 (insert (format "\n\n%s\n\n" (make-string 70 ?-)))
707 (write-region 1 (point-max) gnus-uu-saved-article-name))
709 (set-buffer (get-buffer "*gnus-uu-body*"))
710 (goto-char (point-max))
712 (concat (setq end-string (format "End of %s Digest" name))
714 (insert (concat (make-string (length end-string) ?*) "\n"))
715 (write-region 1 (point-max) gnus-uu-saved-article-name t))
716 (kill-buffer (get-buffer "*gnus-uu-pre*"))
717 (kill-buffer (get-buffer "*gnus-uu-body*"))
718 (setq state (cons 'end state))))
719 (if (memq 'begin state)
720 (cons gnus-uu-saved-article-name state)
723 ;; Binhex treatment - not very advanced.
725 (defconst gnus-uu-binhex-body-line
726 "^[^:]...............................................................$")
727 (defconst gnus-uu-binhex-begin-line
728 "^:...............................................................$")
729 (defconst gnus-uu-binhex-end-line
731 (defvar gnus-uu-binhex-article-name nil)
733 (defun gnus-uu-binhex-article (buffer in-state)
734 (let (state start-char)
738 (goto-char (point-min))
739 (if (not (re-search-forward gnus-uu-binhex-begin-line nil t))
740 (if (not (re-search-forward gnus-uu-binhex-body-line nil t))
741 (setq state (list 'wrong-type))))
743 (if (memq 'wrong-type state)
746 (setq start-char (point))
747 (if (looking-at gnus-uu-binhex-begin-line)
749 (setq state (list 'begin))
750 (write-region 1 1 gnus-uu-binhex-article-name))
751 (setq state (list 'middle)))
752 (goto-char (point-max))
753 (re-search-backward (concat gnus-uu-binhex-body-line "\\|"
754 gnus-uu-binhex-end-line) nil t)
755 (if (looking-at gnus-uu-binhex-end-line)
756 (setq state (if (memq 'begin state)
761 (if (file-exists-p gnus-uu-binhex-article-name)
762 (append-to-file start-char (point) gnus-uu-binhex-article-name))))
763 (if (memq 'begin state)
764 (cons gnus-uu-binhex-article-name state)
769 (defun gnus-uu-decode-postscript-article (process-buffer in-state)
770 (let ((state (list 'ok))
771 start-char end-char file-name)
773 (set-buffer process-buffer)
774 (goto-char (point-min))
775 (if (not (re-search-forward gnus-uu-postscript-begin-string nil t))
776 (setq state (list 'wrong-type))
778 (setq start-char (point))
779 (if (not (re-search-forward gnus-uu-postscript-end-string nil t))
780 (setq state (list 'wrong-type))
781 (setq end-char (point))
782 (set-buffer (get-buffer-create gnus-uu-output-buffer-name))
783 (insert-buffer-substring process-buffer start-char end-char)
784 (setq file-name (concat gnus-uu-work-dir (cdr gnus-article-current) ".ps"))
785 (write-region (point-min) (point-max) file-name)
786 (setq state (list file-name'begin 'end))
795 (defun gnus-uu-get-actions (files)
799 (setq name (cdr (assq 'name (car files))))
801 (setq action (gnus-uu-get-action name))
802 (setcar files (nconc (list (cons 'action action)
803 (cons 'execute (if (string-match "%" action)
805 (concat action " " name))))
807 (setq files (cdr files)))
810 (defun gnus-uu-get-action (file-name)
813 (gnus-uu-choose-action
816 gnus-uu-user-view-rules
817 (if gnus-uu-ignore-default-view-rules
819 gnus-uu-default-view-rules)
820 gnus-uu-user-view-rules-end)))
821 (if (and (not (string= (or action "") "gnus-uu-archive"))
822 gnus-uu-view-with-metamail)
824 (gnus-uu-choose-action file-name gnus-uu-ext-to-mime-list))
825 (setq action (format "metamail -d -b -c \"%s\"" action))))
829 ;; Functions for treating subjects and collecting series.
831 (defun gnus-uu-reginize-string (string)
832 ;; Takes a string and puts a \ in front of every special character;
833 ;; ignores any leading "version numbers" thingies that they use in
834 ;; the comp.binaries groups, and either replaces anything that looks
835 ;; like "2/3" with "[0-9]+/[0-9]+" or, if it can't find something
836 ;; like that, replaces the last two numbers with "[0-9]+". This, in
837 ;; my experience, should get most postings of a series.
839 (vernum "v[0-9]+[a-z][0-9]+:")
842 (set-buffer (get-buffer-create gnus-uu-output-buffer-name))
843 (buffer-disable-undo (current-buffer))
845 (insert (regexp-quote string))
848 (setq case-fold-search nil)
849 (goto-char (point-min))
850 (if (looking-at vernum)
852 (replace-match vernum t t)
853 (setq beg (length vernum))))
856 (if (re-search-forward "[ \t]*[0-9]+/[0-9]+" nil t)
857 (replace-match " [0-9]+/[0-9]+")
860 (if (re-search-forward "[0-9]+[ \t]*of[ \t]*[0-9]+" nil t)
861 (replace-match "[0-9]+ of [0-9]+")
864 (while (and (re-search-backward "[0-9]" nil t) (> count 0))
867 (< 1 (goto-char (1- (point))))))
868 (re-search-forward "[0-9]+" nil t)
869 (replace-match "[0-9]+")
871 (setq count (1- count)))))
874 (while (re-search-forward "[ \t]+" nil t)
875 (replace-match "[ \t]*" t t))
877 (buffer-substring 1 (point-max)))))
879 (defun gnus-uu-get-list-of-articles (n)
880 ;; If N is non-nil, the article numbers of the N next articles
882 ;; If any articles have been marked as processable, they will be
884 ;; Failing that, articles that have subjects that are part of the
885 ;; same "series" as the current will be returned.
886 (let (articles process)
889 (let ((backward (< n 0))
893 (setq articles (cons (gnus-summary-article-number)
895 (gnus-summary-search-forward nil nil backward))
897 (nreverse articles)))
898 (gnus-newsgroup-processable
899 (reverse gnus-newsgroup-processable))
901 (gnus-uu-find-articles-matching)))))
903 (defun gnus-uu-string< (l1 l2)
904 (string< (car l1) (car l2)))
906 (defun gnus-uu-find-articles-matching
907 (&optional subject only-unread do-not-translate)
908 ;; Finds all articles that matches the regexp SUBJECT. If it is
909 ;; nil, the current article name will be used. If ONLY-UNREAD is
910 ;; non-nil, only unread articles are chosen. If DO-NOT-TRANSLATE is
911 ;; non-nil, article names are not equalized before sorting.
912 (let ((subject (or subject
913 (gnus-uu-reginize-string (gnus-summary-subject-string))))
914 beg end list-of-subjects)
918 ;; Collect all subjects matching subject.
919 (let ((case-fold-search t)
921 (goto-char (point-min))
923 (and (setq subj (gnus-summary-subject-string))
924 (string-match subject subj)
925 (or (not only-unread)
926 (= (setq mark (gnus-summary-article-mark))
928 (= mark gnus-ticked-mark)
929 (= mark gnus-dormant-mark))
930 (setq list-of-subjects
931 (cons (cons subj (gnus-summary-article-number))
935 ;; Expand numbers, sort, and return the list of article
937 (mapcar (lambda (sub) (cdr sub))
938 (sort (gnus-uu-expand-numbers
940 (not do-not-translate))
941 'gnus-uu-string<))))))
943 (defun gnus-uu-expand-numbers (string-list &optional translate)
944 ;; Takes a list of strings and "expands" all numbers in all the
945 ;; strings. That is, this function makes all numbers equal length by
946 ;; prepending lots of zeroes before each number. This is to ease later
947 ;; sorting to find out what sequence the articles are supposed to be
948 ;; decoded in. Returns the list of expanded strings.
949 (let ((out-list string-list)
952 (set-buffer (get-buffer-create gnus-uu-output-buffer-name))
953 (buffer-disable-undo (current-buffer))
956 (insert (car (car string-list)))
957 ;; Translate multiple spaces to one space.
958 (goto-char (point-min))
959 (while (re-search-forward "[ \t]+" nil t)
961 ;; Translate all characters to "a".
962 (goto-char (point-min))
964 (while (re-search-forward "[A-Za-z]" nil t)
965 (replace-match "a" t t)))
967 (goto-char (point-min))
968 (while (re-search-forward "[0-9]+" nil t)
971 (string-to-int (buffer-substring
972 (match-beginning 0) (match-end 0))))))
973 (setq string (buffer-substring 1 (point-max)))
974 (setcar (car string-list) string)
975 (setq string-list (cdr string-list))))
979 ;; `gnus-uu-grab-articles' is the general multi-article treatment
980 ;; function. It takes a list of articles to be grabbed and a function
981 ;; to apply to each article.
983 ;; The function to be called should take two parameters. The first
984 ;; parameter is the article buffer. The function should leave the
985 ;; result, if any, in this buffer. Most treatment functions will just
988 ;; The second parameter is the state of the list of articles, and can
989 ;; have four values: `first', `middle', `last' and `first-and-last'.
991 ;; The function should return a list. The list may contain the
992 ;; following symbols:
993 ;; `error' if an error occurred
994 ;; `begin' if the beginning of an encoded file has been received
995 ;; If the list returned contains a `begin', the first element of
996 ;; the list *must* be a string with the file name of the decoded
998 ;; `end' if the the end of an encoded file has been received
999 ;; `middle' if the article was a body part of an encoded file
1000 ;; `wrong-type' if the article was not a part of an encoded file
1001 ;; `ok', which can be used everything is ok
1003 (defvar gnus-uu-has-been-grabbed nil)
1005 (defun gnus-uu-unmark-list-of-grabbed (&optional dont-unmark-last-article)
1007 (if (not (and gnus-uu-has-been-grabbed
1008 gnus-uu-unmark-articles-not-decoded))
1010 (if dont-unmark-last-article
1012 (setq art (car gnus-uu-has-been-grabbed))
1013 (setq gnus-uu-has-been-grabbed (cdr gnus-uu-has-been-grabbed))))
1014 (while gnus-uu-has-been-grabbed
1015 (gnus-summary-tick-article (car gnus-uu-has-been-grabbed) t)
1016 (setq gnus-uu-has-been-grabbed (cdr gnus-uu-has-been-grabbed)))
1017 (if dont-unmark-last-article
1018 (setq gnus-uu-has-been-grabbed (list art))))))
1020 ;; This function takes a list of articles and a function to apply to
1021 ;; each article grabbed.
1023 ;; This function returns a list of files decoded if the grabbing and
1024 ;; the process-function has been successful and nil otherwise.
1025 (defun gnus-uu-grab-articles
1026 (articles process-function &optional sloppy limit no-errors)
1027 (let ((state 'first)
1029 has-been-begin has-been-end
1030 article result-file result-files process-state article-buffer
1033 (if (not (gnus-server-opened gnus-current-select-method))
1035 (gnus-start-news-server)
1036 (gnus-request-group gnus-newsgroup-name)))
1038 (setq gnus-uu-has-been-grabbed nil)
1040 (while (and articles
1041 (not (memq 'error process-state))
1043 (not (memq 'end process-state))))
1045 (setq article (car articles))
1046 (setq articles (cdr articles))
1047 (setq gnus-uu-has-been-grabbed (cons article gnus-uu-has-been-grabbed))
1049 (if (> article gnus-uu-highest-article-number)
1050 (setq gnus-uu-highest-article-number article))
1052 (if (eq articles ())
1053 (if (eq state 'first)
1054 (setq state 'first-and-last)
1055 (setq state 'last)))
1057 (message "Getting article %d, %s" article (gnus-uu-part-number article))
1059 (if (not (= (or gnus-current-article 0) article))
1061 (gnus-request-article article gnus-newsgroup-name
1063 (setq gnus-last-article gnus-current-article)
1064 (setq gnus-current-article article)
1065 (setq gnus-article-current (cons gnus-newsgroup-name article))
1066 (if (stringp nntp-server-buffer)
1067 (setq article-buffer nntp-server-buffer)
1068 (setq article-buffer (buffer-name nntp-server-buffer))))
1069 (setq article-buffer gnus-article-buffer))
1071 (buffer-disable-undo article-buffer)
1072 ;; Mark article as read.
1073 (run-hooks 'gnus-mark-article-hook)
1074 (and (memq article gnus-newsgroup-processable)
1075 (gnus-summary-remove-process-mark article))
1077 (setq process-state (funcall process-function article-buffer state))
1079 (if (or (memq 'begin process-state)
1080 (and (or (eq state 'first) (eq state 'first-and-last))
1081 (memq 'ok process-state)))
1084 (if (and result-file (file-exists-p result-file))
1085 (delete-file result-file)))
1086 (if (memq 'begin process-state)
1087 (setq result-file (car process-state)))
1088 (setq begin-article article)
1089 (setq has-been-begin t)
1090 (setq has-been-end nil)))
1092 (if (memq 'end process-state)
1094 (setq gnus-uu-has-been-grabbed nil)
1095 (setq result-files (cons (list (cons 'name result-file)
1096 (cons 'article article))
1098 (setq has-been-end t)
1099 (setq has-been-begin nil)
1100 (and limit (= (length result-files) limit)
1101 (setq articles nil))))
1103 (if (and (or (eq state 'last) (eq state 'first-and-last))
1104 (not (memq 'end process-state)))
1105 (if (and result-file (file-exists-p result-file))
1106 (delete-file result-file)))
1108 (if (not (memq 'wrong-type process-state))
1109 (setq wrong-type nil)
1110 (if gnus-uu-unmark-articles-not-decoded
1111 (gnus-summary-tick-article article t)))
1113 (if sloppy (setq wrong-type nil))
1115 (if (and (not has-been-begin)
1117 (or (memq 'end process-state)
1118 (memq 'middle process-state)))
1120 (setq process-state (list 'error))
1121 (message "No begin part at the beginning")
1123 (setq state 'middle)))
1125 ;; Make sure the last article is put in the article buffer & fix
1128 (if (not (string= article-buffer gnus-article-buffer))
1130 (set-buffer (get-buffer-create gnus-article-buffer))
1131 (let ((buffer-read-only nil))
1134 (insert-buffer-substring article-buffer)
1135 (goto-char (point-min)))))
1139 (if (not has-been-begin)
1140 (if (not no-errors) (message "Wrong type file"))
1141 (if (memq 'error process-state)
1142 (setq result-files nil)
1143 (if (not (or (memq 'ok process-state)
1144 (memq 'end process-state)))
1147 (message "End of articles reached before end of file"))
1148 (setq result-files nil))
1149 (gnus-uu-unmark-list-of-grabbed)))))
1152 (defun gnus-uu-part-number (article)
1153 (let ((subject (header-subject (gnus-get-header-by-number article))))
1154 (if (string-match "[0-9]+ */[0-9]+\\|[0-9]+ * of *[0-9]+"
1156 (substring subject (match-beginning 0) (match-end 0))
1159 (defun gnus-uu-uudecode-sentinel (process event)
1160 (delete-process (get-process process)))
1162 (defun gnus-uu-uustrip-article (process-buffer in-state)
1163 ;; Uudecodes a file asynchronously.
1164 (let ((state (list 'ok))
1165 (process-connection-type nil)
1166 start-char pst name-beg name-end)
1168 (set-buffer process-buffer)
1169 (let ((case-fold-search nil)
1170 (buffer-read-only nil))
1172 (goto-char (point-min))
1174 (if gnus-uu-kill-carriage-return
1176 (while (search-forward "\r" nil t)
1177 (delete-backward-char 1))
1178 (goto-char (point-min))))
1180 (if (not (re-search-forward gnus-uu-begin-string nil t))
1181 (if (not (re-search-forward gnus-uu-body-line nil t))
1182 (setq state (list 'wrong-type))))
1184 (if (memq 'wrong-type state)
1187 (setq start-char (point))
1189 (if (looking-at gnus-uu-begin-string)
1191 (setq name-end (match-end 1))
1193 ; Replace any slashes and spaces in file names before decoding
1194 (goto-char (setq name-beg (match-beginning 1)))
1195 (while (re-search-forward "/" name-end t)
1196 (replace-match ","))
1197 (goto-char name-beg)
1198 (while (re-search-forward " " name-end t)
1199 (replace-match "_"))
1200 (goto-char name-beg)
1201 (if (re-search-forward "_*$" name-end t)
1204 (setq gnus-uu-file-name (buffer-substring name-beg name-end))
1205 (and gnus-uu-uudecode-process
1206 (setq pst (process-status
1207 (or gnus-uu-uudecode-process "nevair")))
1208 (if (or (eq pst 'stop) (eq pst 'run))
1210 (delete-process gnus-uu-uudecode-process)
1211 (gnus-uu-unmark-list-of-grabbed t))))
1212 (if (get-process "*uudecode*")
1213 (delete-process "*uudecode*"))
1214 (setq gnus-uu-uudecode-process
1217 (get-buffer-create gnus-uu-output-buffer-name)
1219 (format "cd %s ; uudecode" gnus-uu-work-dir)))
1220 (set-process-sentinel
1221 gnus-uu-uudecode-process 'gnus-uu-uudecode-sentinel)
1222 (setq state (list 'begin))
1223 (gnus-uu-add-file (concat gnus-uu-work-dir gnus-uu-file-name)))
1224 (setq state (list 'middle)))
1226 (goto-char (point-max))
1229 (concat gnus-uu-body-line "\\|" gnus-uu-end-string) nil t)
1232 (if (looking-at gnus-uu-end-string)
1233 (setq state (cons 'end state)))
1236 (and gnus-uu-uudecode-process
1237 (setq pst (process-status
1238 (or gnus-uu-uudecode-process "nevair")))
1239 (if (or (eq pst 'run) (eq pst 'stop))
1241 (if gnus-uu-correct-stripped-uucode
1243 (gnus-uu-check-correct-stripped-uucode
1245 (goto-char (point-max))
1247 (concat gnus-uu-body-line "\\|"
1253 (process-send-region gnus-uu-uudecode-process
1257 (delete-process gnus-uu-uudecode-process)
1258 (message "gnus-uu: Couldn't uudecode")
1260 (setq state (list 'wrong-type)))))
1262 (if (memq 'end state)
1263 (accept-process-output gnus-uu-uudecode-process)))
1264 (setq state (list 'wrong-type))))
1265 (if (not gnus-uu-uudecode-process)
1266 (setq state (list 'wrong-type)))))
1268 (if (memq 'begin state)
1269 (cons (concat gnus-uu-work-dir gnus-uu-file-name) state)
1272 ;; This function is used by `gnus-uu-grab-articles' to treat
1273 ;; a shared article.
1274 (defun gnus-uu-unshar-article (process-buffer in-state)
1275 (let ((state (list 'ok))
1278 (set-buffer process-buffer)
1279 (goto-char (point-min))
1280 (if (not (re-search-forward gnus-uu-shar-begin-string nil t))
1281 (setq state (list 'wrong-type))
1283 (setq start-char (point))
1284 (call-process-region
1285 start-char (point-max) "sh" nil
1286 (get-buffer-create gnus-uu-output-buffer-name) nil
1287 "-c" (concat "cd " gnus-uu-work-dir " ; sh"))))
1290 ;; Returns the name of what the shar file is going to unpack.
1291 (defun gnus-uu-find-name-in-shar ()
1292 (let ((oldpoint (point))
1294 (goto-char (point-min))
1295 (if (re-search-forward gnus-uu-shar-name-marker nil t)
1296 (setq res (buffer-substring (match-beginning 1) (match-end 1))))
1297 (goto-char oldpoint)
1300 ;; `gnus-uu-choose-action' chooses what action to perform given the name
1301 ;; and `gnus-uu-file-action-list'. Returns either nil if no action is
1302 ;; found, or the name of the command to run if such a rule is found.
1303 (defun gnus-uu-choose-action (file-name file-action-list &optional no-ignore)
1304 (let ((action-list (copy-sequence file-action-list))
1309 (and gnus-uu-ignore-files-by-name
1310 (string-match gnus-uu-ignore-files-by-name file-name)))
1312 (and gnus-uu-ignore-files-by-type
1313 (string-match gnus-uu-ignore-files-by-type
1314 (or (gnus-uu-choose-action
1315 file-name gnus-uu-ext-to-mime-list t)
1317 (while (not (or (eq action-list ()) action))
1318 (setq rule (car action-list))
1319 (setq action-list (cdr action-list))
1320 (if (string-match (car rule) file-name)
1321 (setq action (car (cdr rule))))))
1324 (defun gnus-uu-treat-archive (file-path)
1325 ;; Unpacks an archive. Returns t if unpacking is successful.
1326 (let ((did-unpack t)
1327 action command files file file-name dir)
1328 (setq action (gnus-uu-choose-action
1329 file-path (append gnus-uu-user-archive-rules
1330 (if gnus-uu-ignore-default-archive-rules
1332 gnus-uu-default-archive-rules))))
1334 (if (not action) (error "No unpackers for the file %s" file-path))
1336 (string-match "/[^/]*$" file-path)
1337 (setq file-name (substring file-path (1+ (match-beginning 0))))
1338 (setq dir (substring file-path 0 (match-beginning 0)))
1340 (if (member action gnus-uu-destructive-archivers)
1341 (copy-file file-path (concat file-path "~") t))
1343 (setq command (format "cd %s ; %s" dir (gnus-uu-command action file-path)))
1346 (set-buffer (get-buffer-create gnus-uu-output-buffer-name))
1349 (message "Unpacking: %s..." (gnus-uu-command action file-path))
1351 (if (= 0 (call-process "sh" nil
1352 (get-buffer-create gnus-uu-output-buffer-name)
1355 (message "Error during unpacking of archive")
1356 (setq did-unpack nil))
1358 (if (member action gnus-uu-destructive-archivers)
1359 (rename-file (concat file-path "~") file-path t))
1363 (defun gnus-uu-dir-files (dir)
1364 (let ((dirs (directory-files dir t "[^/][^\\.][^\\.]?$"))
1367 (if (file-directory-p (setq file (car dirs)))
1368 (setq files (append files (gnus-uu-dir-files file)))
1369 (setq files (cons file files)))
1370 (setq dirs (cdr dirs)))
1373 (defun gnus-uu-unpack-files (files &optional ignore)
1374 ;; Go through FILES and look for files to unpack.
1375 (let* ((totfiles (gnus-uu-ls-r gnus-uu-work-dir))
1378 (gnus-uu-add-file totfiles)
1380 (setq file (cdr (assq 'name (car files))))
1381 (if (and (not (member file ignore))
1382 (equal (gnus-uu-get-action (file-name-nondirectory file))
1385 (setq did-unpack (cons file did-unpack))
1386 (or (gnus-uu-treat-archive file)
1387 (message "Error during unpacking of %s" file))
1388 (let* ((newfiles (gnus-uu-ls-r gnus-uu-work-dir))
1390 (gnus-uu-add-file newfiles)
1392 (or (member (car nfiles) totfiles)
1393 (setq ofiles (cons (list (cons 'name (car nfiles))
1394 (cons 'original file))
1396 (setq nfiles (cdr nfiles)))
1397 (setq totfiles newfiles))))
1398 (setq files (cdr files)))
1400 (gnus-uu-unpack-files ofiles (append did-unpack ignore))
1403 (defun gnus-uu-ls-r (dir)
1404 (let* ((files (gnus-uu-directory-files dir t))
1407 (if (file-directory-p (car files))
1409 (setq ofiles (delete (car files) ofiles))
1410 (setq ofiles (append ofiles (gnus-uu-ls-r (car files))))))
1411 (setq files (cdr files)))
1416 (defun gnus-uu-directory-files (dir &optional full)
1417 (let (files out file)
1418 (setq files (directory-files dir full))
1420 (setq file (car files))
1421 (setq files (cdr files))
1422 (or (string-match "/\\.\\.?$" file)
1423 (setq out (cons file out))))
1424 (setq out (nreverse out))
1427 (defun gnus-uu-check-correct-stripped-uucode (start end)
1428 (let (found beg length short)
1429 (if (not gnus-uu-correct-stripped-uucode)
1433 (if (re-search-forward " \\|`" end t)
1438 (if (looking-at "\n") (replace-match ""))
1442 (if (looking-at (concat gnus-uu-begin-string "\\|"
1443 gnus-uu-end-string))
1450 (setq length (- (point) beg))))
1455 (if (not (= length (- (point) beg)))
1456 (insert (make-string (- length (- (point) beg)) ? ))))
1457 (forward-line 1))))))
1459 (defun gnus-uu-initialize ()
1460 (setq gnus-uu-highest-article-number 1)
1461 (gnus-uu-check-for-generated-files)
1462 (setq gnus-uu-tmp-dir (file-name-as-directory
1463 (expand-file-name gnus-uu-tmp-dir)))
1465 (if (not (file-directory-p gnus-uu-tmp-dir))
1466 (error "Temp directory %s doesn't exist" gnus-uu-tmp-dir)
1467 (if (not (file-writable-p gnus-uu-tmp-dir))
1468 (error "Temp directory %s can't be written to" gnus-uu-tmp-dir)))
1470 (setq gnus-uu-work-dir
1471 (make-temp-name (concat gnus-uu-tmp-dir "gnus")))
1472 (gnus-uu-add-file gnus-uu-work-dir)
1473 (if (not (file-directory-p gnus-uu-work-dir))
1474 (gnus-make-directory gnus-uu-work-dir))
1475 (set-file-modes gnus-uu-work-dir 448)
1476 (setq gnus-uu-work-dir (file-name-as-directory gnus-uu-work-dir)))
1478 ;; Kills the temporary uu buffers, kills any processes, etc.
1479 (defun gnus-uu-clean-up ()
1481 (and gnus-uu-uudecode-process
1482 (setq pst (process-status (or gnus-uu-uudecode-process "nevair")))
1483 (if (or (eq pst 'stop) (eq pst 'run))
1484 (delete-process gnus-uu-uudecode-process)))
1485 (and (setq buf (get-buffer gnus-uu-output-buffer-name))
1486 (kill-buffer buf))))
1488 ;; `gnus-uu-check-for-generated-files' deletes any generated files that
1489 ;; hasn't been deleted, if, for instance, the user terminated decoding
1491 (defun gnus-uu-check-for-generated-files ()
1493 (while gnus-uu-generated-file-list
1494 (setq file (car gnus-uu-generated-file-list))
1495 (setq gnus-uu-generated-file-list (cdr gnus-uu-generated-file-list))
1496 (if (not (string-match "/\\.[\\.]?$" file))
1498 (if (file-directory-p file)
1499 (setq dirs (cons file dirs))
1500 (if (file-exists-p file)
1501 (delete-file file))))))
1502 (setq dirs (nreverse dirs))
1504 (setq file (car dirs))
1505 (setq dirs (cdr dirs))
1506 (if (file-directory-p file)
1507 (if (string-match "/$" file)
1508 (delete-directory (substring file 0 (match-beginning 0)))
1509 (delete-directory file))))))
1511 ;; Add a file (or a list of files) to be checked (and deleted if it/they
1512 ;; still exists upon exiting the newsgroup).
1513 (defun gnus-uu-add-file (file)
1515 (setq gnus-uu-generated-file-list
1516 (cons file gnus-uu-generated-file-list))
1517 (setq gnus-uu-generated-file-list
1518 (append file gnus-uu-generated-file-list))))
1520 ;; Inputs an action and a file and returns a full command, putting
1521 ;; ticks round the file name and escaping any ticks in the file name.
1522 (defun gnus-uu-command (action file)
1524 (while (string-match "`\\|\"\\|\\$\\|\\\\" file)
1527 (concat ofile (substring file 0 (match-beginning 0)) "\\"
1528 (substring file (match-beginning 0) (match-end 0))))
1529 (setq file (substring file (1+ (match-beginning 0))))))
1530 (setq ofile (concat "\"" ofile file "\""))
1531 (if (string-match "%s" action)
1532 (format action ofile)
1533 (concat action " " ofile))))
1538 (add-hook 'gnus-exit-group-hook 'gnus-uu-clean-up)
1539 (add-hook 'gnus-exit-group-hook 'gnus-uu-check-for-generated-files)
1544 ;;; uuencoded posting
1550 ;; Any function that is to be used as and encoding method will take two
1551 ;; parameters: PATH-NAME and FILE-NAME. (E.g. "/home/gaga/spiral.jpg"
1552 ;; and "spiral.jpg", respectively.) The function should return nil if
1553 ;; the encoding wasn't successful.
1554 (defvar gnus-uu-post-encode-method 'gnus-uu-post-encode-uuencode
1555 "Function used for encoding binary files.
1556 There are three functions supplied with gnus-uu for encoding files:
1557 `gnus-uu-post-encode-uuencode', which does straight uuencoding;
1558 `gnus-uu-post-encode-mime', which encodes with base64 and adds MIME
1559 headers; and `gnus-uu-post-encode-mime-uuencode', which encodes with
1560 uuencode and adds MIME headers.")
1562 (defvar gnus-uu-post-include-before-composing nil
1563 "Non-nil means that gnus-uu will ask for a file to encode before you compose the article.
1564 If this variable is t, you can either include an encoded file with
1565 \\[gnus-uu-post-insert-binary-in-article] or have one included for you when you post the article.")
1567 (defvar gnus-uu-post-length 990
1568 "Maximum length of an article.
1569 The encoded file will be split into how many articles it takes to
1570 post the entire file.")
1572 (defvar gnus-uu-post-threaded nil
1573 "Non-nil means that gnus-uu will post the encoded file in a thread.
1574 This may not be smart, as no other decoder I have seen are able to
1575 follow threads when collecting uuencoded articles. (Well, I have seen
1576 one package that does that - gnus-uu, but somehow, I don't think that
1577 counts...) Default is nil.")
1579 (defvar gnus-uu-post-separate-description t
1580 "Non-nil means that the description will be posted in a separate article.
1581 The first article will typically be numbered (0/x). If this variable
1582 is nil, the description the user enters will be included at the
1583 beginning of the first article, which will be numbered (1/x). Default
1586 (defconst gnus-uu-post-binary-separator "--binary follows this line--")
1587 (defvar gnus-uu-post-message-id nil)
1588 (defvar gnus-uu-post-inserted-file-name nil)
1589 (defvar gnus-uu-winconf-post-news nil)
1591 (defun gnus-uu-post-news ()
1592 "Compose an article and post an encoded file."
1594 (setq gnus-uu-post-inserted-file-name nil)
1595 (setq gnus-uu-winconf-post-news (current-window-configuration))
1597 (gnus-summary-post-news)
1599 (use-local-map (copy-keymap (current-local-map)))
1600 (local-set-key "\C-c\C-c" 'gnus-summary-edit-article-done)
1601 (local-set-key "\C-c\C-c" 'gnus-uu-post-news-inews)
1602 (local-set-key "\C-c\C-s" 'gnus-uu-post-news-inews)
1603 (local-set-key "\C-c\C-i" 'gnus-uu-post-insert-binary-in-article)
1605 (if gnus-uu-post-include-before-composing
1606 (save-excursion (setq gnus-uu-post-inserted-file-name
1607 (gnus-uu-post-insert-binary)))))
1609 (defun gnus-uu-post-insert-binary-in-article ()
1610 "Inserts an encoded file in the buffer.
1611 The user will be asked for a file name."
1613 (if (not (eq (current-buffer) (get-buffer gnus-post-news-buffer)))
1614 (error "Not in post-news buffer"))
1616 (setq gnus-uu-post-inserted-file-name (gnus-uu-post-insert-binary))))
1618 ;; Encodes with uuencode and substitutes all spaces with backticks.
1619 (defun gnus-uu-post-encode-uuencode (path file-name)
1620 (if (gnus-uu-post-encode-file "uuencode" path file-name)
1622 (goto-char (point-min))
1624 (while (re-search-forward " " nil t)
1625 (replace-match "`"))
1628 ;; Encodes with uuencode and adds MIME headers.
1629 (defun gnus-uu-post-encode-mime-uuencode (path file-name)
1630 (if (gnus-uu-post-encode-uuencode path file-name)
1632 (gnus-uu-post-make-mime file-name "x-uue")
1635 ;; Encodes with base64 and adds MIME headers
1636 (defun gnus-uu-post-encode-mime (path file-name)
1637 (if (gnus-uu-post-encode-file "mmencode" path file-name)
1639 (gnus-uu-post-make-mime file-name "base64")
1642 ;; Adds MIME headers.
1643 (defun gnus-uu-post-make-mime (file-name encoding)
1644 (goto-char (point-min))
1645 (insert (format "Content-Type: %s; name=\"%s\"\n"
1646 (gnus-uu-choose-action file-name gnus-uu-ext-to-mime-list)
1648 (insert (format "Content-Transfer-Encoding: %s\n\n" encoding))
1650 (set-buffer gnus-post-news-buffer)
1651 (goto-char (point-min))
1652 (re-search-forward (concat "^" (regexp-quote mail-header-separator) "$"))
1654 (narrow-to-region 1 (point))
1655 (or (mail-fetch-field "mime-version")
1658 (insert "MIME-Version: 1.0\n")))
1661 ;; Encodes a file PATH with COMMAND, leaving the result in the
1663 (defun gnus-uu-post-encode-file (command path file-name)
1664 (= 0 (call-process "sh" nil t nil "-c"
1665 (format "%s %s %s" command path file-name))))
1667 (defun gnus-uu-post-news-inews ()
1668 "Posts the composed news article and encoded file.
1669 If no file has been included, the user will be asked for a file."
1671 (if (not (eq (current-buffer) (get-buffer gnus-post-news-buffer)))
1672 (error "Not in post news buffer"))
1676 (if gnus-uu-post-inserted-file-name
1677 (setq file-name gnus-uu-post-inserted-file-name)
1678 (setq file-name (gnus-uu-post-insert-binary)))
1680 (if gnus-uu-post-threaded
1681 (let ((gnus-required-headers
1682 (if (memq 'Message-ID gnus-required-headers)
1683 gnus-required-headers
1684 (cons 'Message-ID gnus-required-headers)))
1685 gnus-inews-article-hook elem)
1687 (setq gnus-inews-article-hook (if (listp gnus-inews-article-hook)
1688 gnus-inews-article-hook
1689 (list gnus-inews-article-hook)))
1690 (setq gnus-inews-article-hook
1694 (goto-char (point-min))
1695 (if (re-search-forward "^Message-ID: \\(.*\\)$" nil t)
1696 (setq gnus-uu-post-message-id
1698 (match-beginning 1) (match-end 1)))
1699 (setq gnus-uu-post-message-id nil))))
1700 gnus-inews-article-hook))
1701 (gnus-uu-post-encoded file-name t))
1702 (gnus-uu-post-encoded file-name nil)))
1703 (setq gnus-uu-post-inserted-file-name nil)
1704 (and gnus-uu-winconf-post-news
1705 (set-window-configuration gnus-uu-winconf-post-news)))
1707 ;; Asks for a file to encode, encodes it and inserts the result in
1708 ;; the current buffer. Returns the file name the user gave.
1709 (defun gnus-uu-post-insert-binary ()
1710 (let ((uuencode-buffer-name "*uuencode buffer*")
1711 file-path post-buf uubuf file-name)
1713 (setq file-path (read-file-name
1714 "What file do you want to encode? "))
1715 (if (not (file-exists-p file-path))
1716 (error "%s: No such file" file-path))
1718 (goto-char (point-max))
1719 (insert (format "\n%s\n" gnus-uu-post-binary-separator))
1721 (if (string-match "^~/" file-path)
1722 (setq file-path (concat "$HOME" (substring file-path 1))))
1723 (if (string-match "/[^/]*$" file-path)
1724 (setq file-name (substring file-path (1+ (match-beginning 0))))
1725 (setq file-name file-path))
1729 (set-buffer (setq uubuf
1730 (get-buffer-create uuencode-buffer-name)))
1732 (funcall gnus-uu-post-encode-method file-path file-name))
1733 (insert-buffer uubuf)
1734 (error "Encoding unsuccessful"))
1735 (kill-buffer uubuf))
1738 ;; Posts the article and all of the encoded file.
1739 (defun gnus-uu-post-encoded (file-name &optional threaded)
1740 (let ((send-buffer-name "*uuencode send buffer*")
1741 (encoded-buffer-name "*encoded buffer*")
1742 (top-string "[ cut here %s (%s %d/%d) %s gnus-uu ]")
1743 (separator (concat mail-header-separator "\n\n"))
1744 file uubuf length parts header i end beg
1745 beg-line minlen buf post-buf whole-len beg-binary end-binary)
1747 (setq post-buf (current-buffer))
1749 (goto-char (point-min))
1750 (if (not (re-search-forward
1751 (if gnus-uu-post-separate-description
1752 (concat "^" (regexp-quote gnus-uu-post-binary-separator)
1754 (concat "^" (regexp-quote mail-header-separator) "$")) nil t))
1755 (error "Internal error: No binary/header separator"))
1758 (setq beg-binary (point))
1759 (setq end-binary (point-max))
1762 (set-buffer (setq uubuf (get-buffer-create encoded-buffer-name)))
1764 (insert-buffer-substring post-buf beg-binary end-binary)
1765 (goto-char (point-min))
1766 (setq length (count-lines 1 (point-max)))
1767 (setq parts (/ length gnus-uu-post-length))
1768 (if (not (< (% length gnus-uu-post-length) 4))
1769 (setq parts (1+ parts))))
1771 (if gnus-uu-post-separate-description
1773 (kill-region (point) (point-max))
1775 (goto-char (point-min))
1777 (concat "^" (regexp-quote mail-header-separator) "$") nil t)
1779 (setq header (buffer-substring 1 (point)))
1781 (goto-char (point-min))
1782 (if (not gnus-uu-post-separate-description)
1784 (if (and (not threaded) (re-search-forward "^Subject: " nil t))
1787 (insert (format " (0/%d)" parts))))
1793 (while (not (> i parts))
1794 (set-buffer (get-buffer-create send-buffer-name))
1797 (if (and threaded gnus-uu-post-message-id)
1798 (insert (format "References: %s\n" gnus-uu-post-message-id)))
1801 (- 62 (length (format top-string "" file-name i parts ""))))
1802 (if (> 1 (setq minlen (/ whole-len 2)))
1807 (make-string minlen ?-)
1810 (if (= 0 (% whole-len 2)) (1- minlen) minlen) ?-)))
1812 (goto-char (point-min))
1813 (if (not (re-search-forward "^Subject: " nil t))
1818 (insert (format " (%d/%d)" i parts)))
1819 (if (or (and (= i 2) gnus-uu-post-separate-description)
1820 (and (= i 1) (not gnus-uu-post-separate-description)))
1821 (replace-match "Subject: Re: "))))
1823 (goto-char (point-max))
1828 (goto-char (point-max))
1829 (forward-line gnus-uu-post-length))
1830 (if (and (= (1+ i) parts) (< (count-lines (point) (point-max)) 4))
1833 (insert-buffer-substring uubuf beg end)
1838 (goto-char (point-min))
1840 (concat "^" (regexp-quote mail-header-separator) "$") nil t)
1843 (if (re-search-forward
1844 (concat "^" (regexp-quote gnus-uu-post-binary-separator) "$")
1853 (and (setq buf (get-buffer send-buffer-name))
1855 (and (setq buf (get-buffer encoded-buffer-name))
1858 (if (not gnus-uu-post-separate-description)
1860 (set-buffer-modified-p nil)
1861 (and (fboundp 'bury-buffer) (bury-buffer))))))
1865 ;; gnus-uu.el ends here