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