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
)
258 (defvar gnus-uu-binhex-article-name nil
)
260 (defvar gnus-uu-generated-file-list nil
)
261 (defvar gnus-uu-work-dir nil
)
263 (defconst gnus-uu-output-buffer-name
" *Gnus UU Output*")
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
))))
370 (setq gnus-uu-binhex-article-name
371 (make-temp-name (concat gnus-uu-work-dir
"binhex")))
372 (gnus-uu-decode-with-method 'gnus-uu-binhex-article n dir
))
374 (defun gnus-uu-decode-uu-view (n)
375 "Uudecodes and views the current article."
377 (let ((gnus-view-pseudos (or gnus-view-pseudos
'automatic
)))
378 (gnus-uu-decode-uu n
)))
380 (defun gnus-uu-decode-uu-and-save-view (n dir
)
381 "Decodes, views and saves the resulting file."
383 (list current-prefix-arg
384 (read-file-name "Uudecode, view and save in dir: "
386 gnus-uu-default-dir t
)))
387 (let ((gnus-view-pseudos (or gnus-view-pseudos
'automatic
)))
388 (gnus-uu-decode-uu-and-save n dir
)))
390 (defun gnus-uu-decode-unshar-view (n)
391 "Unshars and views the current article."
393 (let ((gnus-view-pseudos (or gnus-view-pseudos
'automatic
)))
394 (gnus-uu-decode-unshar n
)))
396 (defun gnus-uu-decode-unshar-and-save-view (n dir
)
397 "Unshars and saves the current article."
399 (list current-prefix-arg
400 (read-file-name "Unshar, view and save in dir: "
402 gnus-uu-default-dir t
)))
403 (let ((gnus-view-pseudos (or gnus-view-pseudos
'automatic
)))
404 (gnus-uu-decode-unshar-and-save n dir
)))
406 (defun gnus-uu-decode-save-view (n file
)
407 "Saves and views the current article."
409 (list current-prefix-arg
410 (read-file-name (if gnus-uu-save-separate-articles
411 "Save articles is dir: "
412 "Save articles in file: ")
413 gnus-uu-default-dir gnus-uu-default-dir
)))
414 (let ((gnus-view-pseudos (or gnus-view-pseudos
'automatic
)))
415 (gnus-uu-decode-save n file
)))
417 (defun gnus-uu-decode-binhex-view (n file
)
418 "Unbinhexes and views the current article."
420 (list current-prefix-arg
421 (read-file-name "Unbinhex, view and save in dir: "
422 gnus-uu-default-dir gnus-uu-default-dir
)))
423 (setq gnus-uu-binhex-article-name
424 (make-temp-name (concat gnus-uu-work-dir
"binhex")))
425 (let ((gnus-view-pseudos (or gnus-view-pseudos
'automatic
)))
426 (gnus-uu-decode-binhex n file
)))
429 ;; Digest and forward articles
431 (defun gnus-uu-digest-mail-forward (n &optional post
)
432 "Digests and forwards all articles in this series."
434 (let ((gnus-uu-save-in-digest t
)
435 (file (make-temp-name (concat gnus-uu-tmp-dir
"forward")))
437 (gnus-uu-decode-save n file
)
438 (gnus-uu-add-file file
)
439 (setq buf
(switch-to-buffer (get-buffer-create " *gnus-uu-forward*")))
440 (gnus-add-current-to-buffer-list)
442 (delete-other-windows)
444 (goto-char (point-min))
445 (and (re-search-forward "^Subject: ")
447 (delete-region (point) (gnus-point-at-eol))
448 (insert "Digested Articles")))
449 (goto-char (point-min))
450 (and (re-search-forward "^From: ")
452 (delete-region (point) (gnus-point-at-eol))
455 (gnus-forward-using-post)
456 (funcall gnus-mail-forward-method
))
460 (defun gnus-uu-digest-post-forward (n)
461 "Digest and forward to a newsgroup."
463 (gnus-uu-digest-mail-forward n t
))
467 (defun gnus-uu-mark-by-regexp (regexp)
468 "Ask for a regular expression and set the process mark on all articles that match."
469 (interactive (list (read-from-minibuffer "Mark (regexp): ")))
470 (gnus-set-global-variables)
471 (let ((articles (gnus-uu-find-articles-matching regexp
)))
473 (gnus-summary-set-process-mark (car articles
))
474 (setq articles
(cdr articles
)))
476 (gnus-summary-position-cursor))
478 (defun gnus-uu-mark-series ()
479 "Mark the current series with the process mark."
481 (gnus-set-global-variables)
482 (let ((articles (gnus-uu-find-articles-matching)))
484 (gnus-summary-set-process-mark (car articles
))
485 (setq articles
(cdr articles
)))
487 (gnus-summary-position-cursor))
489 (defun gnus-uu-mark-region (beg end
)
490 "Marks all articles between point and mark."
492 (gnus-set-global-variables)
495 (while (< (point) end
)
496 (gnus-summary-set-process-mark (gnus-summary-article-number))
498 (gnus-summary-position-cursor))
500 (defun gnus-uu-mark-thread ()
501 "Marks all articles downwards in this thread."
503 (gnus-set-global-variables)
504 (let ((level (gnus-summary-thread-level)))
505 (while (and (gnus-summary-set-process-mark (gnus-summary-article-number))
506 (zerop (gnus-summary-next-subject 1))
507 (> (gnus-summary-thread-level) level
))))
508 (gnus-summary-position-cursor))
510 (defun gnus-uu-mark-sparse ()
511 "Mark all series that have some articles marked."
513 (gnus-set-global-variables)
514 (let ((marked (nreverse gnus-newsgroup-processable
))
515 subject articles total headers
)
516 (or marked
(error "No articles marked with the process mark"))
517 (setq gnus-newsgroup-processable nil
)
520 (and (setq headers
(gnus-get-header-by-number (car marked
)))
521 (setq subject
(mail-header-subject headers
)
522 articles
(gnus-uu-find-articles-matching
523 (gnus-uu-reginize-string subject
))
524 total
(nconc total articles
)))
526 (gnus-summary-set-process-mark (car articles
))
527 (setcdr marked
(delq (car articles
) (cdr marked
)))
528 (setq articles
(cdr articles
)))
529 (setq marked
(cdr marked
)))
530 (setq gnus-newsgroup-processable
(nreverse total
)))
531 (gnus-summary-position-cursor)))
533 (defun gnus-uu-mark-all ()
534 "Mark all articles in \"series\" order."
536 (gnus-set-global-variables)
537 (setq gnus-newsgroup-processable nil
)
539 (goto-char (point-min))
541 (while (and (not (eobp))
542 (setq number
(gnus-summary-article-number)))
543 (if (not (memq number gnus-newsgroup-processable
))
544 (save-excursion (gnus-uu-mark-series)))
546 (gnus-summary-position-cursor))
548 ;; All PostScript functions written by Erik Selberg <speed@cs.washington.edu>.
550 (defun gnus-uu-decode-postscript (n)
551 "Gets postscript of the current article."
553 (gnus-uu-decode-with-method 'gnus-uu-decode-postscript-article n
))
555 (defun gnus-uu-decode-postscript-view (n)
556 "Gets and views the current article."
558 (let ((gnus-view-pseudos (or gnus-view-pseudos
'automatic
)))
559 (gnus-uu-decode-postscript n
)))
561 (defun gnus-uu-decode-postscript-and-save (n dir
)
562 "Extracts postscript and saves the current article."
564 (list current-prefix-arg
565 (file-name-as-directory
566 (read-file-name "Save in dir: "
568 gnus-uu-default-dir t
))))
569 (gnus-uu-decode-with-method 'gnus-uu-decode-postscript-article n dir
))
572 (defun gnus-uu-decode-postscript-and-save-view (n dir
)
573 "Decodes, views and saves the resulting file."
575 (list current-prefix-arg
576 (read-file-name "Where do you want to save the file(s)? "
578 gnus-uu-default-dir t
)))
579 (let ((gnus-view-pseudos (or gnus-view-pseudos
'automatic
)))
580 (gnus-uu-decode-postscript-and-save n dir
)))
583 ;; Internal functions.
585 (defun gnus-uu-decode-with-method (method n
&optional save not-insert scan
)
586 (gnus-uu-initialize scan
)
587 (if save
(setq gnus-uu-default-dir save
))
588 (let ((articles (gnus-uu-get-list-of-articles n
))
590 (setq files
(gnus-uu-grab-articles articles method t
))
591 (let ((gnus-current-article (car articles
)))
592 (and scan
(setq files
(gnus-uu-scan-directory gnus-uu-work-dir
))))
593 (and save
(gnus-uu-save-files files save
))
594 (setq files
(gnus-uu-unpack-files files
))
595 (gnus-uu-add-file (mapcar (lambda (file) (cdr (assq 'name file
))) files
))
596 (setq files
(nreverse (gnus-uu-get-actions files
)))
597 (or not-insert
(gnus-summary-insert-pseudos files save
))))
599 ;; Return a list of files in dir.
600 (defun gnus-uu-scan-directory (dir)
601 (let ((files (directory-files dir t
))
604 (cond ((string-match "/\\.\\.?$" (car files
)))
605 ((file-directory-p (car files
))
606 (setq dirs
(cons (car files
) dirs
)))
607 (t (setq out
(cons (list (cons 'name
(car files
))
608 (cons 'article gnus-current-article
))
610 (setq files
(cdr files
)))
611 (apply 'nconc out
(mapcar (lambda (d) (gnus-uu-scan-directory d
))
614 (defun gnus-uu-save-files (files dir
)
615 (let ((len (length files
))
619 (setq file
(cdr (assq 'name
(car files
))))
622 (setq to-file
(if (file-directory-p dir
)
623 (concat dir
(file-name-nondirectory file
))
625 (and (or (not (file-exists-p to-file
))
626 (gnus-y-or-n-p (format "%s exists; overwrite? "
628 (copy-file file to-file t t
))))
629 (setq files
(cdr files
)))
630 (message "Saved %d file%s" len
(if (> len
1) "s" ""))))
632 ;; Functions for saving and possibly digesting articles without
635 ;; Function called by gnus-uu-grab-articles to treat each article.
636 (defun gnus-uu-save-article (buffer in-state
)
638 (gnus-uu-save-separate-articles
641 (write-region 1 (point-max) (concat gnus-uu-saved-article-name
642 gnus-current-article
))
643 (cond ((eq in-state
'first
) (list gnus-uu-saved-article-name
'begin
))
644 ((eq in-state
'first-and-last
) (list gnus-uu-saved-article-name
646 ((eq in-state
'last
) (list 'end
))
647 (t (list 'middle
)))))
648 ((not gnus-uu-save-in-digest
)
651 (write-region 1 (point-max) gnus-uu-saved-article-name t
)
652 (cond ((eq in-state
'first
) (list gnus-uu-saved-article-name
'begin
))
653 ((eq in-state
'first-and-last
) (list gnus-uu-saved-article-name
655 ((eq in-state
'last
) (list 'end
))
656 (t (list 'middle
)))))
658 (let ((name (file-name-nondirectory gnus-uu-saved-article-name
))
659 beg subj headers headline sorthead body end-string state
)
660 (if (or (eq in-state
'first
)
661 (eq in-state
'first-and-last
))
663 (setq state
(list 'begin
))
664 (save-excursion (set-buffer (get-buffer-create "*gnus-uu-body*"))
667 (set-buffer (get-buffer-create "*gnus-uu-pre*"))
670 "Date: %s\nFrom: %s\nSubject: %s Digest\n\nTopics:\n"
671 (current-time-string) name name
))))
672 (if (not (eq in-state
'end
))
673 (setq state
(list 'middle
))))
675 (set-buffer (get-buffer "*gnus-uu-body*"))
676 (goto-char (setq beg
(point-max)))
680 (let (buffer-read-only)
681 (set-text-properties (point-min) (point-max) nil
)
682 ;; These two are necessary for XEmacs 19.12 fascism.
683 (put-text-property (point-min) (point-max) 'invisible nil
)
684 (put-text-property (point-min) (point-max) 'intangible nil
))
685 (goto-char (point-min))
686 (re-search-forward "\n\n")
687 (setq body
(buffer-substring (1- (point)) (point-max)))
688 (narrow-to-region 1 (point))
689 (if (not (setq headers gnus-uu-digest-headers
))
690 (setq sorthead
(buffer-substring (point-min) (point-max)))
692 (setq headline
(car headers
))
693 (setq headers
(cdr headers
))
694 (goto-char (point-min))
695 (if (re-search-forward headline nil t
)
700 (or (and (re-search-forward "^[^ \t]" nil t
)
702 (progn (forward-line 1) (point)))))))))
704 (insert sorthead
)(goto-char (point-max))
705 (insert body
)(goto-char (point-max))
706 (insert (concat "\n" (make-string 30 ?-
) "\n\n"))
708 (if (re-search-forward "^Subject: \\(.*\\)$" nil t
)
710 (setq subj
(buffer-substring (match-beginning 1) (match-end 1)))
712 (set-buffer (get-buffer "*gnus-uu-pre*"))
713 (insert (format " %s\n" subj
))))))
714 (if (or (eq in-state
'last
)
715 (eq in-state
'first-and-last
))
718 (set-buffer (get-buffer "*gnus-uu-pre*"))
719 (insert (format "\n\n%s\n\n" (make-string 70 ?-
)))
720 (write-region 1 (point-max) gnus-uu-saved-article-name
))
722 (set-buffer (get-buffer "*gnus-uu-body*"))
723 (goto-char (point-max))
725 (concat (setq end-string
(format "End of %s Digest" name
))
727 (insert (concat (make-string (length end-string
) ?
*) "\n"))
728 (write-region 1 (point-max) gnus-uu-saved-article-name t
))
729 (kill-buffer (get-buffer "*gnus-uu-pre*"))
730 (kill-buffer (get-buffer "*gnus-uu-body*"))
731 (setq state
(cons 'end state
))))
732 (if (memq 'begin state
)
733 (cons gnus-uu-saved-article-name state
)
736 ;; Binhex treatment - not very advanced.
738 (defconst gnus-uu-binhex-body-line
739 "^[^:]...............................................................$")
740 (defconst gnus-uu-binhex-begin-line
741 "^:...............................................................$")
742 (defconst gnus-uu-binhex-end-line
745 (defun gnus-uu-binhex-article (buffer in-state
)
746 (let (state start-char
)
750 (goto-char (point-min))
751 (if (not (re-search-forward gnus-uu-binhex-begin-line nil t
))
752 (if (not (re-search-forward gnus-uu-binhex-body-line nil t
))
753 (setq state
(list 'wrong-type
))))
755 (if (memq 'wrong-type state
)
758 (setq start-char
(point))
759 (if (looking-at gnus-uu-binhex-begin-line
)
761 (setq state
(list 'begin
))
762 (write-region 1 1 gnus-uu-binhex-article-name
))
763 (setq state
(list 'middle
)))
764 (goto-char (point-max))
765 (re-search-backward (concat gnus-uu-binhex-body-line
"\\|"
766 gnus-uu-binhex-end-line
) nil t
)
767 (if (looking-at gnus-uu-binhex-end-line
)
768 (setq state
(if (memq 'begin state
)
773 (if (file-exists-p gnus-uu-binhex-article-name
)
774 (append-to-file start-char
(point) gnus-uu-binhex-article-name
))))
775 (if (memq 'begin state
)
776 (cons gnus-uu-binhex-article-name state
)
781 (defun gnus-uu-decode-postscript-article (process-buffer in-state
)
782 (let ((state (list 'ok
))
783 start-char end-char file-name
)
785 (set-buffer process-buffer
)
786 (goto-char (point-min))
787 (if (not (re-search-forward gnus-uu-postscript-begin-string nil t
))
788 (setq state
(list 'wrong-type
))
790 (setq start-char
(point))
791 (if (not (re-search-forward gnus-uu-postscript-end-string nil t
))
792 (setq state
(list 'wrong-type
))
793 (setq end-char
(point))
794 (set-buffer (get-buffer-create gnus-uu-output-buffer-name
))
795 (insert-buffer-substring process-buffer start-char end-char
)
796 (setq file-name
(concat gnus-uu-work-dir
(cdr gnus-article-current
) ".ps"))
797 (write-region (point-min) (point-max) file-name
)
798 (setq state
(list file-name
'begin
'end
))
807 (defun gnus-uu-get-actions (files)
811 (setq name
(cdr (assq 'name
(car files
))))
813 (setq action
(gnus-uu-get-action name
))
814 (setcar files
(nconc (list (if (string= action
"gnus-uu-archive")
815 (cons 'action
"file")
816 (cons 'action action
))
817 (cons 'execute
(if (string-match "%" action
)
819 (concat action
" " name
))))
821 (setq files
(cdr files
)))
824 (defun gnus-uu-get-action (file-name)
827 (gnus-uu-choose-action
830 gnus-uu-user-view-rules
831 (if gnus-uu-ignore-default-view-rules
833 gnus-uu-default-view-rules
)
834 gnus-uu-user-view-rules-end
)))
835 (if (and (not (string= (or action
"") "gnus-uu-archive"))
836 gnus-uu-view-with-metamail
)
838 (gnus-uu-choose-action file-name gnus-uu-ext-to-mime-list
))
839 (setq action
(format "metamail -d -b -c \"%s\"" action
))))
843 ;; Functions for treating subjects and collecting series.
845 (defun gnus-uu-reginize-string (string)
846 ;; Takes a string and puts a \ in front of every special character;
847 ;; ignores any leading "version numbers" thingies that they use in
848 ;; the comp.binaries groups, and either replaces anything that looks
849 ;; like "2/3" with "[0-9]+/[0-9]+" or, if it can't find something
850 ;; like that, replaces the last two numbers with "[0-9]+". This, in
851 ;; my experience, should get most postings of a series.
853 (vernum "v[0-9]+[a-z][0-9]+:")
856 (set-buffer (get-buffer-create gnus-uu-output-buffer-name
))
857 (buffer-disable-undo (current-buffer))
859 (insert (regexp-quote string
))
862 (setq case-fold-search nil
)
863 (goto-char (point-min))
864 (if (looking-at vernum
)
866 (replace-match vernum t t
)
867 (setq beg
(length vernum
))))
870 (if (re-search-forward "[ \t]*[0-9]+/[0-9]+" nil t
)
871 (replace-match " [0-9]+/[0-9]+")
874 (if (re-search-forward "[0-9]+[ \t]*of[ \t]*[0-9]+" nil t
)
875 (replace-match "[0-9]+ of [0-9]+")
878 (while (and (re-search-backward "[0-9]" nil t
) (> count
0))
881 (< 1 (goto-char (1- (point))))))
882 (re-search-forward "[0-9]+" nil t
)
883 (replace-match "[0-9]+")
885 (setq count
(1- count
)))))
888 (while (re-search-forward "[ \t]+" nil t
)
889 (replace-match "[ \t]*" t t
))
891 (buffer-substring 1 (point-max)))))
893 (defun gnus-uu-get-list-of-articles (n)
894 ;; If N is non-nil, the article numbers of the N next articles
896 ;; If any articles have been marked as processable, they will be
898 ;; Failing that, articles that have subjects that are part of the
899 ;; same "series" as the current will be returned.
903 (let ((backward (< n
0))
907 (setq articles
(cons (gnus-summary-article-number)
909 (gnus-summary-search-forward nil nil backward
))
911 (nreverse articles
)))
912 (gnus-newsgroup-processable
913 (reverse gnus-newsgroup-processable
))
915 (gnus-uu-find-articles-matching)))))
917 (defun gnus-uu-string< (l1 l2
)
918 (string< (car l1
) (car l2
)))
920 (defun gnus-uu-find-articles-matching
921 (&optional subject only-unread do-not-translate
)
922 ;; Finds all articles that matches the regexp SUBJECT. If it is
923 ;; nil, the current article name will be used. If ONLY-UNREAD is
924 ;; non-nil, only unread articles are chosen. If DO-NOT-TRANSLATE is
925 ;; non-nil, article names are not equalized before sorting.
926 (let ((subject (or subject
927 (gnus-uu-reginize-string (gnus-summary-subject-string))))
932 ;; Collect all subjects matching subject.
933 (let ((case-fold-search t
)
935 (goto-char (point-min))
937 (and (setq subj
(gnus-summary-subject-string))
938 (string-match subject subj
)
939 (or (not only-unread
)
940 (= (setq mark
(gnus-summary-article-mark))
942 (= mark gnus-ticked-mark
)
943 (= mark gnus-dormant-mark
))
944 (setq list-of-subjects
945 (cons (cons subj
(gnus-summary-article-number))
949 ;; Expand numbers, sort, and return the list of article
951 (mapcar (lambda (sub) (cdr sub
))
952 (sort (gnus-uu-expand-numbers
954 (not do-not-translate
))
955 'gnus-uu-string
<))))))
957 (defun gnus-uu-expand-numbers (string-list &optional translate
)
958 ;; Takes a list of strings and "expands" all numbers in all the
959 ;; strings. That is, this function makes all numbers equal length by
960 ;; prepending lots of zeroes before each number. This is to ease later
961 ;; sorting to find out what sequence the articles are supposed to be
962 ;; decoded in. Returns the list of expanded strings.
963 (let ((out-list string-list
)
966 (set-buffer (get-buffer-create gnus-uu-output-buffer-name
))
967 (buffer-disable-undo (current-buffer))
970 (insert (car (car string-list
)))
971 ;; Translate multiple spaces to one space.
972 (goto-char (point-min))
973 (while (re-search-forward "[ \t]+" nil t
)
975 ;; Translate all characters to "a".
976 (goto-char (point-min))
978 (while (re-search-forward "[A-Za-z]" nil t
)
979 (replace-match "a" t t
)))
981 (goto-char (point-min))
982 (while (re-search-forward "[0-9]+" nil t
)
985 (string-to-int (buffer-substring
986 (match-beginning 0) (match-end 0))))))
987 (setq string
(buffer-substring 1 (point-max)))
988 (setcar (car string-list
) string
)
989 (setq string-list
(cdr string-list
))))
993 ;; `gnus-uu-grab-articles' is the general multi-article treatment
994 ;; function. It takes a list of articles to be grabbed and a function
995 ;; to apply to each article.
997 ;; The function to be called should take two parameters. The first
998 ;; parameter is the article buffer. The function should leave the
999 ;; result, if any, in this buffer. Most treatment functions will just
1000 ;; generate files...
1002 ;; The second parameter is the state of the list of articles, and can
1003 ;; have four values: `first', `middle', `last' and `first-and-last'.
1005 ;; The function should return a list. The list may contain the
1006 ;; following symbols:
1007 ;; `error' if an error occurred
1008 ;; `begin' if the beginning of an encoded file has been received
1009 ;; If the list returned contains a `begin', the first element of
1010 ;; the list *must* be a string with the file name of the decoded
1012 ;; `end' if the the end of an encoded file has been received
1013 ;; `middle' if the article was a body part of an encoded file
1014 ;; `wrong-type' if the article was not a part of an encoded file
1015 ;; `ok', which can be used everything is ok
1017 (defvar gnus-uu-has-been-grabbed nil
)
1019 (defun gnus-uu-unmark-list-of-grabbed (&optional dont-unmark-last-article
)
1021 (if (not (and gnus-uu-has-been-grabbed
1022 gnus-uu-unmark-articles-not-decoded
))
1024 (if dont-unmark-last-article
1026 (setq art
(car gnus-uu-has-been-grabbed
))
1027 (setq gnus-uu-has-been-grabbed
(cdr gnus-uu-has-been-grabbed
))))
1028 (while gnus-uu-has-been-grabbed
1029 (gnus-summary-tick-article (car gnus-uu-has-been-grabbed
) t
)
1030 (setq gnus-uu-has-been-grabbed
(cdr gnus-uu-has-been-grabbed
)))
1031 (if dont-unmark-last-article
1032 (setq gnus-uu-has-been-grabbed
(list art
))))))
1034 ;; This function takes a list of articles and a function to apply to
1035 ;; each article grabbed.
1037 ;; This function returns a list of files decoded if the grabbing and
1038 ;; the process-function has been successful and nil otherwise.
1039 (defun gnus-uu-grab-articles
1040 (articles process-function
&optional sloppy limit no-errors
)
1041 (let ((state 'first
)
1042 has-been-begin article result-file result-files process-state
1045 (if (not (gnus-server-opened gnus-current-select-method
))
1047 (gnus-start-news-server)
1048 (gnus-request-group gnus-newsgroup-name
)))
1050 (setq gnus-uu-has-been-grabbed nil
)
1052 (while (and articles
1053 (not (memq 'error process-state
))
1055 (not (memq 'end process-state
))))
1057 (setq article
(car articles
))
1058 (setq articles
(cdr articles
))
1059 (setq gnus-uu-has-been-grabbed
(cons article gnus-uu-has-been-grabbed
))
1061 (if (eq articles
())
1062 (if (eq state
'first
)
1063 (setq state
'first-and-last
)
1064 (setq state
'last
)))
1066 (message "Getting article %d, %s" article
(gnus-uu-part-number article
))
1068 (if (not (= (or gnus-current-article
0) article
))
1069 (let ((nntp-async-number nil
))
1070 (gnus-request-article article gnus-newsgroup-name
1072 (setq gnus-last-article gnus-current-article
)
1073 (setq gnus-current-article article
)
1074 (setq gnus-article-current
(cons gnus-newsgroup-name article
))
1075 (if (stringp nntp-server-buffer
)
1076 (setq article-buffer nntp-server-buffer
)
1077 (setq article-buffer
(buffer-name nntp-server-buffer
))))
1078 (gnus-summary-stop-page-breaking)
1079 (setq article-buffer gnus-article-buffer
))
1081 (buffer-disable-undo article-buffer
)
1082 ;; Mark article as read.
1083 (and (memq article gnus-newsgroup-processable
)
1084 (gnus-summary-remove-process-mark article
))
1085 (run-hooks 'gnus-mark-article-hook
)
1087 (setq process-state
(funcall process-function article-buffer state
))
1089 (if (or (memq 'begin process-state
)
1090 (and (or (eq state
'first
) (eq state
'first-and-last
))
1091 (memq 'ok process-state
)))
1094 (if (and result-file
(file-exists-p result-file
))
1095 (delete-file result-file
)))
1096 (if (memq 'begin process-state
)
1097 (setq result-file
(car process-state
)))
1098 (setq has-been-begin t
)))
1100 (if (memq 'end process-state
)
1102 (setq gnus-uu-has-been-grabbed nil
)
1103 (setq result-files
(cons (list (cons 'name result-file
)
1104 (cons 'article article
))
1106 (setq has-been-begin nil
)
1107 (and limit
(= (length result-files
) limit
)
1108 (setq articles nil
))))
1110 (if (and (or (eq state
'last
) (eq state
'first-and-last
))
1111 (not (memq 'end process-state
)))
1112 (if (and result-file
(file-exists-p result-file
))
1113 (delete-file result-file
)))
1115 (if (not (memq 'wrong-type process-state
))
1117 (if gnus-uu-unmark-articles-not-decoded
1118 (gnus-summary-tick-article article t
)))
1120 (if (and (not has-been-begin
)
1122 (or (memq 'end process-state
)
1123 (memq 'middle process-state
)))
1125 (setq process-state
(list 'error
))
1126 (message "No begin part at the beginning")
1128 (setq state
'middle
)))
1130 ;; Make sure the last article is put in the article buffer & fix
1133 (if (not (string= article-buffer gnus-article-buffer
))
1135 (set-buffer (get-buffer-create gnus-article-buffer
))
1136 (let ((buffer-read-only nil
))
1139 (insert-buffer-substring article-buffer
)
1140 (gnus-set-mode-line 'article
)
1141 (goto-char (point-min)))))
1143 (gnus-set-mode-line 'summary
)
1147 (if (not has-been-begin
)
1148 (if (not no-errors
) (message "Wrong type file"))
1149 (if (memq 'error process-state
)
1150 (setq result-files nil
)
1151 (if (not (or (memq 'ok process-state
)
1152 (memq 'end process-state
)))
1155 (message "End of articles reached before end of file"))
1156 (setq result-files nil
))
1157 (gnus-uu-unmark-list-of-grabbed)))))
1160 (defun gnus-uu-part-number (article)
1161 (let ((subject (mail-header-subject (gnus-get-header-by-number article
))))
1162 (if (string-match "[0-9]+ */[0-9]+\\|[0-9]+ * of *[0-9]+"
1164 (substring subject
(match-beginning 0) (match-end 0))
1167 (defun gnus-uu-uudecode-sentinel (process event
)
1168 (delete-process (get-process process
)))
1170 (defun gnus-uu-uustrip-article (process-buffer in-state
)
1171 ;; Uudecodes a file asynchronously.
1172 (let ((state (list 'ok
))
1173 (process-connection-type nil
)
1174 start-char pst name-beg name-end
)
1176 (set-buffer process-buffer
)
1177 (let ((case-fold-search nil
)
1178 (buffer-read-only nil
))
1180 (goto-char (point-min))
1182 (if gnus-uu-kill-carriage-return
1184 (while (search-forward "\r" nil t
)
1185 (delete-backward-char 1))
1186 (goto-char (point-min))))
1188 (if (not (re-search-forward gnus-uu-begin-string nil t
))
1189 (if (not (re-search-forward gnus-uu-body-line nil t
))
1190 (setq state
(list 'wrong-type
))))
1192 (if (memq 'wrong-type state
)
1195 (setq start-char
(point))
1197 (if (looking-at gnus-uu-begin-string
)
1199 (setq name-end
(match-end 1)
1200 name-beg
(match-beginning 1))
1201 ;; Remove any non gnus-uu-body-line right after start.
1203 (or (looking-at gnus-uu-body-line
)
1206 ; Replace any slashes and spaces in file names before decoding
1207 (goto-char name-beg
)
1208 (while (re-search-forward "/" name-end t
)
1209 (replace-match ","))
1210 (goto-char name-beg
)
1211 (while (re-search-forward " " name-end t
)
1212 (replace-match "_"))
1213 (goto-char name-beg
)
1214 (if (re-search-forward "_*$" name-end t
)
1217 (setq gnus-uu-file-name
(buffer-substring name-beg name-end
))
1218 (and gnus-uu-uudecode-process
1219 (setq pst
(process-status
1220 (or gnus-uu-uudecode-process
"nevair")))
1221 (if (or (eq pst
'stop
) (eq pst
'run
))
1223 (delete-process gnus-uu-uudecode-process
)
1224 (gnus-uu-unmark-list-of-grabbed t
))))
1225 (if (get-process "*uudecode*")
1226 (delete-process "*uudecode*"))
1227 (setq gnus-uu-uudecode-process
1230 (get-buffer-create gnus-uu-output-buffer-name
)
1232 (format "cd %s ; uudecode" gnus-uu-work-dir
)))
1233 (set-process-sentinel
1234 gnus-uu-uudecode-process
'gnus-uu-uudecode-sentinel
)
1235 (setq state
(list 'begin
))
1236 (gnus-uu-add-file (concat gnus-uu-work-dir gnus-uu-file-name
)))
1237 (setq state
(list 'middle
)))
1239 (goto-char (point-max))
1242 (concat gnus-uu-body-line
"\\|" gnus-uu-end-string
) nil t
)
1245 (if (looking-at gnus-uu-end-string
)
1246 (setq state
(cons 'end state
)))
1249 (and gnus-uu-uudecode-process
1250 (setq pst
(process-status
1251 (or gnus-uu-uudecode-process
"nevair")))
1252 (if (or (eq pst
'run
) (eq pst
'stop
))
1254 (if gnus-uu-correct-stripped-uucode
1256 (gnus-uu-check-correct-stripped-uucode
1258 (goto-char (point-max))
1260 (concat gnus-uu-body-line
"\\|"
1266 (process-send-region gnus-uu-uudecode-process
1270 (delete-process gnus-uu-uudecode-process
)
1271 (message "gnus-uu: Couldn't uudecode")
1273 (setq state
(list 'wrong-type
)))))
1275 (if (memq 'end state
)
1276 (accept-process-output gnus-uu-uudecode-process
)))
1277 (setq state
(list 'wrong-type
))))
1278 (if (not gnus-uu-uudecode-process
)
1279 (setq state
(list 'wrong-type
)))))
1281 (if (memq 'begin state
)
1282 (cons (concat gnus-uu-work-dir gnus-uu-file-name
) state
)
1285 ;; This function is used by `gnus-uu-grab-articles' to treat
1286 ;; a shared article.
1287 (defun gnus-uu-unshar-article (process-buffer in-state
)
1288 (let ((state (list 'ok
))
1291 (set-buffer process-buffer
)
1292 (goto-char (point-min))
1293 (if (not (re-search-forward gnus-uu-shar-begin-string nil t
))
1294 (setq state
(list 'wrong-type
))
1296 (setq start-char
(point))
1297 (call-process-region
1298 start-char
(point-max) "sh" nil
1299 (get-buffer-create gnus-uu-output-buffer-name
) nil
1300 "-c" (concat "cd " gnus-uu-work-dir
" ; sh"))))
1303 ;; Returns the name of what the shar file is going to unpack.
1304 (defun gnus-uu-find-name-in-shar ()
1305 (let ((oldpoint (point))
1307 (goto-char (point-min))
1308 (if (re-search-forward gnus-uu-shar-name-marker nil t
)
1309 (setq res
(buffer-substring (match-beginning 1) (match-end 1))))
1310 (goto-char oldpoint
)
1313 ;; `gnus-uu-choose-action' chooses what action to perform given the name
1314 ;; and `gnus-uu-file-action-list'. Returns either nil if no action is
1315 ;; found, or the name of the command to run if such a rule is found.
1316 (defun gnus-uu-choose-action (file-name file-action-list
&optional no-ignore
)
1317 (let ((action-list (copy-sequence file-action-list
))
1318 (case-fold-search t
)
1323 (and gnus-uu-ignore-files-by-name
1324 (string-match gnus-uu-ignore-files-by-name file-name
)))
1326 (and gnus-uu-ignore-files-by-type
1327 (string-match gnus-uu-ignore-files-by-type
1328 (or (gnus-uu-choose-action
1329 file-name gnus-uu-ext-to-mime-list t
)
1331 (while (not (or (eq action-list
()) action
))
1332 (setq rule
(car action-list
))
1333 (setq action-list
(cdr action-list
))
1334 (if (string-match (car rule
) file-name
)
1335 (setq action
(car (cdr rule
))))))
1338 (defun gnus-uu-treat-archive (file-path)
1339 ;; Unpacks an archive. Returns t if unpacking is successful.
1340 (let ((did-unpack t
)
1342 (setq action
(gnus-uu-choose-action
1343 file-path
(append gnus-uu-user-archive-rules
1344 (if gnus-uu-ignore-default-archive-rules
1346 gnus-uu-default-archive-rules
))))
1348 (if (not action
) (error "No unpackers for the file %s" file-path
))
1350 (string-match "/[^/]*$" file-path
)
1351 (setq dir
(substring file-path
0 (match-beginning 0)))
1353 (if (member action gnus-uu-destructive-archivers
)
1354 (copy-file file-path
(concat file-path
"~") t
))
1356 (setq command
(format "cd %s ; %s" dir
(gnus-uu-command action file-path
)))
1359 (set-buffer (get-buffer-create gnus-uu-output-buffer-name
))
1362 (message "Unpacking: %s..." (gnus-uu-command action file-path
))
1364 (if (= 0 (call-process "sh" nil
1365 (get-buffer-create gnus-uu-output-buffer-name
)
1368 (message "Error during unpacking of archive")
1369 (setq did-unpack nil
))
1371 (if (member action gnus-uu-destructive-archivers
)
1372 (rename-file (concat file-path
"~") file-path t
))
1376 (defun gnus-uu-dir-files (dir)
1377 (let ((dirs (directory-files dir t
"[^/][^\\.][^\\.]?$"))
1380 (if (file-directory-p (setq file
(car dirs
)))
1381 (setq files
(append files
(gnus-uu-dir-files file
)))
1382 (setq files
(cons file files
)))
1383 (setq dirs
(cdr dirs
)))
1386 (defun gnus-uu-unpack-files (files &optional ignore
)
1387 ;; Go through FILES and look for files to unpack.
1388 (let* ((totfiles (gnus-uu-ls-r gnus-uu-work-dir
))
1390 file did-unpack file-entry
)
1391 (gnus-uu-add-file totfiles
)
1393 (setq file
(cdr (setq file-entry
(assq 'name
(car files
)))))
1394 (if (and (not (member file ignore
))
1395 (equal (gnus-uu-get-action (file-name-nondirectory file
))
1398 (setq did-unpack
(cons file did-unpack
))
1399 (or (gnus-uu-treat-archive file
)
1400 (message "Error during unpacking of %s" file
))
1401 (let* ((newfiles (gnus-uu-ls-r gnus-uu-work-dir
))
1403 (gnus-uu-add-file newfiles
)
1405 (or (member (car nfiles
) totfiles
)
1406 (setq ofiles
(cons (list (cons 'name
(car nfiles
))
1407 (cons 'original file
))
1409 (setq nfiles
(cdr nfiles
)))
1410 (setq totfiles newfiles
))))
1411 (setq files
(cdr files
)))
1413 (gnus-uu-unpack-files ofiles
(append did-unpack ignore
))
1416 (defun gnus-uu-ls-r (dir)
1417 (let* ((files (gnus-uu-directory-files dir t
))
1420 (if (file-directory-p (car files
))
1422 (setq ofiles
(delete (car files
) ofiles
))
1423 (setq ofiles
(append ofiles
(gnus-uu-ls-r (car files
))))))
1424 (setq files
(cdr files
)))
1429 (defun gnus-uu-directory-files (dir &optional full
)
1430 (let (files out file
)
1431 (setq files
(directory-files dir full
))
1433 (setq file
(car files
))
1434 (setq files
(cdr files
))
1435 (or (string-match "/\\.\\.?$" file
)
1436 (setq out
(cons file out
))))
1437 (setq out
(nreverse out
))
1440 (defun gnus-uu-check-correct-stripped-uucode (start end
)
1441 (let (found beg length
)
1442 (if (not gnus-uu-correct-stripped-uucode
)
1446 (if (re-search-forward " \\|`" end t
)
1451 (if (looking-at "\n") (replace-match ""))
1455 (if (looking-at (concat gnus-uu-begin-string
"\\|"
1456 gnus-uu-end-string
))
1463 (setq length
(- (point) beg
))))
1468 (if (not (= length
(- (point) beg
)))
1469 (insert (make-string (- length
(- (point) beg
)) ?
))))
1470 (forward-line 1))))))
1472 (defvar gnus-uu-tmp-alist nil
)
1474 (defun gnus-uu-initialize (&optional scan
)
1477 (if (setq entry
(assoc gnus-newsgroup-name gnus-uu-tmp-alist
))
1478 (if (file-exists-p (cdr entry
))
1479 (setq gnus-uu-work-dir
(cdr entry
))
1480 (setq gnus-uu-tmp-alist
(delq entry gnus-uu-tmp-alist
))
1483 (setq gnus-uu-tmp-dir
(file-name-as-directory
1484 (expand-file-name gnus-uu-tmp-dir
)))
1485 (if (not (file-directory-p gnus-uu-tmp-dir
))
1486 (error "Temp directory %s doesn't exist" gnus-uu-tmp-dir
)
1487 (if (not (file-writable-p gnus-uu-tmp-dir
))
1488 (error "Temp directory %s can't be written to"
1491 (setq gnus-uu-work-dir
1492 (make-temp-name (concat gnus-uu-tmp-dir
"gnus")))
1493 (gnus-uu-add-file gnus-uu-work-dir
)
1494 (if (not (file-directory-p gnus-uu-work-dir
))
1495 (gnus-make-directory gnus-uu-work-dir
))
1496 (set-file-modes gnus-uu-work-dir
448)
1497 (setq gnus-uu-work-dir
(file-name-as-directory gnus-uu-work-dir
))
1498 (setq gnus-uu-tmp-alist
(cons (cons gnus-newsgroup-name gnus-uu-work-dir
)
1499 gnus-uu-tmp-alist
)))))
1502 ;; Kills the temporary uu buffers, kills any processes, etc.
1503 (defun gnus-uu-clean-up ()
1505 (and gnus-uu-uudecode-process
1506 (setq pst
(process-status (or gnus-uu-uudecode-process
"nevair")))
1507 (if (or (eq pst
'stop
) (eq pst
'run
))
1508 (delete-process gnus-uu-uudecode-process
)))
1509 (and (setq buf
(get-buffer gnus-uu-output-buffer-name
))
1510 (kill-buffer buf
))))
1512 ;; `gnus-uu-check-for-generated-files' deletes any generated files that
1513 ;; hasn't been deleted, if, for instance, the user terminated decoding
1515 (defun gnus-uu-check-for-generated-files ()
1517 (while gnus-uu-generated-file-list
1518 (setq file
(car gnus-uu-generated-file-list
))
1519 (setq gnus-uu-generated-file-list
(cdr gnus-uu-generated-file-list
))
1520 (if (not (string-match "/\\.[\\.]?$" file
))
1522 (if (file-directory-p file
)
1523 (setq dirs
(cons file dirs
))
1524 (if (file-exists-p file
)
1525 (delete-file file
))))))
1526 (setq dirs
(nreverse dirs
))
1528 (setq file
(car dirs
))
1529 (setq dirs
(cdr dirs
))
1530 (if (file-directory-p file
)
1531 (if (string-match "/$" file
)
1532 (delete-directory (substring file
0 (match-beginning 0)))
1533 (delete-directory file
))))))
1535 ;; Add a file (or a list of files) to be checked (and deleted if it/they
1536 ;; still exists upon exiting the newsgroup).
1537 (defun gnus-uu-add-file (file)
1539 (setq gnus-uu-generated-file-list
1540 (cons file gnus-uu-generated-file-list
))
1541 (setq gnus-uu-generated-file-list
1542 (append file gnus-uu-generated-file-list
))))
1544 ;; Inputs an action and a file and returns a full command, putting
1545 ;; quotes round the file name and escaping any quotes in the file name.
1546 (defun gnus-uu-command (action file
)
1548 (while (string-match "!\\|`\\|\"\\|\\$\\|\\\\\\|&" file
)
1551 (concat ofile
(substring file
0 (match-beginning 0)) "\\"
1552 (substring file
(match-beginning 0) (match-end 0))))
1553 (setq file
(substring file
(1+ (match-beginning 0))))))
1554 (setq ofile
(concat "\"" ofile file
"\""))
1555 (if (string-match "%s" action
)
1556 (format action ofile
)
1557 (concat action
" " ofile
))))
1562 (add-hook 'gnus-exit-group-hook
'gnus-uu-clean-up
)
1563 (add-hook 'gnus-exit-group-hook
'gnus-uu-check-for-generated-files
)
1568 ;;; uuencoded posting
1574 ;; Any function that is to be used as and encoding method will take two
1575 ;; parameters: PATH-NAME and FILE-NAME. (E.g. "/home/gaga/spiral.jpg"
1576 ;; and "spiral.jpg", respectively.) The function should return nil if
1577 ;; the encoding wasn't successful.
1578 (defvar gnus-uu-post-encode-method
'gnus-uu-post-encode-uuencode
1579 "Function used for encoding binary files.
1580 There are three functions supplied with gnus-uu for encoding files:
1581 `gnus-uu-post-encode-uuencode', which does straight uuencoding;
1582 `gnus-uu-post-encode-mime', which encodes with base64 and adds MIME
1583 headers; and `gnus-uu-post-encode-mime-uuencode', which encodes with
1584 uuencode and adds MIME headers.")
1586 (defvar gnus-uu-post-include-before-composing nil
1587 "Non-nil means that gnus-uu will ask for a file to encode before you compose the article.
1588 If this variable is t, you can either include an encoded file with
1589 \\[gnus-uu-post-insert-binary-in-article] or have one included for you when you post the article.")
1591 (defvar gnus-uu-post-length
990
1592 "Maximum length of an article.
1593 The encoded file will be split into how many articles it takes to
1594 post the entire file.")
1596 (defvar gnus-uu-post-threaded nil
1597 "Non-nil means that gnus-uu will post the encoded file in a thread.
1598 This may not be smart, as no other decoder I have seen are able to
1599 follow threads when collecting uuencoded articles. (Well, I have seen
1600 one package that does that - gnus-uu, but somehow, I don't think that
1601 counts...) Default is nil.")
1603 (defvar gnus-uu-post-separate-description t
1604 "Non-nil means that the description will be posted in a separate article.
1605 The first article will typically be numbered (0/x). If this variable
1606 is nil, the description the user enters will be included at the
1607 beginning of the first article, which will be numbered (1/x). Default
1610 (defvar gnus-uu-post-binary-separator
"--binary follows this line--")
1611 (defvar gnus-uu-post-message-id nil
)
1612 (defvar gnus-uu-post-inserted-file-name nil
)
1613 (defvar gnus-uu-winconf-post-news nil
)
1615 (defun gnus-uu-post-news ()
1616 "Compose an article and post an encoded file."
1618 (setq gnus-uu-post-inserted-file-name nil
)
1619 (setq gnus-uu-winconf-post-news
(current-window-configuration))
1621 (gnus-summary-post-news)
1623 (use-local-map (copy-keymap (current-local-map)))
1624 (local-set-key "\C-c\C-c" 'gnus-summary-edit-article-done
)
1625 (local-set-key "\C-c\C-c" 'gnus-uu-post-news-inews
)
1626 (local-set-key "\C-c\C-s" 'gnus-uu-post-news-inews
)
1627 (local-set-key "\C-c\C-i" 'gnus-uu-post-insert-binary-in-article
)
1629 (if gnus-uu-post-include-before-composing
1630 (save-excursion (setq gnus-uu-post-inserted-file-name
1631 (gnus-uu-post-insert-binary)))))
1633 (defun gnus-uu-post-insert-binary-in-article ()
1634 "Inserts an encoded file in the buffer.
1635 The user will be asked for a file name."
1637 (if (not (eq (current-buffer) (get-buffer gnus-post-news-buffer
)))
1638 (error "Not in post-news buffer"))
1640 (setq gnus-uu-post-inserted-file-name
(gnus-uu-post-insert-binary))))
1642 ;; Encodes with uuencode and substitutes all spaces with backticks.
1643 (defun gnus-uu-post-encode-uuencode (path file-name
)
1644 (if (gnus-uu-post-encode-file "uuencode" path file-name
)
1646 (goto-char (point-min))
1648 (while (re-search-forward " " nil t
)
1649 (replace-match "`"))
1652 ;; Encodes with uuencode and adds MIME headers.
1653 (defun gnus-uu-post-encode-mime-uuencode (path file-name
)
1654 (if (gnus-uu-post-encode-uuencode path file-name
)
1656 (gnus-uu-post-make-mime file-name
"x-uue")
1659 ;; Encodes with base64 and adds MIME headers
1660 (defun gnus-uu-post-encode-mime (path file-name
)
1661 (if (gnus-uu-post-encode-file "mmencode" path file-name
)
1663 (gnus-uu-post-make-mime file-name
"base64")
1666 ;; Adds MIME headers.
1667 (defun gnus-uu-post-make-mime (file-name encoding
)
1668 (goto-char (point-min))
1669 (insert (format "Content-Type: %s; name=\"%s\"\n"
1670 (gnus-uu-choose-action file-name gnus-uu-ext-to-mime-list
)
1672 (insert (format "Content-Transfer-Encoding: %s\n\n" encoding
))
1674 (set-buffer gnus-post-news-buffer
)
1675 (goto-char (point-min))
1676 (re-search-forward (concat "^" (regexp-quote mail-header-separator
) "$"))
1678 (narrow-to-region 1 (point))
1679 (or (mail-fetch-field "mime-version")
1682 (insert "MIME-Version: 1.0\n")))
1685 ;; Encodes a file PATH with COMMAND, leaving the result in the
1687 (defun gnus-uu-post-encode-file (command path file-name
)
1688 (= 0 (call-process "sh" nil t nil
"-c"
1689 (format "%s %s %s" command path file-name
))))
1691 (defun gnus-uu-post-news-inews ()
1692 "Posts the composed news article and encoded file.
1693 If no file has been included, the user will be asked for a file."
1695 (if (not (eq (current-buffer) (get-buffer gnus-post-news-buffer
)))
1696 (error "Not in post news buffer"))
1700 (if gnus-uu-post-inserted-file-name
1701 (setq file-name gnus-uu-post-inserted-file-name
)
1702 (setq file-name
(gnus-uu-post-insert-binary)))
1704 (if gnus-uu-post-threaded
1705 (let ((gnus-required-headers
1706 (if (memq 'Message-ID gnus-required-headers
)
1707 gnus-required-headers
1708 (cons 'Message-ID gnus-required-headers
)))
1709 gnus-inews-article-hook
)
1711 (setq gnus-inews-article-hook
(if (listp gnus-inews-article-hook
)
1712 gnus-inews-article-hook
1713 (list gnus-inews-article-hook
)))
1714 (setq gnus-inews-article-hook
1718 (goto-char (point-min))
1719 (if (re-search-forward "^Message-ID: \\(.*\\)$" nil t
)
1720 (setq gnus-uu-post-message-id
1722 (match-beginning 1) (match-end 1)))
1723 (setq gnus-uu-post-message-id nil
))))
1724 gnus-inews-article-hook
))
1725 (gnus-uu-post-encoded file-name t
))
1726 (gnus-uu-post-encoded file-name nil
)))
1727 (setq gnus-uu-post-inserted-file-name nil
)
1728 (and gnus-uu-winconf-post-news
1729 (set-window-configuration gnus-uu-winconf-post-news
)))
1731 ;; Asks for a file to encode, encodes it and inserts the result in
1732 ;; the current buffer. Returns the file name the user gave.
1733 (defun gnus-uu-post-insert-binary ()
1734 (let ((uuencode-buffer-name "*uuencode buffer*")
1735 file-path uubuf file-name
)
1737 (setq file-path
(read-file-name
1738 "What file do you want to encode? "))
1739 (if (not (file-exists-p file-path
))
1740 (error "%s: No such file" file-path
))
1742 (goto-char (point-max))
1743 (insert (format "\n%s\n" gnus-uu-post-binary-separator
))
1745 (if (string-match "^~/" file-path
)
1746 (setq file-path
(concat "$HOME" (substring file-path
1))))
1747 (if (string-match "/[^/]*$" file-path
)
1748 (setq file-name
(substring file-path
(1+ (match-beginning 0))))
1749 (setq file-name file-path
))
1753 (set-buffer (setq uubuf
1754 (get-buffer-create uuencode-buffer-name
)))
1756 (funcall gnus-uu-post-encode-method file-path file-name
))
1757 (insert-buffer uubuf
)
1758 (error "Encoding unsuccessful"))
1759 (kill-buffer uubuf
))
1762 ;; Posts the article and all of the encoded file.
1763 (defun gnus-uu-post-encoded (file-name &optional threaded
)
1764 (let ((send-buffer-name "*uuencode send buffer*")
1765 (encoded-buffer-name "*encoded buffer*")
1766 (top-string "[ cut here %s (%s %d/%d) %s gnus-uu ]")
1767 (separator (concat mail-header-separator
"\n\n"))
1768 uubuf length parts header i end beg
1769 beg-line minlen buf post-buf whole-len beg-binary end-binary
)
1771 (setq post-buf
(current-buffer))
1773 (goto-char (point-min))
1774 (if (not (re-search-forward
1775 (if gnus-uu-post-separate-description
1776 (concat "^" (regexp-quote gnus-uu-post-binary-separator
)
1778 (concat "^" (regexp-quote mail-header-separator
) "$")) nil t
))
1779 (error "Internal error: No binary/header separator"))
1782 (setq beg-binary
(point))
1783 (setq end-binary
(point-max))
1786 (set-buffer (setq uubuf
(get-buffer-create encoded-buffer-name
)))
1788 (insert-buffer-substring post-buf beg-binary end-binary
)
1789 (goto-char (point-min))
1790 (setq length
(count-lines 1 (point-max)))
1791 (setq parts
(/ length gnus-uu-post-length
))
1792 (if (not (< (% length gnus-uu-post-length
) 4))
1793 (setq parts
(1+ parts
))))
1795 (if gnus-uu-post-separate-description
1797 (kill-region (point) (point-max))
1799 (goto-char (point-min))
1801 (concat "^" (regexp-quote mail-header-separator
) "$") nil t
)
1803 (setq header
(buffer-substring 1 (point)))
1805 (goto-char (point-min))
1806 (if (not gnus-uu-post-separate-description
)
1808 (if (and (not threaded
) (re-search-forward "^Subject: " nil t
))
1811 (insert (format " (0/%d)" parts
))))
1817 (while (not (> i parts
))
1818 (set-buffer (get-buffer-create send-buffer-name
))
1821 (if (and threaded gnus-uu-post-message-id
)
1822 (insert (format "References: %s\n" gnus-uu-post-message-id
)))
1825 (- 62 (length (format top-string
"" file-name i parts
""))))
1826 (if (> 1 (setq minlen
(/ whole-len
2)))
1831 (make-string minlen ?-
)
1834 (if (= 0 (% whole-len
2)) (1- minlen
) minlen
) ?-
)))
1836 (goto-char (point-min))
1837 (if (not (re-search-forward "^Subject: " nil t
))
1842 (insert (format " (%d/%d)" i parts
)))
1843 (if (or (and (= i
2) gnus-uu-post-separate-description
)
1844 (and (= i
1) (not gnus-uu-post-separate-description
)))
1845 (replace-match "Subject: Re: "))))
1847 (goto-char (point-max))
1852 (goto-char (point-max))
1853 (forward-line gnus-uu-post-length
))
1854 (if (and (= (1+ i
) parts
) (< (count-lines (point) (point-max)) 4))
1857 (insert-buffer-substring uubuf beg end
)
1862 (goto-char (point-min))
1864 (concat "^" (regexp-quote mail-header-separator
) "$") nil t
)
1867 (if (re-search-forward
1868 (concat "^" (regexp-quote gnus-uu-post-binary-separator
) "$")
1877 (and (setq buf
(get-buffer send-buffer-name
))
1879 (and (setq buf
(get-buffer encoded-buffer-name
))
1882 (if (not gnus-uu-post-separate-description
)
1884 (set-buffer-modified-p nil
)
1885 (and (fboundp 'bury-buffer
) (bury-buffer))))))
1889 ;; gnus-uu.el ends here