1 ;;; gnus-uu.el --- extract (uu)encoded files in Gnus
2 ;; Copyright (C) 1985,86,87,93,94,95 Free Software Foundation, Inc.
4 ;; Author: Lars Magne Ingebrigtsen <larsi@ifi.uio.no>
9 ;; This file is part of GNU Emacs.
11 ;; GNU Emacs is free software; you can redistribute it and/or modify
12 ;; it under the terms of the GNU General Public License as published by
13 ;; the Free Software Foundation; either version 2, or (at your option)
16 ;; GNU Emacs is distributed in the hope that it will be useful,
17 ;; but WITHOUT ANY WARRANTY; without even the implied warranty of
18 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19 ;; GNU General Public License for more details.
21 ;; You should have received a copy of the GNU General Public License
22 ;; along with GNU Emacs; see the file COPYING. If not, write to
23 ;; the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA.
31 ;; Default viewing action rules
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")
43 ("\\.ps$" "ghostview")
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\\)$"
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.
56 To make gnus-uu use 'xli' to display JPEG and GIF files, put the
57 following in your .emacs file
59 (setq gnus-uu-user-view-rules '((\"jpg$\\\\|gif$\" \"xli\")))
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.
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
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
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
84 (defvar gnus-uu-user-view-rules-end
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
90 ;; Default unpacking commands
92 (defvar gnus-uu-default-archive-rules
93 '(("\\.tar$" "tar xf")
94 ("\\.zip$" "unzip -o")
98 ("\\.\\(lzh\\|lha\\)$" "lha x")
99 ("\\.Z$" "uncompress")
101 ("\\.arc$" "arc -x")))
103 (defvar gnus-uu-destructive-archivers
104 (list "uncompress" "gunzip"))
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\")))")
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
119 (setq gnus-uu-ignore-files-by-name \"\\\\.au$\\\\|\\\\.wav$\")
121 Note that this variable can be used in conjunction with the
122 `gnus-uu-ignore-files-by-type' variable.")
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
129 (setq gnus-uu-ignore-files-by-type \"audio/\\\\|video/mpeg\")
131 Note that this variable can be used in conjunction with the
132 `gnus-uu-ignore-files-by-name' variable.")
134 ;; Pseudo-MIME support
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")))
175 ;; Various variables users may set
177 (defvar gnus-uu-tmp-dir "/tmp/"
178 "*Variable saying where gnus-uu is to do its work.
179 Default is \"/tmp/\".")
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.
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.")
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.")
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.")
198 (defvar gnus-uu-kill-carriage-return t
199 "*Non-nil means that gnus-uu will strip all carriage returns from articles.
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
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.
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.
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.")
223 (defvar gnus-uu-save-separate-articles nil
224 "*Non-nil means that gnus-uu will save articles in separate files.")
226 ;; Internal variables
228 (defvar gnus-uu-saved-article-name nil)
230 (defconst gnus-uu-begin-string "^begin[ \t]+[0-7][0-7][0-7][ \t]+\\(.*\\)$")
231 (defconst gnus-uu-end-string "^end[ \t]*$")
233 (defconst gnus-uu-body-line "^M")
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 ".?$")))
239 ;"^M.............................................................?$"
241 (defconst gnus-uu-shar-begin-string "^#! */bin/sh")
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\\)")
246 (defconst gnus-uu-postscript-begin-string "^%!PS-")
247 (defconst gnus-uu-postscript-end-string "^%%EOF$")
249 (defvar gnus-uu-file-name nil)
250 (defconst gnus-uu-uudecode-process nil)
252 (defvar gnus-uu-generated-file-list nil)
253 (defvar gnus-uu-work-dir nil)
255 (defconst gnus-uu-output-buffer-name "*Gnus UU Output*")
257 (defconst gnus-uu-highest-article-number 1)
258 (defvar gnus-uu-default-dir default-directory)
262 (defun gnus-uu-decode-uu (n)
263 "Uudecodes the current article."
265 (gnus-uu-decode-with-method 'gnus-uu-uustrip-article n))
267 (defun gnus-uu-decode-uu-and-save (n dir)
268 "Decodes and saves the resulting file."
270 (list current-prefix-arg
271 (read-file-name "Where do you want to save the file(s)? "
273 gnus-uu-default-dir t)))
274 (gnus-uu-decode-with-method 'gnus-uu-uustrip-article n dir))
276 (defun gnus-uu-decode-unshar (n)
277 "Unshars the current article."
279 (gnus-uu-decode-with-method 'gnus-uu-unshar-article n))
281 (defun gnus-uu-decode-unshar-and-save (n dir)
282 "Unshars and saves the current article."
284 (list current-prefix-arg
285 (read-file-name "Where do you want to save the file(s)? "
287 gnus-uu-default-dir t)))
288 (gnus-uu-decode-with-method 'gnus-uu-unshar-article n dir))
290 (defun gnus-uu-decode-save (n file)
291 "Saves the current article."
293 (list current-prefix-arg
294 (read-file-name "Where do you want to save the file? "
296 gnus-uu-default-dir)))
297 (setq gnus-uu-saved-article-name file)
298 (gnus-uu-decode-with-method 'gnus-uu-save-article n nil)
299 (setq gnus-uu-generated-file-list
300 (delete file gnus-uu-generated-file-list)))
302 (defun gnus-uu-decode-binhex (n dir)
303 "Unbinhexes the current article."
305 (list current-prefix-arg
306 (read-file-name "Where do you want to save the file(s)? "
308 gnus-uu-default-dir t)))
309 (gnus-uu-decode-with-method 'gnus-uu-binhex-article n dir))
311 (defun gnus-uu-decode-uu-view (n)
312 "Uudecodes and views the current article."
314 (let ((gnus-view-pseudos (or gnus-view-pseudos 'automatic)))
315 (gnus-uu-decode-uu n)))
317 (defun gnus-uu-decode-uu-and-save-view (n dir)
318 "Decodes, views and saves the resulting file."
320 (list current-prefix-arg
321 (read-file-name "Where do you want to save the file(s)? "
323 gnus-uu-default-dir t)))
324 (let ((gnus-view-pseudos (or gnus-view-pseudos 'automatic)))
325 (gnus-uu-decode-uu-and-save n dir)))
327 (defun gnus-uu-decode-unshar-view (n)
328 "Unshars and views the current article."
330 (let ((gnus-view-pseudos (or gnus-view-pseudos 'automatic)))
331 (gnus-uu-decode-unshar n)))
333 (defun gnus-uu-decode-unshar-and-save-view (n dir)
334 "Unshars and saves the current article."
336 (list current-prefix-arg
337 (read-file-name "Where do you want to save the file(s)? "
339 gnus-uu-default-dir t)))
340 (let ((gnus-view-pseudos (or gnus-view-pseudos 'automatic)))
341 (gnus-uu-decode-unshar-and-save n dir)))
343 (defun gnus-uu-decode-save-view (n file)
344 "Saves and views the current article."
346 (list current-prefix-arg
347 (read-file-name "Where do you want to save the file? "
348 gnus-uu-default-dir gnus-uu-default-dir)))
349 (let ((gnus-view-pseudos (or gnus-view-pseudos 'automatic)))
350 (gnus-uu-decode-save n file)))
352 (defun gnus-uu-decode-binhex-view (n file)
353 "Unbinhexes and views the current article."
355 (list current-prefix-arg
356 (read-file-name "Where do you want to save the file(s)? "
357 gnus-uu-default-dir gnus-uu-default-dir)))
358 (let ((gnus-view-pseudos (or gnus-view-pseudos 'automatic)))
359 (gnus-uu-decode-binhex n file)))
362 ;; Digest and forward articles
364 (defun gnus-uu-digest-and-forward (n)
365 "Digests and forwards all articles in this series."
368 (let ((gnus-uu-save-in-digest t)
369 (file (concat gnus-uu-work-dir (make-temp-name "forward"))))
370 (gnus-uu-decode-save n file)
371 (switch-to-buffer (get-buffer-create "*gnus-uu-forward*"))
373 (delete-other-windows)
375 (goto-char (point-min))
376 (funcall gnus-mail-forward-method)))
380 (defun gnus-uu-mark-by-regexp (regexp)
381 "Ask for a regular expression and set the process mark on all articles that match."
382 (interactive (list (read-from-minibuffer "Mark (regexp): ")))
383 (let ((articles (gnus-uu-find-articles-matching regexp)))
385 (gnus-summary-set-process-mark (car articles))
386 (setq articles (cdr articles)))
388 (gnus-summary-position-cursor))
390 (defun gnus-uu-mark-series ()
391 "Mark the current series with the process mark."
393 (let ((articles (gnus-uu-find-articles-matching)))
395 (gnus-summary-set-process-mark (car articles))
396 (setq articles (cdr articles)))
398 (gnus-summary-position-cursor))
400 (defun gnus-uu-mark-region (beg end)
401 "Marks all articles between point and mark."
405 (while (< (point) end)
406 (gnus-summary-set-process-mark (gnus-summary-article-number))
408 (gnus-summary-position-cursor))
410 (defun gnus-uu-mark-thread ()
411 "Marks all articles downwards in this thread."
414 (let ((level (gnus-summary-thread-level)))
415 (while (and (gnus-summary-set-process-mark (gnus-summary-article-number))
416 (zerop (gnus-summary-next-subject 1))
417 (> (gnus-summary-thread-level) level)))))
418 (gnus-summary-position-cursor))
420 (defun gnus-uu-mark-sparse ()
421 "Mark all series that have some articles marked."
423 (let ((marked (nreverse gnus-newsgroup-processable))
424 subject articles total)
425 (or marked (error "No articles marked with the process mark"))
426 (setq gnus-newsgroup-processable nil)
429 (setq subject (header-subject (gnus-get-header-by-number (car marked)))
430 articles (gnus-uu-find-articles-matching
431 (gnus-uu-reginize-string subject))
432 total (nconc total articles))
434 (gnus-summary-set-process-mark (car articles))
435 (setcdr marked (delq (car articles) (cdr marked)))
436 (setq articles (cdr articles)))
437 (setq marked (cdr marked)))
438 (setq gnus-newsgroup-processable (nreverse total)))
439 (gnus-summary-position-cursor)))
441 (defun gnus-uu-mark-all ()
442 "Mark all articles in \"series\" order."
444 (setq gnus-newsgroup-processable nil)
446 (goto-char (point-min))
448 (while (and (not (eobp))
449 (setq number (gnus-summary-article-number)))
450 (if (not (memq number gnus-newsgroup-processable))
451 (save-excursion (gnus-uu-mark-series)))
453 (gnus-summary-position-cursor))
455 ;; All PostScript functions written by Erik Selberg <speed@cs.washington.edu>.
457 (defun gnus-uu-decode-postscript (n)
458 "Gets postscript of the current article."
460 (gnus-uu-decode-with-method 'gnus-uu-decode-postscript-article n))
462 (defun gnus-uu-decode-postscript-view (n)
463 "Gets and views the current article."
465 (let ((gnus-view-pseudos (or gnus-view-pseudos 'automatic)))
466 (gnus-uu-decode-postscript n)))
468 (defun gnus-uu-decode-postscript-and-save (n dir)
469 "Extracts postscript and saves the current article."
471 (list current-prefix-arg
472 (read-file-name "Where do you want to save the file(s)? "
474 gnus-uu-default-dir t)))
475 (gnus-uu-decode-with-method 'gnus-uu-decode-postscript-article n dir))
478 (defun gnus-uu-decode-postscript-and-save-view (n dir)
479 "Decodes, views and saves the resulting file."
481 (list current-prefix-arg
482 (read-file-name "Where do you want to save the file(s)? "
484 gnus-uu-default-dir t)))
485 (let ((gnus-view-pseudos (or gnus-view-pseudos 'automatic)))
486 (gnus-uu-decode-postscript-and-save n dir)))
489 ;; Internal functions.
491 (defun gnus-uu-decode-with-method (method n &optional save)
493 (if save (setq gnus-uu-default-dir save))
494 (let ((articles (gnus-uu-get-list-of-articles n))
496 (setq files (gnus-uu-grab-articles articles method t))
497 (and save (gnus-uu-save-files files save))
498 (setq files (gnus-uu-unpack-files files))
499 (gnus-uu-add-file (mapcar (lambda (file) (cdr (assq 'name file))) files))
500 (setq files (nreverse (gnus-uu-get-actions files)))
501 (gnus-summary-insert-pseudos files)))
503 (defun gnus-uu-save-files (files dir)
504 (let ((len (length files))
507 (setq file (cdr (assq 'name (car files))))
508 (and (file-exists-p file)
510 (setq to-file (if (file-directory-p dir)
511 (concat dir (file-name-nondirectory file))
513 (and (or (not (file-exists-p to-file))
514 (gnus-y-or-n-p (format "%s exists; overwrite? " to-file)))
515 (copy-file file to-file 1 t))))
516 (setq files (cdr files)))
517 (message "Saved %d file%s" len (if (> len 1) "s" ""))))
519 ;; Functions for saving and possibly digesting articles without
522 ;; Function called by gnus-uu-grab-articles to treat each article.
523 (defun gnus-uu-save-article (buffer in-state)
525 (gnus-uu-save-separate-articles
528 (write-region 1 (point-max) (concat gnus-uu-saved-article-name
529 gnus-current-article))
530 (cond ((eq in-state 'first) (list gnus-uu-saved-article-name 'begin))
531 ((eq in-state 'first-and-last) (list gnus-uu-saved-article-name
533 ((eq in-state 'last) (list 'end))
534 (t (list 'middle)))))
535 ((not gnus-uu-save-in-digest)
538 (write-region 1 (point-max) gnus-uu-saved-article-name t)
539 (cond ((eq in-state 'first) (list gnus-uu-saved-article-name 'begin))
540 ((eq in-state 'first-and-last) (list gnus-uu-saved-article-name
542 ((eq in-state 'last) (list 'end))
543 (t (list 'middle)))))
545 (let (beg subj name headers headline sorthead body end-string state)
546 (string-match "/\\([^/]*\\)$" gnus-uu-saved-article-name)
547 (setq name (substring gnus-uu-saved-article-name (match-beginning 1)
549 (if (or (eq in-state 'first)
550 (eq in-state 'first-and-last))
552 (setq state (list 'begin))
553 (save-excursion (set-buffer (get-buffer-create "*gnus-uu-body*"))
556 (set-buffer (get-buffer-create "*gnus-uu-pre*"))
559 "Date: %s\nFrom: %s\nSubject: %s Digest\n\nTopics:\n"
560 (current-time-string) name name))))
561 (if (not (eq in-state 'end))
562 (setq state (list 'middle))))
564 (set-buffer (get-buffer "*gnus-uu-body*"))
565 (goto-char (setq beg (point-max)))
570 (re-search-forward "\n\n")
571 (setq body (buffer-substring (1- (point)) (point-max)))
572 (narrow-to-region 1 (point))
573 (setq headers (list "Date:" "From:" "To:" "Cc:" "Subject:"
574 "Message-ID:" "Keywords:" "Summary:"))
576 (setq headline (car headers))
577 (setq headers (cdr headers))
579 (if (re-search-forward (concat "^" headline ".*$") nil t)
581 (concat sorthead (buffer-substring
583 (match-end 0)) "\n"))))
585 (insert sorthead)(goto-char (point-max))
586 (insert body)(goto-char (point-max))
587 (insert (concat "\n" (make-string 30 ?-) "\n\n"))
589 (if (re-search-forward "^Subject: \\(.*\\)$" nil t)
591 (setq subj (buffer-substring (match-beginning 1) (match-end 1)))
593 (set-buffer (get-buffer "*gnus-uu-pre*"))
594 (insert (format " %s\n" subj))))))
595 (if (or (eq in-state 'last)
596 (eq in-state 'first-and-last))
599 (set-buffer (get-buffer "*gnus-uu-pre*"))
600 (insert (format "\n\n%s\n\n" (make-string 70 ?-)))
601 (write-region 1 (point-max) gnus-uu-saved-article-name))
603 (set-buffer (get-buffer "*gnus-uu-body*"))
604 (goto-char (point-max))
606 (concat (setq end-string (format "End of %s Digest" name))
608 (insert (concat (make-string (length end-string) ?*) "\n"))
609 (write-region 1 (point-max) gnus-uu-saved-article-name t))
610 (kill-buffer (get-buffer "*gnus-uu-pre*"))
611 (kill-buffer (get-buffer "*gnus-uu-body*"))
612 (setq state (cons 'end state))))
613 (if (memq 'begin state)
614 (cons gnus-uu-saved-article-name state)
617 ;; Binhex treatment - not very advanced.
619 (defconst gnus-uu-binhex-body-line
620 "^[^:]...............................................................$")
621 (defconst gnus-uu-binhex-begin-line
622 "^:...............................................................$")
623 (defconst gnus-uu-binhex-end-line
625 (defvar gnus-uu-binhex-article-name nil)
627 (defun gnus-uu-binhex-article (buffer in-state)
628 (let (state start-char)
633 (if (not (re-search-forward gnus-uu-binhex-begin-line nil t))
634 (if (not (re-search-forward gnus-uu-binhex-body-line nil t))
635 (setq state (list 'wrong-type))))
637 (if (memq 'wrong-type state)
640 (setq start-char (point))
641 (if (looking-at gnus-uu-binhex-begin-line)
643 (setq state (list 'begin))
644 (write-region 1 1 gnus-uu-binhex-article-name))
645 (setq state (list 'middle)))
646 (goto-char (point-max))
647 (re-search-backward (concat gnus-uu-binhex-body-line "\\|"
648 gnus-uu-binhex-end-line) nil t)
649 (if (looking-at gnus-uu-binhex-end-line)
650 (setq state (if (memq 'begin state)
655 (if (file-exists-p gnus-uu-binhex-article-name)
656 (append-to-file start-char (point) gnus-uu-binhex-article-name))))
657 (if (memq 'begin state)
658 (cons gnus-uu-binhex-article-name state)
663 (defun gnus-uu-decode-postscript-article (process-buffer in-state)
664 (let ((state (list 'ok))
665 start-char end-char file-name)
667 (set-buffer process-buffer)
669 (if (not (re-search-forward gnus-uu-postscript-begin-string nil t))
670 (setq state (list 'wrong-type))
672 (setq start-char (point))
673 (if (not (re-search-forward gnus-uu-postscript-end-string nil t))
674 (setq state (list 'wrong-type))
675 (setq end-char (point))
676 (set-buffer (get-buffer-create gnus-uu-output-buffer-name))
677 (insert-buffer-substring process-buffer start-char end-char)
678 (setq file-name (concat gnus-uu-work-dir (cdr gnus-article-current) ".ps"))
679 (write-region (point-min) (point-max) file-name)
680 (setq state (list file-name'begin 'end))
689 (defun gnus-uu-get-actions (files)
693 (setq name (cdr (assq 'name (car files))))
695 (setq action (gnus-uu-get-action name))
696 (setcar files (cons (cons 'execute (if (string-match "%" action)
698 (concat action " " name)))
700 (setq files (cdr files)))
703 (defun gnus-uu-get-action (file-name)
706 (gnus-uu-choose-action
709 gnus-uu-user-view-rules
710 (if gnus-uu-ignore-default-view-rules
712 gnus-uu-default-view-rules)
713 gnus-uu-user-view-rules-end)))
714 (if (and (not (string= (or action "") "gnus-uu-archive"))
715 gnus-uu-view-with-metamail)
717 (gnus-uu-choose-action file-name gnus-uu-ext-to-mime-list))
718 (setq action (format "metamail -d -b -c \"%s\"" action))))
722 ;; Functions for treating subjects and collecting series.
724 (defun gnus-uu-reginize-string (string)
725 ;; Takes a string and puts a \ in front of every special character;
726 ;; ignores any leading "version numbers" thingies that they use in
727 ;; the comp.binaries groups, and either replaces anything that looks
728 ;; like "2/3" with "[0-9]+/[0-9]+" or, if it can't find something
729 ;; like that, replaces the last two numbers with "[0-9]+". This, in
730 ;; my experience, should get most postings of a series.
732 (vernum "v[0-9]+[a-z][0-9]+:")
735 (set-buffer (get-buffer-create gnus-uu-output-buffer-name))
736 (buffer-disable-undo (current-buffer))
738 (insert (regexp-quote string))
741 (setq case-fold-search nil)
743 (if (looking-at vernum)
745 (replace-match vernum t t)
746 (setq beg (length vernum))))
749 (if (re-search-forward "[ \t]*[0-9]+/[0-9]+" nil t)
750 (replace-match " [0-9]+/[0-9]+")
753 (if (re-search-forward "[0-9]+[ \t]*of[ \t]*[0-9]+" nil t)
754 (replace-match "[0-9]+ of [0-9]+")
757 (while (and (re-search-backward "[0-9]" nil t) (> count 0))
760 (< 1 (goto-char (1- (point))))))
761 (re-search-forward "[0-9]+" nil t)
762 (replace-match "[0-9]+")
764 (setq count (1- count)))))
767 (while (re-search-forward "[ \t]+" nil t)
768 (replace-match "[ \t]*" t t))
770 (buffer-substring 1 (point-max)))))
772 (defun gnus-uu-get-list-of-articles (n)
773 ;; If N is non-nil, the article numbers of the N next articles
775 ;; If any articles have been marked as processable, they will be
777 ;; Failing that, articles that have subjects that are part of the
778 ;; same "series" as the current will be returned.
779 (let (articles process)
782 (let ((backward (< n 0))
786 (setq articles (cons (gnus-summary-article-number)
788 (gnus-summary-search-forward nil nil backward))
790 (nreverse articles)))
791 (gnus-newsgroup-processable
792 (reverse gnus-newsgroup-processable))
794 (gnus-uu-find-articles-matching)))))
796 (defun gnus-uu-string< (l1 l2)
797 (string< (car l1) (car l2)))
799 (defun gnus-uu-find-articles-matching
800 (&optional subject only-unread do-not-translate)
801 ;; Finds all articles that matches the regexp SUBJECT. If it is
802 ;; nil, the current article name will be used. If ONLY-UNREAD is
803 ;; non-nil, only unread articles are chosen. If DO-NOT-TRANSLATE is
804 ;; non-nil, article names are not equalized before sorting.
805 (let ((subject (or subject
806 (gnus-uu-reginize-string (gnus-summary-subject-string))))
807 beg end list-of-subjects)
811 ;; Collect all subjects matching subject.
812 (let ((case-fold-search t)
814 (goto-char (point-min))
816 (and (setq subj (gnus-summary-subject-string))
817 (string-match subject subj)
818 (or (not only-unread)
819 (= (setq mark (gnus-summary-article-mark))
821 (= mark gnus-ticked-mark)
822 (= mark gnus-dormant-mark))
823 (setq list-of-subjects
824 (cons (cons subj (gnus-summary-article-number))
828 ;; Expand numbers, sort, and return the list of article
830 (mapcar (lambda (sub) (cdr sub))
831 (sort (gnus-uu-expand-numbers
833 (not do-not-translate))
834 'gnus-uu-string<))))))
836 (defun gnus-uu-expand-numbers (string-list &optional translate)
837 ;; Takes a list of strings and "expands" all numbers in all the
838 ;; strings. That is, this function makes all numbers equal length by
839 ;; prepending lots of zeroes before each number. This is to ease later
840 ;; sorting to find out what sequence the articles are supposed to be
841 ;; decoded in. Returns the list of expanded strings.
842 (let ((out-list string-list)
845 (set-buffer (get-buffer-create gnus-uu-output-buffer-name))
846 (buffer-disable-undo (current-buffer))
849 (insert (car (car string-list)))
850 ;; Translate multiple spaces to one space.
852 (while (re-search-forward "[ \t]+" nil t)
854 ;; Translate all characters to "a".
857 (while (re-search-forward "[A-Za-z]" nil t)
858 (replace-match "a" t t)))
861 (while (re-search-forward "[0-9]+" nil t)
864 (string-to-int (buffer-substring
865 (match-beginning 0) (match-end 0))))))
866 (setq string (buffer-substring 1 (point-max)))
867 (setcar (car string-list) string)
868 (setq string-list (cdr string-list))))
872 ;; `gnus-uu-grab-articles' is the general multi-article treatment
873 ;; function. It takes a list of articles to be grabbed and a function
874 ;; to apply to each article.
876 ;; The function to be called should take two parameters. The first
877 ;; parameter is the article buffer. The function should leave the
878 ;; result, if any, in this buffer. Most treatment functions will just
881 ;; The second parameter is the state of the list of articles, and can
882 ;; have four values: `first', `middle', `last' and `first-and-last'.
884 ;; The function should return a list. The list may contain the
885 ;; following symbols:
886 ;; `error' if an error occurred
887 ;; `begin' if the beginning of an encoded file has been received
888 ;; If the list returned contains a `begin', the first element of
889 ;; the list *must* be a string with the file name of the decoded
891 ;; `end' if the the end of an encoded file has been received
892 ;; `middle' if the article was a body part of an encoded file
893 ;; `wrong-type' if the article was not a part of an encoded file
894 ;; `ok', which can be used everything is ok
896 (defvar gnus-uu-has-been-grabbed nil)
898 (defun gnus-uu-unmark-list-of-grabbed (&optional dont-unmark-last-article)
900 (if (not (and gnus-uu-has-been-grabbed
901 gnus-uu-unmark-articles-not-decoded))
903 (if dont-unmark-last-article
905 (setq art (car gnus-uu-has-been-grabbed))
906 (setq gnus-uu-has-been-grabbed (cdr gnus-uu-has-been-grabbed))))
907 (while gnus-uu-has-been-grabbed
908 (gnus-summary-tick-article (car gnus-uu-has-been-grabbed) t)
909 (setq gnus-uu-has-been-grabbed (cdr gnus-uu-has-been-grabbed)))
910 (if dont-unmark-last-article
911 (setq gnus-uu-has-been-grabbed (list art))))))
913 ;; This function takes a list of articles and a function to apply to
914 ;; each article grabbed.
916 ;; This function returns a list of files decoded if the grabbing and
917 ;; the process-function has been successful and nil otherwise.
918 (defun gnus-uu-grab-articles
919 (articles process-function &optional sloppy limit no-errors)
922 has-been-begin has-been-end
923 article result-file result-files process-state article-buffer
926 (if (not (gnus-server-opened gnus-current-select-method))
928 (gnus-start-news-server)
929 (gnus-request-group gnus-newsgroup-name)))
931 (setq gnus-uu-has-been-grabbed nil)
934 (not (memq 'error process-state))
936 (not (memq 'end process-state))))
938 (setq article (car articles))
939 (setq articles (cdr articles))
940 (setq gnus-uu-has-been-grabbed (cons article gnus-uu-has-been-grabbed))
942 (if (> article gnus-uu-highest-article-number)
943 (setq gnus-uu-highest-article-number article))
946 (if (eq state 'first)
947 (setq state 'first-and-last)
950 (message "Getting article %d, %s" article (gnus-uu-part-number article))
952 (if (not (= (or gnus-current-article 0) article))
954 (gnus-request-article article gnus-newsgroup-name
956 (setq gnus-last-article gnus-current-article)
957 (setq gnus-current-article article)
958 (if (stringp nntp-server-buffer)
959 (setq article-buffer nntp-server-buffer)
960 (setq article-buffer (buffer-name nntp-server-buffer))))
961 (setq article-buffer gnus-article-buffer))
963 (buffer-disable-undo article-buffer)
964 ;; Mark article as read.
965 (run-hooks 'gnus-mark-article-hook)
966 (and (memq article gnus-newsgroup-processable)
967 (gnus-summary-remove-process-mark article))
969 (setq process-state (funcall process-function article-buffer state))
971 (if (or (memq 'begin process-state)
972 (and (or (eq state 'first) (eq state 'first-and-last))
973 (memq 'ok process-state)))
976 (if (and result-file (file-exists-p result-file))
977 (delete-file result-file)))
978 (if (memq 'begin process-state)
979 (setq result-file (car process-state)))
980 (setq begin-article article)
981 (setq has-been-begin t)
982 (setq has-been-end nil)))
984 (if (memq 'end process-state)
986 (setq gnus-uu-has-been-grabbed nil)
987 (setq result-files (cons (list (cons 'name result-file)
988 (cons 'article article))
990 (setq has-been-end t)
991 (setq has-been-begin nil)
992 (and limit (= (length result-files) limit)
993 (setq articles nil))))
995 (if (and (or (eq state 'last) (eq state 'first-and-last))
996 (not (memq 'end process-state)))
997 (if (and result-file (file-exists-p result-file))
998 (delete-file result-file)))
1000 (if (not (memq 'wrong-type process-state))
1001 (setq wrong-type nil)
1002 (if gnus-uu-unmark-articles-not-decoded
1003 (gnus-summary-tick-article article t)))
1005 (if sloppy (setq wrong-type nil))
1007 (if (and (not has-been-begin)
1009 (or (memq 'end process-state)
1010 (memq 'middle process-state)))
1012 (setq process-state (list 'error))
1013 (message "No begin part at the beginning")
1015 (setq state 'middle)))
1017 ;; Make sure the last article is put in the article buffer & fix
1020 (if (not (string= article-buffer gnus-article-buffer))
1022 (set-buffer (get-buffer-create gnus-article-buffer))
1023 (let ((buffer-read-only nil))
1026 (insert-buffer-substring article-buffer)
1031 (if (not has-been-begin)
1032 (if (not no-errors) (message "Wrong type file"))
1033 (if (memq 'error process-state)
1034 (setq result-files nil)
1035 (if (not (or (memq 'ok process-state)
1036 (memq 'end process-state)))
1039 (message "End of articles reached before end of file"))
1040 (setq result-files nil))
1041 (gnus-uu-unmark-list-of-grabbed)))))
1044 (defun gnus-uu-part-number (article)
1045 (let ((subject (header-subject (gnus-get-header-by-number article))))
1046 (if (string-match "([0-9]+ */[0-9]+)\\|([0-9]+ * of *[0-9]+)"
1048 (substring subject (match-beginning 0) (match-end 0))
1051 (defun gnus-uu-uudecode-sentinel (process event)
1052 (delete-process (get-process process)))
1054 (defun gnus-uu-uustrip-article (process-buffer in-state)
1055 ;; Uudecodes a file asynchronously.
1056 (let ((state (list 'ok))
1057 (process-connection-type nil)
1058 start-char pst name-beg name-end)
1060 (set-buffer process-buffer)
1061 (let ((case-fold-search nil)
1062 (buffer-read-only nil))
1066 (if gnus-uu-kill-carriage-return
1068 (while (search-forward "\r" nil t)
1069 (delete-backward-char 1))
1072 (if (not (re-search-forward gnus-uu-begin-string nil t))
1073 (if (not (re-search-forward gnus-uu-body-line nil t))
1074 (setq state (list 'wrong-type))))
1076 (if (memq 'wrong-type state)
1079 (setq start-char (point))
1081 (if (looking-at gnus-uu-begin-string)
1083 (setq name-end (match-end 1))
1085 ; Replace any slashes and spaces in file names before decoding
1086 (goto-char (setq name-beg (match-beginning 1)))
1087 (while (re-search-forward "/" name-end t)
1088 (replace-match ","))
1089 (goto-char name-beg)
1090 (while (re-search-forward " " name-end t)
1091 (replace-match "_"))
1092 (goto-char name-beg)
1093 (if (re-search-forward "_*$" name-end t)
1096 (setq gnus-uu-file-name (buffer-substring name-beg name-end))
1097 (and gnus-uu-uudecode-process
1098 (setq pst (process-status
1099 (or gnus-uu-uudecode-process "nevair")))
1100 (if (or (eq pst 'stop) (eq pst 'run))
1102 (delete-process gnus-uu-uudecode-process)
1103 (gnus-uu-unmark-list-of-grabbed t))))
1104 (if (get-process "*uudecode*")
1105 (delete-process "*uudecode*"))
1106 (setq gnus-uu-uudecode-process
1109 (get-buffer-create gnus-uu-output-buffer-name)
1111 (format "cd %s ; uudecode" gnus-uu-work-dir)))
1112 (set-process-sentinel
1113 gnus-uu-uudecode-process 'gnus-uu-uudecode-sentinel)
1114 (setq state (list 'begin))
1115 (gnus-uu-add-file (concat gnus-uu-work-dir gnus-uu-file-name)))
1116 (setq state (list 'middle)))
1118 (goto-char (point-max))
1121 (concat gnus-uu-body-line "\\|" gnus-uu-end-string) nil t)
1124 (if (looking-at gnus-uu-end-string)
1125 (setq state (cons 'end state)))
1128 (and gnus-uu-uudecode-process
1129 (setq pst (process-status
1130 (or gnus-uu-uudecode-process "nevair")))
1131 (if (or (eq pst 'run) (eq pst 'stop))
1133 (if gnus-uu-correct-stripped-uucode
1135 (gnus-uu-check-correct-stripped-uucode
1137 (goto-char (point-max))
1139 (concat gnus-uu-body-line "\\|"
1145 (process-send-region gnus-uu-uudecode-process
1149 (delete-process gnus-uu-uudecode-process)
1150 (message "gnus-uu: Couldn't uudecode")
1152 (setq state (list 'wrong-type)))))
1154 (if (memq 'end state)
1155 (accept-process-output gnus-uu-uudecode-process)))
1156 (setq state (list 'wrong-type))))
1157 (if (not gnus-uu-uudecode-process)
1158 (setq state (list 'wrong-type)))))
1160 (if (memq 'begin state)
1161 (cons (concat gnus-uu-work-dir gnus-uu-file-name) state)
1164 ;; This function is used by `gnus-uu-grab-articles' to treat
1165 ;; a shared article.
1166 (defun gnus-uu-unshar-article (process-buffer in-state)
1167 (let ((state (list 'ok))
1170 (set-buffer process-buffer)
1172 (if (not (re-search-forward gnus-uu-shar-begin-string nil t))
1173 (setq state (list 'wrong-type))
1175 (setq start-char (point))
1176 (call-process-region
1177 start-char (point-max) "sh" nil
1178 (get-buffer-create gnus-uu-output-buffer-name) nil
1179 "-c" (concat "cd " gnus-uu-work-dir " ; sh"))))
1182 ;; Returns the name of what the shar file is going to unpack.
1183 (defun gnus-uu-find-name-in-shar ()
1184 (let ((oldpoint (point))
1187 (if (re-search-forward gnus-uu-shar-name-marker nil t)
1188 (setq res (buffer-substring (match-beginning 1) (match-end 1))))
1189 (goto-char oldpoint)
1192 ;; `gnus-uu-choose-action' chooses what action to perform given the name
1193 ;; and `gnus-uu-file-action-list'. Returns either nil if no action is
1194 ;; found, or the name of the command to run if such a rule is found.
1195 (defun gnus-uu-choose-action (file-name file-action-list &optional no-ignore)
1196 (let ((action-list (copy-sequence file-action-list))
1201 (and gnus-uu-ignore-files-by-name
1202 (string-match gnus-uu-ignore-files-by-name file-name)))
1204 (and gnus-uu-ignore-files-by-type
1205 (string-match gnus-uu-ignore-files-by-type
1206 (or (gnus-uu-choose-action
1207 file-name gnus-uu-ext-to-mime-list t)
1209 (while (not (or (eq action-list ()) action))
1210 (setq rule (car action-list))
1211 (setq action-list (cdr action-list))
1212 (if (string-match (car rule) file-name)
1213 (setq action (car (cdr rule))))))
1216 (defun gnus-uu-treat-archive (file-path)
1217 ;; Unpacks an archive. Returns t if unpacking is successful.
1218 (let ((did-unpack t)
1219 action command files file file-name dir)
1220 (setq action (gnus-uu-choose-action
1221 file-path (append gnus-uu-user-archive-rules
1222 (if gnus-uu-ignore-default-archive-rules
1224 gnus-uu-default-archive-rules))))
1226 (if (not action) (error "No unpackers for the file %s" file-path))
1228 (string-match "/[^/]*$" file-path)
1229 (setq file-name (substring file-path (1+ (match-beginning 0))))
1230 (setq dir (substring file-path 0 (match-beginning 0)))
1232 (if (member action gnus-uu-destructive-archivers)
1233 (copy-file file-path (concat file-path "~") t))
1235 (setq command (format "cd %s ; %s" dir (gnus-uu-command action file-path)))
1238 (set-buffer (get-buffer-create gnus-uu-output-buffer-name))
1241 (message "Unpacking: %s..." (gnus-uu-command action file-path))
1243 (if (= 0 (call-process "sh" nil
1244 (get-buffer-create gnus-uu-output-buffer-name)
1247 (message "Error during unpacking of archive")
1248 (setq did-unpack nil))
1250 (if (member action gnus-uu-destructive-archivers)
1251 (rename-file (concat file-path "~") file-path t))
1255 (defun gnus-uu-dir-files (dir)
1256 (let ((dirs (directory-files dir t "[^/][^\\.][^\\.]?$"))
1259 (if (file-directory-p (setq file (car dirs)))
1260 (setq files (append files (gnus-uu-dir-files file)))
1261 (setq files (cons file files)))
1262 (setq dirs (cdr dirs)))
1265 (defun gnus-uu-unpack-files (files &optional ignore)
1266 ;; Go through FILES and look for files to unpack.
1267 (let* ((totfiles (gnus-uu-ls-r gnus-uu-work-dir))
1271 (setq file (cdr (assq 'name (car files))))
1272 (if (and (not (member file ignore))
1273 (equal (gnus-uu-get-action (file-name-nondirectory file))
1276 (setq did-unpack (cons file did-unpack))
1277 (or (gnus-uu-treat-archive file)
1278 (message "Error during unpacking of %s" file))
1279 (let* ((newfiles (gnus-uu-ls-r gnus-uu-work-dir))
1282 (or (member (car nfiles) totfiles)
1283 (setq ofiles (cons (list (cons 'name (car nfiles))
1284 (cons 'original file))
1286 (setq nfiles (cdr nfiles)))
1287 (setq totfiles newfiles))))
1288 (setq files (cdr files)))
1290 (gnus-uu-unpack-files ofiles (append did-unpack ignore))
1293 (defun gnus-uu-ls-r (dir)
1294 (let* ((files (gnus-uu-directory-files dir t))
1297 (if (file-directory-p (car files))
1299 (setq ofiles (delete (car files) ofiles))
1300 (setq ofiles (append ofiles (gnus-uu-ls-r (car files))))))
1301 (setq files (cdr files)))
1306 (defun gnus-uu-directory-files (dir &optional full)
1307 (let (files out file)
1308 (setq files (directory-files dir full))
1310 (setq file (car files))
1311 (setq files (cdr files))
1312 (or (string-match "/\\.\\.?$" file)
1313 (setq out (cons file out))))
1314 (setq out (nreverse out))
1317 (defun gnus-uu-check-correct-stripped-uucode (start end)
1318 (let (found beg length short)
1319 (if (not gnus-uu-correct-stripped-uucode)
1323 (if (re-search-forward " \\|`" end t)
1328 (if (looking-at "\n") (replace-match ""))
1332 (if (looking-at (concat gnus-uu-begin-string "\\|"
1333 gnus-uu-end-string))
1340 (setq length (- (point) beg))))
1345 (if (not (= length (- (point) beg)))
1346 (insert (make-string (- length (- (point) beg)) ? ))))
1347 (forward-line 1))))))
1349 (defun gnus-uu-initialize ()
1350 (setq gnus-uu-highest-article-number 1)
1351 (gnus-uu-check-for-generated-files)
1352 (setq gnus-uu-tmp-dir (expand-file-name gnus-uu-tmp-dir))
1353 (if (string-match "[^/]$" gnus-uu-tmp-dir)
1354 (setq gnus-uu-tmp-dir (concat gnus-uu-tmp-dir "/")))
1355 (if (not (file-directory-p gnus-uu-tmp-dir))
1356 (error "Temp directory %s doesn't exist" gnus-uu-tmp-dir)
1357 (if (not (file-writable-p gnus-uu-tmp-dir))
1358 (error "Temp directory %s can't be written to" gnus-uu-tmp-dir)))
1359 (setq gnus-uu-work-dir
1360 (concat gnus-uu-tmp-dir (make-temp-name "gnus")))
1361 (gnus-uu-add-file gnus-uu-work-dir)
1362 (if (not (file-directory-p gnus-uu-work-dir))
1363 (make-directory gnus-uu-work-dir))
1364 (setq gnus-uu-work-dir (concat gnus-uu-work-dir "/")))
1366 ;; Kills the temporary uu buffers, kills any processes, etc.
1367 (defun gnus-uu-clean-up ()
1369 (and gnus-uu-uudecode-process
1370 (setq pst (process-status (or gnus-uu-uudecode-process "nevair")))
1371 (if (or (eq pst 'stop) (eq pst 'run))
1372 (delete-process gnus-uu-uudecode-process)))
1373 (and (setq buf (get-buffer gnus-uu-output-buffer-name))
1374 (kill-buffer buf))))
1376 ;; `gnus-uu-check-for-generated-files' deletes any generated files that
1377 ;; hasn't been deleted, if, for instance, the user terminated decoding
1379 (defun gnus-uu-check-for-generated-files ()
1381 (while gnus-uu-generated-file-list
1382 (setq file (car gnus-uu-generated-file-list))
1383 (setq gnus-uu-generated-file-list (cdr gnus-uu-generated-file-list))
1384 (if (not (string-match "/\\.[\\.]?$" file))
1386 (if (file-directory-p file)
1387 (setq dirs (cons file dirs))
1388 (if (file-exists-p file)
1389 (delete-file file))))))
1390 (setq dirs (nreverse dirs))
1392 (setq file (car dirs))
1393 (setq dirs (cdr dirs))
1394 (if (file-directory-p file)
1395 (if (string-match "/$" file)
1396 (delete-directory (substring file 0 (match-beginning 0)))
1397 (delete-directory file))))))
1399 ;; Add a file (or a list of files) to be checked (and deleted if it/they
1400 ;; still exists upon exiting the newsgroup).
1401 (defun gnus-uu-add-file (file)
1403 (setq gnus-uu-generated-file-list
1404 (cons file gnus-uu-generated-file-list))
1405 (setq gnus-uu-generated-file-list
1406 (append file gnus-uu-generated-file-list))))
1408 ;; Inputs an action and a file and returns a full command, putting
1409 ;; ticks round the file name and escaping any ticks in the file name.
1410 (defun gnus-uu-command (action file)
1412 (while (string-match "`\\|\"\\|\\$\\|\\\\" file)
1415 (concat ofile (substring file 0 (match-beginning 0)) "\\"
1416 (substring file (match-beginning 0) (match-end 0))))
1417 (setq file (substring file (1+ (match-beginning 0))))))
1418 (setq ofile (concat "\"" ofile file "\""))
1419 (if (string-match "%s" action)
1420 (format action ofile)
1421 (concat action " " ofile))))
1426 (add-hook 'gnus-exit-group-hook 'gnus-uu-clean-up)
1427 (add-hook 'gnus-exit-group-hook 'gnus-uu-check-for-generated-files)
1430 ;; Major mode for posting encoded articles.
1435 ;; Any function that is to be used as and encoding method will take two
1436 ;; parameters: PATH-NAME and FILE-NAME. (E.g. "/home/gaga/spiral.jpg"
1437 ;; and "spiral.jpg", respectively.) The function should return nil if
1438 ;; the encoding wasn't successful.
1439 (defvar gnus-uu-post-encode-method 'gnus-uu-post-encode-uuencode
1440 "Function used for encoding binary files.
1441 There are three functions supplied with gnus-uu for encoding files:
1442 `gnus-uu-post-encode-uuencode', which does straight uuencoding;
1443 `gnus-uu-post-encode-mime', which encodes with base64 and adds MIME
1444 headers; and `gnus-uu-post-encode-mime-uuencode', which encodes with
1445 uuencode and adds MIME headers.")
1447 (defvar gnus-uu-post-include-before-composing nil
1448 "Non-nil means that gnus-uu will ask for a file to encode before you compose the article.
1449 If this variable is t, you can either include an encoded file with
1450 \\<gnus-uu-post-reply-mode-map>\\[gnus-uu-post-insert-binary-in-article] or have one included for you when you post the article.")
1452 (defvar gnus-uu-post-length 990
1453 "Maximum length of an article.
1454 The encoded file will be split into how many articles it takes to
1455 post the entire file.")
1457 (defvar gnus-uu-post-threaded nil
1458 "Non-nil means that gnus-uu will post the encoded file in a thread.
1459 This may not be smart, as no other decoder I have seen are able to
1460 follow threads when collecting uuencoded articles. (Well, I have seen
1461 one package that does that - gnus-uu, but somehow, I don't think that
1462 counts...) Default is nil.")
1464 (defvar gnus-uu-post-separate-description t
1465 "Non-nil means that the description will be posted in a separate article.
1466 The first article will typically be numbered (0/x). If this variable
1467 is nil, the description the user enters will be included at the
1468 beginning of the first article, which will be numbered (1/x). Default
1471 (defconst gnus-uu-post-binary-separator "--binary follows this line--")
1472 (defvar gnus-uu-post-message-id nil)
1473 (defvar gnus-uu-post-inserted-file-name nil)
1474 (defvar gnus-uu-winconf-post-news nil)
1476 ;; The following map and mode was taken from rnewspost.el and edited
1478 (defvar gnus-uu-post-reply-mode-map nil)
1479 (if gnus-uu-post-reply-mode-map
1481 (setq gnus-uu-post-reply-mode-map (make-keymap))
1482 (define-key gnus-uu-post-reply-mode-map "\C-c?" 'describe-mode)
1483 (define-key gnus-uu-post-reply-mode-map "\C-c\C-f\C-d"
1484 'news-reply-distribution)
1485 (define-key gnus-uu-post-reply-mode-map "\C-c\C-f\C-k"
1486 'news-reply-keywords)
1487 (define-key gnus-uu-post-reply-mode-map "\C-c\C-f\C-n"
1488 'news-reply-newsgroups)
1490 (define-key gnus-uu-post-reply-mode-map "\C-c\C-f\C-f"
1491 'news-reply-followup-to)
1492 (define-key gnus-uu-post-reply-mode-map "\C-c\C-f\C-s" 'mail-subject)
1493 (define-key gnus-uu-post-reply-mode-map "\C-c\C-f\C-a"
1494 'gnus-uu-post-reply-summary)
1495 (define-key gnus-uu-post-reply-mode-map "\C-c\C-r"
1496 'news-caesar-buffer-body)
1497 (define-key gnus-uu-post-reply-mode-map "\C-c\C-w" 'news-reply-signature)
1498 (define-key gnus-uu-post-reply-mode-map "\C-c\C-y"
1499 'news-reply-yank-original)
1500 (define-key gnus-uu-post-reply-mode-map "\C-c\C-q"
1501 'mail-fill-yanked-message)
1502 (define-key gnus-uu-post-reply-mode-map "\C-c\C-c"
1503 'gnus-uu-post-news-inews)
1504 (define-key gnus-uu-post-reply-mode-map "\C-c\C-s"
1505 'gnus-uu-post-news-inews)
1506 (define-key gnus-uu-post-reply-mode-map "\C-c\C-i"
1507 'gnus-uu-post-insert-binary-in-article)
1510 ;; This mode was taken from rnewspost.el and modified slightly.
1511 (defun gnus-uu-post-reply-mode ()
1512 "Major mode for editing binary news to be posted on USENET.
1513 First-time posters are asked to please read the articles in newsgroup:
1514 news.announce.newusers .
1516 Like news-reply-mode, which is like Text Mode, but with these
1517 additional commands:
1519 \\<gnus-uu-post-reply-mode-map>\\[gnus-uu-post-news-inews] post the message.
1520 C-c C-f move to a header field (and create it if there isn't):
1521 C-c C-f C-n move to Newsgroups: C-c C-f C-s move to Subj:
1522 C-c C-f C-f move to Followup-To: C-c C-f C-k move to Keywords:
1523 C-c C-f C-d move to Distribution: C-c C-f C-a move to Summary:
1524 C-c C-y news-reply-yank-original (insert current message, in NEWS).
1525 C-c C-q mail-fill-yanked-message (fill what was yanked).
1526 C-c C-r caesar rotate all letters by 13 places in the article's body (rot13).
1527 \\[gnus-uu-post-insert-binary-in-article] encode and include a file in this article.
1529 This mode is almost identical to news-reply-mode, but has some
1530 additional commands for treating encoded binary articles. In
1531 particular, \\[gnus-uu-post-news-inews] will ask for a file to include, if
1532 one hasn't been included already. It will post, first, the message
1533 composed, and then it will post as many additional articles it takes
1534 to post the entire encoded files.
1538 `gnus-uu-post-encode-method'
1539 There are three functions supplied with gnus-uu for encoding files:
1540 `gnus-uu-post-encode-uuencode', which does straight uuencoding;
1541 `gnus-uu-post-encode-mime', which encodes with base64 and adds MIME
1542 headers; and `gnus-uu-post-encode-mime-uuencode', which encodes with
1543 uuencode and adds MIME headers.
1545 `gnus-uu-post-include-before-composing'
1546 Non-nil means that gnus-uu will ask for a file to encode before you
1547 compose the article. If this variable is t, you can either include
1548 an encoded file with `C-c C-i' or have one included for you when you
1551 `gnus-uu-post-length'
1552 Maximum length of an article. The encoded file will be split into how
1553 many articles it takes to post the entire file.
1555 `gnus-uu-post-separate-description'
1556 Non-nil means that the description will be posted in a separate
1557 article. The first article will typically be numbered (0/x). If
1558 this variable is nil, the description the user enters will be
1559 included at the beginning of the first article, which will be
1560 numbered (1/x). Default is t.
1562 `gnus-uu-post-threaded'
1563 Non-nil means that gnus-uu will post the encoded file in a thread.
1564 This may not be smart, as no other decoder I have seen are able to
1565 follow threads when collecting uuencoded articles. (Well, I have seen
1566 one package that does that - gnus-uu, but somehow, I don't think that
1567 counts...) Default is nil.
1571 (or (fboundp 'mail-setup) (load "sendmail"))
1572 (kill-all-local-variables)
1573 (make-local-variable 'mail-reply-buffer)
1574 (setq mail-reply-buffer nil)
1575 (set-syntax-table text-mode-syntax-table)
1576 (use-local-map gnus-uu-post-reply-mode-map)
1577 (setq local-abbrev-table text-mode-abbrev-table)
1578 (setq major-mode 'gnus-uu-post-reply-mode)
1579 (setq mode-name "Gnus UU News")
1580 (make-local-variable 'paragraph-separate)
1581 (make-local-variable 'paragraph-start)
1582 (setq paragraph-start (concat "^" (regexp-quote mail-header-separator)
1583 "$\\|" paragraph-start))
1584 (setq paragraph-separate (concat "^" (regexp-quote mail-header-separator)
1585 "$\\|" paragraph-separate))
1586 (run-hooks 'text-mode-hook 'gnus-uu-post-reply-mode-hook))
1588 (defun gnus-uu-post-news ()
1589 "Compose an article and post an encoded file."
1591 (setq gnus-uu-post-inserted-file-name nil)
1592 (setq gnus-uu-winconf-post-news (current-window-configuration))
1593 (let (news-reply-mode)
1594 (fset 'news-reply-mode 'gnus-uu-post-reply-mode)
1595 (gnus-summary-post-news)
1596 (if gnus-uu-post-include-before-composing
1597 (save-excursion (setq gnus-uu-post-inserted-file-name
1598 (gnus-uu-post-insert-binary))))))
1600 (defun gnus-uu-post-insert-binary-in-article ()
1601 "Inserts an encoded file in the buffer.
1602 The user will be asked for a file name."
1604 (if (not (eq (current-buffer) (get-buffer gnus-post-news-buffer)))
1605 (error "Not in post-news buffer"))
1607 (setq gnus-uu-post-inserted-file-name (gnus-uu-post-insert-binary))))
1609 ;; Encodes with uuencode and substitutes all spaces with backticks.
1610 (defun gnus-uu-post-encode-uuencode (path file-name)
1611 (if (gnus-uu-post-encode-file "uuencode" path file-name)
1615 (while (re-search-forward " " nil t)
1616 (replace-match "`"))
1619 ;; Encodes with uuencode and adds MIME headers.
1620 (defun gnus-uu-post-encode-mime-uuencode (path file-name)
1621 (if (gnus-uu-post-encode-uuencode path file-name)
1623 (gnus-uu-post-make-mime file-name "x-uue")
1626 ;; Encodes with base64 and adds MIME headers
1627 (defun gnus-uu-post-encode-mime (path file-name)
1628 (if (gnus-uu-post-encode-file "mmencode" path file-name)
1630 (gnus-uu-post-make-mime file-name "base64")
1633 ;; Adds MIME headers.
1634 (defun gnus-uu-post-make-mime (file-name encoding)
1636 (insert (format "Content-Type: %s; name=\"%s\"\n"
1637 (gnus-uu-choose-action file-name gnus-uu-ext-to-mime-list)
1639 (insert (format "Content-Transfer-Encoding: %s\n\n" encoding))
1641 (set-buffer gnus-post-news-buffer)
1643 (re-search-forward (regexp-quote mail-header-separator))
1646 (narrow-to-region 1 (point))
1647 (or (mail-fetch-field "mime-version")
1650 (insert "MIME-Version: 1.0\n")))
1653 ;; Encodes a file PATH with COMMAND, leaving the result in the
1655 (defun gnus-uu-post-encode-file (command path file-name)
1656 (= 0 (call-process "sh" nil t nil "-c"
1657 (format "%s %s %s" command path file-name))))
1659 (defun gnus-uu-post-news-inews ()
1660 "Posts the composed news article and encoded file.
1661 If no file has been included, the user will be asked for a file."
1663 (if (not (eq (current-buffer) (get-buffer gnus-post-news-buffer)))
1664 (error "Not in post news buffer"))
1668 (if gnus-uu-post-inserted-file-name
1669 (setq file-name gnus-uu-post-inserted-file-name)
1670 (setq file-name (gnus-uu-post-insert-binary)))
1672 (if gnus-uu-post-threaded
1673 (let ((gnus-required-headers
1674 (if (memq 'Message-ID gnus-required-headers)
1675 gnus-required-headers
1676 (cons 'Message-ID gnus-required-headers)))
1677 gnus-inews-article-hook elem)
1679 (setq gnus-inews-article-hook (if (listp gnus-inews-article-hook)
1680 gnus-inews-article-hook
1681 (list gnus-inews-article-hook)))
1682 (setq gnus-inews-article-hook
1687 (if (re-search-forward "^Message-ID: \\(.*\\)$" nil t)
1688 (setq gnus-uu-post-message-id
1690 (match-beginning 1) (match-end 1)))
1691 (setq gnus-uu-post-message-id nil))))
1692 gnus-inews-article-hook))
1693 (gnus-uu-post-encoded file-name t))
1694 (gnus-uu-post-encoded file-name nil)))
1695 (setq gnus-uu-post-inserted-file-name nil)
1696 (and gnus-uu-winconf-post-news
1697 (set-window-configuration gnus-uu-winconf-post-news)))
1699 ;; Asks for a file to encode, encodes it and inserts the result in
1700 ;; the current buffer. Returns the file name the user gave.
1701 (defun gnus-uu-post-insert-binary ()
1702 (let ((uuencode-buffer-name "*uuencode buffer*")
1703 file-path post-buf uubuf file-name)
1705 (setq file-path (read-file-name
1706 "What file do you want to encode? "))
1707 (if (not (file-exists-p file-path))
1708 (error "%s: No such file" file-path))
1710 (goto-char (point-max))
1711 (insert (format "\n%s\n" gnus-uu-post-binary-separator))
1713 (if (string-match "^~/" file-path)
1714 (setq file-path (concat "$HOME" (substring file-path 1))))
1715 (if (string-match "/[^/]*$" file-path)
1716 (setq file-name (substring file-path (1+ (match-beginning 0))))
1717 (setq file-name file-path))
1721 (set-buffer (setq uubuf
1722 (get-buffer-create uuencode-buffer-name)))
1724 (funcall gnus-uu-post-encode-method file-path file-name))
1725 (insert-buffer uubuf)
1726 (error "Encoding unsuccessful"))
1727 (kill-buffer uubuf))
1730 ;; Posts the article and all of the encoded file.
1731 (defun gnus-uu-post-encoded (file-name &optional threaded)
1732 (let ((send-buffer-name "*uuencode send buffer*")
1733 (encoded-buffer-name "*encoded buffer*")
1734 (top-string "[ cut here %s (%s %d/%d) %s gnus-uu ]")
1735 (separator (concat mail-header-separator "\n\n"))
1736 file uubuf length parts header i end beg
1737 beg-line minlen buf post-buf whole-len beg-binary end-binary)
1739 (setq post-buf (current-buffer))
1742 (if (not (re-search-forward
1743 (if gnus-uu-post-separate-description
1744 gnus-uu-post-binary-separator
1745 (concat "^" (regexp-quote mail-header-separator) "$")) nil t))
1746 (error "Internal error: No binary/header separator"))
1749 (setq beg-binary (point))
1750 (setq end-binary (point-max))
1753 (set-buffer (setq uubuf (get-buffer-create encoded-buffer-name)))
1755 (insert-buffer-substring post-buf beg-binary end-binary)
1757 (setq length (count-lines 1 (point-max)))
1758 (setq parts (/ length gnus-uu-post-length))
1759 (if (not (< (% length gnus-uu-post-length) 4))
1760 (setq parts (1+ parts))))
1762 (if gnus-uu-post-separate-description
1764 (kill-region (point) (point-max))
1768 (concat "^" (regexp-quote mail-header-separator) "$") nil t)
1770 (setq header (buffer-substring 1 (point)))
1773 (if (not gnus-uu-post-separate-description)
1775 (if (and (not threaded) (re-search-forward "^Subject: " nil t))
1778 (insert (format " (0/%d)" parts))))
1784 (while (not (> i parts))
1785 (set-buffer (get-buffer-create send-buffer-name))
1788 (if (and threaded gnus-uu-post-message-id)
1789 (insert (format "References: %s\n" gnus-uu-post-message-id)))
1792 (- 62 (length (format top-string "" file-name i parts ""))))
1793 (if (> 1 (setq minlen (/ whole-len 2)))
1798 (make-string minlen ?-)
1801 (if (= 0 (% whole-len 2)) (1- minlen) minlen) ?-)))
1804 (if (not (re-search-forward "^Subject: " nil t))
1809 (insert (format " (%d/%d)" i parts)))
1810 (if (or (and (= i 2) gnus-uu-post-separate-description)
1811 (and (= i 1) (not gnus-uu-post-separate-description)))
1812 (replace-match "Subject: Re: "))))
1814 (goto-char (point-max))
1819 (goto-char (point-max))
1820 (forward-line gnus-uu-post-length))
1821 (if (and (= (1+ i) parts) (< (count-lines (point) (point-max)) 4))
1824 (insert-buffer-substring uubuf beg end)
1831 (concat "^" (regexp-quote mail-header-separator) "$") nil t)
1834 (if (re-search-forward gnus-uu-post-binary-separator nil t)
1842 (and (setq buf (get-buffer send-buffer-name))
1844 (and (setq buf (get-buffer encoded-buffer-name))
1847 (if (not gnus-uu-post-separate-description)
1849 (set-buffer-modified-p nil)
1850 (and (fboundp 'bury-buffer) (bury-buffer))))))
1854 ;; gnus-uu.el ends here