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