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>
8 ;; This file is part of GNU Emacs.
10 ;; GNU Emacs is free software; you can redistribute it and/or modify
11 ;; it under the terms of the GNU General Public License as published by
12 ;; the Free Software Foundation; either version 2, or (at your option)
15 ;; GNU Emacs is distributed in the hope that it will be useful,
16 ;; but WITHOUT ANY WARRANTY; without even the implied warranty of
17 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 ;; GNU General Public License for more details.
20 ;; You should have received a copy of the GNU General Public License
21 ;; along with GNU Emacs; see the file COPYING. If not, write to
22 ;; the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA.
31 ;; Default viewing action rules
33 (defvar gnus-uu-default-view-rules
34 '(("\\.te?xt$\\|\\.doc$\\|read.*me\\|\\.c?$\\|\\.h$\\|\\.bat$\\|\\.asm$\\|makefile" "cat %s | sed s/\r//g")
35 ("\\.pas$" "cat %s | sed s/\r//g")
36 ("\\.[1-9]$" "groff -mandoc -Tascii %s | sed s/\b.//g")
37 ("\\.\\(jpe?g\\|gif\\|tiff?\\|p[pgb]m\\|xwd\\|xbm\\|pcx\\)$" "xv")
38 ("\\.tga$" "tgatoppm %s | xv -")
39 ("\\.\\(wav\\|aiff\\|hcom\\|u[blw]\\|s[bfw]\\|voc\\|smp\\)$"
40 "sox -v .5 %s -t .au -u - > /dev/audio")
41 ("\\.au$" "cat %s > /dev/audio")
43 ("\\.ps$" "ghostview")
45 ("\\.html$" "xmosaic")
46 ("\\.mpe?g$" "mpeg_play")
47 ("\\.\\(flc\\|fli\\|rle\\|iff\\|pfx\\|avi\\|sme\\|rpza\\|dl\\|qt\\|rsrc\\|mov\\)$" "xanim")
48 ("\\.\\(tar\\|arj\\|zip\\|zoo\\|arc\\|gz\\|Z\\|lzh\\|ar\\|lha\\)$"
50 "*Default actions to be taken when the user asks to view a file.
51 To change the behaviour, you can either edit this variable or set
52 `gnus-uu-user-view-rules' to something useful.
56 To make gnus-uu use 'xli' to display JPEG and GIF files, put the
57 following in your .emacs file:
59 (setq gnus-uu-user-view-rules '((\"jpg$\\\\|gif$\" \"xli\")))
61 Both these variables are lists of lists with two string elements. The
62 first string is a regular expression. If the file name matches this
63 regular expression, the command in the second string is executed with
64 the file as an argument.
66 If the command string contains \"%s\", the file name will be inserted
67 at that point in the command string. If there's no \"%s\" in the
68 command string, the file name will be appended to the command string
71 There are several user variables to tailor the behaviour of gnus-uu to
72 your needs. First we have `gnus-uu-user-view-rules', which is the
73 variable gnus-uu first consults when trying to decide how to view a
74 file. If this variable contains no matches, gnus-uu examines the
75 default rule variable provided in this package. If gnus-uu finds no
76 match here, it uses `gnus-uu-user-view-rules-end' to try to make a
79 (defvar gnus-uu-user-view-rules nil
80 "*Variable detailing what actions are to be taken to view a file.
81 See the documentation on the `gnus-uu-default-view-rules' variable for
84 (defvar gnus-uu-user-view-rules-end
86 "*Variable saying what actions are to be taken if no rule matched the file name.
87 See the documentation on the `gnus-uu-default-view-rules' variable for
90 ;; Default unpacking commands
92 (defvar gnus-uu-default-archive-rules
93 '(("\\.tar$" "tar xf")
94 ("\\.zip$" "unzip -o")
98 ("\\.\\(lzh\\|lha\\)$" "lha x")
99 ("\\.Z$" "uncompress")
101 ("\\.arc$" "arc -x")))
103 (defvar gnus-uu-destructive-archivers
104 (list "uncompress" "gunzip"))
106 (defvar gnus-uu-user-archive-rules nil
107 "*A list that can be set to override the default archive unpacking commands.
108 To use, for instance, 'untar' to unpack tar files and 'zip -x' to
109 unpack zip files, say the following:
110 (setq gnus-uu-user-archive-rules
111 '((\"\\\\.tar$\" \"untar\")
112 (\"\\\\.zip$\" \"zip -x\")))")
114 (defvar gnus-uu-ignore-files-by-name nil
115 "*A regular expression saying what files should not be viewed based on name.
116 If, for instance, you want gnus-uu to ignore all .au and .wav files,
117 you could say something like
119 (setq gnus-uu-ignore-files-by-name \"\\\\.au$\\\\|\\\\.wav$\")
121 Note that this variable can be used in conjunction with the
122 `gnus-uu-ignore-files-by-type' variable.")
124 (defvar gnus-uu-ignore-files-by-type nil
125 "*A regular expression saying what files that shouldn't be viewed, based on MIME file type.
126 If, for instance, you want gnus-uu to ignore all audio files and all mpegs,
127 you could say something like
129 (setq gnus-uu-ignore-files-by-type \"audio/\\\\|video/mpeg\")
131 Note that this variable can be used in conjunction with the
132 `gnus-uu-ignore-files-by-name' variable.")
134 ;; Pseudo-MIME support
136 (defconst gnus-uu-ext-to-mime-list
137 '(("\\.gif$" "image/gif")
138 ("\\.jpe?g$" "image/jpeg")
139 ("\\.tiff?$" "image/tiff")
140 ("\\.xwd$" "image/xwd")
141 ("\\.pbm$" "image/pbm")
142 ("\\.pgm$" "image/pgm")
143 ("\\.ppm$" "image/ppm")
144 ("\\.xbm$" "image/xbm")
145 ("\\.pcx$" "image/pcx")
146 ("\\.tga$" "image/tga")
147 ("\\.ps$" "image/postscript")
148 ("\\.fli$" "video/fli")
149 ("\\.wav$" "audio/wav")
150 ("\\.aiff$" "audio/aiff")
151 ("\\.hcom$" "audio/hcom")
152 ("\\.voc$" "audio/voc")
153 ("\\.smp$" "audio/smp")
154 ("\\.mod$" "audio/mod")
155 ("\\.dvi$" "image/dvi")
156 ("\\.mpe?g$" "video/mpeg")
157 ("\\.au$" "audio/basic")
158 ("\\.\\(te?xt\\|doc\\|c\\|h\\)$" "text/plain")
159 ("\\.\\(c\\|h\\)$" "text/source")
160 ("read.*me" "text/plain")
161 ("\\.html$" "text/html")
162 ("\\.bat$" "text/bat")
163 ("\\.[1-6]$" "text/man")
164 ("\\.flc$" "video/flc")
165 ("\\.rle$" "video/rle")
166 ("\\.pfx$" "video/pfx")
167 ("\\.avi$" "video/avi")
168 ("\\.sme$" "video/sme")
169 ("\\.rpza$" "video/prza")
170 ("\\.dl$" "video/dl")
171 ("\\.qt$" "video/qt")
172 ("\\.rsrc$" "video/rsrc")
173 ("\\..*$" "unknown/unknown")))
175 ;; Various variables users may set
177 (defvar gnus-uu-tmp-dir "/tmp/"
178 "*Variable saying where gnus-uu is to do its work.
179 Default is \"/tmp/\".")
181 (defvar gnus-uu-do-not-unpack-archives nil
182 "*Non-nil means that gnus-uu won't peek inside archives looking for files to dispay.
185 (defvar gnus-uu-view-and-save nil
186 "*Non-nil means that the user will always be asked to save a file after viewing it.
187 If the variable is nil, the user will only be asked to save if the
188 viewing is unsuccessful. Default is nil.")
190 (defvar gnus-uu-ignore-default-view-rules nil
191 "*Non-nil means that gnus-uu will ignore the default viewing rules.
192 Only the user viewing rules will be consulted. Default is nil.")
194 (defvar gnus-uu-ignore-default-archive-rules nil
195 "*Non-nil means that gnus-uu will ignore the default archive unpacking commands.
196 Only the user unpacking commands will be consulted. Default is nil.")
198 (defvar gnus-uu-kill-carriage-return t
199 "*Non-nil means that gnus-uu will strip all carriage returns from articles.
202 (defvar gnus-uu-view-with-metamail nil
203 "*Non-nil means that files will be viewed with metamail.
204 The gnus-uu viewing functions will be ignored and gnus-uu will try
205 to guess at a content-type based on file name suffixes. Default
208 (defvar gnus-uu-unmark-articles-not-decoded nil
209 "*Non-nil means that gnus-uu will mark articles that were unsuccessfully decoded as unread.
212 (defvar gnus-uu-correct-stripped-uucode nil
213 "*Non-nil means that gnus-uu will *try* to fix uuencoded files that have had trailing spaces deleted.
216 (defvar gnus-uu-save-in-digest nil
217 "*Non-nil means that gnus-uu, when asked to save without decoding, will save in digests.
218 If this variable is nil, gnus-uu will just save everything in a
219 file without any embellishments. The digesting almost conforms to RFC1153 -
220 no easy way to specify any meaningful volume and issue numbers were found,
221 so I simply dropped them.")
223 (defvar gnus-uu-digest-headers
224 '("^Date:" "^From:" "^To:" "^Cc:" "^Subject:" "^Message-ID:" "^Keywords:"
225 "^Summary:" "^References:")
226 "*List of regexps to match headers included in digested messages.
227 The headers will be included in the sequence they are matched.")
229 (defvar gnus-uu-save-separate-articles nil
230 "*Non-nil means that gnus-uu will save articles in separate files.")
232 ;; Internal variables
234 (defvar gnus-uu-saved-article-name nil)
236 (defconst gnus-uu-begin-string "^begin[ \t]+[0-7][0-7][0-7][ \t]+\\(.*\\)$")
237 (defconst gnus-uu-end-string "^end[ \t]*$")
239 (defconst gnus-uu-body-line "^M")
241 (while (> (setq i (1- i)) 0)
242 (setq gnus-uu-body-line (concat gnus-uu-body-line "[^a-z]")))
243 (setq gnus-uu-body-line (concat gnus-uu-body-line ".?$")))
245 ;"^M.............................................................?$"
247 (defconst gnus-uu-shar-begin-string "^#! */bin/sh")
249 (defvar gnus-uu-shar-file-name nil)
250 (defconst gnus-uu-shar-name-marker "begin [0-7][0-7][0-7][ \t]+\\(\\(\\w\\|\\.\\)*\\b\\)")
252 (defconst gnus-uu-postscript-begin-string "^%!PS-")
253 (defconst gnus-uu-postscript-end-string "^%%EOF$")
255 (defvar gnus-uu-file-name nil)
256 (defconst gnus-uu-uudecode-process nil)
257 (defvar gnus-uu-binhex-article-name 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 (defvar gnus-uu-default-dir default-directory)
265 (defvar gnus-uu-digest-from-subject nil)
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 "T" 'gnus-uu-unmark-thread)
283 (define-key gnus-uu-mark-map "a" 'gnus-uu-mark-all)
284 (define-key gnus-uu-mark-map "b" 'gnus-uu-mark-buffer)
285 (define-key gnus-uu-mark-map "S" 'gnus-uu-mark-sparse)
287 (define-prefix-command 'gnus-uu-extract-map)
288 (define-key gnus-summary-mode-map "X" 'gnus-uu-extract-map)
289 ;;(define-key gnus-uu-extract-map "x" 'gnus-uu-extract-any)
290 ;;(define-key gnus-uu-extract-map "m" 'gnus-uu-extract-mime)
291 (define-key gnus-uu-extract-map "u" 'gnus-uu-decode-uu)
292 (define-key gnus-uu-extract-map "U" 'gnus-uu-decode-uu-and-save)
293 (define-key gnus-uu-extract-map "s" 'gnus-uu-decode-unshar)
294 (define-key gnus-uu-extract-map "S" 'gnus-uu-decode-unshar-and-save)
295 (define-key gnus-uu-extract-map "o" 'gnus-uu-decode-save)
296 (define-key gnus-uu-extract-map "O" 'gnus-uu-decode-save)
297 (define-key gnus-uu-extract-map "b" 'gnus-uu-decode-binhex)
298 (define-key gnus-uu-extract-map "B" 'gnus-uu-decode-binhex)
299 (define-key gnus-uu-extract-map "p" 'gnus-uu-decode-postscript)
300 (define-key gnus-uu-extract-map "P" 'gnus-uu-decode-postscript-and-save)
302 (define-prefix-command 'gnus-uu-extract-view-map)
303 (define-key gnus-uu-extract-map "v" 'gnus-uu-extract-view-map)
304 (define-key gnus-uu-extract-view-map "u" 'gnus-uu-decode-uu-view)
305 (define-key gnus-uu-extract-view-map "U" 'gnus-uu-decode-uu-and-save-view)
306 (define-key gnus-uu-extract-view-map "s" 'gnus-uu-decode-unshar-view)
307 (define-key gnus-uu-extract-view-map "S" 'gnus-uu-decode-unshar-and-save-view)
308 (define-key gnus-uu-extract-view-map "o" 'gnus-uu-decode-save-view)
309 (define-key gnus-uu-extract-view-map "O" 'gnus-uu-decode-save-view)
310 (define-key gnus-uu-extract-view-map "b" 'gnus-uu-decode-binhex-view)
311 (define-key gnus-uu-extract-view-map "B" 'gnus-uu-decode-binhex-view)
312 (define-key gnus-uu-extract-view-map "p" 'gnus-uu-decode-postscript-view)
313 (define-key gnus-uu-extract-view-map "P" 'gnus-uu-decode-postscript-and-save-view)
319 (defun gnus-uu-decode-uu (n)
320 "Uudecodes the current article."
322 (gnus-uu-decode-with-method 'gnus-uu-uustrip-article n))
324 (defun gnus-uu-decode-uu-and-save (n dir)
325 "Decodes and saves the resulting file."
327 (list current-prefix-arg
328 (file-name-as-directory
329 (read-file-name "Uudecode and save in dir: "
331 gnus-uu-default-dir t))))
332 (gnus-uu-decode-with-method 'gnus-uu-uustrip-article n dir))
334 (defun gnus-uu-decode-unshar (n)
335 "Unshars the current article."
337 (gnus-uu-decode-with-method 'gnus-uu-unshar-article n nil nil 'scan))
339 (defun gnus-uu-decode-unshar-and-save (n dir)
340 "Unshars and saves the current article."
342 (list current-prefix-arg
343 (file-name-as-directory
344 (read-file-name "Unshar and save in dir: "
346 gnus-uu-default-dir t))))
347 (gnus-uu-decode-with-method 'gnus-uu-unshar-article n dir nil 'scan))
349 (defun gnus-uu-decode-save (n file)
350 "Saves the current article."
352 (list current-prefix-arg
354 (if gnus-uu-save-separate-articles
355 "Save articles is dir: "
356 "Save articles in file: ")
358 gnus-uu-default-dir)))
359 (setq gnus-uu-saved-article-name file)
360 (gnus-uu-decode-with-method 'gnus-uu-save-article n nil t)
361 (setq gnus-uu-generated-file-list
362 (delete file gnus-uu-generated-file-list)))
364 (defun gnus-uu-decode-binhex (n dir)
365 "Unbinhexes the current article."
367 (list current-prefix-arg
368 (file-name-as-directory
369 (read-file-name "Unbinhex and save in dir: "
371 gnus-uu-default-dir))))
372 (setq gnus-uu-binhex-article-name
373 (make-temp-name (concat gnus-uu-work-dir "binhex")))
374 (gnus-uu-decode-with-method 'gnus-uu-binhex-article n dir))
376 (defun gnus-uu-decode-uu-view (n)
377 "Uudecodes and views the current article."
379 (let ((gnus-view-pseudos (or gnus-view-pseudos 'automatic)))
380 (gnus-uu-decode-uu n)))
382 (defun gnus-uu-decode-uu-and-save-view (n dir)
383 "Decodes, views and saves the resulting file."
385 (list current-prefix-arg
386 (read-file-name "Uudecode, view and save in dir: "
388 gnus-uu-default-dir t)))
389 (let ((gnus-view-pseudos (or gnus-view-pseudos 'automatic)))
390 (gnus-uu-decode-uu-and-save n dir)))
392 (defun gnus-uu-decode-unshar-view (n)
393 "Unshars and views the current article."
395 (let ((gnus-view-pseudos (or gnus-view-pseudos 'automatic)))
396 (gnus-uu-decode-unshar n)))
398 (defun gnus-uu-decode-unshar-and-save-view (n dir)
399 "Unshars and saves the current article."
401 (list current-prefix-arg
402 (read-file-name "Unshar, view and save in dir: "
404 gnus-uu-default-dir t)))
405 (let ((gnus-view-pseudos (or gnus-view-pseudos 'automatic)))
406 (gnus-uu-decode-unshar-and-save n dir)))
408 (defun gnus-uu-decode-save-view (n file)
409 "Saves and views the current article."
411 (list current-prefix-arg
412 (read-file-name (if gnus-uu-save-separate-articles
413 "Save articles is dir: "
414 "Save articles in file: ")
415 gnus-uu-default-dir gnus-uu-default-dir)))
416 (let ((gnus-view-pseudos (or gnus-view-pseudos 'automatic)))
417 (gnus-uu-decode-save n file)))
419 (defun gnus-uu-decode-binhex-view (n file)
420 "Unbinhexes and views the current article."
422 (list current-prefix-arg
423 (read-file-name "Unbinhex, view and save in dir: "
424 gnus-uu-default-dir gnus-uu-default-dir)))
425 (setq gnus-uu-binhex-article-name
426 (make-temp-name (concat gnus-uu-work-dir "binhex")))
427 (let ((gnus-view-pseudos (or gnus-view-pseudos 'automatic)))
428 (gnus-uu-decode-binhex n file)))
431 ;; Digest and forward articles
433 (defun gnus-uu-digest-mail-forward (n &optional post)
434 "Digests and forwards all articles in this series."
436 (let ((gnus-uu-save-in-digest t)
437 (file (make-temp-name (concat gnus-uu-tmp-dir "forward")))
439 (setq gnus-uu-digest-from-subject nil)
440 (gnus-uu-decode-save n file)
441 (gnus-uu-add-file file)
442 (setq buf (switch-to-buffer (get-buffer-create " *gnus-uu-forward*")))
443 (gnus-add-current-to-buffer-list)
445 (delete-other-windows)
447 (let ((fs gnus-uu-digest-from-subject))
450 (setq from (car (car fs))
451 subject (gnus-simplify-subject-fuzzy (cdr (car fs)))
453 (while (and fs (or from subject))
455 (or (string= from (car (car fs)))
458 (or (string= (gnus-simplify-subject-fuzzy (cdr (car fs)))
462 (or subject (setq subject "Digested Articles"))
463 (or from (setq from "Various")))
464 (goto-char (point-min))
465 (and (re-search-forward "^Subject: ")
467 (delete-region (point) (gnus-point-at-eol))
469 (goto-char (point-min))
470 (and (re-search-forward "^From: ")
472 (delete-region (point) (gnus-point-at-eol))
475 (gnus-forward-using-post)
479 (setq gnus-uu-digest-from-subject nil)))
481 (defun gnus-uu-digest-post-forward (n)
482 "Digest and forward to a newsgroup."
484 (gnus-uu-digest-mail-forward n t))
488 (defun gnus-uu-mark-by-regexp (regexp)
489 "Ask for a regular expression and set the process mark on all articles that match."
490 (interactive (list (read-from-minibuffer "Mark (regexp): ")))
491 (gnus-set-global-variables)
492 (let ((articles (gnus-uu-find-articles-matching regexp)))
494 (gnus-summary-set-process-mark (car articles))
495 (setq articles (cdr articles)))
497 (gnus-summary-position-point))
499 (defun gnus-uu-mark-series ()
500 "Mark the current series with the process mark."
502 (gnus-set-global-variables)
503 (let ((articles (gnus-uu-find-articles-matching)))
505 (gnus-summary-set-process-mark (car articles))
506 (setq articles (cdr articles)))
508 (gnus-summary-position-point))
510 (defun gnus-uu-mark-region (beg end)
511 "Set the process mark on all articles between point and mark."
513 (gnus-set-global-variables)
516 (while (< (point) end)
517 (gnus-summary-set-process-mark (gnus-summary-article-number))
519 (gnus-summary-position-point))
521 (defun gnus-uu-mark-buffer ()
522 "Set the process mark on all articles in the buffer."
524 (gnus-uu-mark-region (point-min) (point-max)))
526 (defun gnus-uu-mark-thread ()
527 "Marks all articles downwards in this thread."
529 (gnus-set-global-variables)
530 (let ((level (gnus-summary-thread-level)))
531 (while (and (gnus-summary-set-process-mark (gnus-summary-article-number))
532 (zerop (gnus-summary-next-subject 1))
533 (> (gnus-summary-thread-level) level))))
534 (gnus-summary-position-point))
536 (defun gnus-uu-unmark-thread ()
537 "Unmarks all articles downwards in this thread."
539 (gnus-set-global-variables)
540 (let ((level (gnus-summary-thread-level)))
541 (while (and (gnus-summary-remove-process-mark
542 (gnus-summary-article-number))
543 (zerop (gnus-summary-next-subject 1))
544 (> (gnus-summary-thread-level) level))))
545 (gnus-summary-position-point))
547 (defun gnus-uu-mark-sparse ()
548 "Mark all series that have some articles marked."
550 (gnus-set-global-variables)
551 (let ((marked (nreverse gnus-newsgroup-processable))
552 subject articles total headers)
553 (or marked (error "No articles marked with the process mark"))
554 (setq gnus-newsgroup-processable nil)
557 (and (setq headers (gnus-summary-article-header (car marked)))
558 (setq subject (mail-header-subject headers)
559 articles (gnus-uu-find-articles-matching
560 (gnus-uu-reginize-string subject))
561 total (nconc total articles)))
563 (gnus-summary-set-process-mark (car articles))
564 (setcdr marked (delq (car articles) (cdr marked)))
565 (setq articles (cdr articles)))
566 (setq marked (cdr marked)))
567 (setq gnus-newsgroup-processable (nreverse total)))
568 (gnus-summary-position-point)))
570 (defun gnus-uu-mark-all ()
571 "Mark all articles in \"series\" order."
573 (gnus-set-global-variables)
574 (setq gnus-newsgroup-processable nil)
576 (goto-char (point-min))
578 (while (and (not (eobp))
579 (setq number (gnus-summary-article-number)))
580 (if (not (memq number gnus-newsgroup-processable))
581 (save-excursion (gnus-uu-mark-series)))
583 (gnus-summary-position-point))
585 ;; All PostScript functions written by Erik Selberg <speed@cs.washington.edu>.
587 (defun gnus-uu-decode-postscript (n)
588 "Gets postscript of the current article."
590 (gnus-uu-decode-with-method 'gnus-uu-decode-postscript-article n))
592 (defun gnus-uu-decode-postscript-view (n)
593 "Gets and views the current article."
595 (let ((gnus-view-pseudos (or gnus-view-pseudos 'automatic)))
596 (gnus-uu-decode-postscript n)))
598 (defun gnus-uu-decode-postscript-and-save (n dir)
599 "Extracts postscript and saves the current article."
601 (list current-prefix-arg
602 (file-name-as-directory
603 (read-file-name "Save in dir: "
605 gnus-uu-default-dir t))))
606 (gnus-uu-decode-with-method 'gnus-uu-decode-postscript-article n dir))
609 (defun gnus-uu-decode-postscript-and-save-view (n dir)
610 "Decodes, views and saves the resulting file."
612 (list current-prefix-arg
613 (read-file-name "Where do you want to save the file(s)? "
615 gnus-uu-default-dir t)))
616 (let ((gnus-view-pseudos (or gnus-view-pseudos 'automatic)))
617 (gnus-uu-decode-postscript-and-save n dir)))
620 ;; Internal functions.
622 (defun gnus-uu-decode-with-method (method n &optional save not-insert scan)
623 (gnus-uu-initialize scan)
624 (if save (setq gnus-uu-default-dir save))
625 (let ((articles (gnus-uu-get-list-of-articles n))
627 (setq files (gnus-uu-grab-articles articles method t))
628 (let ((gnus-current-article (car articles)))
629 (and scan (setq files (gnus-uu-scan-directory gnus-uu-work-dir))))
630 (and save (gnus-uu-save-files files save))
631 (setq files (gnus-uu-unpack-files files))
632 (gnus-uu-add-file (mapcar (lambda (file) (cdr (assq 'name file))) files))
633 (setq files (nreverse (gnus-uu-get-actions files)))
634 (or not-insert (gnus-summary-insert-pseudos files save))))
636 ;; Return a list of files in dir.
637 (defun gnus-uu-scan-directory (dir)
638 (let ((files (directory-files dir t))
641 (cond ((string-match "/\\.\\.?$" (car files)))
642 ((file-directory-p (car files))
643 (setq dirs (cons (car files) dirs)))
644 (t (setq out (cons (list (cons 'name (car files))
645 (cons 'article gnus-current-article))
647 (setq files (cdr files)))
648 (apply 'nconc out (mapcar (lambda (d) (gnus-uu-scan-directory d))
651 (defun gnus-uu-save-files (files dir)
652 (let ((len (length files))
656 (setq file (cdr (assq 'name (car files))))
659 (setq to-file (if (file-directory-p dir)
660 (concat dir (file-name-nondirectory file))
662 (and (or (not (file-exists-p to-file))
663 (gnus-y-or-n-p (format "%s exists; overwrite? "
665 (copy-file file to-file t t))))
666 (setq files (cdr files)))
667 (message "Saved %d file%s" len (if (> len 1) "s" ""))))
669 ;; Functions for saving and possibly digesting articles without
672 ;; Function called by gnus-uu-grab-articles to treat each article.
673 (defun gnus-uu-save-article (buffer in-state)
675 (gnus-uu-save-separate-articles
678 (write-region 1 (point-max) (concat gnus-uu-saved-article-name
679 gnus-current-article))
680 (cond ((eq in-state 'first) (list gnus-uu-saved-article-name 'begin))
681 ((eq in-state 'first-and-last) (list gnus-uu-saved-article-name
683 ((eq in-state 'last) (list 'end))
684 (t (list 'middle)))))
685 ((not gnus-uu-save-in-digest)
688 (write-region 1 (point-max) gnus-uu-saved-article-name t)
689 (cond ((eq in-state 'first) (list gnus-uu-saved-article-name 'begin))
690 ((eq in-state 'first-and-last) (list gnus-uu-saved-article-name
692 ((eq in-state 'last) (list 'end))
693 (t (list 'middle)))))
695 (let ((header (gnus-summary-article-header)))
696 (setq gnus-uu-digest-from-subject
697 (cons (cons (mail-header-from header)
698 (mail-header-subject header))
699 gnus-uu-digest-from-subject)))
700 (let ((name (file-name-nondirectory gnus-uu-saved-article-name))
701 beg subj headers headline sorthead body end-string state)
702 (if (or (eq in-state 'first)
703 (eq in-state 'first-and-last))
705 (setq state (list 'begin))
706 (save-excursion (set-buffer (get-buffer-create "*gnus-uu-body*"))
709 (set-buffer (get-buffer-create "*gnus-uu-pre*"))
712 "Date: %s\nFrom: %s\nSubject: %s Digest\n\nTopics:\n"
713 (current-time-string) name name))))
714 (if (not (eq in-state 'end))
715 (setq state (list 'middle))))
717 (set-buffer (get-buffer "*gnus-uu-body*"))
718 (goto-char (setq beg (point-max)))
722 (let (buffer-read-only)
723 (set-text-properties (point-min) (point-max) nil)
724 ;; These two are necessary for XEmacs 19.12 fascism.
725 (put-text-property (point-min) (point-max) 'invisible nil)
726 (put-text-property (point-min) (point-max) 'intangible nil))
727 (goto-char (point-min))
728 (re-search-forward "\n\n")
729 (setq body (buffer-substring (1- (point)) (point-max)))
730 (narrow-to-region 1 (point))
731 (if (not (setq headers gnus-uu-digest-headers))
732 (setq sorthead (buffer-substring (point-min) (point-max)))
734 (setq headline (car headers))
735 (setq headers (cdr headers))
736 (goto-char (point-min))
737 (if (re-search-forward headline nil t)
742 (or (and (re-search-forward "^[^ \t]" nil t)
744 (progn (forward-line 1) (point)))))))))
746 (insert sorthead) (goto-char (point-max))
747 (insert body) (goto-char (point-max))
748 (insert (concat "\n" (make-string 30 ?-) "\n\n"))
750 (if (re-search-forward "^Subject: \\(.*\\)$" nil t)
752 (setq subj (buffer-substring (match-beginning 1) (match-end 1)))
754 (set-buffer (get-buffer "*gnus-uu-pre*"))
755 (insert (format " %s\n" subj))))))
756 (if (or (eq in-state 'last)
757 (eq in-state 'first-and-last))
760 (set-buffer (get-buffer "*gnus-uu-pre*"))
761 (insert (format "\n\n%s\n\n" (make-string 70 ?-)))
762 (write-region 1 (point-max) gnus-uu-saved-article-name))
764 (set-buffer (get-buffer "*gnus-uu-body*"))
765 (goto-char (point-max))
767 (concat (setq end-string (format "End of %s Digest" name))
769 (insert (concat (make-string (length end-string) ?*) "\n"))
770 (write-region 1 (point-max) gnus-uu-saved-article-name t))
771 (kill-buffer (get-buffer "*gnus-uu-pre*"))
772 (kill-buffer (get-buffer "*gnus-uu-body*"))
773 (setq state (cons 'end state))))
774 (if (memq 'begin state)
775 (cons gnus-uu-saved-article-name state)
778 ;; Binhex treatment - not very advanced.
780 (defconst gnus-uu-binhex-body-line
781 "^[^:]...............................................................$")
782 (defconst gnus-uu-binhex-begin-line
783 "^:...............................................................$")
784 (defconst gnus-uu-binhex-end-line
787 (defun gnus-uu-binhex-article (buffer in-state)
788 (let (state start-char)
792 (goto-char (point-min))
793 (if (not (re-search-forward gnus-uu-binhex-begin-line nil t))
794 (if (not (re-search-forward gnus-uu-binhex-body-line nil t))
795 (setq state (list 'wrong-type))))
797 (if (memq 'wrong-type state)
800 (setq start-char (point))
801 (if (looking-at gnus-uu-binhex-begin-line)
803 (setq state (list 'begin))
804 (write-region 1 1 gnus-uu-binhex-article-name))
805 (setq state (list 'middle)))
806 (goto-char (point-max))
807 (re-search-backward (concat gnus-uu-binhex-body-line "\\|"
808 gnus-uu-binhex-end-line) nil t)
809 (if (looking-at gnus-uu-binhex-end-line)
810 (setq state (if (memq 'begin state)
815 (if (file-exists-p gnus-uu-binhex-article-name)
816 (append-to-file start-char (point) gnus-uu-binhex-article-name))))
817 (if (memq 'begin state)
818 (cons gnus-uu-binhex-article-name state)
823 (defun gnus-uu-decode-postscript-article (process-buffer in-state)
824 (let ((state (list 'ok))
825 start-char end-char file-name)
827 (set-buffer process-buffer)
828 (goto-char (point-min))
829 (if (not (re-search-forward gnus-uu-postscript-begin-string nil t))
830 (setq state (list 'wrong-type))
832 (setq start-char (point))
833 (if (not (re-search-forward gnus-uu-postscript-end-string nil t))
834 (setq state (list 'wrong-type))
835 (setq end-char (point))
836 (set-buffer (get-buffer-create gnus-uu-output-buffer-name))
837 (insert-buffer-substring process-buffer start-char end-char)
838 (setq file-name (concat gnus-uu-work-dir (cdr gnus-article-current) ".ps"))
839 (write-region (point-min) (point-max) file-name)
840 (setq state (list file-name'begin 'end))
849 (defun gnus-uu-get-actions (files)
853 (setq name (cdr (assq 'name (car files))))
855 (setq action (gnus-uu-get-action name))
856 (setcar files (nconc (list (if (string= action "gnus-uu-archive")
857 (cons 'action "file")
858 (cons 'action action))
859 (cons 'execute (if (string-match "%" action)
861 (concat action " " name))))
863 (setq files (cdr files)))
866 (defun gnus-uu-get-action (file-name)
869 (gnus-uu-choose-action
872 gnus-uu-user-view-rules
873 (if gnus-uu-ignore-default-view-rules
875 gnus-uu-default-view-rules)
876 gnus-uu-user-view-rules-end)))
877 (if (and (not (string= (or action "") "gnus-uu-archive"))
878 gnus-uu-view-with-metamail)
880 (gnus-uu-choose-action file-name gnus-uu-ext-to-mime-list))
881 (setq action (format "metamail -d -b -c \"%s\"" action))))
885 ;; Functions for treating subjects and collecting series.
887 (defun gnus-uu-reginize-string (string)
888 ;; Takes a string and puts a \ in front of every special character;
889 ;; ignores any leading "version numbers" thingies that they use in
890 ;; the comp.binaries groups, and either replaces anything that looks
891 ;; like "2/3" with "[0-9]+/[0-9]+" or, if it can't find something
892 ;; like that, replaces the last two numbers with "[0-9]+". This, in
893 ;; my experience, should get most postings of a series.
895 (vernum "v[0-9]+[a-z][0-9]+:")
898 (set-buffer (get-buffer-create gnus-uu-output-buffer-name))
899 (buffer-disable-undo (current-buffer))
901 (insert (regexp-quote string))
904 (setq case-fold-search nil)
905 (goto-char (point-min))
906 (if (looking-at vernum)
908 (replace-match vernum t t)
909 (setq beg (length vernum))))
912 (if (re-search-forward "[ \t]*[0-9]+/[0-9]+" nil t)
913 (replace-match " [0-9]+/[0-9]+")
916 (if (re-search-forward "[0-9]+[ \t]*of[ \t]*[0-9]+" nil t)
917 (replace-match "[0-9]+ of [0-9]+")
920 (while (and (re-search-backward "[0-9]" nil t) (> count 0))
923 (< 1 (goto-char (1- (point))))))
924 (re-search-forward "[0-9]+" nil t)
925 (replace-match "[0-9]+")
927 (setq count (1- count)))))
930 (while (re-search-forward "[ \t]+" nil t)
931 (replace-match "[ \t]*" t t))
933 (buffer-substring 1 (point-max)))))
935 (defun gnus-uu-get-list-of-articles (n)
936 ;; If N is non-nil, the article numbers of the N next articles
938 ;; If any articles have been marked as processable, they will be
940 ;; Failing that, articles that have subjects that are part of the
941 ;; same "series" as the current will be returned.
945 (let ((backward (< n 0))
949 (setq articles (cons (gnus-summary-article-number)
951 (gnus-summary-search-forward nil nil backward))
953 (nreverse articles)))
954 (gnus-newsgroup-processable
955 (reverse gnus-newsgroup-processable))
957 (gnus-uu-find-articles-matching)))))
959 (defun gnus-uu-string< (l1 l2)
960 (string< (car l1) (car l2)))
962 (defun gnus-uu-find-articles-matching
963 (&optional subject only-unread do-not-translate)
964 ;; Finds all articles that matches the regexp SUBJECT. If it is
965 ;; nil, the current article name will be used. If ONLY-UNREAD is
966 ;; non-nil, only unread articles are chosen. If DO-NOT-TRANSLATE is
967 ;; non-nil, article names are not equalized before sorting.
968 (let ((subject (or subject
969 (gnus-uu-reginize-string (gnus-summary-article-subject))))
974 ;; Collect all subjects matching subject.
975 (let ((case-fold-search t)
977 (goto-char (point-min))
979 (and (setq subj (gnus-summary-article-subject))
980 (string-match subject subj)
981 (or (not only-unread)
982 (= (setq mark (gnus-summary-article-mark))
984 (= mark gnus-ticked-mark)
985 (= mark gnus-dormant-mark))
986 (setq list-of-subjects
987 (cons (cons subj (gnus-summary-article-number))
991 ;; Expand numbers, sort, and return the list of article
993 (mapcar (lambda (sub) (cdr sub))
994 (sort (gnus-uu-expand-numbers
996 (not do-not-translate))
997 'gnus-uu-string<))))))
999 (defun gnus-uu-expand-numbers (string-list &optional translate)
1000 ;; Takes a list of strings and "expands" all numbers in all the
1001 ;; strings. That is, this function makes all numbers equal length by
1002 ;; prepending lots of zeroes before each number. This is to ease later
1003 ;; sorting to find out what sequence the articles are supposed to be
1004 ;; decoded in. Returns the list of expanded strings.
1005 (let ((out-list string-list)
1008 (set-buffer (get-buffer-create gnus-uu-output-buffer-name))
1009 (buffer-disable-undo (current-buffer))
1012 (insert (car (car string-list)))
1013 ;; Translate multiple spaces to one space.
1014 (goto-char (point-min))
1015 (while (re-search-forward "[ \t]+" nil t)
1016 (replace-match " "))
1017 ;; Translate all characters to "a".
1018 (goto-char (point-min))
1020 (while (re-search-forward "[A-Za-z]" nil t)
1021 (replace-match "a" t t)))
1023 (goto-char (point-min))
1024 (while (re-search-forward "[0-9]+" nil t)
1027 (string-to-int (buffer-substring
1028 (match-beginning 0) (match-end 0))))))
1029 (setq string (buffer-substring 1 (point-max)))
1030 (setcar (car string-list) string)
1031 (setq string-list (cdr string-list))))
1035 ;; `gnus-uu-grab-articles' is the general multi-article treatment
1036 ;; function. It takes a list of articles to be grabbed and a function
1037 ;; to apply to each article.
1039 ;; The function to be called should take two parameters. The first
1040 ;; parameter is the article buffer. The function should leave the
1041 ;; result, if any, in this buffer. Most treatment functions will just
1042 ;; generate files...
1044 ;; The second parameter is the state of the list of articles, and can
1045 ;; have four values: `first', `middle', `last' and `first-and-last'.
1047 ;; The function should return a list. The list may contain the
1048 ;; following symbols:
1049 ;; `error' if an error occurred
1050 ;; `begin' if the beginning of an encoded file has been received
1051 ;; If the list returned contains a `begin', the first element of
1052 ;; the list *must* be a string with the file name of the decoded
1054 ;; `end' if the the end of an encoded file has been received
1055 ;; `middle' if the article was a body part of an encoded file
1056 ;; `wrong-type' if the article was not a part of an encoded file
1057 ;; `ok', which can be used everything is ok
1059 (defvar gnus-uu-has-been-grabbed nil)
1061 (defun gnus-uu-unmark-list-of-grabbed (&optional dont-unmark-last-article)
1063 (if (not (and gnus-uu-has-been-grabbed
1064 gnus-uu-unmark-articles-not-decoded))
1066 (if dont-unmark-last-article
1068 (setq art (car gnus-uu-has-been-grabbed))
1069 (setq gnus-uu-has-been-grabbed (cdr gnus-uu-has-been-grabbed))))
1070 (while gnus-uu-has-been-grabbed
1071 (gnus-summary-tick-article (car gnus-uu-has-been-grabbed) t)
1072 (setq gnus-uu-has-been-grabbed (cdr gnus-uu-has-been-grabbed)))
1073 (if dont-unmark-last-article
1074 (setq gnus-uu-has-been-grabbed (list art))))))
1076 ;; This function takes a list of articles and a function to apply to
1077 ;; each article grabbed.
1079 ;; This function returns a list of files decoded if the grabbing and
1080 ;; the process-function has been successful and nil otherwise.
1081 (defun gnus-uu-grab-articles
1082 (articles process-function &optional sloppy limit no-errors)
1083 (let ((state 'first)
1084 has-been-begin article result-file result-files process-state
1087 (if (not (gnus-server-opened gnus-current-select-method))
1089 (gnus-start-news-server)
1090 (gnus-request-group gnus-newsgroup-name)))
1092 (setq gnus-uu-has-been-grabbed nil)
1094 (while (and articles
1095 (not (memq 'error process-state))
1097 (not (memq 'end process-state))))
1099 (setq article (car articles))
1100 (setq articles (cdr articles))
1101 (setq gnus-uu-has-been-grabbed (cons article gnus-uu-has-been-grabbed))
1103 (if (eq articles ())
1104 (if (eq state 'first)
1105 (setq state 'first-and-last)
1106 (setq state 'last)))
1108 (message "Getting article %d, %s" article (gnus-uu-part-number article))
1110 (if (not (= (or gnus-current-article 0) article))
1111 (let ((nntp-async-number nil))
1112 (gnus-request-article article gnus-newsgroup-name
1114 (setq gnus-last-article gnus-current-article)
1115 (setq gnus-current-article article)
1116 (setq gnus-article-current (cons gnus-newsgroup-name article))
1117 (if (stringp nntp-server-buffer)
1118 (setq article-buffer nntp-server-buffer)
1119 (setq article-buffer (buffer-name nntp-server-buffer))))
1120 (gnus-summary-stop-page-breaking)
1121 (setq article-buffer gnus-article-buffer))
1123 (buffer-disable-undo article-buffer)
1124 ;; Mark article as read.
1125 (and (memq article gnus-newsgroup-processable)
1126 (gnus-summary-remove-process-mark article))
1127 (run-hooks 'gnus-mark-article-hook)
1129 (setq process-state (funcall process-function article-buffer state))
1131 (if (or (memq 'begin process-state)
1132 (and (or (eq state 'first) (eq state 'first-and-last))
1133 (memq 'ok process-state)))
1136 (if (and result-file (file-exists-p result-file))
1137 (delete-file result-file)))
1138 (if (memq 'begin process-state)
1139 (setq result-file (car process-state)))
1140 (setq has-been-begin t)))
1142 (if (memq 'end process-state)
1144 (setq gnus-uu-has-been-grabbed nil)
1145 (setq result-files (cons (list (cons 'name result-file)
1146 (cons 'article article))
1148 (setq has-been-begin nil)
1149 (and limit (= (length result-files) limit)
1150 (setq articles nil))))
1152 (if (and (or (eq state 'last) (eq state 'first-and-last))
1153 (not (memq 'end process-state)))
1154 (if (and result-file (file-exists-p result-file))
1155 (delete-file result-file)))
1157 (if (not (memq 'wrong-type process-state))
1159 (if gnus-uu-unmark-articles-not-decoded
1160 (gnus-summary-tick-article article t)))
1162 (if (and (not has-been-begin)
1164 (or (memq 'end process-state)
1165 (memq 'middle process-state)))
1167 (setq process-state (list 'error))
1168 (message "No begin part at the beginning")
1170 (setq state 'middle)))
1172 ;; Make sure the last article is put in the article buffer & fix
1175 (if (not (string= article-buffer gnus-article-buffer))
1177 (set-buffer (get-buffer-create gnus-article-buffer))
1178 (let ((buffer-read-only nil))
1181 (insert-buffer-substring article-buffer)
1182 (gnus-set-mode-line 'article)
1183 (goto-char (point-min)))))
1185 (gnus-set-mode-line 'summary)
1189 (if (not has-been-begin)
1190 (if (not no-errors) (message "Wrong type file"))
1191 (if (memq 'error process-state)
1192 (setq result-files nil)
1193 (if (not (or (memq 'ok process-state)
1194 (memq 'end process-state)))
1197 (message "End of articles reached before end of file"))
1198 (setq result-files nil))
1199 (gnus-uu-unmark-list-of-grabbed)))))
1202 (defun gnus-uu-part-number (article)
1203 (let ((subject (mail-header-subject (gnus-summary-article-header article))))
1204 (if (string-match "[0-9]+ */[0-9]+\\|[0-9]+ * of *[0-9]+"
1206 (substring subject (match-beginning 0) (match-end 0))
1209 (defun gnus-uu-uudecode-sentinel (process event)
1210 (delete-process (get-process process)))
1212 (defun gnus-uu-uustrip-article (process-buffer in-state)
1213 ;; Uudecodes a file asynchronously.
1214 (let ((state (list 'ok))
1215 (process-connection-type nil)
1216 start-char pst name-beg name-end)
1218 (set-buffer process-buffer)
1219 (let ((case-fold-search nil)
1220 (buffer-read-only nil))
1222 (goto-char (point-min))
1224 (if gnus-uu-kill-carriage-return
1226 (while (search-forward "\r" nil t)
1227 (delete-backward-char 1))
1228 (goto-char (point-min))))
1230 (if (not (re-search-forward gnus-uu-begin-string nil t))
1231 (if (not (re-search-forward gnus-uu-body-line nil t))
1232 (setq state (list 'wrong-type))))
1234 (if (memq 'wrong-type state)
1237 (setq start-char (point))
1239 (if (looking-at gnus-uu-begin-string)
1241 (setq name-end (match-end 1)
1242 name-beg (match-beginning 1))
1243 ;; Remove any non gnus-uu-body-line right after start.
1245 (or (looking-at gnus-uu-body-line)
1248 ; Replace any slashes and spaces in file names before decoding
1249 (goto-char name-beg)
1250 (while (re-search-forward "/" name-end t)
1251 (replace-match ","))
1252 (goto-char name-beg)
1253 (while (re-search-forward " " name-end t)
1254 (replace-match "_"))
1255 (goto-char name-beg)
1256 (if (re-search-forward "_*$" name-end t)
1259 (setq gnus-uu-file-name (buffer-substring name-beg name-end))
1260 (and gnus-uu-uudecode-process
1261 (setq pst (process-status
1262 (or gnus-uu-uudecode-process "nevair")))
1263 (if (or (eq pst 'stop) (eq pst 'run))
1265 (delete-process gnus-uu-uudecode-process)
1266 (gnus-uu-unmark-list-of-grabbed t))))
1267 (if (get-process "*uudecode*")
1268 (delete-process "*uudecode*"))
1269 (setq gnus-uu-uudecode-process
1272 (get-buffer-create gnus-uu-output-buffer-name)
1274 (format "cd %s ; uudecode" gnus-uu-work-dir)))
1275 (set-process-sentinel
1276 gnus-uu-uudecode-process 'gnus-uu-uudecode-sentinel)
1277 (setq state (list 'begin))
1278 (gnus-uu-add-file (concat gnus-uu-work-dir gnus-uu-file-name)))
1279 (setq state (list 'middle)))
1281 (goto-char (point-max))
1284 (concat gnus-uu-body-line "\\|" gnus-uu-end-string) nil t)
1287 (if (looking-at gnus-uu-end-string)
1288 (setq state (cons 'end state)))
1291 (and gnus-uu-uudecode-process
1292 (setq pst (process-status
1293 (or gnus-uu-uudecode-process "nevair")))
1294 (if (or (eq pst 'run) (eq pst 'stop))
1296 (if gnus-uu-correct-stripped-uucode
1298 (gnus-uu-check-correct-stripped-uucode
1300 (goto-char (point-max))
1302 (concat gnus-uu-body-line "\\|"
1308 (process-send-region gnus-uu-uudecode-process
1312 (delete-process gnus-uu-uudecode-process)
1313 (message "gnus-uu: Couldn't uudecode")
1315 (setq state (list 'wrong-type)))))
1317 (if (memq 'end state)
1318 (accept-process-output gnus-uu-uudecode-process)))
1319 (setq state (list 'wrong-type))))
1320 (if (not gnus-uu-uudecode-process)
1321 (setq state (list 'wrong-type)))))
1323 (if (memq 'begin state)
1324 (cons (concat gnus-uu-work-dir gnus-uu-file-name) state)
1327 ;; This function is used by `gnus-uu-grab-articles' to treat
1328 ;; a shared article.
1329 (defun gnus-uu-unshar-article (process-buffer in-state)
1330 (let ((state (list 'ok))
1333 (set-buffer process-buffer)
1334 (goto-char (point-min))
1335 (if (not (re-search-forward gnus-uu-shar-begin-string nil t))
1336 (setq state (list 'wrong-type))
1338 (setq start-char (point))
1339 (call-process-region
1340 start-char (point-max) "sh" nil
1341 (get-buffer-create gnus-uu-output-buffer-name) nil
1342 "-c" (concat "cd " gnus-uu-work-dir " ; sh"))))
1345 ;; Returns the name of what the shar file is going to unpack.
1346 (defun gnus-uu-find-name-in-shar ()
1347 (let ((oldpoint (point))
1349 (goto-char (point-min))
1350 (if (re-search-forward gnus-uu-shar-name-marker nil t)
1351 (setq res (buffer-substring (match-beginning 1) (match-end 1))))
1352 (goto-char oldpoint)
1355 ;; `gnus-uu-choose-action' chooses what action to perform given the name
1356 ;; and `gnus-uu-file-action-list'. Returns either nil if no action is
1357 ;; found, or the name of the command to run if such a rule is found.
1358 (defun gnus-uu-choose-action (file-name file-action-list &optional no-ignore)
1359 (let ((action-list (copy-sequence file-action-list))
1360 (case-fold-search t)
1365 (and gnus-uu-ignore-files-by-name
1366 (string-match gnus-uu-ignore-files-by-name file-name)))
1368 (and gnus-uu-ignore-files-by-type
1369 (string-match gnus-uu-ignore-files-by-type
1370 (or (gnus-uu-choose-action
1371 file-name gnus-uu-ext-to-mime-list t)
1373 (while (not (or (eq action-list ()) action))
1374 (setq rule (car action-list))
1375 (setq action-list (cdr action-list))
1376 (if (string-match (car rule) file-name)
1377 (setq action (car (cdr rule))))))
1380 (defun gnus-uu-treat-archive (file-path)
1381 ;; Unpacks an archive. Returns t if unpacking is successful.
1382 (let ((did-unpack t)
1384 (setq action (gnus-uu-choose-action
1385 file-path (append gnus-uu-user-archive-rules
1386 (if gnus-uu-ignore-default-archive-rules
1388 gnus-uu-default-archive-rules))))
1390 (if (not action) (error "No unpackers for the file %s" file-path))
1392 (string-match "/[^/]*$" file-path)
1393 (setq dir (substring file-path 0 (match-beginning 0)))
1395 (if (member action gnus-uu-destructive-archivers)
1396 (copy-file file-path (concat file-path "~") t))
1398 (setq command (format "cd %s ; %s" dir (gnus-uu-command action file-path)))
1401 (set-buffer (get-buffer-create gnus-uu-output-buffer-name))
1404 (message "Unpacking: %s..." (gnus-uu-command action file-path))
1406 (if (= 0 (call-process "sh" nil
1407 (get-buffer-create gnus-uu-output-buffer-name)
1410 (message "Error during unpacking of archive")
1411 (setq did-unpack nil))
1413 (if (member action gnus-uu-destructive-archivers)
1414 (rename-file (concat file-path "~") file-path t))
1418 (defun gnus-uu-dir-files (dir)
1419 (let ((dirs (directory-files dir t "[^/][^\\.][^\\.]?$"))
1422 (if (file-directory-p (setq file (car dirs)))
1423 (setq files (append files (gnus-uu-dir-files file)))
1424 (setq files (cons file files)))
1425 (setq dirs (cdr dirs)))
1428 (defun gnus-uu-unpack-files (files &optional ignore)
1429 ;; Go through FILES and look for files to unpack.
1430 (let* ((totfiles (gnus-uu-ls-r gnus-uu-work-dir))
1432 file did-unpack file-entry)
1433 (gnus-uu-add-file totfiles)
1435 (setq file (cdr (setq file-entry (assq 'name (car files)))))
1436 (if (and (not (member file ignore))
1437 (equal (gnus-uu-get-action (file-name-nondirectory file))
1440 (setq did-unpack (cons file did-unpack))
1441 (or (gnus-uu-treat-archive file)
1442 (message "Error during unpacking of %s" file))
1443 (let* ((newfiles (gnus-uu-ls-r gnus-uu-work-dir))
1445 (gnus-uu-add-file newfiles)
1447 (or (member (car nfiles) totfiles)
1448 (setq ofiles (cons (list (cons 'name (car nfiles))
1449 (cons 'original file))
1451 (setq nfiles (cdr nfiles)))
1452 (setq totfiles newfiles))))
1453 (setq files (cdr files)))
1455 (gnus-uu-unpack-files ofiles (append did-unpack ignore))
1458 (defun gnus-uu-ls-r (dir)
1459 (let* ((files (gnus-uu-directory-files dir t))
1462 (if (file-directory-p (car files))
1464 (setq ofiles (delete (car files) ofiles))
1465 (setq ofiles (append ofiles (gnus-uu-ls-r (car files))))))
1466 (setq files (cdr files)))
1471 (defun gnus-uu-directory-files (dir &optional full)
1472 (let (files out file)
1473 (setq files (directory-files dir full))
1475 (setq file (car files))
1476 (setq files (cdr files))
1477 (or (string-match "/\\.\\.?$" file)
1478 (setq out (cons file out))))
1479 (setq out (nreverse out))
1482 (defun gnus-uu-check-correct-stripped-uucode (start end)
1483 (let (found beg length)
1484 (if (not gnus-uu-correct-stripped-uucode)
1488 (if (re-search-forward " \\|`" end t)
1493 (if (looking-at "\n") (replace-match ""))
1497 (if (looking-at (concat gnus-uu-begin-string "\\|"
1498 gnus-uu-end-string))
1505 (setq length (- (point) beg))))
1510 (if (not (= length (- (point) beg)))
1511 (insert (make-string (- length (- (point) beg)) ? ))))
1512 (forward-line 1))))))
1514 (defvar gnus-uu-tmp-alist nil)
1516 (defun gnus-uu-initialize (&optional scan)
1519 (if (setq entry (assoc gnus-newsgroup-name gnus-uu-tmp-alist))
1520 (if (file-exists-p (cdr entry))
1521 (setq gnus-uu-work-dir (cdr entry))
1522 (setq gnus-uu-tmp-alist (delq entry gnus-uu-tmp-alist))
1525 (setq gnus-uu-tmp-dir (file-name-as-directory
1526 (expand-file-name gnus-uu-tmp-dir)))
1527 (if (not (file-directory-p gnus-uu-tmp-dir))
1528 (error "Temp directory %s doesn't exist" gnus-uu-tmp-dir)
1529 (if (not (file-writable-p gnus-uu-tmp-dir))
1530 (error "Temp directory %s can't be written to"
1533 (setq gnus-uu-work-dir
1534 (make-temp-name (concat gnus-uu-tmp-dir "gnus")))
1535 (gnus-uu-add-file gnus-uu-work-dir)
1536 (if (not (file-directory-p gnus-uu-work-dir))
1537 (gnus-make-directory gnus-uu-work-dir))
1538 (set-file-modes gnus-uu-work-dir 448)
1539 (setq gnus-uu-work-dir (file-name-as-directory gnus-uu-work-dir))
1540 (setq gnus-uu-tmp-alist (cons (cons gnus-newsgroup-name gnus-uu-work-dir)
1541 gnus-uu-tmp-alist)))))
1544 ;; Kills the temporary uu buffers, kills any processes, etc.
1545 (defun gnus-uu-clean-up ()
1547 (and gnus-uu-uudecode-process
1548 (setq pst (process-status (or gnus-uu-uudecode-process "nevair")))
1549 (if (or (eq pst 'stop) (eq pst 'run))
1550 (delete-process gnus-uu-uudecode-process)))
1551 (and (setq buf (get-buffer gnus-uu-output-buffer-name))
1552 (kill-buffer buf))))
1554 ;; `gnus-uu-check-for-generated-files' deletes any generated files that
1555 ;; hasn't been deleted, if, for instance, the user terminated decoding
1557 (defun gnus-uu-check-for-generated-files ()
1559 (while gnus-uu-generated-file-list
1560 (setq file (car gnus-uu-generated-file-list))
1561 (setq gnus-uu-generated-file-list (cdr gnus-uu-generated-file-list))
1562 (if (not (string-match "/\\.[\\.]?$" file))
1564 (if (file-directory-p file)
1565 (setq dirs (cons file dirs))
1566 (if (file-exists-p file)
1567 (delete-file file))))))
1568 (setq dirs (nreverse dirs))
1570 (setq file (car dirs))
1571 (setq dirs (cdr dirs))
1572 (if (file-directory-p file)
1573 (if (string-match "/$" file)
1574 (delete-directory (substring file 0 (match-beginning 0)))
1575 (delete-directory file))))))
1577 ;; Add a file (or a list of files) to be checked (and deleted if it/they
1578 ;; still exists upon exiting the newsgroup).
1579 (defun gnus-uu-add-file (file)
1581 (setq gnus-uu-generated-file-list
1582 (cons file gnus-uu-generated-file-list))
1583 (setq gnus-uu-generated-file-list
1584 (append file gnus-uu-generated-file-list))))
1586 ;; Inputs an action and a file and returns a full command, putting
1587 ;; quotes round the file name and escaping any quotes in the file name.
1588 (defun gnus-uu-command (action file)
1590 (while (string-match "!\\|`\\|\"\\|\\$\\|\\\\\\|&" file)
1593 (concat ofile (substring file 0 (match-beginning 0)) "\\"
1594 (substring file (match-beginning 0) (match-end 0))))
1595 (setq file (substring file (1+ (match-beginning 0))))))
1596 (setq ofile (concat "\"" ofile file "\""))
1597 (if (string-match "%s" action)
1598 (format action ofile)
1599 (concat action " " ofile))))
1604 (add-hook 'gnus-exit-group-hook 'gnus-uu-clean-up)
1605 (add-hook 'gnus-exit-group-hook 'gnus-uu-check-for-generated-files)
1610 ;;; uuencoded posting
1616 ;; Any function that is to be used as and encoding method will take two
1617 ;; parameters: PATH-NAME and FILE-NAME. (E.g. "/home/gaga/spiral.jpg"
1618 ;; and "spiral.jpg", respectively.) The function should return nil if
1619 ;; the encoding wasn't successful.
1620 (defvar gnus-uu-post-encode-method 'gnus-uu-post-encode-uuencode
1621 "Function used for encoding binary files.
1622 There are three functions supplied with gnus-uu for encoding files:
1623 `gnus-uu-post-encode-uuencode', which does straight uuencoding;
1624 `gnus-uu-post-encode-mime', which encodes with base64 and adds MIME
1625 headers; and `gnus-uu-post-encode-mime-uuencode', which encodes with
1626 uuencode and adds MIME headers.")
1628 (defvar gnus-uu-post-include-before-composing nil
1629 "Non-nil means that gnus-uu will ask for a file to encode before you compose the article.
1630 If this variable is t, you can either include an encoded file with
1631 \\[gnus-uu-post-insert-binary-in-article] or have one included for you when you post the article.")
1633 (defvar gnus-uu-post-length 990
1634 "Maximum length of an article.
1635 The encoded file will be split into how many articles it takes to
1636 post the entire file.")
1638 (defvar gnus-uu-post-threaded nil
1639 "Non-nil means that gnus-uu will post the encoded file in a thread.
1640 This may not be smart, as no other decoder I have seen are able to
1641 follow threads when collecting uuencoded articles. (Well, I have seen
1642 one package that does that - gnus-uu, but somehow, I don't think that
1643 counts...) Default is nil.")
1645 (defvar gnus-uu-post-separate-description t
1646 "Non-nil means that the description will be posted in a separate article.
1647 The first article will typically be numbered (0/x). If this variable
1648 is nil, the description the user enters will be included at the
1649 beginning of the first article, which will be numbered (1/x). Default
1652 (defvar gnus-uu-post-binary-separator "--binary follows this line--")
1653 (defvar gnus-uu-post-message-id nil)
1654 (defvar gnus-uu-post-inserted-file-name nil)
1655 (defvar gnus-uu-winconf-post-news nil)
1657 (defun gnus-uu-post-news ()
1658 "Compose an article and post an encoded file."
1660 (setq gnus-uu-post-inserted-file-name nil)
1661 (setq gnus-uu-winconf-post-news (current-window-configuration))
1663 (gnus-summary-post-news)
1665 (use-local-map (copy-keymap (current-local-map)))
1666 (local-set-key "\C-c\C-c" 'gnus-summary-edit-article-done)
1667 (local-set-key "\C-c\C-c" 'gnus-uu-post-news-inews)
1668 (local-set-key "\C-c\C-s" 'gnus-uu-post-news-inews)
1669 (local-set-key "\C-c\C-i" 'gnus-uu-post-insert-binary-in-article)
1671 (if gnus-uu-post-include-before-composing
1672 (save-excursion (setq gnus-uu-post-inserted-file-name
1673 (gnus-uu-post-insert-binary)))))
1675 (defun gnus-uu-post-insert-binary-in-article ()
1676 "Inserts an encoded file in the buffer.
1677 The user will be asked for a file name."
1679 (if (not (eq (current-buffer) (get-buffer gnus-post-news-buffer)))
1680 (error "Not in post-news buffer"))
1682 (setq gnus-uu-post-inserted-file-name (gnus-uu-post-insert-binary))))
1684 ;; Encodes with uuencode and substitutes all spaces with backticks.
1685 (defun gnus-uu-post-encode-uuencode (path file-name)
1686 (if (gnus-uu-post-encode-file "uuencode" path file-name)
1688 (goto-char (point-min))
1690 (while (re-search-forward " " nil t)
1691 (replace-match "`"))
1694 ;; Encodes with uuencode and adds MIME headers.
1695 (defun gnus-uu-post-encode-mime-uuencode (path file-name)
1696 (if (gnus-uu-post-encode-uuencode path file-name)
1698 (gnus-uu-post-make-mime file-name "x-uue")
1701 ;; Encodes with base64 and adds MIME headers
1702 (defun gnus-uu-post-encode-mime (path file-name)
1703 (if (gnus-uu-post-encode-file "mmencode" path file-name)
1705 (gnus-uu-post-make-mime file-name "base64")
1708 ;; Adds MIME headers.
1709 (defun gnus-uu-post-make-mime (file-name encoding)
1710 (goto-char (point-min))
1711 (insert (format "Content-Type: %s; name=\"%s\"\n"
1712 (gnus-uu-choose-action file-name gnus-uu-ext-to-mime-list)
1714 (insert (format "Content-Transfer-Encoding: %s\n\n" encoding))
1716 (set-buffer gnus-post-news-buffer)
1717 (goto-char (point-min))
1718 (re-search-forward (concat "^" (regexp-quote mail-header-separator) "$"))
1720 (narrow-to-region 1 (point))
1721 (or (mail-fetch-field "mime-version")
1724 (insert "MIME-Version: 1.0\n")))
1727 ;; Encodes a file PATH with COMMAND, leaving the result in the
1729 (defun gnus-uu-post-encode-file (command path file-name)
1730 (= 0 (call-process "sh" nil t nil "-c"
1731 (format "%s %s %s" command path file-name))))
1733 (defun gnus-uu-post-news-inews ()
1734 "Posts the composed news article and encoded file.
1735 If no file has been included, the user will be asked for a file."
1737 (if (not (eq (current-buffer) (get-buffer gnus-post-news-buffer)))
1738 (error "Not in post news buffer"))
1742 (if gnus-uu-post-inserted-file-name
1743 (setq file-name gnus-uu-post-inserted-file-name)
1744 (setq file-name (gnus-uu-post-insert-binary)))
1746 (if gnus-uu-post-threaded
1747 (let ((gnus-required-headers
1748 (if (memq 'Message-ID gnus-required-headers)
1749 gnus-required-headers
1750 (cons 'Message-ID gnus-required-headers)))
1751 gnus-inews-article-hook)
1753 (setq gnus-inews-article-hook (if (listp gnus-inews-article-hook)
1754 gnus-inews-article-hook
1755 (list gnus-inews-article-hook)))
1756 (setq gnus-inews-article-hook
1760 (goto-char (point-min))
1761 (if (re-search-forward "^Message-ID: \\(.*\\)$" nil t)
1762 (setq gnus-uu-post-message-id
1764 (match-beginning 1) (match-end 1)))
1765 (setq gnus-uu-post-message-id nil))))
1766 gnus-inews-article-hook))
1767 (gnus-uu-post-encoded file-name t))
1768 (gnus-uu-post-encoded file-name nil)))
1769 (setq gnus-uu-post-inserted-file-name nil)
1770 (and gnus-uu-winconf-post-news
1771 (set-window-configuration gnus-uu-winconf-post-news)))
1773 ;; Asks for a file to encode, encodes it and inserts the result in
1774 ;; the current buffer. Returns the file name the user gave.
1775 (defun gnus-uu-post-insert-binary ()
1776 (let ((uuencode-buffer-name "*uuencode buffer*")
1777 file-path uubuf file-name)
1779 (setq file-path (read-file-name
1780 "What file do you want to encode? "))
1781 (if (not (file-exists-p file-path))
1782 (error "%s: No such file" file-path))
1784 (goto-char (point-max))
1785 (insert (format "\n%s\n" gnus-uu-post-binary-separator))
1787 (if (string-match "^~/" file-path)
1788 (setq file-path (concat "$HOME" (substring file-path 1))))
1789 (if (string-match "/[^/]*$" file-path)
1790 (setq file-name (substring file-path (1+ (match-beginning 0))))
1791 (setq file-name file-path))
1795 (set-buffer (setq uubuf
1796 (get-buffer-create uuencode-buffer-name)))
1798 (funcall gnus-uu-post-encode-method file-path file-name))
1799 (insert-buffer-substring uubuf)
1800 (error "Encoding unsuccessful"))
1801 (kill-buffer uubuf))
1804 ;; Posts the article and all of the encoded file.
1805 (defun gnus-uu-post-encoded (file-name &optional threaded)
1806 (let ((send-buffer-name "*uuencode send buffer*")
1807 (encoded-buffer-name "*encoded buffer*")
1808 (top-string "[ cut here %s (%s %d/%d) %s gnus-uu ]")
1809 (separator (concat mail-header-separator "\n\n"))
1810 uubuf length parts header i end beg
1811 beg-line minlen buf post-buf whole-len beg-binary end-binary)
1813 (setq post-buf (current-buffer))
1815 (goto-char (point-min))
1816 (if (not (re-search-forward
1817 (if gnus-uu-post-separate-description
1818 (concat "^" (regexp-quote gnus-uu-post-binary-separator)
1820 (concat "^" (regexp-quote mail-header-separator) "$")) nil t))
1821 (error "Internal error: No binary/header separator"))
1824 (setq beg-binary (point))
1825 (setq end-binary (point-max))
1828 (set-buffer (setq uubuf (get-buffer-create encoded-buffer-name)))
1830 (insert-buffer-substring post-buf beg-binary end-binary)
1831 (goto-char (point-min))
1832 (setq length (count-lines 1 (point-max)))
1833 (setq parts (/ length gnus-uu-post-length))
1834 (if (not (< (% length gnus-uu-post-length) 4))
1835 (setq parts (1+ parts))))
1837 (if gnus-uu-post-separate-description
1839 (kill-region (point) (point-max))
1841 (goto-char (point-min))
1843 (concat "^" (regexp-quote mail-header-separator) "$") nil t)
1845 (setq header (buffer-substring 1 (point)))
1847 (goto-char (point-min))
1848 (if (not gnus-uu-post-separate-description)
1850 (if (and (not threaded) (re-search-forward "^Subject: " nil t))
1853 (insert (format " (0/%d)" parts))))
1859 (while (not (> i parts))
1860 (set-buffer (get-buffer-create send-buffer-name))
1863 (if (and threaded gnus-uu-post-message-id)
1864 (insert (format "References: %s\n" gnus-uu-post-message-id)))
1867 (- 62 (length (format top-string "" file-name i parts ""))))
1868 (if (> 1 (setq minlen (/ whole-len 2)))
1873 (make-string minlen ?-)
1876 (if (= 0 (% whole-len 2)) (1- minlen) minlen) ?-)))
1878 (goto-char (point-min))
1879 (if (not (re-search-forward "^Subject: " nil t))
1884 (insert (format " (%d/%d)" i parts)))
1885 (if (or (and (= i 2) gnus-uu-post-separate-description)
1886 (and (= i 1) (not gnus-uu-post-separate-description)))
1887 (replace-match "Subject: Re: "))))
1889 (goto-char (point-max))
1894 (goto-char (point-max))
1895 (forward-line gnus-uu-post-length))
1896 (if (and (= (1+ i) parts) (< (count-lines (point) (point-max)) 4))
1899 (insert-buffer-substring uubuf beg end)
1904 (goto-char (point-min))
1906 (concat "^" (regexp-quote mail-header-separator) "$") nil t)
1909 (if (re-search-forward
1910 (concat "^" (regexp-quote gnus-uu-post-binary-separator) "$")
1919 (and (setq buf (get-buffer send-buffer-name))
1921 (and (setq buf (get-buffer encoded-buffer-name))
1924 (if (not gnus-uu-post-separate-description)
1926 (set-buffer-modified-p nil)
1927 (and (fboundp 'bury-buffer) (bury-buffer))))))
1931 ;; gnus-uu.el ends here