*** empty log message ***
[gnus] / lisp / gnus-uu.el
1 ;;; gnus-uu.el --- extract (uu)encoded files in Gnus
2 ;; Copyright (C) 1985,86,87,93,94,95 Free Software Foundation, Inc.
3
4 ;; Author: Lars Ingebrigtsen <larsi@ifi.uio.no>
5 ;; Created: 2 Oct 1993
6 ;; Version: v3.0
7 ;; Keyword: news
8
9 ;; This file is part of GNU Emacs.
10
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)
14 ;; any later version.
15
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.
20
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.
24
25 ;;; Commentary:
26
27 ;;; Code: 
28
29 (require 'gnus)
30
31 ;; Default viewing action rules
32
33 (defvar gnus-uu-default-view-rules 
34   '(("\\.te?xt$\\|\\.doc$\\|read.*me\\|\\.c?$\\|\\.h$\\|\\.bat$\\|\\.asm$\\|makefile" "cat %s | sed s/\r//g")
35     ("\\.pas$" "cat %s | sed s/\r//g")
36     ("\\.[1-9]$" "groff -mandoc -Tascii %s | sed s/\b.//g")
37     ("\\.\\(jpe?g\\|gif\\|tiff?\\|p[pgb]m\\|xwd\\|xbm\\|pcx\\)$" "xv")
38     ("\\.tga$" "tgatoppm %s | xv -")
39     ("\\.\\(wav\\|aiff\\|hcom\\|u[blw]\\|s[bfw]\\|voc\\|smp\\)$" 
40      "sox -v .5 %s -t .au -u - > /dev/audio")
41     ("\\.au$" "cat %s > /dev/audio")
42     ("\\.mod$" "str32")
43     ("\\.ps$" "ghostview")
44     ("\\.dvi$" "xdvi")
45     ("\\.html$" "xmosaic")
46     ("\\.mpe?g$" "mpeg_play")
47     ("\\.\\(flc\\|fli\\|rle\\|iff\\|pfx\\|avi\\|sme\\|rpza\\|dl\\|qt\\|rsrc\\|mov\\)$" "xanim")
48     ("\\.\\(tar\\|arj\\|zip\\|zoo\\|arc\\|gz\\|Z\\|lzh\\|ar\\|lha\\)$" 
49      "gnus-uu-archive"))
50
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.
54
55 For example:
56
57 To make gnus-uu use 'xli' to display JPEG and GIF files, put the
58 following in your .emacs file
59
60   (setq gnus-uu-user-view-rules '((\"jpg$\\\\|gif$\" \"xli\")))
61
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.
66
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
70 before executing.
71
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 vaiable 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
78 match.")
79
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 
83 details.")
84
85 (defvar gnus-uu-user-view-rules-end 
86   '(("" "file"))
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 
89 details.")
90
91 ;; Default unpacking commands
92
93 (defvar gnus-uu-default-archive-rules 
94   '(("\\.tar$" "tar xf")
95     ("\\.zip$" "unzip -o")
96     ("\\.ar$" "ar x")
97     ("\\.arj$" "unarj x")
98     ("\\.zoo$" "zoo -e")
99     ("\\.\\(lzh\\|lha\\)$" "lha x")
100     ("\\.Z$" "uncompress")
101     ("\\.gz$" "gunzip")
102     ("\\.arc$" "arc -x")))
103
104 (defvar gnus-uu-destructive-archivers 
105   (list "uncompress" "gunzip"))
106
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\")))")
114
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
119
120   (setq gnus-uu-ignore-files-by-name \"\\\\.au$\\\\|\\\\.wav$\")
121
122 Note that this variable can be used in conjunction with the
123 `gnus-uu-ignore-files-by-type' variable.")
124
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
129
130   (setq gnus-uu-ignore-files-by-type \"audio/\\\\|video/mpeg\")
131
132 Note that this variable can be used in conjunction with the
133 `gnus-uu-ignore-files-by-name' variable.")
134
135 ;; Pseudo-MIME support
136
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")))
175
176 ;; Various variables users may set 
177
178 (defvar gnus-uu-tmp-dir "/tmp/" 
179   "Variable saying where gnus-uu is to do its work.
180 Default is \"/tmp/\".")
181
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. 
184 Default is nil.")
185
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 suer will only be asked to save if the
189 viewing is unsuccessful. Default is nil.")
190
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.")
194
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.")
198
199 (defvar gnus-uu-kill-carriage-return t
200   "Non-nil means that gnus-uu will strip all carriage returns from articles.
201 Default is t.")
202
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
207 it nil.")
208
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. 
211 Default is nil.")
212
213 (defvar gnus-uu-correct-stripped-uucode nil
214   "Non-nil means that gnus-uu will *try* to fix uuencoded files that have had traling spaces deleted. 
215 Default is nil.")
216
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.")
223
224 (defvar gnus-uu-save-separate-articles nil
225   "Non-nil means that gnus-uu will save articles in separate files.")
226
227 ;; Internal variables
228
229 (defvar gnus-uu-saved-article-name nil)
230
231 (defconst gnus-uu-begin-string "^begin[ \t]+[0-7][0-7][0-7][ \t]+\\(.*\\)$")
232 (defconst gnus-uu-end-string "^end[ \t]*$")
233
234 (defconst gnus-uu-body-line "^M")
235 (let ((i 61))
236   (while (> (setq i (1- i)) 0)
237     (setq gnus-uu-body-line (concat gnus-uu-body-line "[^a-z]")))
238   (setq gnus-uu-body-line (concat gnus-uu-body-line ".?$")))
239
240 ;"^M.............................................................?$"
241
242 (defconst gnus-uu-shar-begin-string "^#! */bin/sh")
243
244 (defvar gnus-uu-shar-file-name nil)
245 (defconst gnus-uu-shar-name-marker "begin [0-7][0-7][0-7][ \t]+\\(\\(\\w\\|\\.\\)*\\b\\)")
246
247 (defvar gnus-uu-file-name nil)
248 (defconst gnus-uu-uudecode-process nil)
249
250 (defvar gnus-uu-generated-file-list nil)
251 (defvar gnus-uu-work-dir nil)
252
253 (defconst gnus-uu-output-buffer-name "*Gnus UU Output*")
254
255 (defconst gnus-uu-highest-article-number 1)
256
257 ;; Commands.
258
259 (defun gnus-uu-decode-uu (n)
260   "Uudecodes the current article."
261   (interactive "P") 
262   (gnus-uu-decode-with-method 'gnus-uu-uustrip-article n))
263
264 (defun gnus-uu-decode-uu-and-save (n dir)
265   "Decodes and saves the resulting file."
266   (interactive "P\nDWhere do you want to save the file(s)? ")
267   (gnus-uu-decode-with-method 'gnus-uu-uustrip-article n dir))
268
269 (defun gnus-uu-decode-unshar (n)
270   "Unshars the current article."
271   (interactive "P")
272   (gnus-uu-decode-with-method 'gnus-uu-unshar-article n))
273
274 (defun gnus-uu-decode-unshar-and-save (n dir)
275   "Unshars and saves the current article."
276   (interactive "P\nDWhere do you want to save the file(s)? ")
277   (gnus-uu-decode-with-method 'gnus-uu-unshar-article n dir))
278
279 (defun gnus-uu-decode-save (n file)
280   "Saves the current article."
281   (interactive "P\nDWhere do you want to save the file(s)? ")
282   (setq gnus-uu-saved-article-name file)
283   (gnus-uu-decode-with-method 'gnus-uu-save-article n nil)
284   (setq gnus-uu-generated-file-list 
285         (delete file gnus-uu-generated-file-list)))
286
287 (defun gnus-uu-decode-binhex (n dir)
288   "Unbinhexes the current article."
289   (interactive "P\nDWhere do you want to save the file(s)? ")
290   (gnus-uu-decode-with-method 'gnus-uu-binhex-article n dir))
291
292 (defun gnus-uu-decode-uu-view (n)
293   "Uudecodes and views the current article."    
294   (interactive "P")
295   (let ((gnus-view-pseudos 'automatic))
296     (gnus-uu-decode-uu n)))
297
298 (defun gnus-uu-decode-uu-and-save-view (n dir)
299   "Decodes, views and saves the resulting file."
300   (interactive "P\nDWhere do you want to save the file(s)? ")
301   (let ((gnus-view-pseudos 'automatic))
302     (gnus-uu-decode-uu-and-save n dir)))
303
304 (defun gnus-uu-decode-unshar-view (n)
305   "Unshars and views the current article."
306   (interactive "P")
307   (let ((gnus-view-pseudos 'automatic))
308     (gnus-uu-decode-unshar n)))
309
310 (defun gnus-uu-decode-unshar-and-save-view (n dir)
311   "Unshars and saves the current article."
312   (interactive "P\nDWhere do you want to save the file(s)? ")
313   (let ((gnus-view-pseudos 'automatic))
314     (gnus-uu-decode-unshar-and-save n dir)))
315
316 (defun gnus-uu-decode-save-view (n file)
317   "Saves and views the current article."
318   (interactive "P\nDWhere do you want to save the file(s)? ")
319   (let ((gnus-view-pseudos 'automatic))
320     (gnus-uu-decode-save n file)))
321
322 (defun gnus-uu-decode-binhex-view (n file)
323   "Unbinhexes and views the current article."
324   (interactive "P\nDWhere do you want to save the file(s)? ")
325   (let ((gnus-view-pseudos 'automatic))
326     (gnus-uu-decode-binhex n file)))
327
328
329 ;; Digest and forward articles
330
331 (defun gnus-uu-digest-and-forward (n)
332   "Digests and forwards all articles in this series."
333   (interactive "P")
334   (gnus-uu-initialize)
335   (let ((gnus-uu-save-in-digest t)
336         (file (concat gnus-uu-work-dir (make-temp-name "forward"))))
337     (gnus-uu-decode-save n file)
338     (switch-to-buffer (get-buffer-create "*gnus-uu-forward*"))
339     (erase-buffer)
340     (delete-other-windows)
341     (insert-file file)
342     (goto-char (point-min))
343     (funcall gnus-mail-forward-method)))
344
345 ;; Process marking.
346
347 (defun gnus-uu-mark-by-regexp (regexp)
348   "Ask for a regular expression and set the process mark on all articles that match."
349   (interactive (list (read-from-minibuffer "Mark (regexp): ")))
350   (let ((articles (gnus-uu-find-articles-matching regexp)))
351     (while articles
352       (gnus-summary-set-process-mark (car articles))
353       (setq articles (cdr articles)))
354     (message ""))
355   (gnus-summary-position-cursor))
356
357 (defun gnus-uu-mark-series ()
358   "Mark the current series with the process mark."
359   (interactive)
360   (let ((articles (gnus-uu-find-articles-matching)))
361     (while articles
362       (gnus-summary-set-process-mark (car articles))
363       (setq articles (cdr articles)))
364     (message ""))
365   (gnus-summary-position-cursor))
366
367 (defun gnus-uu-mark-region (beg end)
368   "Marks all articles between point and mark."
369   (interactive "r")
370   (save-excursion
371     (goto-char beg)
372     (while (< (point) end)
373       (gnus-summary-set-process-mark (gnus-summary-article-number))
374       (forward-line 1)))
375   (gnus-summary-position-cursor))
376       
377 (defun gnus-uu-mark-thread ()
378   "Marks all articles downwards in this thread."
379   (interactive)
380   (save-excursion
381     (let ((level (gnus-summary-thread-level)))
382     (while (and (gnus-summary-set-process-mark (gnus-summary-article-number))
383                 (zerop (gnus-summary-next-subject 1))
384                 (> (gnus-summary-thread-level) level)))))
385   (gnus-summary-position-cursor))
386
387 (defun gnus-uu-mark-sparse ()
388   "Mark all series that have some articles marked."
389   (interactive)
390   (let ((marked (nreverse gnus-newsgroup-processable))
391         subject articles total)
392     (or marked (error "No articles marked with the process mark"))
393     (setq gnus-newsgroup-processable nil)
394     (save-excursion
395       (while marked
396         (setq subject (header-subject 
397                        (gnus-gethash 
398                         (int-to-string (car marked))
399                         gnus-newsgroup-headers-hashtb-by-number)))
400         (setq articles (gnus-uu-find-articles-matching 
401                         (gnus-uu-reginize-string subject)))
402         (setq total (nconc total articles))
403         (while articles
404           (gnus-summary-set-process-mark (car articles))
405           (setcdr marked (delq (car articles) (cdr marked)))
406           (setq articles (cdr articles)))
407         (setq marked (cdr marked)))
408       (setq gnus-newsgroup-processable (nreverse total)))
409     (gnus-summary-position-cursor)))
410
411 (defun gnus-uu-mark-all ()
412   "Mark all articles in \"series\" order."
413   (interactive)
414   (setq gnus-newsgroup-processable nil)
415   (save-excursion
416     (goto-char (point-min))
417     (let (number)
418       (while (and (not (eobp)) 
419                   (setq number (gnus-summary-article-number)))
420         (if (not (memq number gnus-newsgroup-processable))
421             (save-excursion (gnus-uu-mark-series)))
422         (forward-line 1))))
423   (gnus-summary-position-cursor))
424
425 ;; Internal functions.
426
427 (defun gnus-uu-decode-with-method (method n &optional save)
428   (gnus-uu-initialize)
429   (let ((articles (gnus-uu-get-list-of-articles n))
430         files)
431     (setq files (gnus-uu-grab-articles articles method t))
432     (and save (gnus-uu-save-files files save))
433     (setq files (gnus-uu-unpack-files files))
434     (gnus-uu-add-file (mapcar (lambda (file) (cdr (assq 'name file))) files))
435     (setq files (nreverse (gnus-uu-get-actions files)))
436     (gnus-summary-insert-pseudos files)))
437
438 (defun gnus-uu-save-files (files dir)
439   (let ((len (length files))
440         file)
441     (while files
442       (setq file (cdr (assq 'name (car files))))
443       (copy-file file (if (file-directory-p dir)
444                           (concat dir (file-name-nondirectory file))
445                         dir))
446       (setq files (cdr files)))
447     (message "Saved %d file%s" len (if (> len 1) "s" ""))))
448
449 ;; Functions for saving and possibly digesting articles without
450 ;; any decoding.
451
452 ;; Function called by gnus-uu-grab-articles to treat each article.
453 (defun gnus-uu-save-article (buffer in-state)
454   (cond 
455    (gnus-uu-save-separate-articles
456     (save-excursion
457       (set-buffer buffer)
458       (write-region 1 (point-max) (concat gnus-uu-saved-article-name 
459                                           gnus-current-article))
460       (cond ((eq in-state 'first) (list gnus-uu-saved-article-name 'begin))
461             ((eq in-state 'first-and-last) (list gnus-uu-saved-article-name 
462                                                  'begin 'end))
463             ((eq in-state 'last) (list 'end))
464             (t (list 'middle)))))
465    ((not gnus-uu-save-in-digest)
466     (save-excursion
467       (set-buffer buffer)
468       (write-region 1 (point-max) gnus-uu-saved-article-name t)
469       (cond ((eq in-state 'first) (list gnus-uu-saved-article-name 'begin))
470             ((eq in-state 'first-and-last) (list gnus-uu-saved-article-name 
471                                                  'begin 'end))
472             ((eq in-state 'last) (list 'end))
473             (t (list 'middle)))))
474     (t
475      (let (beg subj name headers headline sorthead body end-string state)
476        (string-match "/\\([^/]*\\)$" gnus-uu-saved-article-name)
477        (setq name (substring gnus-uu-saved-article-name (match-beginning 1)
478                              (match-end 1)))
479        (if (or (eq in-state 'first) 
480                (eq in-state 'first-and-last))
481            (progn 
482              (setq state (list 'begin))
483              (save-excursion (set-buffer (get-buffer-create "*gnus-uu-body*"))
484                              (erase-buffer))
485              (save-excursion 
486                (set-buffer (get-buffer-create "*gnus-uu-pre*"))
487                (erase-buffer)
488                (insert (format 
489                         "Date: %s\nFrom: %s\nSubject: %s Digest\n\nTopics:\n"
490                         (current-time-string) name name))))
491          (if (not (eq in-state 'end))
492              (setq state (list 'middle))))
493        (save-excursion
494          (set-buffer (get-buffer "*gnus-uu-body*"))
495          (goto-char (setq beg (point-max)))
496          (save-excursion
497            (save-restriction
498              (set-buffer buffer)
499              (goto-char 1)
500              (re-search-forward "\n\n")
501              (setq body (buffer-substring (1- (point)) (point-max)))
502              (narrow-to-region 1 (point))
503              (setq headers (list "Date:" "From:" "To:" "Cc:" "Subject:"
504                                  "Message-ID:" "Keywords:" "Summary:"))
505              (while headers
506                (setq headline (car headers))
507                (setq headers (cdr headers))
508                (goto-char 1)
509                (if (re-search-forward (concat "^" headline ".*$") nil t)
510                    (setq sorthead 
511                          (concat sorthead (buffer-substring 
512                                            (match-beginning 0)
513                                            (match-end 0)) "\n"))))
514              (widen)))
515          (insert sorthead)(goto-char (point-max))
516          (insert body)(goto-char (point-max))
517          (insert (concat "\n" (make-string 30 ?-) "\n\n"))
518          (goto-char beg)
519          (if (re-search-forward "^Subject: \\(.*\\)$" nil t)
520              (progn
521                (setq subj (buffer-substring (match-beginning 1) (match-end 1)))
522                (save-excursion 
523                 (set-buffer (get-buffer "*gnus-uu-pre*"))
524                 (insert (format "   %s\n" subj))))))
525       (if (or (eq in-state 'last)
526               (eq in-state 'first-and-last))
527           (progn
528             (save-excursion
529               (set-buffer (get-buffer "*gnus-uu-pre*"))
530               (insert (format "\n\n%s\n\n" (make-string 70 ?-)))
531               (write-region 1 (point-max) gnus-uu-saved-article-name))
532             (save-excursion
533               (set-buffer (get-buffer "*gnus-uu-body*"))
534               (goto-char (point-max))
535               (insert 
536                (concat (setq end-string (format "End of %s Digest" name)) 
537                        "\n"))
538               (insert (concat (make-string (length end-string) ?*) "\n"))
539               (write-region 1 (point-max) gnus-uu-saved-article-name t))
540             (kill-buffer (get-buffer "*gnus-uu-pre*"))
541             (kill-buffer (get-buffer "*gnus-uu-body*"))
542             (setq state (cons 'end state))))
543       (if (memq 'begin state)
544           (cons gnus-uu-saved-article-name state)
545         state)))))
546
547 ;; Binhex treatment - not very advanced. 
548
549 (defconst gnus-uu-binhex-body-line 
550   "^[^:]...............................................................$")
551 (defconst gnus-uu-binhex-begin-line 
552   "^:...............................................................$")
553 (defconst gnus-uu-binhex-end-line
554   ":$")
555 (defvar gnus-uu-binhex-article-name nil)
556
557 (defun gnus-uu-binhex-article (buffer in-state)
558   (let (state start-char)
559     (save-excursion
560       (set-buffer buffer)
561       (widen)
562       (goto-char 1)
563       (if (not (re-search-forward gnus-uu-binhex-begin-line nil t))
564           (if (not (re-search-forward gnus-uu-binhex-body-line nil t))
565               (setq state (list 'wrong-type))))
566
567       (if (memq 'wrong-type state)
568           ()
569         (beginning-of-line)
570         (setq start-char (point))
571         (if (looking-at gnus-uu-binhex-begin-line)
572             (progn
573               (setq state (list 'begin))
574               (write-region 1 1 gnus-uu-binhex-article-name))
575           (setq state (list 'middle)))
576         (goto-char (point-max))
577         (re-search-backward (concat gnus-uu-binhex-body-line "\\|" 
578                                     gnus-uu-binhex-end-line) nil t)
579         (if (looking-at gnus-uu-binhex-end-line)
580             (setq state (if (memq 'begin state)
581                             (cons 'end state)
582                           (list 'end))))
583         (beginning-of-line)
584         (forward-line 1)
585         (if (file-exists-p gnus-uu-binhex-article-name)
586             (append-to-file start-char (point) gnus-uu-binhex-article-name))))
587     (if (memq 'begin state)
588         (cons gnus-uu-binhex-article-name state)
589       state)))
590       
591
592 ;; Find actions.
593
594 (defun gnus-uu-get-actions (files)
595   (let ((ofiles files)
596         action name)
597     (while files
598       (setq name (cdr (assq 'name (car files))))
599       (and 
600        (setq action (gnus-uu-get-action name))
601        (setcar files (cons (cons 'execute (if (string-match "%" action)
602                                               (format action name)
603                                             (concat action " " name)))
604                            (car files))))
605       (setq files (cdr files)))
606     ofiles))
607
608 (defun gnus-uu-get-action (file-name)
609   (let (action)
610     (setq action 
611           (gnus-uu-choose-action 
612            file-name
613            (append 
614             gnus-uu-user-view-rules
615             (if gnus-uu-ignore-default-view-rules 
616                 nil 
617               gnus-uu-default-view-rules)
618             gnus-uu-user-view-rules-end)))
619     (if (and (not (string= (or action "") "gnus-uu-archive")) 
620              gnus-uu-view-with-metamail)
621         (if (setq action 
622                   (gnus-uu-choose-action file-name gnus-uu-ext-to-mime-list))
623             (setq action (format "metamail -d -b -c \"%s\"" action))))
624     action))
625
626
627 ;; Functions for treating subjects and collecting series.
628
629 (defun gnus-uu-reginize-string (string)
630   ;; Takes a string and puts a \ in front of every special character;
631   ;; ignores any leading "version numbers" thingies that they use in
632   ;; the comp.binaries groups, and either replaces anything that looks
633   ;; like "2/3" with "[0-9]+/[0-9]+" or, if it can't find something
634   ;; like that, replaces the last two numbers with "[0-9]+". This, in
635   ;; my experience, should get most postings of a series.
636   (let ((count 2)
637         (vernum "v[0-9]+[a-z][0-9]+:")
638         reg beg)
639     (save-excursion
640       (set-buffer (get-buffer-create gnus-uu-output-buffer-name))
641       (buffer-disable-undo (current-buffer))
642       (erase-buffer)
643       (insert (regexp-quote string))
644       (setq beg 1)
645
646       (setq case-fold-search nil)
647       (goto-char 1)
648       (if (looking-at vernum)
649           (progn
650             (replace-match vernum t t)
651             (setq beg (length vernum))))
652
653       (goto-char beg)
654       (if (re-search-forward "[ \t]*[0-9]+/[0-9]+" nil t)
655           (replace-match " [0-9]+/[0-9]+")
656
657         (goto-char beg)
658         (if (re-search-forward "[0-9]+[ \t]*of[ \t]*[0-9]+" nil t)
659             (replace-match "[0-9]+ of [0-9]+")
660
661           (end-of-line)
662           (while (and (re-search-backward "[0-9]" nil t) (> count 0))
663             (while (and 
664                     (looking-at "[0-9]") 
665                     (< 1 (goto-char (1- (point))))))
666             (re-search-forward "[0-9]+" nil t)
667             (replace-match "[0-9]+")
668             (backward-char 5)
669             (setq count (1- count)))))
670
671       (goto-char beg)
672       (while (re-search-forward "[ \t]+" nil t)
673         (replace-match "[ \t]*" t t))
674
675       (buffer-substring 1 (point-max)))))
676
677 (defun gnus-uu-get-list-of-articles (n)
678   ;; If N is non-nil, the article numbers of the N next articles
679   ;; will be returned.
680   ;; If any articles have been marked as processable, they will be
681   ;; returned. 
682   ;; Failing that, articles that have subjects that are part of the
683   ;; same "series" as the current will be returned.
684   (let (articles process)
685   (cond 
686    (n
687     (let ((backward (< n 0))
688           (n (abs n)))
689       (save-excursion
690         (while (and (> n 0)
691                     (setq articles (cons (gnus-summary-article-number) 
692                                          articles))
693                     (gnus-summary-search-forward nil nil backward))
694           (setq n (1- n))))
695       (nreverse articles)))
696    (gnus-newsgroup-processable
697     (reverse gnus-newsgroup-processable))
698    (t
699     (gnus-uu-find-articles-matching)))))
700
701 (defun gnus-uu-string< (l1 l2)
702   (string< (car l1) (car l2)))
703
704 (defun gnus-uu-find-articles-matching 
705   (&optional subject only-unread do-not-translate)
706   ;; Finds all articles that matches the regexp SUBJECT.  If it is
707   ;; nil, the current article name will be used. If ONLY-UNREAD is
708   ;; non-nil, only unread articles are chosen. If DO-NOT-TRANSLATE is
709   ;; non-nil, article names are not equalized before sorting.
710   (let ((subject (or subject 
711                      (gnus-uu-reginize-string (gnus-summary-subject-string))))
712         beg end list-of-subjects)
713     (save-excursion
714       (if (not subject)
715           ()
716         ;; Collect all subjects matching subject.
717         (let ((case-fold-search t)
718               subj mark)
719           (goto-char (point-min))
720           (while (not (eobp))
721             (and (setq subj (gnus-summary-subject-string))
722                  (string-match subject subj)
723                  (or (not only-unread)
724                      (= (setq mark (gnus-summary-article-mark)) 
725                         gnus-unread-mark)
726                      (= mark gnus-ticked-mark)
727                      (= mark gnus-dormant-mark))
728                  (setq list-of-subjects 
729                        (cons (cons subj (gnus-summary-article-number))
730                              list-of-subjects)))
731             (forward-line 1)))
732
733         ;; Expand numbers, sort, and return the list of article
734         ;; numbers.
735         (mapcar (lambda (sub) (cdr sub)) 
736                 (sort (gnus-uu-expand-numbers 
737                        list-of-subjects
738                        (not do-not-translate)) 
739                       'gnus-uu-string<))))))
740
741 (defun gnus-uu-expand-numbers (string-list &optional translate)
742   ;; Takes a list of strings and "expands" all numbers in all the
743   ;; strings.  That is, this function makes all numbers equal length by
744   ;; prepending lots of zeroes before each number. This is to ease later
745   ;; sorting to find out what sequence the articles are supposed to be
746   ;; decoded in. Returns the list of expanded strings.
747   (let ((out-list string-list)
748         string pos num)
749     (save-excursion
750       (set-buffer (get-buffer-create gnus-uu-output-buffer-name))
751       (buffer-disable-undo (current-buffer))
752       (while string-list
753         (erase-buffer)
754         (insert (car (car string-list)))
755         ;; Translate multiple spaces to one space.
756         (goto-char 1)
757         (while (re-search-forward "[ \t]+" nil t)
758           (replace-match " "))
759         ;; Translate all characters to "a".
760         (goto-char 1)
761         (if translate 
762             (while (re-search-forward "[A-Za-z]" nil t)
763               (replace-match "a" t t)))
764         ;; Expand numbers.
765         (goto-char 1)
766         (while (re-search-forward "[0-9]+" nil t)
767           (replace-match  
768            (format "%06d" 
769                    (string-to-int (buffer-substring 
770                                    (match-beginning 0) (match-end 0))))))
771         (setq string (buffer-substring 1 (point-max)))
772         (setcar (car string-list) string)
773         (setq string-list (cdr string-list))))
774     out-list))
775
776
777 ;; `gnus-uu-grab-articles' is the general multi-article treatment
778 ;; function.  It takes a list of articles to be grabbed and a function
779 ;; to apply to each article.
780 ;;
781 ;; The function to be called should take two parameters.  The first
782 ;; parameter is the article buffer. The function should leave the
783 ;; result, if any, in this buffer. Most treatment functions will just
784 ;; generate files...
785 ;;
786 ;; The second parameter is the state of the list of articles, and can
787 ;; have four values: `first', `middle', `last' and `first-and-last'.
788 ;;
789 ;; The function should return a list. The list may contain the
790 ;; following symbols:
791 ;; `error' if an error occurred
792 ;; `begin' if the beginning of an encoded file has been received
793 ;;   If the list returned contains a `begin', the first element of
794 ;;   the list *must* be a string with the file name of the decoded
795 ;;   file.
796 ;; `end' if the the end of an encoded file has been received
797 ;; `middle' if the article was a body part of an encoded file
798 ;; `wrong-type' if the article was not a part of an encoded file
799 ;; `ok', which can be used everything is ok
800
801 (defvar gnus-uu-has-been-grabbed nil)
802
803 (defun gnus-uu-unmark-list-of-grabbed (&optional dont-unmark-last-article)
804   (let (art)
805     (if (not (and gnus-uu-has-been-grabbed
806                   gnus-uu-unmark-articles-not-decoded))
807         ()
808       (if dont-unmark-last-article
809           (progn
810             (setq art (car gnus-uu-has-been-grabbed))
811             (setq gnus-uu-has-been-grabbed (cdr gnus-uu-has-been-grabbed))))
812       (while gnus-uu-has-been-grabbed
813         (gnus-summary-tick-article (car gnus-uu-has-been-grabbed) t)
814         (setq gnus-uu-has-been-grabbed (cdr gnus-uu-has-been-grabbed)))
815       (if dont-unmark-last-article
816           (setq gnus-uu-has-been-grabbed (list art))))))
817
818 ;; This function takes a list of articles and a function to apply to
819 ;; each article grabbed. 
820 ;; 
821 ;; This function returns a list of files decoded if the grabbing and
822 ;; the process-function has been successful and nil otherwise.
823 (defun gnus-uu-grab-articles 
824   (articles process-function &optional sloppy limit no-errors)
825   (let ((state 'first) 
826         (wrong-type t)
827         has-been-begin has-been-end 
828         article result-file result-files process-state article-buffer
829         begin-article)
830  
831     (if (not (gnus-server-opened gnus-current-select-method))
832         (progn
833           (gnus-start-news-server)
834           (gnus-request-group gnus-newsgroup-name)))
835
836     (setq gnus-uu-has-been-grabbed nil)
837
838     (while (and articles 
839                 (not (memq 'error process-state))
840                 (or sloppy
841                     (not (memq 'end process-state))))
842
843       (setq article (car articles))
844       (setq articles (cdr articles))
845       (setq gnus-uu-has-been-grabbed (cons article gnus-uu-has-been-grabbed))
846
847       (if (> article gnus-uu-highest-article-number) 
848           (setq gnus-uu-highest-article-number article))
849
850       (if (eq articles ()) 
851           (if (eq state 'first)
852               (setq state 'first-and-last)
853             (setq state 'last)))
854
855       (message "Getting article %d" article)
856
857       (if (not (= (or gnus-current-article 0) article))
858           (progn
859             (gnus-request-article article gnus-newsgroup-name
860                                   nntp-server-buffer)
861             (setq gnus-last-article gnus-current-article)
862             (setq gnus-current-article article)
863             (if (stringp nntp-server-buffer)
864                 (setq article-buffer nntp-server-buffer)
865               (setq article-buffer (buffer-name nntp-server-buffer))))
866         (setq article-buffer gnus-article-buffer))
867
868       (buffer-disable-undo article-buffer)
869       (gnus-summary-mark-as-read article)
870       (and (memq article gnus-newsgroup-processable)
871            (gnus-summary-remove-process-mark article))
872
873       (setq process-state (funcall process-function article-buffer state))
874
875       (if (or (memq 'begin process-state)
876               (and (or (eq state 'first) (eq state 'first-and-last))
877                    (memq 'ok process-state)))
878           (progn
879             (if has-been-begin
880                 (if (and result-file (file-exists-p result-file)) 
881                     (delete-file result-file)))
882             (if (memq 'begin process-state)
883                 (setq result-file (car process-state)))
884             (setq begin-article article)
885             (setq has-been-begin t)
886             (setq has-been-end nil)))
887
888       (if (memq 'end process-state)
889           (progn
890             (setq gnus-uu-has-been-grabbed nil)
891             (setq result-files (cons (list (cons 'name result-file)
892                                            (cons 'article article))
893                                      result-files))
894             (setq has-been-end t)
895             (setq has-been-begin nil)
896             (and limit (= (length result-files) limit)
897                  (setq articles nil))))
898
899       (if (and (or (eq state 'last) (eq state 'first-and-last))
900                (not (memq 'end process-state)))
901                 (if (and result-file (file-exists-p result-file))
902                     (delete-file result-file)))
903
904       (if (not (memq 'wrong-type process-state))
905           (setq wrong-type nil)
906         (if gnus-uu-unmark-articles-not-decoded
907             (gnus-summary-tick-article article t)))
908
909       (if sloppy (setq wrong-type nil))
910
911       (if (and (not has-been-begin)
912                (not sloppy)
913                (or (memq 'end process-state)
914                    (memq 'middle process-state)))
915           (progn
916             (setq process-state (list 'error))
917             (message "No begin part at the beginning")
918             (sleep-for 2))
919         (setq state 'middle)))
920
921     ;; Make sure the last article is put in the article buffer & fix
922     ;; windows etc.
923
924     (if (not (string= article-buffer gnus-article-buffer))
925         (save-excursion
926           (set-buffer (get-buffer-create gnus-article-buffer))
927           (let ((buffer-read-only nil))
928             (widen)
929             (erase-buffer)
930             (insert-buffer-substring article-buffer)
931             (goto-char 1))))
932     (run-hooks 'gnus-mark-article-hook)
933
934     (if result-files
935         ()
936       (if (not has-been-begin)
937           (if (not no-errors) (message "Wrong type file"))
938         (if (memq 'error process-state)
939             (setq result-files nil)
940           (if (not (or (memq 'ok process-state) 
941                        (memq 'end process-state)))
942               (progn
943                 (if (not no-errors)
944                     (message "End of articles reached before end of file"))
945                 (setq result-files nil))
946             (gnus-uu-unmark-list-of-grabbed)))))
947     result-files))
948
949 (defun gnus-uu-uudecode-sentinel (process event)
950   (delete-process (get-process process)))
951
952 (defun gnus-uu-uustrip-article (process-buffer in-state)
953   ;; Uudecodes a file asynchronously.
954   (let ((state (list 'ok))
955         (process-connection-type nil)
956         start-char pst name-beg name-end)
957     (save-excursion
958       (set-buffer process-buffer)
959       (let ((case-fold-search nil)
960             (buffer-read-only nil))
961
962         (goto-char 1)
963
964         (if gnus-uu-kill-carriage-return
965             (progn
966               (while (search-forward "\r" nil t)
967                 (delete-backward-char 1))
968               (goto-char 1)))
969
970         (if (not (re-search-forward gnus-uu-begin-string nil t))
971             (if (not (re-search-forward gnus-uu-body-line nil t))
972                 (setq state (list 'wrong-type))))
973      
974         (if (memq 'wrong-type state)
975             ()
976           (beginning-of-line)
977           (setq start-char (point))
978
979           (if (looking-at gnus-uu-begin-string)
980               (progn 
981                 (setq name-end (match-end 1))
982
983                 ; Replace any slashes and spaces in file names before decoding
984                 (goto-char (setq name-beg (match-beginning 1)))
985                 (while (re-search-forward "/" name-end t)
986                   (replace-match ","))
987                 (goto-char name-beg)
988                 (while (re-search-forward " " name-end t)
989                   (replace-match "_"))
990                 (goto-char name-beg)
991                 (if (re-search-forward "_*$" name-end t)
992                   (replace-match ""))
993
994                 (setq gnus-uu-file-name (buffer-substring name-beg name-end))
995                 (and gnus-uu-uudecode-process
996                      (setq pst (process-status 
997                                 (or gnus-uu-uudecode-process "nevair")))
998                      (if (or (eq pst 'stop) (eq pst 'run))
999                          (progn
1000                            (delete-process gnus-uu-uudecode-process)
1001                            (gnus-uu-unmark-list-of-grabbed t))))
1002                 (if (get-process "*uudecode*")
1003                     (delete-process "*uudecode*"))
1004                 (setq gnus-uu-uudecode-process
1005                       (start-process 
1006                        "*uudecode*" 
1007                        (get-buffer-create gnus-uu-output-buffer-name)
1008                        "sh" "-c" 
1009                        (format "cd %s ; uudecode" gnus-uu-work-dir)))
1010                 (set-process-sentinel 
1011                  gnus-uu-uudecode-process 'gnus-uu-uudecode-sentinel)
1012                 (setq state (list 'begin))
1013                 (gnus-uu-add-file (concat gnus-uu-work-dir gnus-uu-file-name)))
1014             (setq state (list 'middle)))
1015         
1016           (goto-char (point-max))
1017
1018           (re-search-backward 
1019            (concat gnus-uu-body-line "\\|" gnus-uu-end-string) nil t)
1020           (beginning-of-line)
1021
1022           (if (looking-at gnus-uu-end-string)
1023               (setq state (cons 'end state)))
1024           (forward-line 1)
1025
1026           (and gnus-uu-uudecode-process
1027                (setq pst (process-status 
1028                           (or gnus-uu-uudecode-process "nevair")))
1029                (if (or (eq pst 'run) (eq pst 'stop))
1030                    (progn
1031                      (if gnus-uu-correct-stripped-uucode
1032                          (progn
1033                            (gnus-uu-check-correct-stripped-uucode 
1034                             start-char (point))
1035                            (goto-char (point-max))
1036                            (re-search-backward 
1037                             (concat gnus-uu-body-line "\\|" 
1038                                     gnus-uu-end-string) 
1039                             nil t)
1040                            (forward-line 1)))
1041
1042                      (condition-case err
1043                          (process-send-region gnus-uu-uudecode-process 
1044                                               start-char (point))
1045                        (error 
1046                         (progn 
1047                           (delete-process gnus-uu-uudecode-process)
1048                           (message "gnus-uu: Couldn't uudecode")
1049 ;                         (sleep-for 2)
1050                           (setq state (list 'wrong-type)))))
1051
1052                      (if (memq 'end state)
1053                          (accept-process-output gnus-uu-uudecode-process)))
1054                  (setq state (list 'wrong-type))))
1055           (if (not gnus-uu-uudecode-process)
1056               (setq state (list 'wrong-type)))))
1057
1058       (if (memq 'begin state)
1059           (cons (concat gnus-uu-work-dir gnus-uu-file-name) state)
1060         state))))
1061
1062 ;; This function is used by `gnus-uu-grab-articles' to treat
1063 ;; a shared article.
1064 (defun gnus-uu-unshar-article (process-buffer in-state)
1065   (let ((state (list 'ok))
1066         start-char)
1067     (save-excursion
1068      (set-buffer process-buffer)
1069      (goto-char 1)
1070      (if (not (re-search-forward gnus-uu-shar-begin-string nil t))
1071          (setq state (list 'wrong-type))
1072        (beginning-of-line)
1073        (setq start-char (point))
1074        (call-process-region 
1075         start-char (point-max) "sh" nil 
1076         (get-buffer-create gnus-uu-output-buffer-name) nil 
1077         "-c" (concat "cd " gnus-uu-work-dir " ; sh"))))
1078     state))
1079
1080 ;; Returns the name of what the shar file is going to unpack.
1081 (defun gnus-uu-find-name-in-shar ()
1082   (let ((oldpoint (point))
1083         res)
1084     (goto-char 1)
1085     (if (re-search-forward gnus-uu-shar-name-marker nil t)
1086         (setq res (buffer-substring (match-beginning 1) (match-end 1))))
1087     (goto-char oldpoint)
1088     res))
1089
1090 ;; `gnus-uu-choose-action' chooses what action to perform given the name
1091 ;; and `gnus-uu-file-action-list'.  Returns either nil if no action is
1092 ;; found, or the name of the command to run if such a rule is found.
1093 (defun gnus-uu-choose-action (file-name file-action-list &optional no-ignore)
1094   (let ((action-list (copy-sequence file-action-list))
1095         rule action)
1096     (and 
1097      (or no-ignore 
1098          (and (not 
1099                (and gnus-uu-ignore-files-by-name
1100                     (string-match gnus-uu-ignore-files-by-name file-name)))
1101               (not 
1102                (and gnus-uu-ignore-files-by-type
1103                     (string-match gnus-uu-ignore-files-by-type 
1104                                   (or (gnus-uu-choose-action 
1105                                        file-name gnus-uu-ext-to-mime-list t) 
1106                                       ""))))))
1107      (while (not (or (eq action-list ()) action))
1108        (setq rule (car action-list))
1109        (setq action-list (cdr action-list))
1110        (if (string-match (car rule) file-name)
1111            (setq action (car (cdr rule))))))
1112     action))
1113
1114 (defun gnus-uu-treat-archive (file-path)
1115   ;; Unpacks an archive. Returns t if unpacking is successful.
1116   (let ((did-unpack t)
1117         action command files file file-name dir)
1118     (setq action (gnus-uu-choose-action 
1119                   file-path (append gnus-uu-user-archive-rules
1120                                     (if gnus-uu-ignore-default-archive-rules
1121                                         nil
1122                                       gnus-uu-default-archive-rules))))
1123
1124     (if (not action) (error "No unpackers for the file %s" file-path))
1125
1126     (string-match "/[^/]*$" file-path)
1127     (setq file-name (substring file-path (1+ (match-beginning 0))))
1128     (setq dir (substring file-path 0 (match-beginning 0)))
1129
1130     (if (member action gnus-uu-destructive-archivers)
1131         (copy-file file-path (concat file-path "~") t))
1132
1133     (setq command (format "cd %s ; %s" dir (gnus-uu-command action file-path)))
1134
1135     (save-excursion
1136       (set-buffer (get-buffer-create gnus-uu-output-buffer-name))
1137       (erase-buffer))
1138
1139     (message "Unpacking: %s..." (gnus-uu-command action file-path))
1140
1141     (if (= 0 (call-process "sh" nil 
1142                            (get-buffer-create gnus-uu-output-buffer-name)
1143                            nil "-c" command))
1144         (message "")
1145       (message "Error during unpacking of archive")
1146       (setq did-unpack nil))
1147
1148     (if (member action gnus-uu-destructive-archivers)
1149         (rename-file (concat file-path "~") file-path t))
1150
1151     did-unpack))
1152
1153 (defun gnus-uu-dir-files (dir)
1154   (let ((dirs (directory-files dir t "[^/][^\\.][^\\.]?$"))
1155         files file)
1156     (while dirs
1157       (if (file-directory-p (setq file (car dirs)))
1158           (setq files (append files (gnus-uu-dir-files file)))
1159         (setq files (cons file files)))
1160       (setq dirs (cdr dirs)))
1161     files))
1162
1163 (defun gnus-uu-unpack-files (files &optional ignore)
1164   ;; Go through FILES and look for files to unpack. 
1165   (let* ((totfiles (gnus-uu-ls-r gnus-uu-work-dir))
1166          (ofiles files)
1167          file did-unpack)
1168     (while files
1169       (setq file (cdr (assq 'name (car files))))
1170       (if (and (not (member file ignore))
1171                (equal (gnus-uu-get-action (file-name-nondirectory file))
1172                       "gnus-uu-archive"))
1173           (progn
1174             (setq did-unpack (cons file did-unpack))
1175             (or (gnus-uu-treat-archive file)
1176                 (message "Error during unpacking of %s" file))
1177             (let* ((newfiles (gnus-uu-ls-r gnus-uu-work-dir))
1178                    (nfiles newfiles))
1179               (while nfiles
1180                 (or (member (car nfiles) totfiles)
1181                     (setq ofiles (cons (list (cons 'name (car nfiles))
1182                                              (cons 'original file))
1183                                        ofiles)))
1184                 (setq nfiles (cdr nfiles)))
1185               (setq totfiles newfiles))))
1186       (setq files (cdr files)))
1187     (if did-unpack 
1188         (gnus-uu-unpack-files ofiles (append did-unpack ignore))
1189       ofiles)))
1190
1191 (defun gnus-uu-ls-r (dir)
1192   (let* ((files (gnus-uu-directory-files dir t))
1193          (ofiles files))
1194     (while files
1195       (if (file-directory-p (car files))
1196           (progn
1197             (setq ofiles (delete (car files) ofiles))
1198             (setq ofiles (append ofiles (gnus-uu-ls-r (car files))))))
1199       (setq files (cdr files)))
1200     ofiles))
1201
1202 ;; Various stuff
1203
1204 (defun gnus-uu-directory-files (dir &optional full)
1205   (let (files out file)
1206     (setq files (directory-files dir full))
1207     (while files
1208       (setq file (car files))
1209       (setq files (cdr files))
1210       (or (string-match "/\\.\\.?$" file)
1211           (setq out (cons file out))))
1212     (setq out (nreverse out))
1213     out))
1214
1215 (defun gnus-uu-check-correct-stripped-uucode (start end)
1216   (let (found beg length short)
1217     (if (not gnus-uu-correct-stripped-uucode)
1218         ()
1219       (goto-char start)
1220
1221       (if (re-search-forward " \\|`" end t)
1222           (progn
1223             (goto-char start)
1224             (while (not (eobp))
1225               (progn
1226                 (if (looking-at "\n") (replace-match ""))
1227                 (forward-line 1))))
1228             
1229         (while (not (eobp))
1230           (if (looking-at (concat gnus-uu-begin-string "\\|" 
1231                                   gnus-uu-end-string))
1232               ()
1233             (if (not found)
1234                 (progn
1235                   (beginning-of-line)
1236                   (setq beg (point))
1237                   (end-of-line)
1238                   (setq length (- (point) beg))))
1239             (setq found t)
1240             (beginning-of-line)
1241             (setq beg (point))
1242             (end-of-line)
1243             (if (not (= length (- (point) beg)))
1244                 (insert (make-string (- length (- (point) beg)) ? ))))
1245           (forward-line 1))))))
1246
1247 (defun gnus-uu-initialize ()
1248   (setq gnus-uu-highest-article-number 1)
1249   (gnus-uu-check-for-generated-files)
1250   (setq gnus-uu-tmp-dir (expand-file-name gnus-uu-tmp-dir))
1251   (if (string-match "[^/]$" gnus-uu-tmp-dir) 
1252       (setq gnus-uu-tmp-dir (concat gnus-uu-tmp-dir "/")))
1253   (if (not (file-directory-p gnus-uu-tmp-dir))
1254       (error "Temp directory %s doesn't exist" gnus-uu-tmp-dir)
1255     (if (not (file-writable-p gnus-uu-tmp-dir))
1256         (error "Temp directory %s can't be written to" gnus-uu-tmp-dir)))
1257   (setq gnus-uu-work-dir 
1258         (concat gnus-uu-tmp-dir (make-temp-name "gnus")))
1259   (gnus-uu-add-file gnus-uu-work-dir)
1260   (if (not (file-directory-p gnus-uu-work-dir)) 
1261       (make-directory gnus-uu-work-dir))
1262   (setq gnus-uu-work-dir (concat gnus-uu-work-dir "/")))
1263
1264 ;; Kills the temporary uu buffers, kills any processes, etc.
1265 (defun gnus-uu-clean-up ()
1266   (let (buf pst)
1267     (and gnus-uu-uudecode-process
1268          (setq pst (process-status (or gnus-uu-uudecode-process "nevair")))
1269          (if (or (eq pst 'stop) (eq pst 'run))
1270              (delete-process gnus-uu-uudecode-process)))
1271     (and (setq buf (get-buffer gnus-uu-output-buffer-name))
1272          (kill-buffer buf))))
1273
1274 ;; `gnus-uu-check-for-generated-files' deletes any generated files that
1275 ;; hasn't been deleted, if, for instance, the user terminated decoding
1276 ;; with `C-g'.
1277 (defun gnus-uu-check-for-generated-files ()
1278   (let (file dirs)
1279     (while gnus-uu-generated-file-list
1280       (setq file (car gnus-uu-generated-file-list))
1281       (setq gnus-uu-generated-file-list (cdr gnus-uu-generated-file-list))
1282       (if (not (string-match "/\\.[\\.]?$" file))
1283           (progn
1284             (if (file-directory-p file)
1285                 (setq dirs (cons file dirs))
1286               (if (file-exists-p file)
1287                   (delete-file file))))))
1288     (setq dirs (nreverse dirs))
1289     (while dirs
1290       (setq file (car dirs))
1291       (setq dirs (cdr dirs))
1292       (if (file-directory-p file)
1293           (if (string-match "/$" file)
1294               (delete-directory (substring file 0 (match-beginning 0)))
1295             (delete-directory file))))))
1296
1297 ;; Add a file (or a list of files) to be checked (and deleted if it/they
1298 ;; still exists upon exiting the newsgroup).
1299 (defun gnus-uu-add-file (file)
1300   (if (stringp file)
1301       (setq gnus-uu-generated-file-list 
1302             (cons file gnus-uu-generated-file-list))
1303     (setq gnus-uu-generated-file-list 
1304           (append file gnus-uu-generated-file-list))))
1305
1306 ;; Inputs an action and a file and returns a full command, putting
1307 ;; ticks round the file name and escaping any ticks in the file name.
1308 (defun gnus-uu-command (action file)
1309   (let ((ofile ""))
1310     (while (string-match "`\\|\"\\|\\$\\|\\\\" file)
1311       (progn
1312         (setq ofile
1313               (concat ofile (substring file 0 (match-beginning 0)) "\\"
1314                       (substring file (match-beginning 0) (match-end 0))))
1315         (setq file (substring file (1+ (match-beginning 0))))))
1316     (setq ofile (concat "\"" ofile file "\""))
1317     (if (string-match "%s" action)
1318         (format action ofile)
1319       (concat action " " ofile))))
1320
1321
1322 ;; Initializing
1323
1324 (add-hook 'gnus-exit-group-hook 'gnus-uu-clean-up)
1325 (add-hook 'gnus-exit-group-hook 'gnus-uu-check-for-generated-files)
1326
1327
1328 ;; Major mode for posting encoded articles.
1329
1330 (require 'sendmail)
1331 (require 'rnews)
1332
1333 ;; Any function that is to be used as and encoding method will take two
1334 ;; parameters: PATH-NAME and FILE-NAME. (E.g. "/home/gaga/spiral.jpg"
1335 ;; and "spiral.jpg", respectively.) The function should return nil if
1336 ;; the encoding wasn't successful.
1337 (defvar gnus-uu-post-encode-method 'gnus-uu-post-encode-uuencode
1338   "Function used for encoding binary files.
1339 There are three functions supplied with gnus-uu for encoding files:
1340 `gnus-uu-post-encode-uuencode', which does straight uuencoding;
1341 `gnus-uu-post-encode-mime', which encodes with base64 and adds MIME 
1342 headers; and `gnus-uu-post-encode-mime-uuencode', which encodes with 
1343 uuencode and adds MIME headers.")
1344
1345 (defvar gnus-uu-post-include-before-composing nil
1346   "Non-nil means that gnus-uu will ask for a file to encode before you compose the article.
1347 If this variable is t, you can either include an encoded file with
1348 \\<gnus-uu-post-reply-mode-map>\\[gnus-uu-post-insert-binary-in-article] or have one included for you when you post the article.")
1349
1350 (defvar gnus-uu-post-length 990
1351   "Maximum length of an article.
1352 The encoded file will be split into how many articles it takes to
1353 post the entire file.")
1354
1355 (defvar gnus-uu-post-threaded nil
1356   "Non-nil means that gnus-uu will post the encoded file in a thread.
1357 This may not be smart, as no other decoder I have seen are able to
1358 follow threads when collecting uuencoded articles. (Well, I have seen
1359 one package that does that - gnus-uu, but somehow, I don't think that 
1360 counts...) Default is nil.")
1361
1362 (defvar gnus-uu-post-separate-description t
1363   "Non-nil means that the description will be posted in a separate article.
1364 The first article will typically be numbered (0/x). If this variable
1365 is nil, the description the user enters will be included at the 
1366 beginning of the first article, which will be numbered (1/x). Default 
1367 is t.")
1368
1369 (defconst gnus-uu-post-binary-separator "--binary follows this line--")
1370 (defvar gnus-uu-post-message-id nil)
1371 (defvar gnus-uu-post-inserted-file-name nil)
1372 (defvar gnus-uu-winconf-post-news nil)
1373
1374 ;; The following map and mode was taken from rnewspost.el and edited
1375 ;; somewhat.
1376 (defvar gnus-uu-post-reply-mode-map nil)
1377 (if gnus-uu-post-reply-mode-map
1378     ()
1379   (setq gnus-uu-post-reply-mode-map (make-keymap))
1380   (define-key gnus-uu-post-reply-mode-map "\C-c?" 'describe-mode)
1381   (define-key gnus-uu-post-reply-mode-map "\C-c\C-f\C-d" 
1382     'news-reply-distribution)
1383   (define-key gnus-uu-post-reply-mode-map "\C-c\C-f\C-k" 
1384     'news-reply-keywords)
1385   (define-key gnus-uu-post-reply-mode-map "\C-c\C-f\C-n" 
1386     'news-reply-newsgroups)
1387       
1388   (define-key gnus-uu-post-reply-mode-map "\C-c\C-f\C-f" 
1389     'news-reply-followup-to)
1390   (define-key gnus-uu-post-reply-mode-map "\C-c\C-f\C-s" 'mail-subject)
1391   (define-key gnus-uu-post-reply-mode-map "\C-c\C-f\C-a" 
1392     'gnus-uu-post-reply-summary)
1393   (define-key gnus-uu-post-reply-mode-map "\C-c\C-r" 
1394     'news-caesar-buffer-body)
1395   (define-key gnus-uu-post-reply-mode-map "\C-c\C-w" 'news-reply-signature)
1396   (define-key gnus-uu-post-reply-mode-map "\C-c\C-y" 
1397     'news-reply-yank-original)
1398   (define-key gnus-uu-post-reply-mode-map "\C-c\C-q" 
1399     'mail-fill-yanked-message)
1400   (define-key gnus-uu-post-reply-mode-map "\C-c\C-c" 
1401     'gnus-uu-post-news-inews)
1402   (define-key gnus-uu-post-reply-mode-map "\C-c\C-s" 
1403     'gnus-uu-post-news-inews)
1404   (define-key gnus-uu-post-reply-mode-map "\C-c\C-i" 
1405     'gnus-uu-post-insert-binary-in-article)
1406   )
1407
1408 ;; This mode was taken from rnewspost.el and modified slightly.
1409 (defun gnus-uu-post-reply-mode ()
1410   "Major mode for editing binary news to be posted on USENET.
1411 First-time posters are asked to please read the articles in newsgroup:
1412                                                      news.announce.newusers .
1413
1414 Like news-reply-mode, which is like Text Mode, but with these
1415 additional commands:
1416
1417 \\<gnus-uu-post-reply-mode-map>\\[gnus-uu-post-news-inews]  post the message.
1418 C-c C-f  move to a header field (and create it if there isn't):
1419          C-c C-f C-n  move to Newsgroups:       C-c C-f C-s  move to Subj:
1420          C-c C-f C-f  move to Followup-To:      C-c C-f C-k  move to Keywords:
1421          C-c C-f C-d  move to Distribution:     C-c C-f C-a  move to Summary:
1422 C-c C-y  news-reply-yank-original (insert current message, in NEWS).
1423 C-c C-q  mail-fill-yanked-message (fill what was yanked).
1424 C-c C-r  caesar rotate all letters by 13 places in the article's body (rot13).
1425 \\[gnus-uu-post-insert-binary-in-article]  encode and include a file in this article.
1426
1427 This mode is almost identical to news-reply-mode, but has some
1428 additional commands for treating encoded binary articles. In
1429 particular, \\[gnus-uu-post-news-inews] will ask for a file to include, if
1430 one hasn't been included already. It will post, first, the message
1431 composed, and then it will post as many additional articles it takes
1432 to post the entire encoded files.
1433
1434    Relevant Variables
1435
1436    `gnus-uu-post-encode-method' 
1437    There are three functions supplied with gnus-uu for encoding files:
1438    `gnus-uu-post-encode-uuencode', which does straight uuencoding;
1439    `gnus-uu-post-encode-mime', which encodes with base64 and adds MIME 
1440    headers; and `gnus-uu-post-encode-mime-uuencode', which encodes with 
1441    uuencode and adds MIME headers.
1442  
1443    `gnus-uu-post-include-before-composing'
1444    Non-nil means that gnus-uu will ask for a file to encode before you
1445    compose the article.  If this variable is t, you can either include
1446    an encoded file with `C-c C-i' or have one included for you when you 
1447    post the article.
1448
1449    `gnus-uu-post-length'
1450    Maximum length of an article. The encoded file will be split into how 
1451    many articles it takes to post the entire file.
1452
1453    `gnus-uu-post-separate-description'
1454    Non-nil means that the description will be posted in a separate 
1455    article. The first article will typically be numbered (0/x). If 
1456    this variable is nil, the description the user enters will be 
1457    included at the beginning of the first article, which will be 
1458    numbered (1/x). Default is t.
1459
1460    `gnus-uu-post-threaded'
1461    Non-nil means that gnus-uu will post the encoded file in a thread.
1462    This may not be smart, as no other decoder I have seen are able to
1463    follow threads when collecting uuencoded articles. (Well, I have seen
1464    one package that does that - gnus-uu, but somehow, I don't think that 
1465    counts...) Default is nil.
1466 "
1467   (interactive)
1468   ;; require...
1469   (or (fboundp 'mail-setup) (load "sendmail"))
1470   (kill-all-local-variables)
1471   (make-local-variable 'mail-reply-buffer)
1472   (setq mail-reply-buffer nil)
1473   (set-syntax-table text-mode-syntax-table)
1474   (use-local-map gnus-uu-post-reply-mode-map)
1475   (setq local-abbrev-table text-mode-abbrev-table)
1476   (setq major-mode 'gnus-uu-post-reply-mode)
1477   (setq mode-name "Gnus UU News")
1478   (make-local-variable 'paragraph-separate)
1479   (make-local-variable 'paragraph-start)
1480   (setq paragraph-start (concat "^" mail-header-separator "$\\|"
1481                                 paragraph-start))
1482   (setq paragraph-separate (concat "^" mail-header-separator "$\\|"
1483                                    paragraph-separate))
1484   (run-hooks 'text-mode-hook 'gnus-uu-post-reply-mode-hook))
1485
1486 (defun gnus-uu-post-news ()
1487   "Compose an article and post an encoded file."
1488   (interactive)
1489   (setq gnus-uu-post-inserted-file-name nil)
1490   (setq gnus-uu-winconf-post-news (current-window-configuration))
1491   (let (news-reply-mode)
1492     (fset 'news-reply-mode 'gnus-uu-post-reply-mode)
1493     (gnus-summary-post-news)
1494     (if gnus-uu-post-include-before-composing
1495         (save-excursion (setq gnus-uu-post-inserted-file-name 
1496                               (gnus-uu-post-insert-binary))))))
1497
1498 (defun gnus-uu-post-insert-binary-in-article ()
1499   "Inserts an encoded file in the buffer.
1500 The user will be asked for a file name."
1501   (interactive)
1502   (if (not (eq (current-buffer) (get-buffer gnus-post-news-buffer)))
1503       (error "Not in post-news buffer"))
1504   (save-excursion 
1505     (setq gnus-uu-post-inserted-file-name (gnus-uu-post-insert-binary))))
1506
1507 ;; Encodes with uuencode and substitutes all spaces with backticks.
1508 (defun gnus-uu-post-encode-uuencode (path file-name)
1509   (if (gnus-uu-post-encode-file "uuencode" path file-name)
1510       (progn
1511         (goto-char 1)
1512         (forward-line 1)
1513         (while (re-search-forward " " nil t)
1514           (replace-match "`"))
1515         t)))
1516
1517 ;; Encodes with uuencode and adds MIME headers.
1518 (defun gnus-uu-post-encode-mime-uuencode (path file-name)
1519   (if (gnus-uu-post-encode-uuencode path file-name)
1520       (progn
1521         (gnus-uu-post-make-mime file-name "x-uue")
1522         t)))
1523
1524 ;; Encodes with base64 and adds MIME headers
1525 (defun gnus-uu-post-encode-mime (path file-name)
1526   (if (gnus-uu-post-encode-file "mmencode" path file-name)
1527       (progn
1528         (gnus-uu-post-make-mime file-name "base64")
1529         t)))
1530
1531 ;; Adds MIME headers.
1532 (defun gnus-uu-post-make-mime (file-name encoding)
1533   (goto-char 1)
1534   (insert (format "Content-Type: %s; name=\"%s\"\n" 
1535                   (gnus-uu-choose-action file-name gnus-uu-ext-to-mime-list) 
1536                   file-name))
1537   (insert (format "Content-Transfer-Encoding: %s\n\n" encoding))
1538   (save-restriction
1539     (set-buffer gnus-post-news-buffer)
1540     (goto-char 1)
1541     (re-search-forward mail-header-separator)
1542     (beginning-of-line)
1543     (forward-line -1)
1544     (narrow-to-region 1 (point))
1545     (or (mail-fetch-field "mime-version")
1546         (progn
1547           (widen)
1548           (insert "MIME-Version: 1.0\n")))
1549     (widen)))
1550
1551 ;; Encodes a file PATH with COMMAND, leaving the result in the
1552 ;; current buffer.
1553 (defun gnus-uu-post-encode-file (command path file-name)
1554   (= 0 (call-process "sh" nil t nil "-c" 
1555                      (format "%s %s %s" command path file-name))))
1556
1557 (defun gnus-uu-post-news-inews ()
1558   "Posts the composed news article and encoded file.
1559 If no file has been included, the user will be asked for a file."
1560   (interactive)
1561   (if (not (eq (current-buffer) (get-buffer gnus-post-news-buffer)))
1562       (error "Not in post news buffer"))
1563
1564   (let (file-name)
1565
1566     (if gnus-uu-post-inserted-file-name
1567         (setq file-name gnus-uu-post-inserted-file-name)
1568       (setq file-name (gnus-uu-post-insert-binary)))
1569   
1570     (if gnus-uu-post-threaded
1571         (let ((gnus-required-headers 
1572                (if (memq 'Message-ID gnus-required-headers)
1573                    gnus-required-headers
1574                  (cons 'Message-ID gnus-required-headers)))
1575               gnus-inews-article-hook elem)
1576
1577           (setq gnus-inews-article-hook (if (listp gnus-inews-article-hook)
1578                                             gnus-inews-article-hook
1579                                           (list gnus-inews-article-hook)))
1580           (setq gnus-inews-article-hook 
1581                 (cons
1582                  '(lambda ()
1583                     (save-excursion
1584                       (goto-char 1)
1585                       (if (re-search-forward "^Message-ID: \\(.*\\)$" nil t)
1586                           (setq gnus-uu-post-message-id 
1587                                 (buffer-substring 
1588                                  (match-beginning 1) (match-end 1)))
1589                         (setq gnus-uu-post-message-id nil))))
1590                  gnus-inews-article-hook))
1591           (gnus-uu-post-encoded file-name t))
1592       (gnus-uu-post-encoded file-name nil)))
1593   (setq gnus-uu-post-inserted-file-name nil)
1594   (and gnus-uu-winconf-post-news
1595        (set-window-configuration gnus-uu-winconf-post-news)))
1596       
1597 ;; Asks for a file to encode, encodes it and inserts the result in
1598 ;; the current buffer. Returns the file name the user gave.
1599 (defun gnus-uu-post-insert-binary ()
1600   (let ((uuencode-buffer-name "*uuencode buffer*")
1601         file-path post-buf uubuf file-name)
1602
1603     (setq file-path (read-file-name 
1604                      "What file do you want to encode? "))
1605     (if (not (file-exists-p file-path))
1606         (error "%s: No such file" file-path))
1607
1608     (goto-char (point-max))
1609     (insert (format "\n%s\n" gnus-uu-post-binary-separator))
1610     
1611     (if (string-match "^~/" file-path)
1612         (setq file-path (concat "$HOME" (substring file-path 1))))
1613     (if (string-match "/[^/]*$" file-path)
1614         (setq file-name (substring file-path (1+ (match-beginning 0))))
1615       (setq file-name file-path))
1616
1617     (unwind-protect
1618         (if (save-excursion
1619               (set-buffer (setq uubuf 
1620                                 (get-buffer-create uuencode-buffer-name)))
1621               (erase-buffer)
1622               (funcall gnus-uu-post-encode-method file-path file-name))
1623             (insert-buffer uubuf)
1624           (error "Encoding unsuccessful"))
1625       (kill-buffer uubuf))
1626     file-name))
1627
1628 ;; Posts the article and all of the encoded file.
1629 (defun gnus-uu-post-encoded (file-name &optional threaded)
1630   (let ((send-buffer-name "*uuencode send buffer*")
1631         (encoded-buffer-name "*encoded buffer*")
1632         (top-string "[ cut here %s (%s %d/%d) %s gnus-uu ]")
1633         (separator (concat mail-header-separator "\n\n"))
1634         file uubuf length parts header i end beg
1635         beg-line minlen buf post-buf whole-len beg-binary end-binary)
1636
1637     (setq post-buf (current-buffer))
1638
1639     (goto-char 1)
1640     (if (not (re-search-forward 
1641               (if gnus-uu-post-separate-description 
1642                   gnus-uu-post-binary-separator 
1643                 mail-header-separator) nil t))
1644         (error "Internal error: No binary/header separator"))
1645     (beginning-of-line)
1646     (forward-line 1)
1647     (setq beg-binary (point))
1648     (setq end-binary (point-max))
1649
1650     (save-excursion 
1651       (set-buffer (setq uubuf (get-buffer-create encoded-buffer-name)))
1652       (erase-buffer)
1653       (insert-buffer-substring post-buf beg-binary end-binary)
1654       (goto-char 1)
1655       (setq length (count-lines 1 (point-max)))
1656       (setq parts (/ length gnus-uu-post-length))
1657       (if (not (< (% length gnus-uu-post-length) 4))
1658           (setq parts (1+ parts))))
1659
1660     (if gnus-uu-post-separate-description
1661         (forward-line -1))
1662     (kill-region (point) (point-max))
1663
1664     (goto-char 1)
1665     (search-forward mail-header-separator nil t)
1666     (beginning-of-line)
1667     (setq header (buffer-substring 1 (point)))
1668
1669     (goto-char 1)
1670     (if (not gnus-uu-post-separate-description)
1671         ()
1672       (if (and (not threaded) (re-search-forward "^Subject: " nil t))
1673           (progn
1674             (end-of-line)
1675             (insert (format " (0/%d)" parts))))
1676       (gnus-inews-news))
1677
1678     (save-excursion
1679       (setq i 1)
1680       (setq beg 1)
1681       (while (not (> i parts))
1682         (set-buffer (get-buffer-create send-buffer-name))
1683         (erase-buffer)
1684         (insert header)
1685         (if (and threaded gnus-uu-post-message-id)
1686             (insert (format "References: %s\n" gnus-uu-post-message-id)))
1687         (insert separator)
1688         (setq whole-len
1689               (- 62 (length (format top-string "" file-name i parts ""))))
1690         (if (> 1 (setq minlen (/ whole-len 2)))
1691             (setq minlen 1))
1692         (setq 
1693          beg-line 
1694          (format top-string
1695                  (make-string minlen ?-) 
1696                  file-name i parts
1697                  (make-string 
1698                   (if (= 0 (% whole-len 2)) (1- minlen) minlen) ?-)))
1699
1700         (goto-char 1)
1701         (if (not (re-search-forward "^Subject: " nil t))
1702             ()
1703           (if (not threaded)
1704               (progn
1705                 (end-of-line)
1706                 (insert (format " (%d/%d)" i parts)))
1707             (if (or (and (= i 2) gnus-uu-post-separate-description)
1708                     (and (= i 1) (not gnus-uu-post-separate-description)))
1709                 (replace-match "Subject: Re: "))))
1710                   
1711         (goto-char (point-max))
1712         (save-excursion
1713           (set-buffer uubuf)
1714           (goto-char beg)
1715           (if (= i parts)
1716               (goto-char (point-max))
1717             (forward-line gnus-uu-post-length))
1718           (if (and (= (1+ i) parts) (< (count-lines (point) (point-max)) 4))
1719               (forward-line -4))
1720           (setq end (point)))
1721         (insert-buffer-substring uubuf beg end)
1722         (insert beg-line)
1723         (insert "\n")
1724         (setq beg end)
1725         (setq i (1+ i))
1726         (goto-char 1)
1727         (re-search-forward mail-header-separator nil t)
1728         (beginning-of-line)
1729         (forward-line 2)
1730         (if (re-search-forward gnus-uu-post-binary-separator nil t)
1731             (progn 
1732               (replace-match "")
1733               (forward-line 1)))
1734         (insert beg-line)
1735         (insert "\n")
1736         (gnus-inews-news)))
1737
1738     (and (setq buf (get-buffer send-buffer-name))
1739          (kill-buffer buf))
1740     (and (setq buf (get-buffer encoded-buffer-name))
1741          (kill-buffer buf))
1742
1743     (if (not gnus-uu-post-separate-description)
1744         (progn
1745           (set-buffer-modified-p nil)
1746           (and (fboundp 'bury-buffer) (bury-buffer))))))
1747
1748 (provide 'gnus-uu)
1749
1750 ;; gnus-uu.el ends here