1 ;;; gnus-uu.el --- extract (uu)encoded files in Gnus
2 ;; Copyright (C) 1985,86,87,93,94,95,96 Free Software Foundation, Inc.
4 ;; Author: Lars Magne Ingebrigtsen <larsi@ifi.uio.no>
8 ;; This file is part of GNU Emacs.
10 ;; GNU Emacs is free software; you can redistribute it and/or modify
11 ;; it under the terms of the GNU General Public License as published by
12 ;; the Free Software Foundation; either version 2, or (at your option)
15 ;; GNU Emacs is distributed in the hope that it will be useful,
16 ;; but WITHOUT ANY WARRANTY; without even the implied warranty of
17 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 ;; GNU General Public License for more details.
20 ;; You should have received a copy of the GNU General Public License
21 ;; along with GNU Emacs; see the file COPYING. If not, write to the
22 ;; Free Software Foundation, Inc., 59 Temple Place - Suite 330,
23 ;; Boston, MA 02111-1307, USA.
34 ;; Default viewing action rules
36 (defvar gnus-uu-default-view-rules
37 '(("\\.te?xt$\\|\\.doc$\\|read.*me\\|\\.c?$\\|\\.h$\\|\\.bat$\\|\\.asm$\\|makefile" "cat %s | sed s/\r//g")
38 ("\\.pas$" "cat %s | sed s/\r//g")
39 ("\\.[1-9]$" "groff -mandoc -Tascii %s | sed s/\b.//g")
40 ("\\.\\(jpe?g\\|gif\\|tiff?\\|p[pgb]m\\|xwd\\|xbm\\|pcx\\)$" "xv")
41 ("\\.tga$" "tgatoppm %s | xv -")
42 ("\\.\\(wav\\|aiff\\|hcom\\|u[blw]\\|s[bfw]\\|voc\\|smp\\)$"
43 "sox -v .5 %s -t .au -u - > /dev/audio")
44 ("\\.au$" "cat %s > /dev/audio")
45 ("\\.midi?$" "playmidi -f")
47 ("\\.ps$" "ghostview")
49 ("\\.html$" "xmosaic")
50 ("\\.mpe?g$" "mpeg_play")
51 ("\\.\\(flc\\|fli\\|rle\\|iff\\|pfx\\|avi\\|sme\\|rpza\\|dl\\|qt\\|rsrc\\|mov\\)$" "xanim")
52 ("\\.\\(tar\\|arj\\|zip\\|zoo\\|arc\\|gz\\|Z\\|lzh\\|ar\\|lha\\)$"
54 "*Default actions to be taken when the user asks to view a file.
55 To change the behaviour, you can either edit this variable or set
56 `gnus-uu-user-view-rules' to something useful.
60 To make gnus-uu use 'xli' to display JPEG and GIF files, put the
61 following in your .emacs file:
63 (setq gnus-uu-user-view-rules '((\"jpg$\\\\|gif$\" \"xli\")))
65 Both these variables are lists of lists with two string elements. The
66 first string is a regular expression. If the file name matches this
67 regular expression, the command in the second string is executed with
68 the file as an argument.
70 If the command string contains \"%s\", the file name will be inserted
71 at that point in the command string. If there's no \"%s\" in the
72 command string, the file name will be appended to the command string
75 There are several user variables to tailor the behaviour of gnus-uu to
76 your needs. First we have `gnus-uu-user-view-rules', which is the
77 variable gnus-uu first consults when trying to decide how to view a
78 file. If this variable contains no matches, gnus-uu examines the
79 default rule variable provided in this package. If gnus-uu finds no
80 match here, it uses `gnus-uu-user-view-rules-end' to try to make a
83 (defvar gnus-uu-user-view-rules nil
84 "*Variable detailing what actions are to be taken to view a file.
85 See the documentation on the `gnus-uu-default-view-rules' variable for
88 (defvar gnus-uu-user-view-rules-end
90 "*Variable saying what actions are to be taken if no rule matched the file name.
91 See the documentation on the `gnus-uu-default-view-rules' variable for
94 ;; Default unpacking commands
96 (defvar gnus-uu-default-archive-rules
97 '(("\\.tar$" "tar xf")
98 ("\\.zip$" "unzip -o")
100 ("\\.arj$" "unarj x")
102 ("\\.\\(lzh\\|lha\\)$" "lha x")
103 ("\\.Z$" "uncompress")
105 ("\\.arc$" "arc -x")))
107 (defvar gnus-uu-destructive-archivers
108 (list "uncompress" "gunzip"))
110 (defvar gnus-uu-user-archive-rules nil
111 "*A list that can be set to override the default archive unpacking commands.
112 To use, for instance, 'untar' to unpack tar files and 'zip -x' to
113 unpack zip files, say the following:
114 (setq gnus-uu-user-archive-rules
115 '((\"\\\\.tar$\" \"untar\")
116 (\"\\\\.zip$\" \"zip -x\")))")
118 (defvar gnus-uu-ignore-files-by-name nil
119 "*A regular expression saying what files should not be viewed based on name.
120 If, for instance, you want gnus-uu to ignore all .au and .wav files,
121 you could say something like
123 (setq gnus-uu-ignore-files-by-name \"\\\\.au$\\\\|\\\\.wav$\")
125 Note that this variable can be used in conjunction with the
126 `gnus-uu-ignore-files-by-type' variable.")
128 (defvar gnus-uu-ignore-files-by-type nil
129 "*A regular expression saying what files that shouldn't be viewed, based on MIME file type.
130 If, for instance, you want gnus-uu to ignore all audio files and all mpegs,
131 you could say something like
133 (setq gnus-uu-ignore-files-by-type \"audio/\\\\|video/mpeg\")
135 Note that this variable can be used in conjunction with the
136 `gnus-uu-ignore-files-by-name' variable.")
138 ;; Pseudo-MIME support
140 (defconst gnus-uu-ext-to-mime-list
141 '(("\\.gif$" "image/gif")
142 ("\\.jpe?g$" "image/jpeg")
143 ("\\.tiff?$" "image/tiff")
144 ("\\.xwd$" "image/xwd")
145 ("\\.pbm$" "image/pbm")
146 ("\\.pgm$" "image/pgm")
147 ("\\.ppm$" "image/ppm")
148 ("\\.xbm$" "image/xbm")
149 ("\\.pcx$" "image/pcx")
150 ("\\.tga$" "image/tga")
151 ("\\.ps$" "image/postscript")
152 ("\\.fli$" "video/fli")
153 ("\\.wav$" "audio/wav")
154 ("\\.aiff$" "audio/aiff")
155 ("\\.hcom$" "audio/hcom")
156 ("\\.voc$" "audio/voc")
157 ("\\.smp$" "audio/smp")
158 ("\\.mod$" "audio/mod")
159 ("\\.dvi$" "image/dvi")
160 ("\\.mpe?g$" "video/mpeg")
161 ("\\.au$" "audio/basic")
162 ("\\.\\(te?xt\\|doc\\|c\\|h\\)$" "text/plain")
163 ("\\.\\(c\\|h\\)$" "text/source")
164 ("read.*me" "text/plain")
165 ("\\.html$" "text/html")
166 ("\\.bat$" "text/bat")
167 ("\\.[1-6]$" "text/man")
168 ("\\.flc$" "video/flc")
169 ("\\.rle$" "video/rle")
170 ("\\.pfx$" "video/pfx")
171 ("\\.avi$" "video/avi")
172 ("\\.sme$" "video/sme")
173 ("\\.rpza$" "video/prza")
174 ("\\.dl$" "video/dl")
175 ("\\.qt$" "video/qt")
176 ("\\.rsrc$" "video/rsrc")
177 ("\\..*$" "unknown/unknown")))
179 ;; Various variables users may set
181 (defvar gnus-uu-tmp-dir "/tmp/"
182 "*Variable saying where gnus-uu is to do its work.
183 Default is \"/tmp/\".")
185 (defvar gnus-uu-do-not-unpack-archives nil
186 "*Non-nil means that gnus-uu won't peek inside archives looking for files to display.
189 (defvar gnus-uu-ignore-default-view-rules nil
190 "*Non-nil means that gnus-uu will ignore the default viewing rules.
191 Only the user viewing rules will be consulted. Default is nil.")
193 (defvar gnus-uu-grabbed-file-functions nil
194 "*Functions run on each file after successful decoding.
195 They will be called with the name of the file as the argument.
196 Likely functions you can use in this list are `gnus-uu-grab-view'
197 and `gnus-uu-grab-move'.")
199 (defvar gnus-uu-ignore-default-archive-rules nil
200 "*Non-nil means that gnus-uu will ignore the default archive unpacking commands.
201 Only the user unpacking commands will be consulted. Default is nil.")
203 (defvar gnus-uu-kill-carriage-return t
204 "*Non-nil means that gnus-uu will strip all carriage returns from articles.
207 (defvar gnus-uu-view-with-metamail nil
208 "*Non-nil means that files will be viewed with metamail.
209 The gnus-uu viewing functions will be ignored and gnus-uu will try
210 to guess at a content-type based on file name suffixes. Default
213 (defvar gnus-uu-unmark-articles-not-decoded nil
214 "*Non-nil means that gnus-uu will mark articles that were unsuccessfully decoded as unread.
217 (defvar gnus-uu-correct-stripped-uucode nil
218 "*Non-nil means that gnus-uu will *try* to fix uuencoded files that have had trailing spaces deleted.
221 (defvar gnus-uu-save-in-digest nil
222 "*Non-nil means that gnus-uu, when asked to save without decoding, will save in digests.
223 If this variable is nil, gnus-uu will just save everything in a
224 file without any embellishments. The digesting almost conforms to RFC1153 -
225 no easy way to specify any meaningful volume and issue numbers were found,
226 so I simply dropped them.")
228 (defvar gnus-uu-digest-headers
229 '("^Date:" "^From:" "^To:" "^Cc:" "^Subject:" "^Message-ID:" "^Keywords:"
230 "^Summary:" "^References:")
231 "*List of regexps to match headers included in digested messages.
232 The headers will be included in the sequence they are matched.")
234 (defvar gnus-uu-save-separate-articles nil
235 "*Non-nil means that gnus-uu will save articles in separate files.")
237 ;; Internal variables
239 (defvar gnus-uu-saved-article-name nil)
241 (defconst gnus-uu-begin-string "^begin[ \t]+[0-7][0-7][0-7][ \t]+\\(.*\\)$")
242 (defconst gnus-uu-end-string "^end[ \t]*$")
244 (defconst gnus-uu-body-line "^M")
246 (while (> (setq i (1- i)) 0)
247 (setq gnus-uu-body-line (concat gnus-uu-body-line "[^a-z]")))
248 (setq gnus-uu-body-line (concat gnus-uu-body-line ".?$")))
250 ;"^M.............................................................?$"
252 (defconst gnus-uu-shar-begin-string "^#! */bin/sh")
254 (defvar gnus-uu-shar-file-name nil)
255 (defconst gnus-uu-shar-name-marker "begin [0-7][0-7][0-7][ \t]+\\(\\(\\w\\|\\.\\)*\\b\\)")
257 (defconst gnus-uu-postscript-begin-string "^%!PS-")
258 (defconst gnus-uu-postscript-end-string "^%%EOF$")
260 (defvar gnus-uu-file-name nil)
261 (defconst gnus-uu-uudecode-process nil)
262 (defvar gnus-uu-binhex-article-name nil)
264 (defvar gnus-uu-work-dir nil)
266 (defconst gnus-uu-output-buffer-name " *Gnus UU Output*")
268 (defvar gnus-uu-default-dir gnus-article-save-directory)
269 (defvar gnus-uu-digest-from-subject nil)
273 (gnus-define-keys (gnus-uu-mark-map "P" gnus-summary-mark-map)
274 "p" gnus-summary-mark-as-processable
275 "u" gnus-summary-unmark-as-processable
276 "U" gnus-summary-unmark-all-processable
277 "v" gnus-uu-mark-over
278 "s" gnus-uu-mark-series
279 "r" gnus-uu-mark-region
280 "R" gnus-uu-mark-by-regexp
281 "t" gnus-uu-mark-thread
282 "T" gnus-uu-unmark-thread
284 "b" gnus-uu-mark-buffer
285 "S" gnus-uu-mark-sparse
286 "k" gnus-summary-kill-process-mark
287 "y" gnus-summary-yank-process-mark
288 "w" gnus-summary-save-process-mark
289 "i" gnus-uu-invert-processable)
291 (gnus-define-keys (gnus-uu-extract-map "X" gnus-summary-mode-map)
292 ;;"x" gnus-uu-extract-any
293 ;;"m" gnus-uu-extract-mime
294 "u" gnus-uu-decode-uu
295 "U" gnus-uu-decode-uu-and-save
296 "s" gnus-uu-decode-unshar
297 "S" gnus-uu-decode-unshar-and-save
298 "o" gnus-uu-decode-save
299 "O" gnus-uu-decode-save
300 "b" gnus-uu-decode-binhex
301 "B" gnus-uu-decode-binhex
302 "p" gnus-uu-decode-postscript
303 "P" gnus-uu-decode-postscript-and-save)
306 (gnus-uu-extract-view-map "v" gnus-uu-extract-map)
307 "u" gnus-uu-decode-uu-view
308 "U" gnus-uu-decode-uu-and-save-view
309 "s" gnus-uu-decode-unshar-view
310 "S" gnus-uu-decode-unshar-and-save-view
311 "o" gnus-uu-decode-save-view
312 "O" gnus-uu-decode-save-view
313 "b" gnus-uu-decode-binhex-view
314 "B" gnus-uu-decode-binhex-view
315 "p" gnus-uu-decode-postscript-view
316 "P" gnus-uu-decode-postscript-and-save-view)
321 (defun gnus-uu-decode-uu (&optional n)
322 "Uudecodes the current article."
324 (gnus-uu-decode-with-method 'gnus-uu-uustrip-article n))
326 (defun gnus-uu-decode-uu-and-save (n dir)
327 "Decodes and saves the resulting file."
329 (list current-prefix-arg
330 (file-name-as-directory
331 (read-file-name "Uudecode and save in dir: "
333 gnus-uu-default-dir t))))
334 (gnus-uu-decode-with-method 'gnus-uu-uustrip-article n dir nil nil t))
336 (defun gnus-uu-decode-unshar (&optional n)
337 "Unshars the current article."
339 (gnus-uu-decode-with-method 'gnus-uu-unshar-article n nil nil 'scan t))
341 (defun gnus-uu-decode-unshar-and-save (n dir)
342 "Unshars and saves the current article."
344 (list current-prefix-arg
345 (file-name-as-directory
346 (read-file-name "Unshar and save in dir: "
348 gnus-uu-default-dir t))))
349 (gnus-uu-decode-with-method 'gnus-uu-unshar-article n dir nil 'scan t))
351 (defun gnus-uu-decode-save (n file)
352 "Saves the current article."
354 (list current-prefix-arg
356 (if gnus-uu-save-separate-articles
357 "Save articles is dir: "
358 "Save articles in file: ")
360 gnus-uu-default-dir)))
361 (setq gnus-uu-saved-article-name file)
362 (gnus-uu-decode-with-method 'gnus-uu-save-article n nil t))
364 (defun gnus-uu-decode-binhex (n dir)
365 "Unbinhexes the current article."
367 (list current-prefix-arg
368 (file-name-as-directory
369 (read-file-name "Unbinhex and save in dir: "
371 gnus-uu-default-dir))))
372 (setq gnus-uu-binhex-article-name
373 (make-temp-name (concat gnus-uu-work-dir "binhex")))
374 (gnus-uu-decode-with-method 'gnus-uu-binhex-article n dir))
376 (defun gnus-uu-decode-uu-view (&optional n)
377 "Uudecodes and views the current article."
379 (let ((gnus-view-pseudos (or gnus-view-pseudos 'automatic)))
380 (gnus-uu-decode-uu n)))
382 (defun gnus-uu-decode-uu-and-save-view (n dir)
383 "Decodes, views and saves the resulting file."
385 (list current-prefix-arg
386 (read-file-name "Uudecode, view and save in dir: "
388 gnus-uu-default-dir t)))
389 (let ((gnus-view-pseudos (or gnus-view-pseudos 'automatic)))
390 (gnus-uu-decode-uu-and-save n dir)))
392 (defun gnus-uu-decode-unshar-view (&optional n)
393 "Unshars and views the current article."
395 (let ((gnus-view-pseudos (or gnus-view-pseudos 'automatic)))
396 (gnus-uu-decode-unshar n)))
398 (defun gnus-uu-decode-unshar-and-save-view (n dir)
399 "Unshars and saves the current article."
401 (list current-prefix-arg
402 (read-file-name "Unshar, view and save in dir: "
404 gnus-uu-default-dir t)))
405 (let ((gnus-view-pseudos (or gnus-view-pseudos 'automatic)))
406 (gnus-uu-decode-unshar-and-save n dir)))
408 (defun gnus-uu-decode-save-view (n file)
409 "Saves and views the current article."
411 (list current-prefix-arg
412 (read-file-name (if gnus-uu-save-separate-articles
413 "Save articles is dir: "
414 "Save articles in file: ")
415 gnus-uu-default-dir gnus-uu-default-dir)))
416 (let ((gnus-view-pseudos (or gnus-view-pseudos 'automatic)))
417 (gnus-uu-decode-save n file)))
419 (defun gnus-uu-decode-binhex-view (n file)
420 "Unbinhexes and views the current article."
422 (list current-prefix-arg
423 (read-file-name "Unbinhex, view and save in dir: "
424 gnus-uu-default-dir gnus-uu-default-dir)))
425 (setq gnus-uu-binhex-article-name
426 (make-temp-name (concat gnus-uu-work-dir "binhex")))
427 (let ((gnus-view-pseudos (or gnus-view-pseudos 'automatic)))
428 (gnus-uu-decode-binhex n file)))
431 ;; Digest and forward articles
433 (defun gnus-uu-digest-mail-forward (&optional n post)
434 "Digests and forwards all articles in this series."
436 (let ((gnus-uu-save-in-digest t)
437 (file (make-temp-name (concat gnus-uu-tmp-dir "forward")))
439 (setq gnus-uu-digest-from-subject nil)
440 (gnus-uu-decode-save n file)
441 (setq buf (switch-to-buffer (get-buffer-create " *gnus-uu-forward*")))
442 (gnus-add-current-to-buffer-list)
444 (delete-other-windows)
446 (let ((fs gnus-uu-digest-from-subject))
450 subject (gnus-simplify-subject-fuzzy (cdar fs))
452 (while (and fs (or from subject))
454 (or (string= from (caar fs))
457 (or (string= (gnus-simplify-subject-fuzzy (cdar fs))
461 (or subject (setq subject "Digested Articles"))
462 (or from (setq from "Various")))
463 (goto-char (point-min))
464 (and (re-search-forward "^Subject: ")
466 (delete-region (point) (gnus-point-at-eol))
468 (goto-char (point-min))
469 (and (re-search-forward "^From: ")
471 (delete-region (point) (gnus-point-at-eol))
473 (message-forward post)
476 (setq gnus-uu-digest-from-subject nil)))
478 (defun gnus-uu-digest-post-forward (&optional n)
479 "Digest and forward to a newsgroup."
481 (gnus-uu-digest-mail-forward n t))
485 (defun gnus-uu-mark-by-regexp (regexp &optional unmark)
486 "Ask for a regular expression and set the process mark on all articles that match."
487 (interactive (list (read-from-minibuffer "Mark (regexp): ")))
488 (gnus-set-global-variables)
489 (let ((articles (gnus-uu-find-articles-matching regexp)))
492 (gnus-summary-remove-process-mark (pop articles))
493 (gnus-summary-set-process-mark (pop articles))))
495 (gnus-summary-position-point))
497 (defun gnus-uu-unmark-by-regexp (regexp &optional unmark)
498 "Ask for a regular expression and remove the process mark on all articles that match."
499 (interactive (list (read-from-minibuffer "Mark (regexp): ")))
500 (gnus-uu-mark-by-regexp regexp t))
502 (defun gnus-uu-mark-series ()
503 "Mark the current series with the process mark."
505 (gnus-set-global-variables)
506 (let ((articles (gnus-uu-find-articles-matching)))
508 (gnus-summary-set-process-mark (car articles))
509 (setq articles (cdr articles)))
511 (gnus-summary-position-point))
513 (defun gnus-uu-mark-region (beg end &optional unmark)
514 "Set the process mark on all articles between point and mark."
516 (gnus-set-global-variables)
519 (while (< (point) end)
521 (gnus-summary-remove-process-mark (gnus-summary-article-number))
522 (gnus-summary-set-process-mark (gnus-summary-article-number)))
524 (gnus-summary-position-point))
526 (defun gnus-uu-unmark-region (beg end)
527 "Remove the process mark from all articles between point and mark."
529 (gnus-uu-mark-region beg end t))
531 (defun gnus-uu-mark-buffer ()
532 "Set the process mark on all articles in the buffer."
534 (gnus-uu-mark-region (point-min) (point-max)))
536 (defun gnus-uu-unmark-buffer ()
537 "Remove the process mark on all articles in the buffer."
539 (gnus-uu-mark-region (point-min) (point-max) t))
541 (defun gnus-uu-mark-thread ()
542 "Marks all articles downwards in this thread."
544 (gnus-set-global-variables)
545 (let ((level (gnus-summary-thread-level)))
546 (while (and (gnus-summary-set-process-mark (gnus-summary-article-number))
547 (zerop (gnus-summary-next-subject 1))
548 (> (gnus-summary-thread-level) level))))
549 (gnus-summary-position-point))
551 (defun gnus-uu-unmark-thread ()
552 "Unmarks all articles downwards in this thread."
554 (gnus-set-global-variables)
555 (let ((level (gnus-summary-thread-level)))
556 (while (and (gnus-summary-remove-process-mark
557 (gnus-summary-article-number))
558 (zerop (gnus-summary-next-subject 1))
559 (> (gnus-summary-thread-level) level))))
560 (gnus-summary-position-point))
562 (defun gnus-uu-invert-processable ()
563 "Invert the list of process-marked articles."
564 (let ((data gnus-newsgroup-data)
568 (if (memq (setq number (gnus-data-number (pop data)))
569 gnus-newsgroup-processable)
570 (gnus-summary-remove-process-mark number)
571 (gnus-summary-set-process-mark number)))))
572 (gnus-summary-position-point))
574 (defun gnus-uu-mark-over (&optional score)
575 "Mark all articles with a score over SCORE (the prefix.)"
577 (let ((score (gnus-score-default score))
578 (data gnus-newsgroup-data))
581 (when (> (or (cdr (assq (gnus-data-number (car data))
582 gnus-newsgroup-scored))
583 gnus-summary-default-score 0)
585 (gnus-summary-set-process-mark (caar data)))
586 (setq data (cdr data))))
587 (gnus-summary-position-point)))
589 (defun gnus-uu-mark-sparse ()
590 "Mark all series that have some articles marked."
592 (gnus-set-global-variables)
593 (let ((marked (nreverse gnus-newsgroup-processable))
594 subject articles total headers)
595 (or marked (error "No articles marked with the process mark"))
596 (setq gnus-newsgroup-processable nil)
599 (and (vectorp (setq headers
600 (gnus-summary-article-header (car marked))))
601 (setq subject (mail-header-subject headers)
602 articles (gnus-uu-find-articles-matching
603 (gnus-uu-reginize-string subject))
604 total (nconc total articles)))
606 (gnus-summary-set-process-mark (car articles))
607 (setcdr marked (delq (car articles) (cdr marked)))
608 (setq articles (cdr articles)))
609 (setq marked (cdr marked)))
610 (setq gnus-newsgroup-processable (nreverse total)))
611 (gnus-summary-position-point)))
613 (defun gnus-uu-mark-all ()
614 "Mark all articles in \"series\" order."
616 (gnus-set-global-variables)
617 (setq gnus-newsgroup-processable nil)
619 (let ((data gnus-newsgroup-data)
622 (when (and (not (memq (setq number (gnus-data-number (car data)))
623 gnus-newsgroup-processable))
624 (vectorp (gnus-data-header (car data))))
625 (gnus-summary-goto-subject number)
626 (gnus-uu-mark-series))
627 (setq data (cdr data)))))
628 (gnus-summary-position-point))
630 ;; All PostScript functions written by Erik Selberg <speed@cs.washington.edu>.
632 (defun gnus-uu-decode-postscript (&optional n)
633 "Gets postscript of the current article."
635 (gnus-uu-decode-with-method 'gnus-uu-decode-postscript-article n))
637 (defun gnus-uu-decode-postscript-view (&optional n)
638 "Gets and views the current article."
640 (let ((gnus-view-pseudos (or gnus-view-pseudos 'automatic)))
641 (gnus-uu-decode-postscript n)))
643 (defun gnus-uu-decode-postscript-and-save (n dir)
644 "Extracts postscript and saves the current article."
646 (list current-prefix-arg
647 (file-name-as-directory
648 (read-file-name "Save in dir: "
650 gnus-uu-default-dir t))))
651 (gnus-uu-decode-with-method 'gnus-uu-decode-postscript-article
654 (defun gnus-uu-decode-postscript-and-save-view (n dir)
655 "Decodes, views and saves the resulting file."
657 (list current-prefix-arg
658 (read-file-name "Where do you want to save the file(s)? "
660 gnus-uu-default-dir t)))
661 (let ((gnus-view-pseudos (or gnus-view-pseudos 'automatic)))
662 (gnus-uu-decode-postscript-and-save n dir)))
665 ;; Internal functions.
667 (defun gnus-uu-decode-with-method (method n &optional save not-insert
669 (gnus-uu-initialize scan)
670 (if save (setq gnus-uu-default-dir save))
671 ;; Create the directory we save to.
672 (when (and scan cdir save
673 (not (file-exists-p save)))
674 (make-directory save t))
675 (let ((articles (gnus-uu-get-list-of-articles n))
677 (setq files (gnus-uu-grab-articles articles method t))
678 (let ((gnus-current-article (car articles)))
679 (and scan (setq files (gnus-uu-scan-directory gnus-uu-work-dir))))
680 (and save (gnus-uu-save-files files save))
681 (if (eq gnus-uu-do-not-unpack-archives nil)
682 (setq files (gnus-uu-unpack-files files)))
683 (setq files (nreverse (gnus-uu-get-actions files)))
684 (or not-insert (not gnus-insert-pseudo-articles)
685 (gnus-summary-insert-pseudos files save))))
687 (defun gnus-uu-scan-directory (dir &optional rec)
688 "Return a list of all files under DIR."
689 (let ((files (directory-files dir t))
691 (while (setq file (pop files))
692 (unless (member (file-name-nondirectory file) '("." ".."))
693 (push (list (cons 'name file)
694 (cons 'article gnus-current-article))
696 (when (file-directory-p file)
697 (setq out (nconc (gnus-uu-scan-directory file t) out)))))
702 (defun gnus-uu-save-files (files dir)
704 (let ((len (length files))
705 (reg (concat "^" (regexp-quote gnus-uu-work-dir)))
706 to-file file fromdir)
707 (while (setq file (cdr (assq 'name (pop files))))
708 (when (file-exists-p file)
709 (string-match reg file)
710 (setq fromdir (substring file (match-end 0)))
711 (if (file-directory-p file)
712 (gnus-make-directory (concat dir fromdir))
713 (setq to-file (concat dir fromdir))
714 (when (or (not (file-exists-p to-file))
715 (gnus-y-or-n-p (format "%s exists; overwrite? " to-file)))
716 (copy-file file to-file t t)))))
717 (gnus-message 5 "Saved %d file%s" len (if (= len 1) "" "s"))))
719 ;; Functions for saving and possibly digesting articles without
722 ;; Function called by gnus-uu-grab-articles to treat each article.
723 (defun gnus-uu-save-article (buffer in-state)
725 (gnus-uu-save-separate-articles
728 (write-region 1 (point-max) (concat gnus-uu-saved-article-name
729 gnus-current-article))
730 (cond ((eq in-state 'first) (list gnus-uu-saved-article-name 'begin))
731 ((eq in-state 'first-and-last) (list gnus-uu-saved-article-name
733 ((eq in-state 'last) (list 'end))
734 (t (list 'middle)))))
735 ((not gnus-uu-save-in-digest)
738 (write-region 1 (point-max) gnus-uu-saved-article-name t)
739 (cond ((eq in-state 'first) (list gnus-uu-saved-article-name 'begin))
740 ((eq in-state 'first-and-last) (list gnus-uu-saved-article-name
742 ((eq in-state 'last) (list 'end))
743 (t (list 'middle)))))
745 (let ((header (gnus-summary-article-header)))
746 (setq gnus-uu-digest-from-subject
747 (cons (cons (mail-header-from header)
748 (mail-header-subject header))
749 gnus-uu-digest-from-subject)))
750 (let ((name (file-name-nondirectory gnus-uu-saved-article-name))
751 (delim (concat "^" (make-string 30 ?-) "$"))
752 beg subj headers headline sorthead body end-string state)
753 (if (or (eq in-state 'first)
754 (eq in-state 'first-and-last))
756 (setq state (list 'begin))
757 (save-excursion (set-buffer (get-buffer-create "*gnus-uu-body*"))
760 (set-buffer (get-buffer-create "*gnus-uu-pre*"))
763 "Date: %s\nFrom: %s\nSubject: %s Digest\n\nTopics:\n"
764 (current-time-string) name name))))
765 (if (not (eq in-state 'end))
766 (setq state (list 'middle))))
768 (set-buffer (get-buffer "*gnus-uu-body*"))
769 (goto-char (setq beg (point-max)))
773 (let (buffer-read-only)
774 (gnus-set-text-properties (point-min) (point-max) nil)
775 ;; These two are necessary for XEmacs 19.12 fascism.
776 (put-text-property (point-min) (point-max) 'invisible nil)
777 (put-text-property (point-min) (point-max) 'intangible nil))
778 (goto-char (point-min))
779 (re-search-forward "\n\n")
780 ;; Quote all 30-dash lines.
782 (while (re-search-forward delim nil t)
786 (setq body (buffer-substring (1- (point)) (point-max)))
787 (narrow-to-region (point-min) (point))
788 (if (not (setq headers gnus-uu-digest-headers))
789 (setq sorthead (buffer-substring (point-min) (point-max)))
791 (setq headline (car headers))
792 (setq headers (cdr headers))
793 (goto-char (point-min))
794 (while (re-search-forward headline nil t)
799 (or (and (re-search-forward "^[^ \t]" nil t)
801 (progn (forward-line 1) (point)))))))))
803 (insert sorthead) (goto-char (point-max))
804 (insert body) (goto-char (point-max))
805 (insert (concat "\n" (make-string 30 ?-) "\n\n"))
807 (if (re-search-forward "^Subject: \\(.*\\)$" nil t)
809 (setq subj (buffer-substring (match-beginning 1) (match-end 1)))
811 (set-buffer (get-buffer "*gnus-uu-pre*"))
812 (insert (format " %s\n" subj))))))
813 (if (or (eq in-state 'last)
814 (eq in-state 'first-and-last))
817 (set-buffer (get-buffer "*gnus-uu-pre*"))
818 (insert (format "\n\n%s\n\n" (make-string 70 ?-)))
819 (write-region 1 (point-max) gnus-uu-saved-article-name))
821 (set-buffer (get-buffer "*gnus-uu-body*"))
822 (goto-char (point-max))
824 (concat (setq end-string (format "End of %s Digest" name))
826 (insert (concat (make-string (length end-string) ?*) "\n"))
827 (write-region 1 (point-max) gnus-uu-saved-article-name t))
828 (kill-buffer (get-buffer "*gnus-uu-pre*"))
829 (kill-buffer (get-buffer "*gnus-uu-body*"))
830 (setq state (cons 'end state))))
831 (if (memq 'begin state)
832 (cons gnus-uu-saved-article-name state)
835 ;; Binhex treatment - not very advanced.
837 (defconst gnus-uu-binhex-body-line
838 "^[^:]...............................................................$")
839 (defconst gnus-uu-binhex-begin-line
840 "^:...............................................................$")
841 (defconst gnus-uu-binhex-end-line
844 (defun gnus-uu-binhex-article (buffer in-state)
845 (let (state start-char)
849 (goto-char (point-min))
850 (if (not (re-search-forward gnus-uu-binhex-begin-line nil t))
851 (if (not (re-search-forward gnus-uu-binhex-body-line nil t))
852 (setq state (list 'wrong-type))))
854 (if (memq 'wrong-type state)
857 (setq start-char (point))
858 (if (looking-at gnus-uu-binhex-begin-line)
860 (setq state (list 'begin))
861 (write-region 1 1 gnus-uu-binhex-article-name))
862 (setq state (list 'middle)))
863 (goto-char (point-max))
864 (re-search-backward (concat gnus-uu-binhex-body-line "\\|"
865 gnus-uu-binhex-end-line) nil t)
866 (if (looking-at gnus-uu-binhex-end-line)
867 (setq state (if (memq 'begin state)
872 (if (file-exists-p gnus-uu-binhex-article-name)
873 (append-to-file start-char (point) gnus-uu-binhex-article-name))))
874 (if (memq 'begin state)
875 (cons gnus-uu-binhex-article-name state)
880 (defun gnus-uu-decode-postscript-article (process-buffer in-state)
881 (let ((state (list 'ok))
882 start-char end-char file-name)
884 (set-buffer process-buffer)
885 (goto-char (point-min))
886 (if (not (re-search-forward gnus-uu-postscript-begin-string nil t))
887 (setq state (list 'wrong-type))
889 (setq start-char (point))
890 (if (not (re-search-forward gnus-uu-postscript-end-string nil t))
891 (setq state (list 'wrong-type))
892 (setq end-char (point))
893 (set-buffer (get-buffer-create gnus-uu-output-buffer-name))
894 (insert-buffer-substring process-buffer start-char end-char)
895 (setq file-name (concat gnus-uu-work-dir
896 (cdr gnus-article-current) ".ps"))
897 (write-region (point-min) (point-max) file-name)
898 (setq state (list file-name 'begin 'end)))))
904 (defun gnus-uu-get-actions (files)
908 (setq name (cdr (assq 'name (car files))))
910 (setq action (gnus-uu-get-action name))
911 (setcar files (nconc (list (if (string= action "gnus-uu-archive")
912 (cons 'action "file")
913 (cons 'action action))
914 (cons 'execute (gnus-uu-command
917 (setq files (cdr files)))
920 (defun gnus-uu-get-action (file-name)
923 (gnus-uu-choose-action
926 gnus-uu-user-view-rules
927 (if gnus-uu-ignore-default-view-rules
929 gnus-uu-default-view-rules)
930 gnus-uu-user-view-rules-end)))
931 (if (and (not (string= (or action "") "gnus-uu-archive"))
932 gnus-uu-view-with-metamail)
934 (gnus-uu-choose-action file-name gnus-uu-ext-to-mime-list))
935 (setq action (format "metamail -d -b -c \"%s\"" action))))
939 ;; Functions for treating subjects and collecting series.
941 (defun gnus-uu-reginize-string (string)
942 ;; Takes a string and puts a \ in front of every special character;
943 ;; ignores any leading "version numbers" thingies that they use in
944 ;; the comp.binaries groups, and either replaces anything that looks
945 ;; like "2/3" with "[0-9]+/[0-9]+" or, if it can't find something
946 ;; like that, replaces the last two numbers with "[0-9]+". This, in
947 ;; my experience, should get most postings of a series.
949 (vernum "v[0-9]+[a-z][0-9]+:")
952 (set-buffer (get-buffer-create gnus-uu-output-buffer-name))
953 (buffer-disable-undo (current-buffer))
955 (insert (regexp-quote string))
958 (setq case-fold-search nil)
959 (goto-char (point-min))
960 (if (looking-at vernum)
962 (replace-match vernum t t)
963 (setq beg (length vernum))))
966 (if (re-search-forward "[ \t]*[0-9]+/[0-9]+" nil t)
967 (replace-match " [0-9]+/[0-9]+")
970 (if (re-search-forward "[0-9]+[ \t]*of[ \t]*[0-9]+" nil t)
971 (replace-match "[0-9]+ of [0-9]+")
974 (while (and (re-search-backward "[0-9]" nil t) (> count 0))
977 (< 1 (goto-char (1- (point))))))
978 (re-search-forward "[0-9]+" nil t)
979 (replace-match "[0-9]+")
981 (setq count (1- count)))))
984 (while (re-search-forward "[ \t]+" nil t)
985 (replace-match "[ \t]*" t t))
987 (buffer-substring 1 (point-max)))))
989 (defun gnus-uu-get-list-of-articles (n)
990 ;; If N is non-nil, the article numbers of the N next articles
992 ;; If any articles have been marked as processable, they will be
994 ;; Failing that, articles that have subjects that are part of the
995 ;; same "series" as the current will be returned.
999 (let ((backward (< n 0))
1003 (setq articles (cons (gnus-summary-article-number)
1005 (gnus-summary-search-forward nil nil backward))
1007 (nreverse articles)))
1008 (gnus-newsgroup-processable
1009 (reverse gnus-newsgroup-processable))
1011 (gnus-uu-find-articles-matching)))))
1013 (defun gnus-uu-string< (l1 l2)
1014 (string< (car l1) (car l2)))
1016 (defun gnus-uu-find-articles-matching
1017 (&optional subject only-unread do-not-translate)
1018 ;; Finds all articles that matches the regexp SUBJECT. If it is
1019 ;; nil, the current article name will be used. If ONLY-UNREAD is
1020 ;; non-nil, only unread articles are chosen. If DO-NOT-TRANSLATE is
1021 ;; non-nil, article names are not equalized before sorting.
1022 (let ((subject (or subject
1023 (gnus-uu-reginize-string (gnus-summary-article-subject))))
1028 ;; Collect all subjects matching subject.
1029 (let ((case-fold-search t)
1030 (data gnus-newsgroup-data)
1034 (and (not (gnus-data-pseudo-p d))
1035 (or (not only-unread)
1036 (= (setq mark (gnus-data-mark d))
1038 (= mark gnus-ticked-mark)
1039 (= mark gnus-dormant-mark))
1040 (setq subj (mail-header-subject (gnus-data-header d)))
1041 (string-match subject subj)
1042 (setq list-of-subjects
1043 (cons (cons subj (gnus-data-number d))
1044 list-of-subjects)))))
1046 ;; Expand numbers, sort, and return the list of article
1048 (mapcar (lambda (sub) (cdr sub))
1049 (sort (gnus-uu-expand-numbers
1051 (not do-not-translate))
1052 'gnus-uu-string<))))))
1054 (defun gnus-uu-expand-numbers (string-list &optional translate)
1055 ;; Takes a list of strings and "expands" all numbers in all the
1056 ;; strings. That is, this function makes all numbers equal length by
1057 ;; prepending lots of zeroes before each number. This is to ease later
1058 ;; sorting to find out what sequence the articles are supposed to be
1059 ;; decoded in. Returns the list of expanded strings.
1060 (let ((out-list string-list)
1063 (set-buffer (get-buffer-create gnus-uu-output-buffer-name))
1064 (buffer-disable-undo (current-buffer))
1067 (insert (caar string-list))
1068 ;; Translate multiple spaces to one space.
1069 (goto-char (point-min))
1070 (while (re-search-forward "[ \t]+" nil t)
1071 (replace-match " "))
1072 ;; Translate all characters to "a".
1073 (goto-char (point-min))
1075 (while (re-search-forward "[A-Za-z]" nil t)
1076 (replace-match "a" t t)))
1078 (goto-char (point-min))
1079 (while (re-search-forward "[0-9]+" nil t)
1082 (string-to-int (buffer-substring
1083 (match-beginning 0) (match-end 0))))))
1084 (setq string (buffer-substring 1 (point-max)))
1085 (setcar (car string-list) string)
1086 (setq string-list (cdr string-list))))
1090 ;; `gnus-uu-grab-articles' is the general multi-article treatment
1091 ;; function. It takes a list of articles to be grabbed and a function
1092 ;; to apply to each article.
1094 ;; The function to be called should take two parameters. The first
1095 ;; parameter is the article buffer. The function should leave the
1096 ;; result, if any, in this buffer. Most treatment functions will just
1097 ;; generate files...
1099 ;; The second parameter is the state of the list of articles, and can
1100 ;; have four values: `first', `middle', `last' and `first-and-last'.
1102 ;; The function should return a list. The list may contain the
1103 ;; following symbols:
1104 ;; `error' if an error occurred
1105 ;; `begin' if the beginning of an encoded file has been received
1106 ;; If the list returned contains a `begin', the first element of
1107 ;; the list *must* be a string with the file name of the decoded
1109 ;; `end' if the end of an encoded file has been received
1110 ;; `middle' if the article was a body part of an encoded file
1111 ;; `wrong-type' if the article was not a part of an encoded file
1112 ;; `ok', which can be used everything is ok
1114 (defvar gnus-uu-has-been-grabbed nil)
1116 (defun gnus-uu-unmark-list-of-grabbed (&optional dont-unmark-last-article)
1118 (if (not (and gnus-uu-has-been-grabbed
1119 gnus-uu-unmark-articles-not-decoded))
1121 (if dont-unmark-last-article
1123 (setq art (car gnus-uu-has-been-grabbed))
1124 (setq gnus-uu-has-been-grabbed (cdr gnus-uu-has-been-grabbed))))
1125 (while gnus-uu-has-been-grabbed
1126 (gnus-summary-tick-article (car gnus-uu-has-been-grabbed) t)
1127 (setq gnus-uu-has-been-grabbed (cdr gnus-uu-has-been-grabbed)))
1128 (if dont-unmark-last-article
1129 (setq gnus-uu-has-been-grabbed (list art))))))
1131 ;; This function takes a list of articles and a function to apply to
1132 ;; each article grabbed.
1134 ;; This function returns a list of files decoded if the grabbing and
1135 ;; the process-function has been successful and nil otherwise.
1136 (defun gnus-uu-grab-articles (articles process-function
1137 &optional sloppy limit no-errors)
1138 (let ((state 'first)
1139 has-been-begin article result-file result-files process-state
1140 gnus-summary-display-article-function
1141 gnus-article-display-hook gnus-article-prepare-hook
1142 article-series files)
1144 (while (and articles
1145 (not (memq 'error process-state))
1147 (not (memq 'end process-state))))
1149 (setq article (pop articles))
1150 (push article article-series)
1153 (if (eq state 'first)
1154 (setq state 'first-and-last)
1155 (setq state 'last)))
1157 (let ((part (gnus-uu-part-number article)))
1158 (gnus-message 6 "Getting article %d%s..."
1159 article (if (string= part "") "" (concat ", " part))))
1160 (gnus-summary-display-article article)
1162 ;; Push the article to the processing function.
1164 (set-buffer gnus-original-article-buffer)
1165 (let ((buffer-read-only nil))
1167 (set-buffer gnus-summary-buffer)
1169 (funcall process-function
1170 gnus-original-article-buffer state)))))
1172 (gnus-summary-remove-process-mark article)
1174 ;; If this is the beginning of a decoded file, we push it
1176 (when (or (memq 'begin process-state)
1177 (and (or (eq state 'first)
1178 (eq state 'first-and-last))
1179 (memq 'ok process-state)))
1181 ;; If there is a `result-file' here, that means that the
1182 ;; file was unsuccessfully decoded, so we delete it.
1183 (when (and result-file
1184 (file-exists-p result-file))
1185 (delete-file result-file)))
1186 (when (memq 'begin process-state)
1187 (setq result-file (car process-state)))
1188 (setq has-been-begin t))
1190 ;; Check whether we have decoded one complete file.
1191 (when (memq 'end process-state)
1192 (setq article-series nil)
1193 (setq has-been-begin nil)
1194 (if (stringp result-file)
1195 (setq files (list result-file))
1196 (setq files result-file))
1197 (setq result-file (car files))
1199 (push (list (cons 'name (pop files))
1200 (cons 'article article))
1202 ;; Allow user-defined functions to be run on this file.
1203 (when gnus-uu-grabbed-file-functions
1204 (let ((funcs gnus-uu-grabbed-file-functions))
1205 (unless (listp funcs)
1206 (setq funcs (list funcs)))
1208 (funcall (pop funcs) result-file))))
1209 ;; Check whether we have decoded enough articles.
1210 (and limit (= (length result-files) limit)
1211 (setq articles nil)))
1213 ;; If this is the last article to be decoded, and
1214 ;; we still haven't reached the end, then we delete
1215 ;; the partially decoded file.
1216 (and (or (eq state 'last) (eq state 'first-and-last))
1217 (not (memq 'end process-state))
1219 (file-exists-p result-file)
1220 (delete-file result-file))
1222 ;; If this was a file of the wrong sort, then
1223 (when (and (or (memq 'wrong-type process-state)
1224 (memq 'error process-state))
1225 gnus-uu-unmark-articles-not-decoded)
1226 (gnus-summary-tick-article article t))
1228 ;; Set the new series state.
1229 (if (and (not has-been-begin)
1231 (or (memq 'end process-state)
1232 (memq 'middle process-state)))
1234 (setq process-state (list 'error))
1235 (gnus-message 2 "No begin part at the beginning")
1237 (setq state 'middle)))
1239 ;; When there are no result-files, then something must be wrong.
1243 ((not has-been-begin)
1244 (gnus-message 2 "Wrong type file"))
1245 ((memq 'error process-state)
1246 (gnus-message 2 "An error occurred during decoding"))
1247 ((not (or (memq 'ok process-state)
1248 (memq 'end process-state)))
1249 (gnus-message 2 "End of articles reached before end of file")))
1250 ;; Make unsuccessfully decoded articles unread.
1251 (when gnus-uu-unmark-articles-not-decoded
1252 (while article-series
1253 (gnus-summary-tick-article (pop article-series) t))))
1257 (defun gnus-uu-grab-view (file)
1258 "View FILE using the gnus-uu methods."
1259 (let ((action (gnus-uu-get-action file)))
1260 (gnus-execute-command
1261 (if (string-match "%" action)
1262 (format action file)
1263 (concat action " " file))
1264 (eq gnus-view-pseudos 'not-confirm))))
1266 (defun gnus-uu-grab-move (file)
1267 "Move FILE to somewhere."
1268 (when gnus-uu-default-dir
1269 (let ((to-file (concat (file-name-as-directory gnus-uu-default-dir)
1270 (file-name-nondirectory file))))
1271 (rename-file file to-file)
1272 (unless (file-exists-p file)
1273 (make-symbolic-link to-file file)))))
1275 (defun gnus-uu-part-number (article)
1276 (let* ((header (gnus-summary-article-header article))
1277 (subject (and header (mail-header-subject header))))
1279 (string-match "[0-9]+ */[0-9]+\\|[0-9]+ * of *[0-9]+" subject))
1280 (match-string 0 subject)
1283 (defun gnus-uu-uudecode-sentinel (process event)
1284 (delete-process (get-process process)))
1286 (defun gnus-uu-uustrip-article (process-buffer in-state)
1287 ;; Uudecodes a file asynchronously.
1289 (set-buffer process-buffer)
1290 (let ((state (list 'wrong-type))
1291 process-connection-type case-fold-search buffer-read-only
1293 (goto-char (point-min))
1295 ;; Deal with ^M at the end of the lines.
1296 (when gnus-uu-kill-carriage-return
1298 (while (search-forward "\r" nil t)
1299 (delete-backward-char 1))))
1301 (while (or (re-search-forward gnus-uu-begin-string nil t)
1302 (re-search-forward gnus-uu-body-line nil t))
1303 (setq state (list 'ok))
1304 ;; Ok, we are at the first uucoded line.
1306 (setq start-char (point))
1308 (if (not (looking-at gnus-uu-begin-string))
1309 (setq state (list 'middle))
1310 ;; This is the beginning of an uuencoded article.
1311 ;; We replace certain characters that could make things messy.
1312 (setq gnus-uu-file-name
1313 (let ((nnheader-file-name-translation-alist
1314 '((?/ . ?,) (? . ?_) (?* . ?_) (?$ . ?_))))
1315 (nnheader-translate-file-chars (match-string 1))))
1317 ;; Remove any non gnus-uu-body-line right after start.
1319 (while (and (not (eobp))
1320 (not (looking-at gnus-uu-body-line)))
1323 ;; If a process is running, we kill it.
1324 (when (and gnus-uu-uudecode-process
1325 (memq (process-status gnus-uu-uudecode-process)
1327 (delete-process gnus-uu-uudecode-process)
1328 (gnus-uu-unmark-list-of-grabbed t))
1330 ;; Start a new uudecoding process.
1331 (let ((cdir default-directory))
1334 (cd gnus-uu-work-dir)
1335 (setq gnus-uu-uudecode-process
1338 (get-buffer-create gnus-uu-output-buffer-name)
1339 shell-file-name shell-command-switch
1340 (format "cd %s %s uudecode" gnus-uu-work-dir
1341 gnus-shell-command-separator))))
1343 (set-process-sentinel
1344 gnus-uu-uudecode-process 'gnus-uu-uudecode-sentinel)
1345 (setq state (list 'begin))
1346 (push (concat gnus-uu-work-dir gnus-uu-file-name) files))
1348 ;; We look for the end of the thing to be decoded.
1349 (if (re-search-forward gnus-uu-end-string nil t)
1350 (setq state (cons 'end state))
1351 (goto-char (point-max))
1352 (re-search-backward gnus-uu-body-line nil t))
1356 (when gnus-uu-uudecode-process
1357 (when (memq (process-status gnus-uu-uudecode-process) '(run stop))
1358 ;; Try to correct mishandled uucode.
1359 (when gnus-uu-correct-stripped-uucode
1360 (gnus-uu-check-correct-stripped-uucode start-char (point)))
1362 ;; Send the text to the process.
1364 (process-send-region
1365 gnus-uu-uudecode-process start-char (point))
1368 (delete-process gnus-uu-uudecode-process)
1369 (gnus-message 2 "gnus-uu: Couldn't uudecode")
1370 (setq state (list 'wrong-type)))))
1372 (if (memq 'end state)
1374 ;; Send an EOF, just in case.
1376 (process-send-eof gnus-uu-uudecode-process)
1378 (while (memq (process-status gnus-uu-uudecode-process)
1380 (accept-process-output gnus-uu-uudecode-process 1)))
1381 (when (or (not gnus-uu-uudecode-process)
1382 (not (memq (process-status gnus-uu-uudecode-process)
1384 (setq state (list 'wrong-type)))))))
1386 (if (memq 'begin state)
1387 (cons (if (= (length files) 1) (car files) files) state)
1390 ;; This function is used by `gnus-uu-grab-articles' to treat
1391 ;; a shared article.
1392 (defun gnus-uu-unshar-article (process-buffer in-state)
1393 (let ((state (list 'ok))
1396 (set-buffer process-buffer)
1397 (goto-char (point-min))
1398 (if (not (re-search-forward gnus-uu-shar-begin-string nil t))
1399 (setq state (list 'wrong-type))
1401 (setq start-char (point))
1402 (call-process-region
1403 start-char (point-max) shell-file-name nil
1404 (get-buffer-create gnus-uu-output-buffer-name) nil
1405 shell-command-switch
1406 (concat "cd " gnus-uu-work-dir " "
1407 gnus-shell-command-separator " sh"))))
1410 ;; Returns the name of what the shar file is going to unpack.
1411 (defun gnus-uu-find-name-in-shar ()
1412 (let ((oldpoint (point))
1414 (goto-char (point-min))
1415 (if (re-search-forward gnus-uu-shar-name-marker nil t)
1416 (setq res (buffer-substring (match-beginning 1) (match-end 1))))
1417 (goto-char oldpoint)
1420 ;; `gnus-uu-choose-action' chooses what action to perform given the name
1421 ;; and `gnus-uu-file-action-list'. Returns either nil if no action is
1422 ;; found, or the name of the command to run if such a rule is found.
1423 (defun gnus-uu-choose-action (file-name file-action-list &optional no-ignore)
1424 (let ((action-list (copy-sequence file-action-list))
1425 (case-fold-search t)
1430 (and gnus-uu-ignore-files-by-name
1431 (string-match gnus-uu-ignore-files-by-name file-name)))
1433 (and gnus-uu-ignore-files-by-type
1434 (string-match gnus-uu-ignore-files-by-type
1435 (or (gnus-uu-choose-action
1436 file-name gnus-uu-ext-to-mime-list t)
1438 (while (not (or (eq action-list ()) action))
1439 (setq rule (car action-list))
1440 (setq action-list (cdr action-list))
1441 (if (string-match (car rule) file-name)
1442 (setq action (cadr rule)))))
1445 (defun gnus-uu-treat-archive (file-path)
1446 ;; Unpacks an archive. Returns t if unpacking is successful.
1447 (let ((did-unpack t)
1449 (setq action (gnus-uu-choose-action
1450 file-path (append gnus-uu-user-archive-rules
1451 (if gnus-uu-ignore-default-archive-rules
1453 gnus-uu-default-archive-rules))))
1455 (if (not action) (error "No unpackers for the file %s" file-path))
1457 (string-match "/[^/]*$" file-path)
1458 (setq dir (substring file-path 0 (match-beginning 0)))
1460 (if (member action gnus-uu-destructive-archivers)
1461 (copy-file file-path (concat file-path "~") t))
1463 (setq command (format "cd %s ; %s" dir (gnus-uu-command action file-path)))
1466 (set-buffer (get-buffer-create gnus-uu-output-buffer-name))
1469 (gnus-message 5 "Unpacking: %s..." (gnus-uu-command action file-path))
1471 (if (= 0 (call-process shell-file-name nil
1472 (get-buffer-create gnus-uu-output-buffer-name)
1473 nil shell-command-switch command))
1475 (gnus-message 2 "Error during unpacking of archive")
1476 (setq did-unpack nil))
1478 (if (member action gnus-uu-destructive-archivers)
1479 (rename-file (concat file-path "~") file-path t))
1483 (defun gnus-uu-dir-files (dir)
1484 (let ((dirs (directory-files dir t "[^/][^\\.][^\\.]?$"))
1487 (if (file-directory-p (setq file (car dirs)))
1488 (setq files (append files (gnus-uu-dir-files file)))
1489 (setq files (cons file files)))
1490 (setq dirs (cdr dirs)))
1493 (defun gnus-uu-unpack-files (files &optional ignore)
1494 ;; Go through FILES and look for files to unpack.
1495 (let* ((totfiles (gnus-uu-ls-r gnus-uu-work-dir))
1499 (setq file (cdr (assq 'name (car files))))
1500 (if (and (not (member file ignore))
1501 (equal (gnus-uu-get-action (file-name-nondirectory file))
1504 (setq did-unpack (cons file did-unpack))
1505 (or (gnus-uu-treat-archive file)
1506 (gnus-message 2 "Error during unpacking of %s" file))
1507 (let* ((newfiles (gnus-uu-ls-r gnus-uu-work-dir))
1510 (or (member (car nfiles) totfiles)
1511 (setq ofiles (cons (list (cons 'name (car nfiles))
1512 (cons 'original file))
1514 (setq nfiles (cdr nfiles)))
1515 (setq totfiles newfiles))))
1516 (setq files (cdr files)))
1518 (gnus-uu-unpack-files ofiles (append did-unpack ignore))
1521 (defun gnus-uu-ls-r (dir)
1522 (let* ((files (gnus-uu-directory-files dir t))
1525 (if (file-directory-p (car files))
1527 (setq ofiles (delete (car files) ofiles))
1528 (setq ofiles (append ofiles (gnus-uu-ls-r (car files))))))
1529 (setq files (cdr files)))
1534 (defun gnus-uu-directory-files (dir &optional full)
1535 (let (files out file)
1536 (setq files (directory-files dir full))
1538 (setq file (car files))
1539 (setq files (cdr files))
1540 (or (member (file-name-nondirectory file) '("." ".."))
1541 (setq out (cons file out))))
1542 (setq out (nreverse out))
1545 (defun gnus-uu-check-correct-stripped-uucode (start end)
1547 (let (found beg length)
1548 (if (not gnus-uu-correct-stripped-uucode)
1552 (if (re-search-forward " \\|`" end t)
1557 (if (looking-at "\n") (replace-match ""))
1561 (if (looking-at (concat gnus-uu-begin-string "\\|"
1562 gnus-uu-end-string))
1569 (setq length (- (point) beg))))
1574 (if (not (= length (- (point) beg)))
1575 (insert (make-string (- length (- (point) beg)) ? ))))
1576 (forward-line 1)))))))
1578 (defvar gnus-uu-tmp-alist nil)
1580 (defun gnus-uu-initialize (&optional scan)
1583 (if (setq entry (assoc gnus-newsgroup-name gnus-uu-tmp-alist))
1584 (if (file-exists-p (cdr entry))
1585 (setq gnus-uu-work-dir (cdr entry))
1586 (setq gnus-uu-tmp-alist (delq entry gnus-uu-tmp-alist))
1589 (setq gnus-uu-tmp-dir (file-name-as-directory
1590 (expand-file-name gnus-uu-tmp-dir)))
1591 (if (not (file-directory-p gnus-uu-tmp-dir))
1592 (error "Temp directory %s doesn't exist" gnus-uu-tmp-dir)
1593 (if (not (file-writable-p gnus-uu-tmp-dir))
1594 (error "Temp directory %s can't be written to"
1597 (setq gnus-uu-work-dir
1598 (make-temp-name (concat gnus-uu-tmp-dir "gnus")))
1599 (gnus-make-directory gnus-uu-work-dir)
1600 (set-file-modes gnus-uu-work-dir 448)
1601 (setq gnus-uu-work-dir (file-name-as-directory gnus-uu-work-dir))
1602 (setq gnus-uu-tmp-alist (cons (cons gnus-newsgroup-name gnus-uu-work-dir)
1603 gnus-uu-tmp-alist)))))
1606 ;; Kills the temporary uu buffers, kills any processes, etc.
1607 (defun gnus-uu-clean-up ()
1609 (and gnus-uu-uudecode-process
1610 (memq (process-status (or gnus-uu-uudecode-process "nevair"))
1612 (delete-process gnus-uu-uudecode-process))
1613 (and (setq buf (get-buffer gnus-uu-output-buffer-name))
1614 (kill-buffer buf))))
1616 ;; Inputs an action and a file and returns a full command, putting
1617 ;; quotes round the file name and escaping any quotes in the file name.
1618 (defun gnus-uu-command (action file)
1620 (while (string-match "!\\|`\\|\"\\|\\$\\|\\\\\\|&" file)
1623 (concat ofile (substring file 0 (match-beginning 0)) "\\"
1624 (substring file (match-beginning 0) (match-end 0))))
1625 (setq file (substring file (1+ (match-beginning 0))))))
1626 (setq ofile (concat "\"" ofile file "\""))
1627 (if (string-match "%s" action)
1628 (format action ofile)
1629 (concat action " " ofile))))
1631 (defun gnus-uu-delete-work-dir (&optional dir)
1632 "Delete recursively all files and directories under `gnus-uu-work-dir'."
1634 (gnus-message 7 "Deleting directory %s..." dir)
1635 (setq dir gnus-uu-work-dir))
1637 (file-exists-p dir))
1638 (let ((files (directory-files dir t nil t))
1640 (while (setq file (pop files))
1641 (unless (member (file-name-nondirectory file) '("." ".."))
1642 (if (file-directory-p file)
1643 (gnus-uu-delete-work-dir file)
1644 (gnus-message 9 "Deleting file %s..." file)
1645 (delete-file file))))
1646 (delete-directory dir)))
1647 (gnus-message 7 ""))
1651 (add-hook 'gnus-exit-group-hook 'gnus-uu-clean-up)
1652 (add-hook 'gnus-exit-group-hook 'gnus-uu-delete-work-dir)
1657 ;;; uuencoded posting
1660 ;; Any function that is to be used as and encoding method will take two
1661 ;; parameters: PATH-NAME and FILE-NAME. (E.g. "/home/gaga/spiral.jpg"
1662 ;; and "spiral.jpg", respectively.) The function should return nil if
1663 ;; the encoding wasn't successful.
1664 (defvar gnus-uu-post-encode-method 'gnus-uu-post-encode-uuencode
1665 "Function used for encoding binary files.
1666 There are three functions supplied with gnus-uu for encoding files:
1667 `gnus-uu-post-encode-uuencode', which does straight uuencoding;
1668 `gnus-uu-post-encode-mime', which encodes with base64 and adds MIME
1669 headers; and `gnus-uu-post-encode-mime-uuencode', which encodes with
1670 uuencode and adds MIME headers.")
1672 (defvar gnus-uu-post-include-before-composing nil
1673 "Non-nil means that gnus-uu will ask for a file to encode before you compose the article.
1674 If this variable is t, you can either include an encoded file with
1675 \\[gnus-uu-post-insert-binary-in-article] or have one included for you when you post the article.")
1677 (defvar gnus-uu-post-length 990
1678 "Maximum length of an article.
1679 The encoded file will be split into how many articles it takes to
1680 post the entire file.")
1682 (defvar gnus-uu-post-threaded nil
1683 "Non-nil means that gnus-uu will post the encoded file in a thread.
1684 This may not be smart, as no other decoder I have seen are able to
1685 follow threads when collecting uuencoded articles. (Well, I have seen
1686 one package that does that - gnus-uu, but somehow, I don't think that
1687 counts...) Default is nil.")
1689 (defvar gnus-uu-post-separate-description t
1690 "Non-nil means that the description will be posted in a separate article.
1691 The first article will typically be numbered (0/x). If this variable
1692 is nil, the description the user enters will be included at the
1693 beginning of the first article, which will be numbered (1/x). Default
1696 (defvar gnus-uu-post-binary-separator "--binary follows this line--")
1697 (defvar gnus-uu-post-message-id nil)
1698 (defvar gnus-uu-post-inserted-file-name nil)
1699 (defvar gnus-uu-winconf-post-news nil)
1701 (defun gnus-uu-post-news ()
1702 "Compose an article and post an encoded file."
1704 (setq gnus-uu-post-inserted-file-name nil)
1705 (setq gnus-uu-winconf-post-news (current-window-configuration))
1707 (gnus-summary-post-news)
1709 (use-local-map (copy-keymap (current-local-map)))
1710 (local-set-key "\C-c\C-c" 'gnus-summary-edit-article-done)
1711 (local-set-key "\C-c\C-c" 'gnus-uu-post-news-inews)
1712 (local-set-key "\C-c\C-s" 'gnus-uu-post-news-inews)
1713 (local-set-key "\C-c\C-i" 'gnus-uu-post-insert-binary-in-article)
1715 (if gnus-uu-post-include-before-composing
1716 (save-excursion (setq gnus-uu-post-inserted-file-name
1717 (gnus-uu-post-insert-binary)))))
1719 (defun gnus-uu-post-insert-binary-in-article ()
1720 "Inserts an encoded file in the buffer.
1721 The user will be asked for a file name."
1724 (setq gnus-uu-post-inserted-file-name (gnus-uu-post-insert-binary))))
1726 ;; Encodes with uuencode and substitutes all spaces with backticks.
1727 (defun gnus-uu-post-encode-uuencode (path file-name)
1728 (if (gnus-uu-post-encode-file "uuencode" path file-name)
1730 (goto-char (point-min))
1732 (while (re-search-forward " " nil t)
1733 (replace-match "`"))
1736 ;; Encodes with uuencode and adds MIME headers.
1737 (defun gnus-uu-post-encode-mime-uuencode (path file-name)
1738 (if (gnus-uu-post-encode-uuencode path file-name)
1740 (gnus-uu-post-make-mime file-name "x-uue")
1743 ;; Encodes with base64 and adds MIME headers
1744 (defun gnus-uu-post-encode-mime (path file-name)
1745 (if (gnus-uu-post-encode-file "mmencode" path file-name)
1747 (gnus-uu-post-make-mime file-name "base64")
1750 ;; Adds MIME headers.
1751 (defun gnus-uu-post-make-mime (file-name encoding)
1752 (goto-char (point-min))
1753 (insert (format "Content-Type: %s; name=\"%s\"\n"
1754 (gnus-uu-choose-action file-name gnus-uu-ext-to-mime-list)
1756 (insert (format "Content-Transfer-Encoding: %s\n\n" encoding))
1758 (set-buffer gnus-message-buffer)
1759 (goto-char (point-min))
1760 (re-search-forward (concat "^" (regexp-quote mail-header-separator) "$"))
1762 (narrow-to-region 1 (point))
1763 (or (mail-fetch-field "mime-version")
1766 (insert "MIME-Version: 1.0\n")))
1769 ;; Encodes a file PATH with COMMAND, leaving the result in the
1771 (defun gnus-uu-post-encode-file (command path file-name)
1772 (= 0 (call-process shell-file-name nil t nil shell-command-switch
1773 (format "%s %s %s" command path file-name))))
1775 (defun gnus-uu-post-news-inews ()
1776 "Posts the composed news article and encoded file.
1777 If no file has been included, the user will be asked for a file."
1782 (if gnus-uu-post-inserted-file-name
1783 (setq file-name gnus-uu-post-inserted-file-name)
1784 (setq file-name (gnus-uu-post-insert-binary)))
1786 (if gnus-uu-post-threaded
1787 (let ((message-required-news-headers
1788 (if (memq 'Message-ID message-required-news-headers)
1789 message-required-news-headers
1790 (cons 'Message-ID message-required-news-headers)))
1791 gnus-inews-article-hook)
1793 (setq gnus-inews-article-hook (if (listp gnus-inews-article-hook)
1794 gnus-inews-article-hook
1795 (list gnus-inews-article-hook)))
1796 (setq gnus-inews-article-hook
1800 (goto-char (point-min))
1801 (if (re-search-forward "^Message-ID: \\(.*\\)$" nil t)
1802 (setq gnus-uu-post-message-id
1804 (match-beginning 1) (match-end 1)))
1805 (setq gnus-uu-post-message-id nil))))
1806 gnus-inews-article-hook))
1807 (gnus-uu-post-encoded file-name t))
1808 (gnus-uu-post-encoded file-name nil)))
1809 (setq gnus-uu-post-inserted-file-name nil)
1810 (and gnus-uu-winconf-post-news
1811 (set-window-configuration gnus-uu-winconf-post-news)))
1813 ;; Asks for a file to encode, encodes it and inserts the result in
1814 ;; the current buffer. Returns the file name the user gave.
1815 (defun gnus-uu-post-insert-binary ()
1816 (let ((uuencode-buffer-name "*uuencode buffer*")
1817 file-path uubuf file-name)
1819 (setq file-path (read-file-name
1820 "What file do you want to encode? "))
1821 (if (not (file-exists-p file-path))
1822 (error "%s: No such file" file-path))
1824 (goto-char (point-max))
1825 (insert (format "\n%s\n" gnus-uu-post-binary-separator))
1827 (if (string-match "^~/" file-path)
1828 (setq file-path (concat "$HOME" (substring file-path 1))))
1829 (if (string-match "/[^/]*$" file-path)
1830 (setq file-name (substring file-path (1+ (match-beginning 0))))
1831 (setq file-name file-path))
1835 (set-buffer (setq uubuf
1836 (get-buffer-create uuencode-buffer-name)))
1838 (funcall gnus-uu-post-encode-method file-path file-name))
1839 (insert-buffer-substring uubuf)
1840 (error "Encoding unsuccessful"))
1841 (kill-buffer uubuf))
1844 ;; Posts the article and all of the encoded file.
1845 (defun gnus-uu-post-encoded (file-name &optional threaded)
1846 (let ((send-buffer-name "*uuencode send buffer*")
1847 (encoded-buffer-name "*encoded buffer*")
1848 (top-string "[ cut here %s (%s %d/%d) %s gnus-uu ]")
1849 (separator (concat mail-header-separator "\n\n"))
1850 uubuf length parts header i end beg
1851 beg-line minlen buf post-buf whole-len beg-binary end-binary)
1853 (setq post-buf (current-buffer))
1855 (goto-char (point-min))
1856 (if (not (re-search-forward
1857 (if gnus-uu-post-separate-description
1858 (concat "^" (regexp-quote gnus-uu-post-binary-separator)
1860 (concat "^" (regexp-quote mail-header-separator) "$")) nil t))
1861 (error "Internal error: No binary/header separator"))
1864 (setq beg-binary (point))
1865 (setq end-binary (point-max))
1868 (set-buffer (setq uubuf (get-buffer-create encoded-buffer-name)))
1870 (insert-buffer-substring post-buf beg-binary end-binary)
1871 (goto-char (point-min))
1872 (setq length (count-lines 1 (point-max)))
1873 (setq parts (/ length gnus-uu-post-length))
1874 (if (not (< (% length gnus-uu-post-length) 4))
1875 (setq parts (1+ parts))))
1877 (if gnus-uu-post-separate-description
1879 (kill-region (point) (point-max))
1881 (goto-char (point-min))
1883 (concat "^" (regexp-quote mail-header-separator) "$") nil t)
1885 (setq header (buffer-substring 1 (point)))
1887 (goto-char (point-min))
1888 (if (not gnus-uu-post-separate-description)
1890 (if (and (not threaded) (re-search-forward "^Subject: " nil t))
1893 (insert (format " (0/%d)" parts))))
1899 (while (not (> i parts))
1900 (set-buffer (get-buffer-create send-buffer-name))
1903 (if (and threaded gnus-uu-post-message-id)
1904 (insert (format "References: %s\n" gnus-uu-post-message-id)))
1907 (- 62 (length (format top-string "" file-name i parts ""))))
1908 (if (> 1 (setq minlen (/ whole-len 2)))
1913 (make-string minlen ?-)
1916 (if (= 0 (% whole-len 2)) (1- minlen) minlen) ?-)))
1918 (goto-char (point-min))
1919 (if (not (re-search-forward "^Subject: " nil t))
1924 (insert (format " (%d/%d)" i parts)))
1925 (if (or (and (= i 2) gnus-uu-post-separate-description)
1926 (and (= i 1) (not gnus-uu-post-separate-description)))
1927 (replace-match "Subject: Re: "))))
1929 (goto-char (point-max))
1934 (goto-char (point-max))
1935 (forward-line gnus-uu-post-length))
1936 (if (and (= (1+ i) parts) (< (count-lines (point) (point-max)) 4))
1939 (insert-buffer-substring uubuf beg end)
1944 (goto-char (point-min))
1946 (concat "^" (regexp-quote mail-header-separator) "$") nil t)
1949 (if (re-search-forward
1950 (concat "^" (regexp-quote gnus-uu-post-binary-separator) "$")
1957 (let (message-sent-message-via)
1960 (and (setq buf (get-buffer send-buffer-name))
1962 (and (setq buf (get-buffer encoded-buffer-name))
1965 (if (not gnus-uu-post-separate-description)
1967 (set-buffer-modified-p nil)
1968 (and (fboundp 'bury-buffer) (bury-buffer))))))
1972 ;; gnus-uu.el ends here