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 (file-name-as-directory
327 (read-file-name "Uudecode and save in dir: "
329 gnus-uu-default-dir t))))
330 (gnus-uu-decode-with-method 'gnus-uu-uustrip-article n dir))
332 (defun gnus-uu-decode-unshar (n)
333 "Unshars the current article."
335 (gnus-uu-decode-with-method 'gnus-uu-unshar-article n nil nil 'scan))
337 (defun gnus-uu-decode-unshar-and-save (n dir)
338 "Unshars and saves the current article."
340 (list current-prefix-arg
341 (file-name-as-directory
342 (read-file-name "Unshar and save in dir: "
344 gnus-uu-default-dir t))))
345 (gnus-uu-decode-with-method 'gnus-uu-unshar-article n dir nil 'scan))
347 (defun gnus-uu-decode-save (n file)
348 "Saves the current article."
350 (list current-prefix-arg
352 (if gnus-uu-save-separate-articles
353 "Save articles is dir: "
354 "Save articles in file: ")
356 gnus-uu-default-dir)))
357 (setq gnus-uu-saved-article-name file)
358 (gnus-uu-decode-with-method 'gnus-uu-save-article n nil t)
359 (setq gnus-uu-generated-file-list
360 (delete file gnus-uu-generated-file-list)))
362 (defun gnus-uu-decode-binhex (n dir)
363 "Unbinhexes the current article."
365 (list current-prefix-arg
366 (file-name-as-directory
367 (read-file-name "Unbinhex and save in dir: "
369 gnus-uu-default-dir t))))
370 (gnus-uu-decode-with-method 'gnus-uu-binhex-article n dir))
372 (defun gnus-uu-decode-uu-view (n)
373 "Uudecodes and views the current article."
375 (let ((gnus-view-pseudos (or gnus-view-pseudos 'automatic)))
376 (gnus-uu-decode-uu n)))
378 (defun gnus-uu-decode-uu-and-save-view (n dir)
379 "Decodes, views and saves the resulting file."
381 (list current-prefix-arg
382 (read-file-name "Uudecode, view and save in dir: "
384 gnus-uu-default-dir t)))
385 (let ((gnus-view-pseudos (or gnus-view-pseudos 'automatic)))
386 (gnus-uu-decode-uu-and-save n dir)))
388 (defun gnus-uu-decode-unshar-view (n)
389 "Unshars and views the current article."
391 (let ((gnus-view-pseudos (or gnus-view-pseudos 'automatic)))
392 (gnus-uu-decode-unshar n)))
394 (defun gnus-uu-decode-unshar-and-save-view (n dir)
395 "Unshars and saves the current article."
397 (list current-prefix-arg
398 (read-file-name "Unshar, view and save in dir: "
400 gnus-uu-default-dir t)))
401 (let ((gnus-view-pseudos (or gnus-view-pseudos 'automatic)))
402 (gnus-uu-decode-unshar-and-save n dir)))
404 (defun gnus-uu-decode-save-view (n file)
405 "Saves and views the current article."
407 (list current-prefix-arg
408 (read-file-name (if gnus-uu-save-separate-articles
409 "Save articles is dir: "
410 "Save articles in file: ")
411 gnus-uu-default-dir gnus-uu-default-dir)))
412 (let ((gnus-view-pseudos (or gnus-view-pseudos 'automatic)))
413 (gnus-uu-decode-save n file)))
415 (defun gnus-uu-decode-binhex-view (n file)
416 "Unbinhexes and views the current article."
418 (list current-prefix-arg
419 (read-file-name "Unbinhex, view and save in dir: "
420 gnus-uu-default-dir gnus-uu-default-dir)))
421 (let ((gnus-view-pseudos (or gnus-view-pseudos 'automatic)))
422 (gnus-uu-decode-binhex n file)))
425 ;; Digest and forward articles
427 (defun gnus-uu-digest-mail-forward (n &optional post)
428 "Digests and forwards all articles in this series."
430 (let ((gnus-uu-save-in-digest t)
431 (file (make-temp-name (concat gnus-uu-tmp-dir "forward")))
433 (gnus-uu-decode-save n file)
434 (gnus-uu-add-file file)
435 (setq buf (switch-to-buffer (get-buffer-create " *gnus-uu-forward*")))
436 (gnus-add-current-to-buffer-list)
438 (delete-other-windows)
440 (goto-char (point-min))
441 (and (re-search-forward "^Subject: ")
443 (delete-region (point) (gnus-point-at-eol))
444 (insert "Digested Articles")))
445 (goto-char (point-min))
446 (and (re-search-forward "^From: ")
448 (delete-region (point) (gnus-point-at-eol))
451 (gnus-forward-using-post)
452 (funcall gnus-mail-forward-method))
456 (defun gnus-uu-digest-post-forward (n)
457 "Digest and forward to a newsgroup."
459 (gnus-uu-digest-mail-forward n t))
463 (defun gnus-uu-mark-by-regexp (regexp)
464 "Ask for a regular expression and set the process mark on all articles that match."
465 (interactive (list (read-from-minibuffer "Mark (regexp): ")))
466 (gnus-set-global-variables)
467 (let ((articles (gnus-uu-find-articles-matching regexp)))
469 (gnus-summary-set-process-mark (car articles))
470 (setq articles (cdr articles)))
472 (gnus-summary-position-cursor))
474 (defun gnus-uu-mark-series ()
475 "Mark the current series with the process mark."
477 (gnus-set-global-variables)
478 (let ((articles (gnus-uu-find-articles-matching)))
480 (gnus-summary-set-process-mark (car articles))
481 (setq articles (cdr articles)))
483 (gnus-summary-position-cursor))
485 (defun gnus-uu-mark-region (beg end)
486 "Marks all articles between point and mark."
488 (gnus-set-global-variables)
491 (while (< (point) end)
492 (gnus-summary-set-process-mark (gnus-summary-article-number))
494 (gnus-summary-position-cursor))
496 (defun gnus-uu-mark-thread ()
497 "Marks all articles downwards in this thread."
499 (gnus-set-global-variables)
501 (let ((level (gnus-summary-thread-level)))
502 (while (and (gnus-summary-set-process-mark (gnus-summary-article-number))
503 (zerop (gnus-summary-next-subject 1))
504 (> (gnus-summary-thread-level) level)))))
505 (gnus-summary-position-cursor))
507 (defun gnus-uu-mark-sparse ()
508 "Mark all series that have some articles marked."
510 (gnus-set-global-variables)
511 (let ((marked (nreverse gnus-newsgroup-processable))
512 subject articles total headers)
513 (or marked (error "No articles marked with the process mark"))
514 (setq gnus-newsgroup-processable nil)
517 (and (setq headers (gnus-get-header-by-number (car marked)))
518 (setq subject (header-subject headers)
519 articles (gnus-uu-find-articles-matching
520 (gnus-uu-reginize-string subject))
521 total (nconc total articles)))
523 (gnus-summary-set-process-mark (car articles))
524 (setcdr marked (delq (car articles) (cdr marked)))
525 (setq articles (cdr articles)))
526 (setq marked (cdr marked)))
527 (setq gnus-newsgroup-processable (nreverse total)))
528 (gnus-summary-position-cursor)))
530 (defun gnus-uu-mark-all ()
531 "Mark all articles in \"series\" order."
533 (gnus-set-global-variables)
534 (setq gnus-newsgroup-processable nil)
536 (goto-char (point-min))
538 (while (and (not (eobp))
539 (setq number (gnus-summary-article-number)))
540 (if (not (memq number gnus-newsgroup-processable))
541 (save-excursion (gnus-uu-mark-series)))
543 (gnus-summary-position-cursor))
545 ;; All PostScript functions written by Erik Selberg <speed@cs.washington.edu>.
547 (defun gnus-uu-decode-postscript (n)
548 "Gets postscript of the current article."
550 (gnus-uu-decode-with-method 'gnus-uu-decode-postscript-article n))
552 (defun gnus-uu-decode-postscript-view (n)
553 "Gets and views the current article."
555 (let ((gnus-view-pseudos (or gnus-view-pseudos 'automatic)))
556 (gnus-uu-decode-postscript n)))
558 (defun gnus-uu-decode-postscript-and-save (n dir)
559 "Extracts postscript and saves the current article."
561 (list current-prefix-arg
562 (file-name-as-directory
563 (read-file-name "Save in dir: "
565 gnus-uu-default-dir t))))
566 (gnus-uu-decode-with-method 'gnus-uu-decode-postscript-article n dir))
569 (defun gnus-uu-decode-postscript-and-save-view (n dir)
570 "Decodes, views and saves the resulting file."
572 (list current-prefix-arg
573 (read-file-name "Where do you want to save the file(s)? "
575 gnus-uu-default-dir t)))
576 (let ((gnus-view-pseudos (or gnus-view-pseudos 'automatic)))
577 (gnus-uu-decode-postscript-and-save n dir)))
580 ;; Internal functions.
582 (defun gnus-uu-decode-with-method (method n &optional save not-insert scan)
584 (if save (setq gnus-uu-default-dir save))
585 (let ((articles (gnus-uu-get-list-of-articles n))
587 (setq files (gnus-uu-grab-articles articles method t))
588 (let ((gnus-current-article (car articles)))
589 (and scan (setq files (gnus-uu-scan-directory gnus-uu-work-dir))))
590 (and save (gnus-uu-save-files files save))
591 (setq files (gnus-uu-unpack-files files))
592 (gnus-uu-add-file (mapcar (lambda (file) (cdr (assq 'name file))) files))
593 (setq files (nreverse (gnus-uu-get-actions files)))
594 (or not-insert (gnus-summary-insert-pseudos files save))))
596 ;; Return a list of files in dir.
597 (defun gnus-uu-scan-directory (dir)
598 (let ((files (directory-files dir t))
601 (cond ((string-match "/\\.\\.?$" (car files)))
602 ((file-directory-p (car files))
603 (setq dirs (cons (car files) dirs)))
604 (t (setq out (cons (list (cons 'name (car files))
605 (cons 'article gnus-current-article))
607 (setq files (cdr files)))
608 (apply 'nconc out (mapcar (lambda (d) (gnus-uu-scan-directory d))
611 (defun gnus-uu-save-files (files dir)
612 (let ((len (length files))
615 (setq file (cdr (assq 'name (car files))))
616 (and (file-exists-p file)
618 (setq to-file (if (file-directory-p dir)
619 (concat dir (file-name-nondirectory file))
621 (and (or (not (file-exists-p to-file))
622 (gnus-y-or-n-p (format "%s exists; overwrite? "
624 (copy-file file to-file 1 t))))
625 (setq files (cdr files)))
626 (message "Saved %d file%s" len (if (> len 1) "s" ""))))
628 ;; Functions for saving and possibly digesting articles without
631 ;; Function called by gnus-uu-grab-articles to treat each article.
632 (defun gnus-uu-save-article (buffer in-state)
634 (gnus-uu-save-separate-articles
637 (write-region 1 (point-max) (concat gnus-uu-saved-article-name
638 gnus-current-article))
639 (cond ((eq in-state 'first) (list gnus-uu-saved-article-name 'begin))
640 ((eq in-state 'first-and-last) (list gnus-uu-saved-article-name
642 ((eq in-state 'last) (list 'end))
643 (t (list 'middle)))))
644 ((not gnus-uu-save-in-digest)
647 (write-region 1 (point-max) gnus-uu-saved-article-name t)
648 (cond ((eq in-state 'first) (list gnus-uu-saved-article-name 'begin))
649 ((eq in-state 'first-and-last) (list gnus-uu-saved-article-name
651 ((eq in-state 'last) (list 'end))
652 (t (list 'middle)))))
654 (let ((name (file-name-nondirectory gnus-uu-saved-article-name))
655 beg subj headers headline sorthead body end-string state)
656 (if (or (eq in-state 'first)
657 (eq in-state 'first-and-last))
659 (setq state (list 'begin))
660 (save-excursion (set-buffer (get-buffer-create "*gnus-uu-body*"))
663 (set-buffer (get-buffer-create "*gnus-uu-pre*"))
666 "Date: %s\nFrom: %s\nSubject: %s Digest\n\nTopics:\n"
667 (current-time-string) name name))))
668 (if (not (eq in-state 'end))
669 (setq state (list 'middle))))
671 (set-buffer (get-buffer "*gnus-uu-body*"))
672 (goto-char (setq beg (point-max)))
676 (goto-char (point-min))
677 (re-search-forward "\n\n")
678 (setq body (buffer-substring (1- (point)) (point-max)))
679 (narrow-to-region 1 (point))
680 (setq headers gnus-uu-digest-headers)
682 (setq headline (car headers))
683 (setq headers (cdr headers))
684 (goto-char (point-min))
685 (if (re-search-forward headline nil t)
690 (or (and (re-search-forward "^[^ \t]" nil t)
692 (progn (forward-line 1) (point))))))))
694 (insert sorthead)(goto-char (point-max))
695 (insert body)(goto-char (point-max))
696 (insert (concat "\n" (make-string 30 ?-) "\n\n"))
698 (if (re-search-forward "^Subject: \\(.*\\)$" nil t)
700 (setq subj (buffer-substring (match-beginning 1) (match-end 1)))
702 (set-buffer (get-buffer "*gnus-uu-pre*"))
703 (insert (format " %s\n" subj))))))
704 (if (or (eq in-state 'last)
705 (eq in-state 'first-and-last))
708 (set-buffer (get-buffer "*gnus-uu-pre*"))
709 (insert (format "\n\n%s\n\n" (make-string 70 ?-)))
710 (write-region 1 (point-max) gnus-uu-saved-article-name))
712 (set-buffer (get-buffer "*gnus-uu-body*"))
713 (goto-char (point-max))
715 (concat (setq end-string (format "End of %s Digest" name))
717 (insert (concat (make-string (length end-string) ?*) "\n"))
718 (write-region 1 (point-max) gnus-uu-saved-article-name t))
719 (kill-buffer (get-buffer "*gnus-uu-pre*"))
720 (kill-buffer (get-buffer "*gnus-uu-body*"))
721 (setq state (cons 'end state))))
722 (if (memq 'begin state)
723 (cons gnus-uu-saved-article-name state)
726 ;; Binhex treatment - not very advanced.
728 (defconst gnus-uu-binhex-body-line
729 "^[^:]...............................................................$")
730 (defconst gnus-uu-binhex-begin-line
731 "^:...............................................................$")
732 (defconst gnus-uu-binhex-end-line
734 (defvar gnus-uu-binhex-article-name nil)
736 (defun gnus-uu-binhex-article (buffer in-state)
737 (let (state start-char)
741 (goto-char (point-min))
742 (if (not (re-search-forward gnus-uu-binhex-begin-line nil t))
743 (if (not (re-search-forward gnus-uu-binhex-body-line nil t))
744 (setq state (list 'wrong-type))))
746 (if (memq 'wrong-type state)
749 (setq start-char (point))
750 (if (looking-at gnus-uu-binhex-begin-line)
752 (setq state (list 'begin))
753 (write-region 1 1 gnus-uu-binhex-article-name))
754 (setq state (list 'middle)))
755 (goto-char (point-max))
756 (re-search-backward (concat gnus-uu-binhex-body-line "\\|"
757 gnus-uu-binhex-end-line) nil t)
758 (if (looking-at gnus-uu-binhex-end-line)
759 (setq state (if (memq 'begin state)
764 (if (file-exists-p gnus-uu-binhex-article-name)
765 (append-to-file start-char (point) gnus-uu-binhex-article-name))))
766 (if (memq 'begin state)
767 (cons gnus-uu-binhex-article-name state)
772 (defun gnus-uu-decode-postscript-article (process-buffer in-state)
773 (let ((state (list 'ok))
774 start-char end-char file-name)
776 (set-buffer process-buffer)
777 (goto-char (point-min))
778 (if (not (re-search-forward gnus-uu-postscript-begin-string nil t))
779 (setq state (list 'wrong-type))
781 (setq start-char (point))
782 (if (not (re-search-forward gnus-uu-postscript-end-string nil t))
783 (setq state (list 'wrong-type))
784 (setq end-char (point))
785 (set-buffer (get-buffer-create gnus-uu-output-buffer-name))
786 (insert-buffer-substring process-buffer start-char end-char)
787 (setq file-name (concat gnus-uu-work-dir (cdr gnus-article-current) ".ps"))
788 (write-region (point-min) (point-max) file-name)
789 (setq state (list file-name'begin 'end))
798 (defun gnus-uu-get-actions (files)
802 (setq name (cdr (assq 'name (car files))))
804 (setq action (gnus-uu-get-action name))
805 (setcar files (nconc (list (cons 'action action)
806 (cons 'execute (if (string-match "%" action)
808 (concat action " " name))))
810 (setq files (cdr files)))
813 (defun gnus-uu-get-action (file-name)
816 (gnus-uu-choose-action
819 gnus-uu-user-view-rules
820 (if gnus-uu-ignore-default-view-rules
822 gnus-uu-default-view-rules)
823 gnus-uu-user-view-rules-end)))
824 (if (and (not (string= (or action "") "gnus-uu-archive"))
825 gnus-uu-view-with-metamail)
827 (gnus-uu-choose-action file-name gnus-uu-ext-to-mime-list))
828 (setq action (format "metamail -d -b -c \"%s\"" action))))
832 ;; Functions for treating subjects and collecting series.
834 (defun gnus-uu-reginize-string (string)
835 ;; Takes a string and puts a \ in front of every special character;
836 ;; ignores any leading "version numbers" thingies that they use in
837 ;; the comp.binaries groups, and either replaces anything that looks
838 ;; like "2/3" with "[0-9]+/[0-9]+" or, if it can't find something
839 ;; like that, replaces the last two numbers with "[0-9]+". This, in
840 ;; my experience, should get most postings of a series.
842 (vernum "v[0-9]+[a-z][0-9]+:")
845 (set-buffer (get-buffer-create gnus-uu-output-buffer-name))
846 (buffer-disable-undo (current-buffer))
848 (insert (regexp-quote string))
851 (setq case-fold-search nil)
852 (goto-char (point-min))
853 (if (looking-at vernum)
855 (replace-match vernum t t)
856 (setq beg (length vernum))))
859 (if (re-search-forward "[ \t]*[0-9]+/[0-9]+" nil t)
860 (replace-match " [0-9]+/[0-9]+")
863 (if (re-search-forward "[0-9]+[ \t]*of[ \t]*[0-9]+" nil t)
864 (replace-match "[0-9]+ of [0-9]+")
867 (while (and (re-search-backward "[0-9]" nil t) (> count 0))
870 (< 1 (goto-char (1- (point))))))
871 (re-search-forward "[0-9]+" nil t)
872 (replace-match "[0-9]+")
874 (setq count (1- count)))))
877 (while (re-search-forward "[ \t]+" nil t)
878 (replace-match "[ \t]*" t t))
880 (buffer-substring 1 (point-max)))))
882 (defun gnus-uu-get-list-of-articles (n)
883 ;; If N is non-nil, the article numbers of the N next articles
885 ;; If any articles have been marked as processable, they will be
887 ;; Failing that, articles that have subjects that are part of the
888 ;; same "series" as the current will be returned.
892 (let ((backward (< n 0))
896 (setq articles (cons (gnus-summary-article-number)
898 (gnus-summary-search-forward nil nil backward))
900 (nreverse articles)))
901 (gnus-newsgroup-processable
902 (reverse gnus-newsgroup-processable))
904 (gnus-uu-find-articles-matching)))))
906 (defun gnus-uu-string< (l1 l2)
907 (string< (car l1) (car l2)))
909 (defun gnus-uu-find-articles-matching
910 (&optional subject only-unread do-not-translate)
911 ;; Finds all articles that matches the regexp SUBJECT. If it is
912 ;; nil, the current article name will be used. If ONLY-UNREAD is
913 ;; non-nil, only unread articles are chosen. If DO-NOT-TRANSLATE is
914 ;; non-nil, article names are not equalized before sorting.
915 (let ((subject (or subject
916 (gnus-uu-reginize-string (gnus-summary-subject-string))))
921 ;; Collect all subjects matching subject.
922 (let ((case-fold-search t)
924 (goto-char (point-min))
926 (and (setq subj (gnus-summary-subject-string))
927 (string-match subject subj)
928 (or (not only-unread)
929 (= (setq mark (gnus-summary-article-mark))
931 (= mark gnus-ticked-mark)
932 (= mark gnus-dormant-mark))
933 (setq list-of-subjects
934 (cons (cons subj (gnus-summary-article-number))
938 ;; Expand numbers, sort, and return the list of article
940 (mapcar (lambda (sub) (cdr sub))
941 (sort (gnus-uu-expand-numbers
943 (not do-not-translate))
944 'gnus-uu-string<))))))
946 (defun gnus-uu-expand-numbers (string-list &optional translate)
947 ;; Takes a list of strings and "expands" all numbers in all the
948 ;; strings. That is, this function makes all numbers equal length by
949 ;; prepending lots of zeroes before each number. This is to ease later
950 ;; sorting to find out what sequence the articles are supposed to be
951 ;; decoded in. Returns the list of expanded strings.
952 (let ((out-list string-list)
955 (set-buffer (get-buffer-create gnus-uu-output-buffer-name))
956 (buffer-disable-undo (current-buffer))
959 (insert (car (car string-list)))
960 ;; Translate multiple spaces to one space.
961 (goto-char (point-min))
962 (while (re-search-forward "[ \t]+" nil t)
964 ;; Translate all characters to "a".
965 (goto-char (point-min))
967 (while (re-search-forward "[A-Za-z]" nil t)
968 (replace-match "a" t t)))
970 (goto-char (point-min))
971 (while (re-search-forward "[0-9]+" nil t)
974 (string-to-int (buffer-substring
975 (match-beginning 0) (match-end 0))))))
976 (setq string (buffer-substring 1 (point-max)))
977 (setcar (car string-list) string)
978 (setq string-list (cdr string-list))))
982 ;; `gnus-uu-grab-articles' is the general multi-article treatment
983 ;; function. It takes a list of articles to be grabbed and a function
984 ;; to apply to each article.
986 ;; The function to be called should take two parameters. The first
987 ;; parameter is the article buffer. The function should leave the
988 ;; result, if any, in this buffer. Most treatment functions will just
991 ;; The second parameter is the state of the list of articles, and can
992 ;; have four values: `first', `middle', `last' and `first-and-last'.
994 ;; The function should return a list. The list may contain the
995 ;; following symbols:
996 ;; `error' if an error occurred
997 ;; `begin' if the beginning of an encoded file has been received
998 ;; If the list returned contains a `begin', the first element of
999 ;; the list *must* be a string with the file name of the decoded
1001 ;; `end' if the the end of an encoded file has been received
1002 ;; `middle' if the article was a body part of an encoded file
1003 ;; `wrong-type' if the article was not a part of an encoded file
1004 ;; `ok', which can be used everything is ok
1006 (defvar gnus-uu-has-been-grabbed nil)
1008 (defun gnus-uu-unmark-list-of-grabbed (&optional dont-unmark-last-article)
1010 (if (not (and gnus-uu-has-been-grabbed
1011 gnus-uu-unmark-articles-not-decoded))
1013 (if dont-unmark-last-article
1015 (setq art (car gnus-uu-has-been-grabbed))
1016 (setq gnus-uu-has-been-grabbed (cdr gnus-uu-has-been-grabbed))))
1017 (while gnus-uu-has-been-grabbed
1018 (gnus-summary-tick-article (car gnus-uu-has-been-grabbed) t)
1019 (setq gnus-uu-has-been-grabbed (cdr gnus-uu-has-been-grabbed)))
1020 (if dont-unmark-last-article
1021 (setq gnus-uu-has-been-grabbed (list art))))))
1023 ;; This function takes a list of articles and a function to apply to
1024 ;; each article grabbed.
1026 ;; This function returns a list of files decoded if the grabbing and
1027 ;; the process-function has been successful and nil otherwise.
1028 (defun gnus-uu-grab-articles
1029 (articles process-function &optional sloppy limit no-errors)
1030 (let ((state 'first)
1031 has-been-begin article result-file result-files process-state
1034 (if (not (gnus-server-opened gnus-current-select-method))
1036 (gnus-start-news-server)
1037 (gnus-request-group gnus-newsgroup-name)))
1039 (setq gnus-uu-has-been-grabbed nil)
1041 (while (and articles
1042 (not (memq 'error process-state))
1044 (not (memq 'end process-state))))
1046 (setq article (car articles))
1047 (setq articles (cdr articles))
1048 (setq gnus-uu-has-been-grabbed (cons article gnus-uu-has-been-grabbed))
1050 (if (> article gnus-uu-highest-article-number)
1051 (setq gnus-uu-highest-article-number article))
1053 (if (eq articles ())
1054 (if (eq state 'first)
1055 (setq state 'first-and-last)
1056 (setq state 'last)))
1058 (message "Getting article %d, %s" article (gnus-uu-part-number article))
1060 (if (not (= (or gnus-current-article 0) article))
1062 (gnus-request-article article gnus-newsgroup-name
1064 (setq gnus-last-article gnus-current-article)
1065 (setq gnus-current-article article)
1066 (setq gnus-article-current (cons gnus-newsgroup-name article))
1067 (if (stringp nntp-server-buffer)
1068 (setq article-buffer nntp-server-buffer)
1069 (setq article-buffer (buffer-name nntp-server-buffer))))
1070 (setq article-buffer gnus-article-buffer))
1072 (buffer-disable-undo article-buffer)
1073 ;; Mark article as read.
1074 (run-hooks 'gnus-mark-article-hook)
1075 (and (memq article gnus-newsgroup-processable)
1076 (gnus-summary-remove-process-mark article))
1078 (setq process-state (funcall process-function article-buffer state))
1080 (if (or (memq 'begin process-state)
1081 (and (or (eq state 'first) (eq state 'first-and-last))
1082 (memq 'ok process-state)))
1085 (if (and result-file (file-exists-p result-file))
1086 (delete-file result-file)))
1087 (if (memq 'begin process-state)
1088 (setq result-file (car process-state)))
1089 (setq has-been-begin t)))
1091 (if (memq 'end process-state)
1093 (setq gnus-uu-has-been-grabbed nil)
1094 (setq result-files (cons (list (cons 'name result-file)
1095 (cons 'article article))
1097 (setq has-been-begin nil)
1098 (and limit (= (length result-files) limit)
1099 (setq articles nil))))
1101 (if (and (or (eq state 'last) (eq state 'first-and-last))
1102 (not (memq 'end process-state)))
1103 (if (and result-file (file-exists-p result-file))
1104 (delete-file result-file)))
1106 (if (not (memq 'wrong-type process-state))
1108 (if gnus-uu-unmark-articles-not-decoded
1109 (gnus-summary-tick-article article t)))
1111 (if (and (not has-been-begin)
1113 (or (memq 'end process-state)
1114 (memq 'middle process-state)))
1116 (setq process-state (list 'error))
1117 (message "No begin part at the beginning")
1119 (setq state 'middle)))
1121 ;; Make sure the last article is put in the article buffer & fix
1124 (if (not (string= article-buffer gnus-article-buffer))
1126 (set-buffer (get-buffer-create gnus-article-buffer))
1127 (let ((buffer-read-only nil))
1130 (insert-buffer-substring article-buffer)
1131 (goto-char (point-min)))))
1135 (if (not has-been-begin)
1136 (if (not no-errors) (message "Wrong type file"))
1137 (if (memq 'error process-state)
1138 (setq result-files nil)
1139 (if (not (or (memq 'ok process-state)
1140 (memq 'end process-state)))
1143 (message "End of articles reached before end of file"))
1144 (setq result-files nil))
1145 (gnus-uu-unmark-list-of-grabbed)))))
1148 (defun gnus-uu-part-number (article)
1149 (let ((subject (header-subject (gnus-get-header-by-number article))))
1150 (if (string-match "[0-9]+ */[0-9]+\\|[0-9]+ * of *[0-9]+"
1152 (substring subject (match-beginning 0) (match-end 0))
1155 (defun gnus-uu-uudecode-sentinel (process event)
1156 (delete-process (get-process process)))
1158 (defun gnus-uu-uustrip-article (process-buffer in-state)
1159 ;; Uudecodes a file asynchronously.
1160 (let ((state (list 'ok))
1161 (process-connection-type nil)
1162 start-char pst name-beg name-end)
1164 (set-buffer process-buffer)
1165 (let ((case-fold-search nil)
1166 (buffer-read-only nil))
1168 (goto-char (point-min))
1170 (if gnus-uu-kill-carriage-return
1172 (while (search-forward "\r" nil t)
1173 (delete-backward-char 1))
1174 (goto-char (point-min))))
1176 (if (not (re-search-forward gnus-uu-begin-string nil t))
1177 (if (not (re-search-forward gnus-uu-body-line nil t))
1178 (setq state (list 'wrong-type))))
1180 (if (memq 'wrong-type state)
1183 (setq start-char (point))
1185 (if (looking-at gnus-uu-begin-string)
1187 (setq name-end (match-end 1))
1189 ; Replace any slashes and spaces in file names before decoding
1190 (goto-char (setq name-beg (match-beginning 1)))
1191 (while (re-search-forward "/" name-end t)
1192 (replace-match ","))
1193 (goto-char name-beg)
1194 (while (re-search-forward " " name-end t)
1195 (replace-match "_"))
1196 (goto-char name-beg)
1197 (if (re-search-forward "_*$" name-end t)
1200 (setq gnus-uu-file-name (buffer-substring name-beg name-end))
1201 (and gnus-uu-uudecode-process
1202 (setq pst (process-status
1203 (or gnus-uu-uudecode-process "nevair")))
1204 (if (or (eq pst 'stop) (eq pst 'run))
1206 (delete-process gnus-uu-uudecode-process)
1207 (gnus-uu-unmark-list-of-grabbed t))))
1208 (if (get-process "*uudecode*")
1209 (delete-process "*uudecode*"))
1210 (setq gnus-uu-uudecode-process
1213 (get-buffer-create gnus-uu-output-buffer-name)
1215 (format "cd %s ; uudecode" gnus-uu-work-dir)))
1216 (set-process-sentinel
1217 gnus-uu-uudecode-process 'gnus-uu-uudecode-sentinel)
1218 (setq state (list 'begin))
1219 (gnus-uu-add-file (concat gnus-uu-work-dir gnus-uu-file-name)))
1220 (setq state (list 'middle)))
1222 (goto-char (point-max))
1225 (concat gnus-uu-body-line "\\|" gnus-uu-end-string) nil t)
1228 (if (looking-at gnus-uu-end-string)
1229 (setq state (cons 'end state)))
1232 (and gnus-uu-uudecode-process
1233 (setq pst (process-status
1234 (or gnus-uu-uudecode-process "nevair")))
1235 (if (or (eq pst 'run) (eq pst 'stop))
1237 (if gnus-uu-correct-stripped-uucode
1239 (gnus-uu-check-correct-stripped-uucode
1241 (goto-char (point-max))
1243 (concat gnus-uu-body-line "\\|"
1249 (process-send-region gnus-uu-uudecode-process
1253 (delete-process gnus-uu-uudecode-process)
1254 (message "gnus-uu: Couldn't uudecode")
1256 (setq state (list 'wrong-type)))))
1258 (if (memq 'end state)
1259 (accept-process-output gnus-uu-uudecode-process)))
1260 (setq state (list 'wrong-type))))
1261 (if (not gnus-uu-uudecode-process)
1262 (setq state (list 'wrong-type)))))
1264 (if (memq 'begin state)
1265 (cons (concat gnus-uu-work-dir gnus-uu-file-name) state)
1268 ;; This function is used by `gnus-uu-grab-articles' to treat
1269 ;; a shared article.
1270 (defun gnus-uu-unshar-article (process-buffer in-state)
1271 (let ((state (list 'ok))
1274 (set-buffer process-buffer)
1275 (goto-char (point-min))
1276 (if (not (re-search-forward gnus-uu-shar-begin-string nil t))
1277 (setq state (list 'wrong-type))
1279 (setq start-char (point))
1280 (call-process-region
1281 start-char (point-max) "sh" nil
1282 (get-buffer-create gnus-uu-output-buffer-name) nil
1283 "-c" (concat "cd " gnus-uu-work-dir " ; sh"))))
1286 ;; Returns the name of what the shar file is going to unpack.
1287 (defun gnus-uu-find-name-in-shar ()
1288 (let ((oldpoint (point))
1290 (goto-char (point-min))
1291 (if (re-search-forward gnus-uu-shar-name-marker nil t)
1292 (setq res (buffer-substring (match-beginning 1) (match-end 1))))
1293 (goto-char oldpoint)
1296 ;; `gnus-uu-choose-action' chooses what action to perform given the name
1297 ;; and `gnus-uu-file-action-list'. Returns either nil if no action is
1298 ;; found, or the name of the command to run if such a rule is found.
1299 (defun gnus-uu-choose-action (file-name file-action-list &optional no-ignore)
1300 (let ((action-list (copy-sequence file-action-list))
1305 (and gnus-uu-ignore-files-by-name
1306 (string-match gnus-uu-ignore-files-by-name file-name)))
1308 (and gnus-uu-ignore-files-by-type
1309 (string-match gnus-uu-ignore-files-by-type
1310 (or (gnus-uu-choose-action
1311 file-name gnus-uu-ext-to-mime-list t)
1313 (while (not (or (eq action-list ()) action))
1314 (setq rule (car action-list))
1315 (setq action-list (cdr action-list))
1316 (if (string-match (car rule) file-name)
1317 (setq action (car (cdr rule))))))
1320 (defun gnus-uu-treat-archive (file-path)
1321 ;; Unpacks an archive. Returns t if unpacking is successful.
1322 (let ((did-unpack t)
1324 (setq action (gnus-uu-choose-action
1325 file-path (append gnus-uu-user-archive-rules
1326 (if gnus-uu-ignore-default-archive-rules
1328 gnus-uu-default-archive-rules))))
1330 (if (not action) (error "No unpackers for the file %s" file-path))
1332 (string-match "/[^/]*$" file-path)
1333 (setq dir (substring file-path 0 (match-beginning 0)))
1335 (if (member action gnus-uu-destructive-archivers)
1336 (copy-file file-path (concat file-path "~") t))
1338 (setq command (format "cd %s ; %s" dir (gnus-uu-command action file-path)))
1341 (set-buffer (get-buffer-create gnus-uu-output-buffer-name))
1344 (message "Unpacking: %s..." (gnus-uu-command action file-path))
1346 (if (= 0 (call-process "sh" nil
1347 (get-buffer-create gnus-uu-output-buffer-name)
1350 (message "Error during unpacking of archive")
1351 (setq did-unpack nil))
1353 (if (member action gnus-uu-destructive-archivers)
1354 (rename-file (concat file-path "~") file-path t))
1358 (defun gnus-uu-dir-files (dir)
1359 (let ((dirs (directory-files dir t "[^/][^\\.][^\\.]?$"))
1362 (if (file-directory-p (setq file (car dirs)))
1363 (setq files (append files (gnus-uu-dir-files file)))
1364 (setq files (cons file files)))
1365 (setq dirs (cdr dirs)))
1368 (defun gnus-uu-unpack-files (files &optional ignore)
1369 ;; Go through FILES and look for files to unpack.
1370 (let* ((totfiles (gnus-uu-ls-r gnus-uu-work-dir))
1373 (gnus-uu-add-file totfiles)
1375 (setq file (cdr (assq 'name (car files))))
1376 (if (and (not (member file ignore))
1377 (equal (gnus-uu-get-action (file-name-nondirectory file))
1380 (setq did-unpack (cons file did-unpack))
1381 (or (gnus-uu-treat-archive file)
1382 (message "Error during unpacking of %s" file))
1383 (let* ((newfiles (gnus-uu-ls-r gnus-uu-work-dir))
1385 (gnus-uu-add-file newfiles)
1387 (or (member (car nfiles) totfiles)
1388 (setq ofiles (cons (list (cons 'name (car nfiles))
1389 (cons 'original file))
1391 (setq nfiles (cdr nfiles)))
1392 (setq totfiles newfiles))))
1393 (setq files (cdr files)))
1395 (gnus-uu-unpack-files ofiles (append did-unpack ignore))
1398 (defun gnus-uu-ls-r (dir)
1399 (let* ((files (gnus-uu-directory-files dir t))
1402 (if (file-directory-p (car files))
1404 (setq ofiles (delete (car files) ofiles))
1405 (setq ofiles (append ofiles (gnus-uu-ls-r (car files))))))
1406 (setq files (cdr files)))
1411 (defun gnus-uu-directory-files (dir &optional full)
1412 (let (files out file)
1413 (setq files (directory-files dir full))
1415 (setq file (car files))
1416 (setq files (cdr files))
1417 (or (string-match "/\\.\\.?$" file)
1418 (setq out (cons file out))))
1419 (setq out (nreverse out))
1422 (defun gnus-uu-check-correct-stripped-uucode (start end)
1423 (let (found beg length)
1424 (if (not gnus-uu-correct-stripped-uucode)
1428 (if (re-search-forward " \\|`" end t)
1433 (if (looking-at "\n") (replace-match ""))
1437 (if (looking-at (concat gnus-uu-begin-string "\\|"
1438 gnus-uu-end-string))
1445 (setq length (- (point) beg))))
1450 (if (not (= length (- (point) beg)))
1451 (insert (make-string (- length (- (point) beg)) ? ))))
1452 (forward-line 1))))))
1454 (defun gnus-uu-initialize ()
1455 (setq gnus-uu-highest-article-number 1)
1456 (gnus-uu-check-for-generated-files)
1457 (setq gnus-uu-tmp-dir (file-name-as-directory
1458 (expand-file-name gnus-uu-tmp-dir)))
1460 (if (not (file-directory-p gnus-uu-tmp-dir))
1461 (error "Temp directory %s doesn't exist" gnus-uu-tmp-dir)
1462 (if (not (file-writable-p gnus-uu-tmp-dir))
1463 (error "Temp directory %s can't be written to" gnus-uu-tmp-dir)))
1465 (setq gnus-uu-work-dir
1466 (make-temp-name (concat gnus-uu-tmp-dir "gnus")))
1467 (gnus-uu-add-file gnus-uu-work-dir)
1468 (if (not (file-directory-p gnus-uu-work-dir))
1469 (gnus-make-directory gnus-uu-work-dir))
1470 (set-file-modes gnus-uu-work-dir 448)
1471 (setq gnus-uu-work-dir (file-name-as-directory gnus-uu-work-dir)))
1473 ;; Kills the temporary uu buffers, kills any processes, etc.
1474 (defun gnus-uu-clean-up ()
1476 (and gnus-uu-uudecode-process
1477 (setq pst (process-status (or gnus-uu-uudecode-process "nevair")))
1478 (if (or (eq pst 'stop) (eq pst 'run))
1479 (delete-process gnus-uu-uudecode-process)))
1480 (and (setq buf (get-buffer gnus-uu-output-buffer-name))
1481 (kill-buffer buf))))
1483 ;; `gnus-uu-check-for-generated-files' deletes any generated files that
1484 ;; hasn't been deleted, if, for instance, the user terminated decoding
1486 (defun gnus-uu-check-for-generated-files ()
1488 (while gnus-uu-generated-file-list
1489 (setq file (car gnus-uu-generated-file-list))
1490 (setq gnus-uu-generated-file-list (cdr gnus-uu-generated-file-list))
1491 (if (not (string-match "/\\.[\\.]?$" file))
1493 (if (file-directory-p file)
1494 (setq dirs (cons file dirs))
1495 (if (file-exists-p file)
1496 (delete-file file))))))
1497 (setq dirs (nreverse dirs))
1499 (setq file (car dirs))
1500 (setq dirs (cdr dirs))
1501 (if (file-directory-p file)
1502 (if (string-match "/$" file)
1503 (delete-directory (substring file 0 (match-beginning 0)))
1504 (delete-directory file))))))
1506 ;; Add a file (or a list of files) to be checked (and deleted if it/they
1507 ;; still exists upon exiting the newsgroup).
1508 (defun gnus-uu-add-file (file)
1510 (setq gnus-uu-generated-file-list
1511 (cons file gnus-uu-generated-file-list))
1512 (setq gnus-uu-generated-file-list
1513 (append file gnus-uu-generated-file-list))))
1515 ;; Inputs an action and a file and returns a full command, putting
1516 ;; ticks round the file name and escaping any ticks in the file name.
1517 (defun gnus-uu-command (action file)
1519 (while (string-match "`\\|\"\\|\\$\\|\\\\" file)
1522 (concat ofile (substring file 0 (match-beginning 0)) "\\"
1523 (substring file (match-beginning 0) (match-end 0))))
1524 (setq file (substring file (1+ (match-beginning 0))))))
1525 (setq ofile (concat "\"" ofile file "\""))
1526 (if (string-match "%s" action)
1527 (format action ofile)
1528 (concat action " " ofile))))
1533 (add-hook 'gnus-exit-group-hook 'gnus-uu-clean-up)
1534 (add-hook 'gnus-exit-group-hook 'gnus-uu-check-for-generated-files)
1539 ;;; uuencoded posting
1545 ;; Any function that is to be used as and encoding method will take two
1546 ;; parameters: PATH-NAME and FILE-NAME. (E.g. "/home/gaga/spiral.jpg"
1547 ;; and "spiral.jpg", respectively.) The function should return nil if
1548 ;; the encoding wasn't successful.
1549 (defvar gnus-uu-post-encode-method 'gnus-uu-post-encode-uuencode
1550 "Function used for encoding binary files.
1551 There are three functions supplied with gnus-uu for encoding files:
1552 `gnus-uu-post-encode-uuencode', which does straight uuencoding;
1553 `gnus-uu-post-encode-mime', which encodes with base64 and adds MIME
1554 headers; and `gnus-uu-post-encode-mime-uuencode', which encodes with
1555 uuencode and adds MIME headers.")
1557 (defvar gnus-uu-post-include-before-composing nil
1558 "Non-nil means that gnus-uu will ask for a file to encode before you compose the article.
1559 If this variable is t, you can either include an encoded file with
1560 \\[gnus-uu-post-insert-binary-in-article] or have one included for you when you post the article.")
1562 (defvar gnus-uu-post-length 990
1563 "Maximum length of an article.
1564 The encoded file will be split into how many articles it takes to
1565 post the entire file.")
1567 (defvar gnus-uu-post-threaded nil
1568 "Non-nil means that gnus-uu will post the encoded file in a thread.
1569 This may not be smart, as no other decoder I have seen are able to
1570 follow threads when collecting uuencoded articles. (Well, I have seen
1571 one package that does that - gnus-uu, but somehow, I don't think that
1572 counts...) Default is nil.")
1574 (defvar gnus-uu-post-separate-description t
1575 "Non-nil means that the description will be posted in a separate article.
1576 The first article will typically be numbered (0/x). If this variable
1577 is nil, the description the user enters will be included at the
1578 beginning of the first article, which will be numbered (1/x). Default
1581 (defconst gnus-uu-post-binary-separator "--binary follows this line--")
1582 (defvar gnus-uu-post-message-id nil)
1583 (defvar gnus-uu-post-inserted-file-name nil)
1584 (defvar gnus-uu-winconf-post-news nil)
1586 (defun gnus-uu-post-news ()
1587 "Compose an article and post an encoded file."
1589 (setq gnus-uu-post-inserted-file-name nil)
1590 (setq gnus-uu-winconf-post-news (current-window-configuration))
1592 (gnus-summary-post-news)
1594 (use-local-map (copy-keymap (current-local-map)))
1595 (local-set-key "\C-c\C-c" 'gnus-summary-edit-article-done)
1596 (local-set-key "\C-c\C-c" 'gnus-uu-post-news-inews)
1597 (local-set-key "\C-c\C-s" 'gnus-uu-post-news-inews)
1598 (local-set-key "\C-c\C-i" 'gnus-uu-post-insert-binary-in-article)
1600 (if gnus-uu-post-include-before-composing
1601 (save-excursion (setq gnus-uu-post-inserted-file-name
1602 (gnus-uu-post-insert-binary)))))
1604 (defun gnus-uu-post-insert-binary-in-article ()
1605 "Inserts an encoded file in the buffer.
1606 The user will be asked for a file name."
1608 (if (not (eq (current-buffer) (get-buffer gnus-post-news-buffer)))
1609 (error "Not in post-news buffer"))
1611 (setq gnus-uu-post-inserted-file-name (gnus-uu-post-insert-binary))))
1613 ;; Encodes with uuencode and substitutes all spaces with backticks.
1614 (defun gnus-uu-post-encode-uuencode (path file-name)
1615 (if (gnus-uu-post-encode-file "uuencode" path file-name)
1617 (goto-char (point-min))
1619 (while (re-search-forward " " nil t)
1620 (replace-match "`"))
1623 ;; Encodes with uuencode and adds MIME headers.
1624 (defun gnus-uu-post-encode-mime-uuencode (path file-name)
1625 (if (gnus-uu-post-encode-uuencode path file-name)
1627 (gnus-uu-post-make-mime file-name "x-uue")
1630 ;; Encodes with base64 and adds MIME headers
1631 (defun gnus-uu-post-encode-mime (path file-name)
1632 (if (gnus-uu-post-encode-file "mmencode" path file-name)
1634 (gnus-uu-post-make-mime file-name "base64")
1637 ;; Adds MIME headers.
1638 (defun gnus-uu-post-make-mime (file-name encoding)
1639 (goto-char (point-min))
1640 (insert (format "Content-Type: %s; name=\"%s\"\n"
1641 (gnus-uu-choose-action file-name gnus-uu-ext-to-mime-list)
1643 (insert (format "Content-Transfer-Encoding: %s\n\n" encoding))
1645 (set-buffer gnus-post-news-buffer)
1646 (goto-char (point-min))
1647 (re-search-forward (concat "^" (regexp-quote mail-header-separator) "$"))
1649 (narrow-to-region 1 (point))
1650 (or (mail-fetch-field "mime-version")
1653 (insert "MIME-Version: 1.0\n")))
1656 ;; Encodes a file PATH with COMMAND, leaving the result in the
1658 (defun gnus-uu-post-encode-file (command path file-name)
1659 (= 0 (call-process "sh" nil t nil "-c"
1660 (format "%s %s %s" command path file-name))))
1662 (defun gnus-uu-post-news-inews ()
1663 "Posts the composed news article and encoded file.
1664 If no file has been included, the user will be asked for a file."
1666 (if (not (eq (current-buffer) (get-buffer gnus-post-news-buffer)))
1667 (error "Not in post news buffer"))
1671 (if gnus-uu-post-inserted-file-name
1672 (setq file-name gnus-uu-post-inserted-file-name)
1673 (setq file-name (gnus-uu-post-insert-binary)))
1675 (if gnus-uu-post-threaded
1676 (let ((gnus-required-headers
1677 (if (memq 'Message-ID gnus-required-headers)
1678 gnus-required-headers
1679 (cons 'Message-ID gnus-required-headers)))
1680 gnus-inews-article-hook)
1682 (setq gnus-inews-article-hook (if (listp gnus-inews-article-hook)
1683 gnus-inews-article-hook
1684 (list gnus-inews-article-hook)))
1685 (setq gnus-inews-article-hook
1689 (goto-char (point-min))
1690 (if (re-search-forward "^Message-ID: \\(.*\\)$" nil t)
1691 (setq gnus-uu-post-message-id
1693 (match-beginning 1) (match-end 1)))
1694 (setq gnus-uu-post-message-id nil))))
1695 gnus-inews-article-hook))
1696 (gnus-uu-post-encoded file-name t))
1697 (gnus-uu-post-encoded file-name nil)))
1698 (setq gnus-uu-post-inserted-file-name nil)
1699 (and gnus-uu-winconf-post-news
1700 (set-window-configuration gnus-uu-winconf-post-news)))
1702 ;; Asks for a file to encode, encodes it and inserts the result in
1703 ;; the current buffer. Returns the file name the user gave.
1704 (defun gnus-uu-post-insert-binary ()
1705 (let ((uuencode-buffer-name "*uuencode buffer*")
1706 file-path uubuf file-name)
1708 (setq file-path (read-file-name
1709 "What file do you want to encode? "))
1710 (if (not (file-exists-p file-path))
1711 (error "%s: No such file" file-path))
1713 (goto-char (point-max))
1714 (insert (format "\n%s\n" gnus-uu-post-binary-separator))
1716 (if (string-match "^~/" file-path)
1717 (setq file-path (concat "$HOME" (substring file-path 1))))
1718 (if (string-match "/[^/]*$" file-path)
1719 (setq file-name (substring file-path (1+ (match-beginning 0))))
1720 (setq file-name file-path))
1724 (set-buffer (setq uubuf
1725 (get-buffer-create uuencode-buffer-name)))
1727 (funcall gnus-uu-post-encode-method file-path file-name))
1728 (insert-buffer uubuf)
1729 (error "Encoding unsuccessful"))
1730 (kill-buffer uubuf))
1733 ;; Posts the article and all of the encoded file.
1734 (defun gnus-uu-post-encoded (file-name &optional threaded)
1735 (let ((send-buffer-name "*uuencode send buffer*")
1736 (encoded-buffer-name "*encoded buffer*")
1737 (top-string "[ cut here %s (%s %d/%d) %s gnus-uu ]")
1738 (separator (concat mail-header-separator "\n\n"))
1739 uubuf length parts header i end beg
1740 beg-line minlen buf post-buf whole-len beg-binary end-binary)
1742 (setq post-buf (current-buffer))
1744 (goto-char (point-min))
1745 (if (not (re-search-forward
1746 (if gnus-uu-post-separate-description
1747 (concat "^" (regexp-quote gnus-uu-post-binary-separator)
1749 (concat "^" (regexp-quote mail-header-separator) "$")) nil t))
1750 (error "Internal error: No binary/header separator"))
1753 (setq beg-binary (point))
1754 (setq end-binary (point-max))
1757 (set-buffer (setq uubuf (get-buffer-create encoded-buffer-name)))
1759 (insert-buffer-substring post-buf beg-binary end-binary)
1760 (goto-char (point-min))
1761 (setq length (count-lines 1 (point-max)))
1762 (setq parts (/ length gnus-uu-post-length))
1763 (if (not (< (% length gnus-uu-post-length) 4))
1764 (setq parts (1+ parts))))
1766 (if gnus-uu-post-separate-description
1768 (kill-region (point) (point-max))
1770 (goto-char (point-min))
1772 (concat "^" (regexp-quote mail-header-separator) "$") nil t)
1774 (setq header (buffer-substring 1 (point)))
1776 (goto-char (point-min))
1777 (if (not gnus-uu-post-separate-description)
1779 (if (and (not threaded) (re-search-forward "^Subject: " nil t))
1782 (insert (format " (0/%d)" parts))))
1788 (while (not (> i parts))
1789 (set-buffer (get-buffer-create send-buffer-name))
1792 (if (and threaded gnus-uu-post-message-id)
1793 (insert (format "References: %s\n" gnus-uu-post-message-id)))
1796 (- 62 (length (format top-string "" file-name i parts ""))))
1797 (if (> 1 (setq minlen (/ whole-len 2)))
1802 (make-string minlen ?-)
1805 (if (= 0 (% whole-len 2)) (1- minlen) minlen) ?-)))
1807 (goto-char (point-min))
1808 (if (not (re-search-forward "^Subject: " nil t))
1813 (insert (format " (%d/%d)" i parts)))
1814 (if (or (and (= i 2) gnus-uu-post-separate-description)
1815 (and (= i 1) (not gnus-uu-post-separate-description)))
1816 (replace-match "Subject: Re: "))))
1818 (goto-char (point-max))
1823 (goto-char (point-max))
1824 (forward-line gnus-uu-post-length))
1825 (if (and (= (1+ i) parts) (< (count-lines (point) (point-max)) 4))
1828 (insert-buffer-substring uubuf beg end)
1833 (goto-char (point-min))
1835 (concat "^" (regexp-quote mail-header-separator) "$") nil t)
1838 (if (re-search-forward
1839 (concat "^" (regexp-quote gnus-uu-post-binary-separator) "$")
1848 (and (setq buf (get-buffer send-buffer-name))
1850 (and (setq buf (get-buffer encoded-buffer-name))
1853 (if (not gnus-uu-post-separate-description)
1855 (set-buffer-modified-p nil)
1856 (and (fboundp 'bury-buffer) (bury-buffer))))))
1860 ;; gnus-uu.el ends here