1 ;;; gnus-uu.el --- extract (uu)encoded files in Gnus
3 ;; Copyright (C) 1985,86,87,93,94,95 Free Software Foundation, Inc.
5 ;; Author: Lars Magne Ingebrigtsen <larsi@ifi.uio.no>
10 ;; This file is part of GNU Emacs.
12 ;; GNU Emacs is free software; you can redistribute it and/or modify
13 ;; it under the terms of the GNU General Public License as published by
14 ;; the Free Software Foundation; either version 2, or (at your option)
17 ;; GNU Emacs is distributed in the hope that it will be useful,
18 ;; but WITHOUT ANY WARRANTY; without even the implied warranty of
19 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
20 ;; GNU General Public License for more details.
22 ;; You should have received a copy of the GNU General Public License
23 ;; along with GNU Emacs; see the file COPYING. If not, write to the
24 ;; Free Software Foundation, Inc., 59 Temple Place - Suite 330,
25 ;; Boston, MA 02111-1307, USA.
34 ;; Default viewing action rules
36 (defvar gnus-uu-default-view-rules
37 '(("\\.te?xt$\\|\\.doc$\\|read.*me\\|\\.c?$\\|\\.h$\\|\\.bat$\\|\\.asm$\\|makefile" "cat %s | sed s/\r//g")
38 ("\\.pas$" "cat %s | sed s/\r//g")
39 ("\\.[1-9]$" "groff -mandoc -Tascii %s | sed s/\b.//g")
40 ("\\.\\(jpe?g\\|gif\\|tiff?\\|p[pgb]m\\|xwd\\|xbm\\|pcx\\)$" "xv")
41 ("\\.tga$" "tgatoppm %s | xv -")
42 ("\\.\\(wav\\|aiff\\|hcom\\|u[blw]\\|s[bfw]\\|voc\\|smp\\)$"
43 "sox -v .5 %s -t .au -u - > /dev/audio")
44 ("\\.au$" "cat %s > /dev/audio")
46 ("\\.ps$" "ghostview")
48 ("\\.html$" "xmosaic")
49 ("\\.mpe?g$" "mpeg_play")
50 ("\\.\\(flc\\|fli\\|rle\\|iff\\|pfx\\|avi\\|sme\\|rpza\\|dl\\|qt\\|rsrc\\|mov\\)$" "xanim")
51 ("\\.\\(tar\\|arj\\|zip\\|zoo\\|arc\\|gz\\|Z\\|lzh\\|ar\\|lha\\)$"
53 "*Default actions to be taken when the user asks to view a file.
54 To change the behaviour, you can either edit this variable or set
55 `gnus-uu-user-view-rules' to something useful.
59 To make gnus-uu use 'xli' to display JPEG and GIF files, put the
60 following in your .emacs file:
62 (setq gnus-uu-user-view-rules '((\"jpg$\\\\|gif$\" \"xli\")))
64 Both these variables are lists of lists with two string elements. The
65 first string is a regular expression. If the file name matches this
66 regular expression, the command in the second string is executed with
67 the file as an argument.
69 If the command string contains \"%s\", the file name will be inserted
70 at that point in the command string. If there's no \"%s\" in the
71 command string, the file name will be appended to the command string
74 There are several user variables to tailor the behaviour of gnus-uu to
75 your needs. First we have `gnus-uu-user-view-rules', which is the
76 variable gnus-uu first consults when trying to decide how to view a
77 file. If this variable contains no matches, gnus-uu examines the
78 default rule variable provided in this package. If gnus-uu finds no
79 match here, it uses `gnus-uu-user-view-rules-end' to try to make a
82 (defvar gnus-uu-user-view-rules nil
83 "*Variable detailing what actions are to be taken to view a file.
84 See the documentation on the `gnus-uu-default-view-rules' variable for
87 (defvar gnus-uu-user-view-rules-end
89 "*Variable saying what actions are to be taken if no rule matched the file name.
90 See the documentation on the `gnus-uu-default-view-rules' variable for
93 ;; Default unpacking commands
95 (defvar gnus-uu-default-archive-rules
96 '(("\\.tar$" "tar xf")
97 ("\\.zip$" "unzip -o")
101 ("\\.\\(lzh\\|lha\\)$" "lha x")
102 ("\\.Z$" "uncompress")
104 ("\\.arc$" "arc -x")))
106 (defvar gnus-uu-destructive-archivers
107 (list "uncompress" "gunzip"))
109 (defvar gnus-uu-user-archive-rules nil
110 "*A list that can be set to override the default archive unpacking commands.
111 To use, for instance, 'untar' to unpack tar files and 'zip -x' to
112 unpack zip files, say the following:
113 (setq gnus-uu-user-archive-rules
114 '((\"\\\\.tar$\" \"untar\")
115 (\"\\\\.zip$\" \"zip -x\")))")
117 (defvar gnus-uu-ignore-files-by-name nil
118 "*A regular expression saying what files should not be viewed based on name.
119 If, for instance, you want gnus-uu to ignore all .au and .wav files,
120 you could say something like
122 (setq gnus-uu-ignore-files-by-name \"\\\\.au$\\\\|\\\\.wav$\")
124 Note that this variable can be used in conjunction with the
125 `gnus-uu-ignore-files-by-type' variable.")
127 (defvar gnus-uu-ignore-files-by-type nil
128 "*A regular expression saying what files that shouldn't be viewed, based on MIME file type.
129 If, for instance, you want gnus-uu to ignore all audio files and all mpegs,
130 you could say something like
132 (setq gnus-uu-ignore-files-by-type \"audio/\\\\|video/mpeg\")
134 Note that this variable can be used in conjunction with the
135 `gnus-uu-ignore-files-by-name' variable.")
137 ;; Pseudo-MIME support
139 (defconst gnus-uu-ext-to-mime-list
140 '(("\\.gif$" "image/gif")
141 ("\\.jpe?g$" "image/jpeg")
142 ("\\.tiff?$" "image/tiff")
143 ("\\.xwd$" "image/xwd")
144 ("\\.pbm$" "image/pbm")
145 ("\\.pgm$" "image/pgm")
146 ("\\.ppm$" "image/ppm")
147 ("\\.xbm$" "image/xbm")
148 ("\\.pcx$" "image/pcx")
149 ("\\.tga$" "image/tga")
150 ("\\.ps$" "image/postscript")
151 ("\\.fli$" "video/fli")
152 ("\\.wav$" "audio/wav")
153 ("\\.aiff$" "audio/aiff")
154 ("\\.hcom$" "audio/hcom")
155 ("\\.voc$" "audio/voc")
156 ("\\.smp$" "audio/smp")
157 ("\\.mod$" "audio/mod")
158 ("\\.dvi$" "image/dvi")
159 ("\\.mpe?g$" "video/mpeg")
160 ("\\.au$" "audio/basic")
161 ("\\.\\(te?xt\\|doc\\|c\\|h\\)$" "text/plain")
162 ("\\.\\(c\\|h\\)$" "text/source")
163 ("read.*me" "text/plain")
164 ("\\.html$" "text/html")
165 ("\\.bat$" "text/bat")
166 ("\\.[1-6]$" "text/man")
167 ("\\.flc$" "video/flc")
168 ("\\.rle$" "video/rle")
169 ("\\.pfx$" "video/pfx")
170 ("\\.avi$" "video/avi")
171 ("\\.sme$" "video/sme")
172 ("\\.rpza$" "video/prza")
173 ("\\.dl$" "video/dl")
174 ("\\.qt$" "video/qt")
175 ("\\.rsrc$" "video/rsrc")
176 ("\\..*$" "unknown/unknown")))
178 ;; Various variables users may set
180 (defvar gnus-uu-tmp-dir
"/tmp/"
181 "*Variable saying where gnus-uu is to do its work.
182 Default is \"/tmp/\".")
184 (defvar gnus-uu-do-not-unpack-archives nil
185 "*Non-nil means that gnus-uu won't peek inside archives looking for files to display.
188 (defvar gnus-uu-view-and-save nil
189 "*Non-nil means that the user will always be asked to save a file after viewing it.
190 If the variable is nil, the user will only be asked to save if the
191 viewing is unsuccessful. Default is nil.")
193 (defvar gnus-uu-ignore-default-view-rules nil
194 "*Non-nil means that gnus-uu will ignore the default viewing rules.
195 Only the user viewing rules will be consulted. Default is nil.")
197 (defvar gnus-uu-ignore-default-archive-rules nil
198 "*Non-nil means that gnus-uu will ignore the default archive unpacking commands.
199 Only the user unpacking commands will be consulted. Default is nil.")
201 (defvar gnus-uu-kill-carriage-return t
202 "*Non-nil means that gnus-uu will strip all carriage returns from articles.
205 (defvar gnus-uu-view-with-metamail nil
206 "*Non-nil means that files will be viewed with metamail.
207 The gnus-uu viewing functions will be ignored and gnus-uu will try
208 to guess at a content-type based on file name suffixes. Default
211 (defvar gnus-uu-unmark-articles-not-decoded nil
212 "*Non-nil means that gnus-uu will mark articles that were unsuccessfully decoded as unread.
215 (defvar gnus-uu-correct-stripped-uucode nil
216 "*Non-nil means that gnus-uu will *try* to fix uuencoded files that have had trailing spaces deleted.
219 (defvar gnus-uu-save-in-digest nil
220 "*Non-nil means that gnus-uu, when asked to save without decoding, will save in digests.
221 If this variable is nil, gnus-uu will just save everything in a
222 file without any embellishments. The digesting almost conforms to RFC1153 -
223 no easy way to specify any meaningful volume and issue numbers were found,
224 so I simply dropped them.")
226 (defvar gnus-uu-digest-headers
227 '("^Date:" "^From:" "^To:" "^Cc:" "^Subject:" "^Message-ID:" "^Keywords:"
228 "^Summary:" "^References:")
229 "*List of regexps to match headers included in digested messages.
230 The headers will be included in the sequence they are matched.")
232 (defvar gnus-uu-save-separate-articles nil
233 "*Non-nil means that gnus-uu will save articles in separate files.")
235 ;; Internal variables
237 (defvar gnus-uu-saved-article-name nil
)
239 (defconst gnus-uu-begin-string
"^begin[ \t]+[0-7][0-7][0-7][ \t]+\\(.*\\)$")
240 (defconst gnus-uu-end-string
"^end[ \t]*$")
242 (defconst gnus-uu-body-line
"^M")
244 (while (> (setq i
(1- i
)) 0)
245 (setq gnus-uu-body-line
(concat gnus-uu-body-line
"[^a-z]")))
246 (setq gnus-uu-body-line
(concat gnus-uu-body-line
".?$")))
248 ;"^M.............................................................?$"
250 (defconst gnus-uu-shar-begin-string
"^#! */bin/sh")
252 (defvar gnus-uu-shar-file-name nil
)
253 (defconst gnus-uu-shar-name-marker
"begin [0-7][0-7][0-7][ \t]+\\(\\(\\w\\|\\.\\)*\\b\\)")
255 (defconst gnus-uu-postscript-begin-string
"^%!PS-")
256 (defconst gnus-uu-postscript-end-string
"^%%EOF$")
258 (defvar gnus-uu-file-name nil
)
259 (defconst gnus-uu-uudecode-process nil
)
260 (defvar gnus-uu-binhex-article-name nil
)
262 (defvar gnus-uu-generated-file-list nil
)
263 (defvar gnus-uu-work-dir nil
)
265 (defconst gnus-uu-output-buffer-name
" *Gnus UU Output*")
267 (defvar gnus-uu-default-dir default-directory
)
271 (defvar gnus-uu-extract-map nil
)
272 (defvar gnus-uu-extract-view-map nil
)
273 (defvar gnus-uu-mark-map nil
)
275 (define-prefix-command 'gnus-uu-mark-map
)
276 (define-key gnus-summary-mark-map
"P" 'gnus-uu-mark-map
)
277 (define-key gnus-uu-mark-map
"p" 'gnus-summary-mark-as-processable
)
278 (define-key gnus-uu-mark-map
"u" 'gnus-summary-unmark-as-processable
)
279 (define-key gnus-uu-mark-map
"U" 'gnus-summary-unmark-all-processable
)
280 (define-key gnus-uu-mark-map
"s" 'gnus-uu-mark-series
)
281 (define-key gnus-uu-mark-map
"r" 'gnus-uu-mark-region
)
282 (define-key gnus-uu-mark-map
"R" 'gnus-uu-mark-by-regexp
)
283 (define-key gnus-uu-mark-map
"t" 'gnus-uu-mark-thread
)
284 (define-key gnus-uu-mark-map
"a" 'gnus-uu-mark-all
)
285 (define-key gnus-uu-mark-map
"S" 'gnus-uu-mark-sparse
)
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 (gnus-uu-decode-save n file
)
440 (gnus-uu-add-file file
)
441 (setq buf
(switch-to-buffer (get-buffer-create " *gnus-uu-forward*")))
442 (gnus-add-current-to-buffer-list)
444 (delete-other-windows)
446 (goto-char (point-min))
447 (and (re-search-forward "^Subject: ")
449 (delete-region (point) (gnus-point-at-eol))
450 (insert "Digested Articles")))
451 (goto-char (point-min))
452 (and (re-search-forward "^From: ")
454 (delete-region (point) (gnus-point-at-eol))
457 (gnus-forward-using-post)
458 (funcall gnus-mail-forward-method
))
462 (defun gnus-uu-digest-post-forward (n)
463 "Digest and forward to a newsgroup."
465 (gnus-uu-digest-mail-forward n t
))
469 (defun gnus-uu-mark-by-regexp (regexp)
470 "Ask for a regular expression and set the process mark on all articles that match."
471 (interactive (list (read-from-minibuffer "Mark (regexp): ")))
472 (gnus-set-global-variables)
473 (let ((articles (gnus-uu-find-articles-matching regexp
)))
475 (gnus-summary-set-process-mark (car articles
))
476 (setq articles
(cdr articles
)))
478 (gnus-summary-position-cursor))
480 (defun gnus-uu-mark-series ()
481 "Mark the current series with the process mark."
483 (gnus-set-global-variables)
484 (let ((articles (gnus-uu-find-articles-matching)))
486 (gnus-summary-set-process-mark (car articles
))
487 (setq articles
(cdr articles
)))
489 (gnus-summary-position-cursor))
491 (defun gnus-uu-mark-region (beg end
)
492 "Marks all articles between point and mark."
494 (gnus-set-global-variables)
497 (while (< (point) end
)
498 (gnus-summary-set-process-mark (gnus-summary-article-number))
500 (gnus-summary-position-cursor))
502 (defun gnus-uu-mark-thread ()
503 "Marks all articles downwards in this thread."
505 (gnus-set-global-variables)
506 (let ((level (gnus-summary-thread-level)))
507 (while (and (gnus-summary-set-process-mark (gnus-summary-article-number))
508 (zerop (gnus-summary-next-subject 1))
509 (> (gnus-summary-thread-level) level
))))
510 (gnus-summary-position-cursor))
512 (defun gnus-uu-mark-sparse ()
513 "Mark all series that have some articles marked."
515 (gnus-set-global-variables)
516 (let ((marked (nreverse gnus-newsgroup-processable
))
517 subject articles total headers
)
518 (or marked
(error "No articles marked with the process mark"))
519 (setq gnus-newsgroup-processable nil
)
522 (and (setq headers
(gnus-get-header-by-number (car marked
)))
523 (setq subject
(mail-header-subject headers
)
524 articles
(gnus-uu-find-articles-matching
525 (gnus-uu-reginize-string subject
))
526 total
(nconc total articles
)))
528 (gnus-summary-set-process-mark (car articles
))
529 (setcdr marked
(delq (car articles
) (cdr marked
)))
530 (setq articles
(cdr articles
)))
531 (setq marked
(cdr marked
)))
532 (setq gnus-newsgroup-processable
(nreverse total
)))
533 (gnus-summary-position-cursor)))
535 (defun gnus-uu-mark-all ()
536 "Mark all articles in \"series\" order."
538 (gnus-set-global-variables)
539 (setq gnus-newsgroup-processable nil
)
541 (goto-char (point-min))
543 (while (and (not (eobp))
544 (setq number
(gnus-summary-article-number)))
545 (if (not (memq number gnus-newsgroup-processable
))
546 (save-excursion (gnus-uu-mark-series)))
548 (gnus-summary-position-cursor))
550 ;; All PostScript functions written by Erik Selberg <speed@cs.washington.edu>.
552 (defun gnus-uu-decode-postscript (n)
553 "Gets postscript of the current article."
555 (gnus-uu-decode-with-method 'gnus-uu-decode-postscript-article n
))
557 (defun gnus-uu-decode-postscript-view (n)
558 "Gets and views the current article."
560 (let ((gnus-view-pseudos (or gnus-view-pseudos
'automatic
)))
561 (gnus-uu-decode-postscript n
)))
563 (defun gnus-uu-decode-postscript-and-save (n dir
)
564 "Extracts postscript and saves the current article."
566 (list current-prefix-arg
567 (file-name-as-directory
568 (read-file-name "Save in dir: "
570 gnus-uu-default-dir t
))))
571 (gnus-uu-decode-with-method 'gnus-uu-decode-postscript-article n dir
))
574 (defun gnus-uu-decode-postscript-and-save-view (n dir
)
575 "Decodes, views and saves the resulting file."
577 (list current-prefix-arg
578 (read-file-name "Where do you want to save the file(s)? "
580 gnus-uu-default-dir t
)))
581 (let ((gnus-view-pseudos (or gnus-view-pseudos
'automatic
)))
582 (gnus-uu-decode-postscript-and-save n dir
)))
585 ;; Internal functions.
587 (defun gnus-uu-decode-with-method (method n
&optional save not-insert scan
)
588 (gnus-uu-initialize scan
)
589 (if save
(setq gnus-uu-default-dir save
))
590 (let ((articles (gnus-uu-get-list-of-articles n
))
592 (setq files
(gnus-uu-grab-articles articles method t
))
593 (let ((gnus-current-article (car articles
)))
594 (and scan
(setq files
(gnus-uu-scan-directory gnus-uu-work-dir
))))
595 (and save
(gnus-uu-save-files files save
))
596 (setq files
(gnus-uu-unpack-files files
))
597 (gnus-uu-add-file (mapcar (lambda (file) (cdr (assq 'name file
))) files
))
598 (setq files
(nreverse (gnus-uu-get-actions files
)))
599 (or not-insert
(gnus-summary-insert-pseudos files save
))))
601 ;; Return a list of files in dir.
602 (defun gnus-uu-scan-directory (dir)
603 (let ((files (directory-files dir t
))
606 (cond ((string-match "/\\.\\.?$" (car files
)))
607 ((file-directory-p (car files
))
608 (setq dirs
(cons (car files
) dirs
)))
609 (t (setq out
(cons (list (cons 'name
(car files
))
610 (cons 'article gnus-current-article
))
612 (setq files
(cdr files
)))
613 (apply 'nconc out
(mapcar (lambda (d) (gnus-uu-scan-directory d
))
616 (defun gnus-uu-save-files (files dir
)
617 (let ((len (length files
))
621 (setq file
(cdr (assq 'name
(car files
))))
624 (setq to-file
(if (file-directory-p dir
)
625 (concat dir
(file-name-nondirectory file
))
627 (and (or (not (file-exists-p to-file
))
628 (gnus-y-or-n-p (format "%s exists; overwrite? "
630 (copy-file file to-file t t
))))
631 (setq files
(cdr files
)))
632 (message "Saved %d file%s" len
(if (> len
1) "s" ""))))
634 ;; Functions for saving and possibly digesting articles without
637 ;; Function called by gnus-uu-grab-articles to treat each article.
638 (defun gnus-uu-save-article (buffer in-state
)
640 (gnus-uu-save-separate-articles
643 (write-region 1 (point-max) (concat gnus-uu-saved-article-name
644 gnus-current-article
))
645 (cond ((eq in-state
'first
) (list gnus-uu-saved-article-name
'begin
))
646 ((eq in-state
'first-and-last
) (list gnus-uu-saved-article-name
648 ((eq in-state
'last
) (list 'end
))
649 (t (list 'middle
)))))
650 ((not gnus-uu-save-in-digest
)
653 (write-region 1 (point-max) gnus-uu-saved-article-name t
)
654 (cond ((eq in-state
'first
) (list gnus-uu-saved-article-name
'begin
))
655 ((eq in-state
'first-and-last
) (list gnus-uu-saved-article-name
657 ((eq in-state
'last
) (list 'end
))
658 (t (list 'middle
)))))
660 (let ((name (file-name-nondirectory gnus-uu-saved-article-name
))
661 beg subj headers headline sorthead body end-string state
)
662 (if (or (eq in-state
'first
)
663 (eq in-state
'first-and-last
))
665 (setq state
(list 'begin
))
666 (save-excursion (set-buffer (get-buffer-create "*gnus-uu-body*"))
669 (set-buffer (get-buffer-create "*gnus-uu-pre*"))
672 "Date: %s\nFrom: %s\nSubject: %s Digest\n\nTopics:\n"
673 (current-time-string) name name
))))
674 (if (not (eq in-state
'end
))
675 (setq state
(list 'middle
))))
677 (set-buffer (get-buffer "*gnus-uu-body*"))
678 (goto-char (setq beg
(point-max)))
682 (let (buffer-read-only)
683 (set-text-properties (point-min) (point-max) nil
)
684 ;; These two are necessary for XEmacs 19.12 fascism.
685 (put-text-property (point-min) (point-max) 'invisible nil
)
686 (put-text-property (point-min) (point-max) 'intangible nil
))
687 (goto-char (point-min))
688 (re-search-forward "\n\n")
689 (setq body
(buffer-substring (1- (point)) (point-max)))
690 (narrow-to-region 1 (point))
691 (if (not (setq headers gnus-uu-digest-headers
))
692 (setq sorthead
(buffer-substring (point-min) (point-max)))
694 (setq headline
(car headers
))
695 (setq headers
(cdr headers
))
696 (goto-char (point-min))
697 (if (re-search-forward headline nil t
)
702 (or (and (re-search-forward "^[^ \t]" nil t
)
704 (progn (forward-line 1) (point)))))))))
706 (insert sorthead
)(goto-char (point-max))
707 (insert body
)(goto-char (point-max))
708 (insert (concat "\n" (make-string 30 ?-
) "\n\n"))
710 (if (re-search-forward "^Subject: \\(.*\\)$" nil t
)
712 (setq subj
(buffer-substring (match-beginning 1) (match-end 1)))
714 (set-buffer (get-buffer "*gnus-uu-pre*"))
715 (insert (format " %s\n" subj
))))))
716 (if (or (eq in-state
'last
)
717 (eq in-state
'first-and-last
))
720 (set-buffer (get-buffer "*gnus-uu-pre*"))
721 (insert (format "\n\n%s\n\n" (make-string 70 ?-
)))
722 (write-region 1 (point-max) gnus-uu-saved-article-name
))
724 (set-buffer (get-buffer "*gnus-uu-body*"))
725 (goto-char (point-max))
727 (concat (setq end-string
(format "End of %s Digest" name
))
729 (insert (concat (make-string (length end-string
) ?
*) "\n"))
730 (write-region 1 (point-max) gnus-uu-saved-article-name t
))
731 (kill-buffer (get-buffer "*gnus-uu-pre*"))
732 (kill-buffer (get-buffer "*gnus-uu-body*"))
733 (setq state
(cons 'end state
))))
734 (if (memq 'begin state
)
735 (cons gnus-uu-saved-article-name state
)
738 ;; Binhex treatment - not very advanced.
740 (defconst gnus-uu-binhex-body-line
741 "^[^:]...............................................................$")
742 (defconst gnus-uu-binhex-begin-line
743 "^:...............................................................$")
744 (defconst gnus-uu-binhex-end-line
747 (defun gnus-uu-binhex-article (buffer in-state
)
748 (let (state start-char
)
752 (goto-char (point-min))
753 (if (not (re-search-forward gnus-uu-binhex-begin-line nil t
))
754 (if (not (re-search-forward gnus-uu-binhex-body-line nil t
))
755 (setq state
(list 'wrong-type
))))
757 (if (memq 'wrong-type state
)
760 (setq start-char
(point))
761 (if (looking-at gnus-uu-binhex-begin-line
)
763 (setq state
(list 'begin
))
764 (write-region 1 1 gnus-uu-binhex-article-name
))
765 (setq state
(list 'middle
)))
766 (goto-char (point-max))
767 (re-search-backward (concat gnus-uu-binhex-body-line
"\\|"
768 gnus-uu-binhex-end-line
) nil t
)
769 (if (looking-at gnus-uu-binhex-end-line
)
770 (setq state
(if (memq 'begin state
)
775 (if (file-exists-p gnus-uu-binhex-article-name
)
776 (append-to-file start-char
(point) gnus-uu-binhex-article-name
))))
777 (if (memq 'begin state
)
778 (cons gnus-uu-binhex-article-name state
)
783 (defun gnus-uu-decode-postscript-article (process-buffer in-state
)
784 (let ((state (list 'ok
))
785 start-char end-char file-name
)
787 (set-buffer process-buffer
)
788 (goto-char (point-min))
789 (if (not (re-search-forward gnus-uu-postscript-begin-string nil t
))
790 (setq state
(list 'wrong-type
))
792 (setq start-char
(point))
793 (if (not (re-search-forward gnus-uu-postscript-end-string nil t
))
794 (setq state
(list 'wrong-type
))
795 (setq end-char
(point))
796 (set-buffer (get-buffer-create gnus-uu-output-buffer-name
))
797 (insert-buffer-substring process-buffer start-char end-char
)
798 (setq file-name
(concat gnus-uu-work-dir
(cdr gnus-article-current
) ".ps"))
799 (write-region (point-min) (point-max) file-name
)
800 (setq state
(list file-name
'begin
'end
))
809 (defun gnus-uu-get-actions (files)
813 (setq name
(cdr (assq 'name
(car files
))))
815 (setq action
(gnus-uu-get-action name
))
816 (setcar files
(nconc (list (if (string= action
"gnus-uu-archive")
817 (cons 'action
"file")
818 (cons 'action action
))
819 (cons 'execute
(if (string-match "%" action
)
821 (concat action
" " name
))))
823 (setq files
(cdr files
)))
826 (defun gnus-uu-get-action (file-name)
829 (gnus-uu-choose-action
832 gnus-uu-user-view-rules
833 (if gnus-uu-ignore-default-view-rules
835 gnus-uu-default-view-rules
)
836 gnus-uu-user-view-rules-end
)))
837 (if (and (not (string= (or action
"") "gnus-uu-archive"))
838 gnus-uu-view-with-metamail
)
840 (gnus-uu-choose-action file-name gnus-uu-ext-to-mime-list
))
841 (setq action
(format "metamail -d -b -c \"%s\"" action
))))
845 ;; Functions for treating subjects and collecting series.
847 (defun gnus-uu-reginize-string (string)
848 ;; Takes a string and puts a \ in front of every special character;
849 ;; ignores any leading "version numbers" thingies that they use in
850 ;; the comp.binaries groups, and either replaces anything that looks
851 ;; like "2/3" with "[0-9]+/[0-9]+" or, if it can't find something
852 ;; like that, replaces the last two numbers with "[0-9]+". This, in
853 ;; my experience, should get most postings of a series.
855 (vernum "v[0-9]+[a-z][0-9]+:")
858 (set-buffer (get-buffer-create gnus-uu-output-buffer-name
))
859 (buffer-disable-undo (current-buffer))
861 (insert (regexp-quote string
))
864 (setq case-fold-search nil
)
865 (goto-char (point-min))
866 (if (looking-at vernum
)
868 (replace-match vernum t t
)
869 (setq beg
(length vernum
))))
872 (if (re-search-forward "[ \t]*[0-9]+/[0-9]+" nil t
)
873 (replace-match " [0-9]+/[0-9]+")
876 (if (re-search-forward "[0-9]+[ \t]*of[ \t]*[0-9]+" nil t
)
877 (replace-match "[0-9]+ of [0-9]+")
880 (while (and (re-search-backward "[0-9]" nil t
) (> count
0))
883 (< 1 (goto-char (1- (point))))))
884 (re-search-forward "[0-9]+" nil t
)
885 (replace-match "[0-9]+")
887 (setq count
(1- count
)))))
890 (while (re-search-forward "[ \t]+" nil t
)
891 (replace-match "[ \t]*" t t
))
893 (buffer-substring 1 (point-max)))))
895 (defun gnus-uu-get-list-of-articles (n)
896 ;; If N is non-nil, the article numbers of the N next articles
898 ;; If any articles have been marked as processable, they will be
900 ;; Failing that, articles that have subjects that are part of the
901 ;; same "series" as the current will be returned.
905 (let ((backward (< n
0))
909 (setq articles
(cons (gnus-summary-article-number)
911 (gnus-summary-search-forward nil nil backward
))
913 (nreverse articles
)))
914 (gnus-newsgroup-processable
915 (reverse gnus-newsgroup-processable
))
917 (gnus-uu-find-articles-matching)))))
919 (defun gnus-uu-string< (l1 l2
)
920 (string< (car l1
) (car l2
)))
922 (defun gnus-uu-find-articles-matching
923 (&optional subject only-unread do-not-translate
)
924 ;; Finds all articles that matches the regexp SUBJECT. If it is
925 ;; nil, the current article name will be used. If ONLY-UNREAD is
926 ;; non-nil, only unread articles are chosen. If DO-NOT-TRANSLATE is
927 ;; non-nil, article names are not equalized before sorting.
928 (let ((subject (or subject
929 (gnus-uu-reginize-string (gnus-summary-subject-string))))
934 ;; Collect all subjects matching subject.
935 (let ((case-fold-search t
)
937 (goto-char (point-min))
939 (and (setq subj
(gnus-summary-subject-string))
940 (string-match subject subj
)
941 (or (not only-unread
)
942 (= (setq mark
(gnus-summary-article-mark))
944 (= mark gnus-ticked-mark
)
945 (= mark gnus-dormant-mark
))
946 (setq list-of-subjects
947 (cons (cons subj
(gnus-summary-article-number))
951 ;; Expand numbers, sort, and return the list of article
953 (mapcar (lambda (sub) (cdr sub
))
954 (sort (gnus-uu-expand-numbers
956 (not do-not-translate
))
957 'gnus-uu-string
<))))))
959 (defun gnus-uu-expand-numbers (string-list &optional translate
)
960 ;; Takes a list of strings and "expands" all numbers in all the
961 ;; strings. That is, this function makes all numbers equal length by
962 ;; prepending lots of zeroes before each number. This is to ease later
963 ;; sorting to find out what sequence the articles are supposed to be
964 ;; decoded in. Returns the list of expanded strings.
965 (let ((out-list string-list
)
968 (set-buffer (get-buffer-create gnus-uu-output-buffer-name
))
969 (buffer-disable-undo (current-buffer))
972 (insert (car (car string-list
)))
973 ;; Translate multiple spaces to one space.
974 (goto-char (point-min))
975 (while (re-search-forward "[ \t]+" nil t
)
977 ;; Translate all characters to "a".
978 (goto-char (point-min))
980 (while (re-search-forward "[A-Za-z]" nil t
)
981 (replace-match "a" t t
)))
983 (goto-char (point-min))
984 (while (re-search-forward "[0-9]+" nil t
)
987 (string-to-int (buffer-substring
988 (match-beginning 0) (match-end 0))))))
989 (setq string
(buffer-substring 1 (point-max)))
990 (setcar (car string-list
) string
)
991 (setq string-list
(cdr string-list
))))
995 ;; `gnus-uu-grab-articles' is the general multi-article treatment
996 ;; function. It takes a list of articles to be grabbed and a function
997 ;; to apply to each article.
999 ;; The function to be called should take two parameters. The first
1000 ;; parameter is the article buffer. The function should leave the
1001 ;; result, if any, in this buffer. Most treatment functions will just
1002 ;; generate files...
1004 ;; The second parameter is the state of the list of articles, and can
1005 ;; have four values: `first', `middle', `last' and `first-and-last'.
1007 ;; The function should return a list. The list may contain the
1008 ;; following symbols:
1009 ;; `error' if an error occurred
1010 ;; `begin' if the beginning of an encoded file has been received
1011 ;; If the list returned contains a `begin', the first element of
1012 ;; the list *must* be a string with the file name of the decoded
1014 ;; `end' if the the end of an encoded file has been received
1015 ;; `middle' if the article was a body part of an encoded file
1016 ;; `wrong-type' if the article was not a part of an encoded file
1017 ;; `ok', which can be used everything is ok
1019 (defvar gnus-uu-has-been-grabbed nil
)
1021 (defun gnus-uu-unmark-list-of-grabbed (&optional dont-unmark-last-article
)
1023 (if (not (and gnus-uu-has-been-grabbed
1024 gnus-uu-unmark-articles-not-decoded
))
1026 (if dont-unmark-last-article
1028 (setq art
(car gnus-uu-has-been-grabbed
))
1029 (setq gnus-uu-has-been-grabbed
(cdr gnus-uu-has-been-grabbed
))))
1030 (while gnus-uu-has-been-grabbed
1031 (gnus-summary-tick-article (car gnus-uu-has-been-grabbed
) t
)
1032 (setq gnus-uu-has-been-grabbed
(cdr gnus-uu-has-been-grabbed
)))
1033 (if dont-unmark-last-article
1034 (setq gnus-uu-has-been-grabbed
(list art
))))))
1036 ;; This function takes a list of articles and a function to apply to
1037 ;; each article grabbed.
1039 ;; This function returns a list of files decoded if the grabbing and
1040 ;; the process-function has been successful and nil otherwise.
1041 (defun gnus-uu-grab-articles
1042 (articles process-function
&optional sloppy limit no-errors
)
1043 (let ((state 'first
)
1044 has-been-begin article result-file result-files process-state
1047 (if (not (gnus-server-opened gnus-current-select-method
))
1049 (gnus-start-news-server)
1050 (gnus-request-group gnus-newsgroup-name
)))
1052 (setq gnus-uu-has-been-grabbed nil
)
1054 (while (and articles
1055 (not (memq 'error process-state
))
1057 (not (memq 'end process-state
))))
1059 (setq article
(car articles
))
1060 (setq articles
(cdr articles
))
1061 (setq gnus-uu-has-been-grabbed
(cons article gnus-uu-has-been-grabbed
))
1063 (if (eq articles
())
1064 (if (eq state
'first
)
1065 (setq state
'first-and-last
)
1066 (setq state
'last
)))
1068 (message "Getting article %d, %s" article
(gnus-uu-part-number article
))
1070 (if (not (= (or gnus-current-article
0) article
))
1071 (let ((nntp-async-number nil
))
1072 (gnus-request-article article gnus-newsgroup-name
1074 (setq gnus-last-article gnus-current-article
)
1075 (setq gnus-current-article article
)
1076 (setq gnus-article-current
(cons gnus-newsgroup-name article
))
1077 (if (stringp nntp-server-buffer
)
1078 (setq article-buffer nntp-server-buffer
)
1079 (setq article-buffer
(buffer-name nntp-server-buffer
))))
1080 (gnus-summary-stop-page-breaking)
1081 (setq article-buffer gnus-article-buffer
))
1083 (buffer-disable-undo article-buffer
)
1084 ;; Mark article as read.
1085 (and (memq article gnus-newsgroup-processable
)
1086 (gnus-summary-remove-process-mark article
))
1087 (run-hooks 'gnus-mark-article-hook
)
1089 (setq process-state
(funcall process-function article-buffer state
))
1091 (if (or (memq 'begin process-state
)
1092 (and (or (eq state
'first
) (eq state
'first-and-last
))
1093 (memq 'ok process-state
)))
1096 (if (and result-file
(file-exists-p result-file
))
1097 (delete-file result-file
)))
1098 (if (memq 'begin process-state
)
1099 (setq result-file
(car process-state
)))
1100 (setq has-been-begin t
)))
1102 (if (memq 'end process-state
)
1104 (setq gnus-uu-has-been-grabbed nil
)
1105 (setq result-files
(cons (list (cons 'name result-file
)
1106 (cons 'article article
))
1108 (setq has-been-begin nil
)
1109 (and limit
(= (length result-files
) limit
)
1110 (setq articles nil
))))
1112 (if (and (or (eq state
'last
) (eq state
'first-and-last
))
1113 (not (memq 'end process-state
)))
1114 (if (and result-file
(file-exists-p result-file
))
1115 (delete-file result-file
)))
1117 (if (not (memq 'wrong-type process-state
))
1119 (if gnus-uu-unmark-articles-not-decoded
1120 (gnus-summary-tick-article article t
)))
1122 (if (and (not has-been-begin
)
1124 (or (memq 'end process-state
)
1125 (memq 'middle process-state
)))
1127 (setq process-state
(list 'error
))
1128 (message "No begin part at the beginning")
1130 (setq state
'middle
)))
1132 ;; Make sure the last article is put in the article buffer & fix
1135 (if (not (string= article-buffer gnus-article-buffer
))
1137 (set-buffer (get-buffer-create gnus-article-buffer
))
1138 (let ((buffer-read-only nil
))
1141 (insert-buffer-substring article-buffer
)
1142 (gnus-set-mode-line 'article
)
1143 (goto-char (point-min)))))
1145 (gnus-set-mode-line 'summary
)
1149 (if (not has-been-begin
)
1150 (if (not no-errors
) (message "Wrong type file"))
1151 (if (memq 'error process-state
)
1152 (setq result-files nil
)
1153 (if (not (or (memq 'ok process-state
)
1154 (memq 'end process-state
)))
1157 (message "End of articles reached before end of file"))
1158 (setq result-files nil
))
1159 (gnus-uu-unmark-list-of-grabbed)))))
1162 (defun gnus-uu-part-number (article)
1163 (let ((subject (mail-header-subject (gnus-get-header-by-number article
))))
1164 (if (string-match "[0-9]+ */[0-9]+\\|[0-9]+ * of *[0-9]+"
1166 (substring subject
(match-beginning 0) (match-end 0))
1169 (defun gnus-uu-uudecode-sentinel (process event
)
1170 (delete-process (get-process process
)))
1172 (defun gnus-uu-uustrip-article (process-buffer in-state
)
1173 ;; Uudecodes a file asynchronously.
1174 (let ((state (list 'ok
))
1175 (process-connection-type nil
)
1176 start-char pst name-beg name-end
)
1178 (set-buffer process-buffer
)
1179 (let ((case-fold-search nil
)
1180 (buffer-read-only nil
))
1182 (goto-char (point-min))
1184 (if gnus-uu-kill-carriage-return
1186 (while (search-forward "\r" nil t
)
1187 (delete-backward-char 1))
1188 (goto-char (point-min))))
1190 (if (not (re-search-forward gnus-uu-begin-string nil t
))
1191 (if (not (re-search-forward gnus-uu-body-line nil t
))
1192 (setq state
(list 'wrong-type
))))
1194 (if (memq 'wrong-type state
)
1197 (setq start-char
(point))
1199 (if (looking-at gnus-uu-begin-string
)
1201 (setq name-end
(match-end 1)
1202 name-beg
(match-beginning 1))
1203 ;; Remove any non gnus-uu-body-line right after start.
1205 (or (looking-at gnus-uu-body-line
)
1208 ; Replace any slashes and spaces in file names before decoding
1209 (goto-char name-beg
)
1210 (while (re-search-forward "/" name-end t
)
1211 (replace-match ","))
1212 (goto-char name-beg
)
1213 (while (re-search-forward " " name-end t
)
1214 (replace-match "_"))
1215 (goto-char name-beg
)
1216 (if (re-search-forward "_*$" name-end t
)
1219 (setq gnus-uu-file-name
(buffer-substring name-beg name-end
))
1220 (and gnus-uu-uudecode-process
1221 (setq pst
(process-status
1222 (or gnus-uu-uudecode-process
"nevair")))
1223 (if (or (eq pst
'stop
) (eq pst
'run
))
1225 (delete-process gnus-uu-uudecode-process
)
1226 (gnus-uu-unmark-list-of-grabbed t
))))
1227 (if (get-process "*uudecode*")
1228 (delete-process "*uudecode*"))
1229 (setq gnus-uu-uudecode-process
1232 (get-buffer-create gnus-uu-output-buffer-name
)
1234 (format "cd %s ; uudecode" gnus-uu-work-dir
)))
1235 (set-process-sentinel
1236 gnus-uu-uudecode-process
'gnus-uu-uudecode-sentinel
)
1237 (setq state
(list 'begin
))
1238 (gnus-uu-add-file (concat gnus-uu-work-dir gnus-uu-file-name
)))
1239 (setq state
(list 'middle
)))
1241 (goto-char (point-max))
1244 (concat gnus-uu-body-line
"\\|" gnus-uu-end-string
) nil t
)
1247 (if (looking-at gnus-uu-end-string
)
1248 (setq state
(cons 'end state
)))
1251 (and gnus-uu-uudecode-process
1252 (setq pst
(process-status
1253 (or gnus-uu-uudecode-process
"nevair")))
1254 (if (or (eq pst
'run
) (eq pst
'stop
))
1256 (if gnus-uu-correct-stripped-uucode
1258 (gnus-uu-check-correct-stripped-uucode
1260 (goto-char (point-max))
1262 (concat gnus-uu-body-line
"\\|"
1268 (process-send-region gnus-uu-uudecode-process
1272 (delete-process gnus-uu-uudecode-process
)
1273 (message "gnus-uu: Couldn't uudecode")
1275 (setq state
(list 'wrong-type
)))))
1277 (if (memq 'end state
)
1278 (accept-process-output gnus-uu-uudecode-process
)))
1279 (setq state
(list 'wrong-type
))))
1280 (if (not gnus-uu-uudecode-process
)
1281 (setq state
(list 'wrong-type
)))))
1283 (if (memq 'begin state
)
1284 (cons (concat gnus-uu-work-dir gnus-uu-file-name
) state
)
1287 ;; This function is used by `gnus-uu-grab-articles' to treat
1288 ;; a shared article.
1289 (defun gnus-uu-unshar-article (process-buffer in-state
)
1290 (let ((state (list 'ok
))
1293 (set-buffer process-buffer
)
1294 (goto-char (point-min))
1295 (if (not (re-search-forward gnus-uu-shar-begin-string nil t
))
1296 (setq state
(list 'wrong-type
))
1298 (setq start-char
(point))
1299 (call-process-region
1300 start-char
(point-max) "sh" nil
1301 (get-buffer-create gnus-uu-output-buffer-name
) nil
1302 "-c" (concat "cd " gnus-uu-work-dir
" ; sh"))))
1305 ;; Returns the name of what the shar file is going to unpack.
1306 (defun gnus-uu-find-name-in-shar ()
1307 (let ((oldpoint (point))
1309 (goto-char (point-min))
1310 (if (re-search-forward gnus-uu-shar-name-marker nil t
)
1311 (setq res
(buffer-substring (match-beginning 1) (match-end 1))))
1312 (goto-char oldpoint
)
1315 ;; `gnus-uu-choose-action' chooses what action to perform given the name
1316 ;; and `gnus-uu-file-action-list'. Returns either nil if no action is
1317 ;; found, or the name of the command to run if such a rule is found.
1318 (defun gnus-uu-choose-action (file-name file-action-list
&optional no-ignore
)
1319 (let ((action-list (copy-sequence file-action-list
))
1320 (case-fold-search t
)
1325 (and gnus-uu-ignore-files-by-name
1326 (string-match gnus-uu-ignore-files-by-name file-name
)))
1328 (and gnus-uu-ignore-files-by-type
1329 (string-match gnus-uu-ignore-files-by-type
1330 (or (gnus-uu-choose-action
1331 file-name gnus-uu-ext-to-mime-list t
)
1333 (while (not (or (eq action-list
()) action
))
1334 (setq rule
(car action-list
))
1335 (setq action-list
(cdr action-list
))
1336 (if (string-match (car rule
) file-name
)
1337 (setq action
(car (cdr rule
))))))
1340 (defun gnus-uu-treat-archive (file-path)
1341 ;; Unpacks an archive. Returns t if unpacking is successful.
1342 (let ((did-unpack t
)
1344 (setq action
(gnus-uu-choose-action
1345 file-path
(append gnus-uu-user-archive-rules
1346 (if gnus-uu-ignore-default-archive-rules
1348 gnus-uu-default-archive-rules
))))
1350 (if (not action
) (error "No unpackers for the file %s" file-path
))
1352 (string-match "/[^/]*$" file-path
)
1353 (setq dir
(substring file-path
0 (match-beginning 0)))
1355 (if (member action gnus-uu-destructive-archivers
)
1356 (copy-file file-path
(concat file-path
"~") t
))
1358 (setq command
(format "cd %s ; %s" dir
(gnus-uu-command action file-path
)))
1361 (set-buffer (get-buffer-create gnus-uu-output-buffer-name
))
1364 (message "Unpacking: %s..." (gnus-uu-command action file-path
))
1366 (if (= 0 (call-process "sh" nil
1367 (get-buffer-create gnus-uu-output-buffer-name
)
1370 (message "Error during unpacking of archive")
1371 (setq did-unpack nil
))
1373 (if (member action gnus-uu-destructive-archivers
)
1374 (rename-file (concat file-path
"~") file-path t
))
1378 (defun gnus-uu-dir-files (dir)
1379 (let ((dirs (directory-files dir t
"[^/][^\\.][^\\.]?$"))
1382 (if (file-directory-p (setq file
(car dirs
)))
1383 (setq files
(append files
(gnus-uu-dir-files file
)))
1384 (setq files
(cons file files
)))
1385 (setq dirs
(cdr dirs
)))
1388 (defun gnus-uu-unpack-files (files &optional ignore
)
1389 ;; Go through FILES and look for files to unpack.
1390 (let* ((totfiles (gnus-uu-ls-r gnus-uu-work-dir
))
1392 file did-unpack file-entry
)
1393 (gnus-uu-add-file totfiles
)
1395 (setq file
(cdr (setq file-entry
(assq 'name
(car files
)))))
1396 (if (and (not (member file ignore
))
1397 (equal (gnus-uu-get-action (file-name-nondirectory file
))
1400 (setq did-unpack
(cons file did-unpack
))
1401 (or (gnus-uu-treat-archive file
)
1402 (message "Error during unpacking of %s" file
))
1403 (let* ((newfiles (gnus-uu-ls-r gnus-uu-work-dir
))
1405 (gnus-uu-add-file newfiles
)
1407 (or (member (car nfiles
) totfiles
)
1408 (setq ofiles
(cons (list (cons 'name
(car nfiles
))
1409 (cons 'original file
))
1411 (setq nfiles
(cdr nfiles
)))
1412 (setq totfiles newfiles
))))
1413 (setq files
(cdr files
)))
1415 (gnus-uu-unpack-files ofiles
(append did-unpack ignore
))
1418 (defun gnus-uu-ls-r (dir)
1419 (let* ((files (gnus-uu-directory-files dir t
))
1422 (if (file-directory-p (car files
))
1424 (setq ofiles
(delete (car files
) ofiles
))
1425 (setq ofiles
(append ofiles
(gnus-uu-ls-r (car files
))))))
1426 (setq files
(cdr files
)))
1431 (defun gnus-uu-directory-files (dir &optional full
)
1432 (let (files out file
)
1433 (setq files
(directory-files dir full
))
1435 (setq file
(car files
))
1436 (setq files
(cdr files
))
1437 (or (string-match "/\\.\\.?$" file
)
1438 (setq out
(cons file out
))))
1439 (setq out
(nreverse out
))
1442 (defun gnus-uu-check-correct-stripped-uucode (start end
)
1443 (let (found beg length
)
1444 (if (not gnus-uu-correct-stripped-uucode
)
1448 (if (re-search-forward " \\|`" end t
)
1453 (if (looking-at "\n") (replace-match ""))
1457 (if (looking-at (concat gnus-uu-begin-string
"\\|"
1458 gnus-uu-end-string
))
1465 (setq length
(- (point) beg
))))
1470 (if (not (= length
(- (point) beg
)))
1471 (insert (make-string (- length
(- (point) beg
)) ?
))))
1472 (forward-line 1))))))
1474 (defvar gnus-uu-tmp-alist nil
)
1476 (defun gnus-uu-initialize (&optional scan
)
1479 (if (setq entry
(assoc gnus-newsgroup-name gnus-uu-tmp-alist
))
1480 (if (file-exists-p (cdr entry
))
1481 (setq gnus-uu-work-dir
(cdr entry
))
1482 (setq gnus-uu-tmp-alist
(delq entry gnus-uu-tmp-alist
))
1485 (setq gnus-uu-tmp-dir
(file-name-as-directory
1486 (expand-file-name gnus-uu-tmp-dir
)))
1487 (if (not (file-directory-p gnus-uu-tmp-dir
))
1488 (error "Temp directory %s doesn't exist" gnus-uu-tmp-dir
)
1489 (if (not (file-writable-p gnus-uu-tmp-dir
))
1490 (error "Temp directory %s can't be written to"
1493 (setq gnus-uu-work-dir
1494 (make-temp-name (concat gnus-uu-tmp-dir
"gnus")))
1495 (gnus-uu-add-file gnus-uu-work-dir
)
1496 (if (not (file-directory-p gnus-uu-work-dir
))
1497 (gnus-make-directory gnus-uu-work-dir
))
1498 (set-file-modes gnus-uu-work-dir
448)
1499 (setq gnus-uu-work-dir
(file-name-as-directory gnus-uu-work-dir
))
1500 (setq gnus-uu-tmp-alist
(cons (cons gnus-newsgroup-name gnus-uu-work-dir
)
1501 gnus-uu-tmp-alist
)))))
1504 ;; Kills the temporary uu buffers, kills any processes, etc.
1505 (defun gnus-uu-clean-up ()
1507 (and gnus-uu-uudecode-process
1508 (setq pst
(process-status (or gnus-uu-uudecode-process
"nevair")))
1509 (if (or (eq pst
'stop
) (eq pst
'run
))
1510 (delete-process gnus-uu-uudecode-process
)))
1511 (and (setq buf
(get-buffer gnus-uu-output-buffer-name
))
1512 (kill-buffer buf
))))
1514 ;; `gnus-uu-check-for-generated-files' deletes any generated files that
1515 ;; hasn't been deleted, if, for instance, the user terminated decoding
1517 (defun gnus-uu-check-for-generated-files ()
1519 (while gnus-uu-generated-file-list
1520 (setq file
(car gnus-uu-generated-file-list
))
1521 (setq gnus-uu-generated-file-list
(cdr gnus-uu-generated-file-list
))
1522 (if (not (string-match "/\\.[\\.]?$" file
))
1524 (if (file-directory-p file
)
1525 (setq dirs
(cons file dirs
))
1526 (if (file-exists-p file
)
1527 (delete-file file
))))))
1528 (setq dirs
(nreverse dirs
))
1530 (setq file
(car dirs
))
1531 (setq dirs
(cdr dirs
))
1532 (if (file-directory-p file
)
1533 (if (string-match "/$" file
)
1534 (delete-directory (substring file
0 (match-beginning 0)))
1535 (delete-directory file
))))))
1537 ;; Add a file (or a list of files) to be checked (and deleted if it/they
1538 ;; still exists upon exiting the newsgroup).
1539 (defun gnus-uu-add-file (file)
1541 (setq gnus-uu-generated-file-list
1542 (cons file gnus-uu-generated-file-list
))
1543 (setq gnus-uu-generated-file-list
1544 (append file gnus-uu-generated-file-list
))))
1546 ;; Inputs an action and a file and returns a full command, putting
1547 ;; quotes round the file name and escaping any quotes in the file name.
1548 (defun gnus-uu-command (action file
)
1550 (while (string-match "!\\|`\\|\"\\|\\$\\|\\\\\\|&" file
)
1553 (concat ofile
(substring file
0 (match-beginning 0)) "\\"
1554 (substring file
(match-beginning 0) (match-end 0))))
1555 (setq file
(substring file
(1+ (match-beginning 0))))))
1556 (setq ofile
(concat "\"" ofile file
"\""))
1557 (if (string-match "%s" action
)
1558 (format action ofile
)
1559 (concat action
" " ofile
))))
1564 (add-hook 'gnus-exit-group-hook
'gnus-uu-clean-up
)
1565 (add-hook 'gnus-exit-group-hook
'gnus-uu-check-for-generated-files
)
1570 ;;; uuencoded posting
1576 ;; Any function that is to be used as and encoding method will take two
1577 ;; parameters: PATH-NAME and FILE-NAME. (E.g. "/home/gaga/spiral.jpg"
1578 ;; and "spiral.jpg", respectively.) The function should return nil if
1579 ;; the encoding wasn't successful.
1580 (defvar gnus-uu-post-encode-method
'gnus-uu-post-encode-uuencode
1581 "Function used for encoding binary files.
1582 There are three functions supplied with gnus-uu for encoding files:
1583 `gnus-uu-post-encode-uuencode', which does straight uuencoding;
1584 `gnus-uu-post-encode-mime', which encodes with base64 and adds MIME
1585 headers; and `gnus-uu-post-encode-mime-uuencode', which encodes with
1586 uuencode and adds MIME headers.")
1588 (defvar gnus-uu-post-include-before-composing nil
1589 "Non-nil means that gnus-uu will ask for a file to encode before you compose the article.
1590 If this variable is t, you can either include an encoded file with
1591 \\[gnus-uu-post-insert-binary-in-article] or have one included for you when you post the article.")
1593 (defvar gnus-uu-post-length
990
1594 "Maximum length of an article.
1595 The encoded file will be split into how many articles it takes to
1596 post the entire file.")
1598 (defvar gnus-uu-post-threaded nil
1599 "Non-nil means that gnus-uu will post the encoded file in a thread.
1600 This may not be smart, as no other decoder I have seen are able to
1601 follow threads when collecting uuencoded articles. (Well, I have seen
1602 one package that does that - gnus-uu, but somehow, I don't think that
1603 counts...) Default is nil.")
1605 (defvar gnus-uu-post-separate-description t
1606 "Non-nil means that the description will be posted in a separate article.
1607 The first article will typically be numbered (0/x). If this variable
1608 is nil, the description the user enters will be included at the
1609 beginning of the first article, which will be numbered (1/x). Default
1612 (defvar gnus-uu-post-binary-separator
"--binary follows this line--")
1613 (defvar gnus-uu-post-message-id nil
)
1614 (defvar gnus-uu-post-inserted-file-name nil
)
1615 (defvar gnus-uu-winconf-post-news nil
)
1617 (defun gnus-uu-post-news ()
1618 "Compose an article and post an encoded file."
1620 (setq gnus-uu-post-inserted-file-name nil
)
1621 (setq gnus-uu-winconf-post-news
(current-window-configuration))
1623 (gnus-summary-post-news)
1625 (use-local-map (copy-keymap (current-local-map)))
1626 (local-set-key "\C-c\C-c" 'gnus-summary-edit-article-done
)
1627 (local-set-key "\C-c\C-c" 'gnus-uu-post-news-inews
)
1628 (local-set-key "\C-c\C-s" 'gnus-uu-post-news-inews
)
1629 (local-set-key "\C-c\C-i" 'gnus-uu-post-insert-binary-in-article
)
1631 (if gnus-uu-post-include-before-composing
1632 (save-excursion (setq gnus-uu-post-inserted-file-name
1633 (gnus-uu-post-insert-binary)))))
1635 (defun gnus-uu-post-insert-binary-in-article ()
1636 "Inserts an encoded file in the buffer.
1637 The user will be asked for a file name."
1639 (if (not (eq (current-buffer) (get-buffer gnus-post-news-buffer
)))
1640 (error "Not in post-news buffer"))
1642 (setq gnus-uu-post-inserted-file-name
(gnus-uu-post-insert-binary))))
1644 ;; Encodes with uuencode and substitutes all spaces with backticks.
1645 (defun gnus-uu-post-encode-uuencode (path file-name
)
1646 (if (gnus-uu-post-encode-file "uuencode" path file-name
)
1648 (goto-char (point-min))
1650 (while (re-search-forward " " nil t
)
1651 (replace-match "`"))
1654 ;; Encodes with uuencode and adds MIME headers.
1655 (defun gnus-uu-post-encode-mime-uuencode (path file-name
)
1656 (if (gnus-uu-post-encode-uuencode path file-name
)
1658 (gnus-uu-post-make-mime file-name
"x-uue")
1661 ;; Encodes with base64 and adds MIME headers
1662 (defun gnus-uu-post-encode-mime (path file-name
)
1663 (if (gnus-uu-post-encode-file "mmencode" path file-name
)
1665 (gnus-uu-post-make-mime file-name
"base64")
1668 ;; Adds MIME headers.
1669 (defun gnus-uu-post-make-mime (file-name encoding
)
1670 (goto-char (point-min))
1671 (insert (format "Content-Type: %s; name=\"%s\"\n"
1672 (gnus-uu-choose-action file-name gnus-uu-ext-to-mime-list
)
1674 (insert (format "Content-Transfer-Encoding: %s\n\n" encoding
))
1676 (set-buffer gnus-post-news-buffer
)
1677 (goto-char (point-min))
1678 (re-search-forward (concat "^" (regexp-quote mail-header-separator
) "$"))
1680 (narrow-to-region 1 (point))
1681 (or (mail-fetch-field "mime-version")
1684 (insert "MIME-Version: 1.0\n")))
1687 ;; Encodes a file PATH with COMMAND, leaving the result in the
1689 (defun gnus-uu-post-encode-file (command path file-name
)
1690 (= 0 (call-process "sh" nil t nil
"-c"
1691 (format "%s %s %s" command path file-name
))))
1693 (defun gnus-uu-post-news-inews ()
1694 "Posts the composed news article and encoded file.
1695 If no file has been included, the user will be asked for a file."
1697 (if (not (eq (current-buffer) (get-buffer gnus-post-news-buffer
)))
1698 (error "Not in post news buffer"))
1702 (if gnus-uu-post-inserted-file-name
1703 (setq file-name gnus-uu-post-inserted-file-name
)
1704 (setq file-name
(gnus-uu-post-insert-binary)))
1706 (if gnus-uu-post-threaded
1707 (let ((gnus-required-headers
1708 (if (memq 'Message-ID gnus-required-headers
)
1709 gnus-required-headers
1710 (cons 'Message-ID gnus-required-headers
)))
1711 gnus-inews-article-hook
)
1713 (setq gnus-inews-article-hook
(if (listp gnus-inews-article-hook
)
1714 gnus-inews-article-hook
1715 (list gnus-inews-article-hook
)))
1716 (setq gnus-inews-article-hook
1720 (goto-char (point-min))
1721 (if (re-search-forward "^Message-ID: \\(.*\\)$" nil t
)
1722 (setq gnus-uu-post-message-id
1724 (match-beginning 1) (match-end 1)))
1725 (setq gnus-uu-post-message-id nil
))))
1726 gnus-inews-article-hook
))
1727 (gnus-uu-post-encoded file-name t
))
1728 (gnus-uu-post-encoded file-name nil
)))
1729 (setq gnus-uu-post-inserted-file-name nil
)
1730 (and gnus-uu-winconf-post-news
1731 (set-window-configuration gnus-uu-winconf-post-news
)))
1733 ;; Asks for a file to encode, encodes it and inserts the result in
1734 ;; the current buffer. Returns the file name the user gave.
1735 (defun gnus-uu-post-insert-binary ()
1736 (let ((uuencode-buffer-name "*uuencode buffer*")
1737 file-path uubuf file-name
)
1739 (setq file-path
(read-file-name
1740 "What file do you want to encode? "))
1741 (if (not (file-exists-p file-path
))
1742 (error "%s: No such file" file-path
))
1744 (goto-char (point-max))
1745 (insert (format "\n%s\n" gnus-uu-post-binary-separator
))
1747 (if (string-match "^~/" file-path
)
1748 (setq file-path
(concat "$HOME" (substring file-path
1))))
1749 (if (string-match "/[^/]*$" file-path
)
1750 (setq file-name
(substring file-path
(1+ (match-beginning 0))))
1751 (setq file-name file-path
))
1755 (set-buffer (setq uubuf
1756 (get-buffer-create uuencode-buffer-name
)))
1758 (funcall gnus-uu-post-encode-method file-path file-name
))
1759 (insert-buffer uubuf
)
1760 (error "Encoding unsuccessful"))
1761 (kill-buffer uubuf
))
1764 ;; Posts the article and all of the encoded file.
1765 (defun gnus-uu-post-encoded (file-name &optional threaded
)
1766 (let ((send-buffer-name "*uuencode send buffer*")
1767 (encoded-buffer-name "*encoded buffer*")
1768 (top-string "[ cut here %s (%s %d/%d) %s gnus-uu ]")
1769 (separator (concat mail-header-separator
"\n\n"))
1770 uubuf length parts header i end beg
1771 beg-line minlen buf post-buf whole-len beg-binary end-binary
)
1773 (setq post-buf
(current-buffer))
1775 (goto-char (point-min))
1776 (if (not (re-search-forward
1777 (if gnus-uu-post-separate-description
1778 (concat "^" (regexp-quote gnus-uu-post-binary-separator
)
1780 (concat "^" (regexp-quote mail-header-separator
) "$")) nil t
))
1781 (error "Internal error: No binary/header separator"))
1784 (setq beg-binary
(point))
1785 (setq end-binary
(point-max))
1788 (set-buffer (setq uubuf
(get-buffer-create encoded-buffer-name
)))
1790 (insert-buffer-substring post-buf beg-binary end-binary
)
1791 (goto-char (point-min))
1792 (setq length
(count-lines 1 (point-max)))
1793 (setq parts
(/ length gnus-uu-post-length
))
1794 (if (not (< (% length gnus-uu-post-length
) 4))
1795 (setq parts
(1+ parts
))))
1797 (if gnus-uu-post-separate-description
1799 (kill-region (point) (point-max))
1801 (goto-char (point-min))
1803 (concat "^" (regexp-quote mail-header-separator
) "$") nil t
)
1805 (setq header
(buffer-substring 1 (point)))
1807 (goto-char (point-min))
1808 (if (not gnus-uu-post-separate-description
)
1810 (if (and (not threaded
) (re-search-forward "^Subject: " nil t
))
1813 (insert (format " (0/%d)" parts
))))
1819 (while (not (> i parts
))
1820 (set-buffer (get-buffer-create send-buffer-name
))
1823 (if (and threaded gnus-uu-post-message-id
)
1824 (insert (format "References: %s\n" gnus-uu-post-message-id
)))
1827 (- 62 (length (format top-string
"" file-name i parts
""))))
1828 (if (> 1 (setq minlen
(/ whole-len
2)))
1833 (make-string minlen ?-
)
1836 (if (= 0 (% whole-len
2)) (1- minlen
) minlen
) ?-
)))
1838 (goto-char (point-min))
1839 (if (not (re-search-forward "^Subject: " nil t
))
1844 (insert (format " (%d/%d)" i parts
)))
1845 (if (or (and (= i
2) gnus-uu-post-separate-description
)
1846 (and (= i
1) (not gnus-uu-post-separate-description
)))
1847 (replace-match "Subject: Re: "))))
1849 (goto-char (point-max))
1854 (goto-char (point-max))
1855 (forward-line gnus-uu-post-length
))
1856 (if (and (= (1+ i
) parts
) (< (count-lines (point) (point-max)) 4))
1859 (insert-buffer-substring uubuf beg end
)
1864 (goto-char (point-min))
1866 (concat "^" (regexp-quote mail-header-separator
) "$") nil t
)
1869 (if (re-search-forward
1870 (concat "^" (regexp-quote gnus-uu-post-binary-separator
) "$")
1879 (and (setq buf
(get-buffer send-buffer-name
))
1881 (and (setq buf
(get-buffer encoded-buffer-name
))
1884 (if (not gnus-uu-post-separate-description
)
1886 (set-buffer-modified-p nil
)
1887 (and (fboundp 'bury-buffer
) (bury-buffer))))))
1891 ;; gnus-uu.el ends here