1 ;;; gnus-uu.el --- extract (uu)encoded files in Gnus
2 ;; Copyright (C) 1985,86,87,93,94,95,96,97 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 (defgroup gnus-extract nil
35 "Extracting encoded files."
39 (defgroup gnus-extract-view nil
40 "Viewwing extracted files."
43 (defgroup gnus-extract-archive nil
44 "Extracting encoded archives."
47 (defgroup gnus-extract-post nil
48 "Extracting encoded archives."
49 :prefix "gnus-uu-post"
52 ;; Default viewing action rules
54 (defcustom gnus-uu-default-view-rules
55 '(("\\.te?xt$\\|\\.doc$\\|read.*me\\|\\.c?$\\|\\.h$\\|\\.bat$\\|\\.asm$\\|makefile" "cat %s | sed s/\r//g")
56 ("\\.pas$" "cat %s | sed s/\r//g")
57 ("\\.[1-9]$" "groff -mandoc -Tascii %s | sed s/\b.//g")
58 ("\\.\\(jpe?g\\|gif\\|tiff?\\|p[pgb]m\\|xwd\\|xbm\\|pcx\\)$" "xv")
59 ("\\.tga$" "tgatoppm %s | xv -")
60 ("\\.\\(wav\\|aiff\\|hcom\\|u[blw]\\|s[bfw]\\|voc\\|smp\\)$"
61 "sox -v .5 %s -t .au -u - > /dev/audio")
62 ("\\.au$" "cat %s > /dev/audio")
63 ("\\.midi?$" "playmidi -f")
65 ("\\.ps$" "ghostview")
67 ("\\.html$" "xmosaic")
68 ("\\.mpe?g$" "mpeg_play")
69 ("\\.\\(flc\\|fli\\|rle\\|iff\\|pfx\\|avi\\|sme\\|rpza\\|dl\\|qt\\|rsrc\\|mov\\)$" "xanim")
70 ("\\.\\(tar\\|arj\\|zip\\|zoo\\|arc\\|gz\\|Z\\|lzh\\|ar\\|lha\\)$"
72 "Default actions to be taken when the user asks to view a file.
73 To change the behaviour, you can either edit this variable or set
74 `gnus-uu-user-view-rules' to something useful.
78 To make gnus-uu use 'xli' to display JPEG and GIF files, put the
79 following in your .emacs file:
81 (setq gnus-uu-user-view-rules '((\"jpg$\\\\|gif$\" \"xli\")))
83 Both these variables are lists of lists with two string elements. The
84 first string is a regular expression. If the file name matches this
85 regular expression, the command in the second string is executed with
86 the file as an argument.
88 If the command string contains \"%s\", the file name will be inserted
89 at that point in the command string. If there's no \"%s\" in the
90 command string, the file name will be appended to the command string
93 There are several user variables to tailor the behaviour of gnus-uu to
94 your needs. First we have `gnus-uu-user-view-rules', which is the
95 variable gnus-uu first consults when trying to decide how to view a
96 file. If this variable contains no matches, gnus-uu examines the
97 default rule variable provided in this package. If gnus-uu finds no
98 match here, it uses `gnus-uu-user-view-rules-end' to try to make a
100 :group 'gnus-extract-view
101 :type '(repeat (group regexp (string :tag "Command"))))
103 (defcustom gnus-uu-user-view-rules nil
104 "What actions are to be taken to view a file.
105 See the documentation on the `gnus-uu-default-view-rules' variable for
107 :group 'gnus-extract-view
108 :type '(repeat (group regexp (string :tag "Command"))))
110 (defcustom gnus-uu-user-view-rules-end
112 "What actions are to be taken if no rule matched the file name.
113 See the documentation on the `gnus-uu-default-view-rules' variable for
115 :group 'gnus-extract-view
116 :type '(repeat (group regexp (string :tag "Command"))))
118 ;; Default unpacking commands
120 (defcustom gnus-uu-default-archive-rules
121 '(("\\.tar$" "tar xf")
122 ("\\.zip$" "unzip -o")
124 ("\\.arj$" "unarj x")
126 ("\\.\\(lzh\\|lha\\)$" "lha x")
127 ("\\.Z$" "uncompress")
129 ("\\.arc$" "arc -x"))
130 "See `gnus-uu-user-archive-rules'."
131 :group 'gnus-extract-archive
132 :type '(repeat (group regexp (string :tag "Command"))))
134 (defvar gnus-uu-destructive-archivers
135 (list "uncompress" "gunzip"))
137 (defcustom gnus-uu-user-archive-rules nil
138 "A list that can be set to override the default archive unpacking commands.
139 To use, for instance, 'untar' to unpack tar files and 'zip -x' to
140 unpack zip files, say the following:
141 (setq gnus-uu-user-archive-rules
142 '((\"\\\\.tar$\" \"untar\")
143 (\"\\\\.zip$\" \"zip -x\")))"
144 :group 'gnus-extract-archive
145 :type '(repeat (group regexp (string :tag "Command"))))
147 (defcustom gnus-uu-ignore-files-by-name nil
148 "*A regular expression saying what files should not be viewed based on name.
149 If, for instance, you want gnus-uu to ignore all .au and .wav files,
150 you could say something like
152 (setq gnus-uu-ignore-files-by-name \"\\\\.au$\\\\|\\\\.wav$\")
154 Note that this variable can be used in conjunction with the
155 `gnus-uu-ignore-files-by-type' variable."
157 :type '(choice (const :tag "off" nil)
158 (regexp :format "%v")))
160 (defcustom gnus-uu-ignore-files-by-type nil
161 "*A regular expression saying what files that shouldn't be viewed, based on MIME file type.
162 If, for instance, you want gnus-uu to ignore all audio files and all mpegs,
163 you could say something like
165 (setq gnus-uu-ignore-files-by-type \"audio/\\\\|video/mpeg\")
167 Note that this variable can be used in conjunction with the
168 `gnus-uu-ignore-files-by-name' variable."
170 :type '(choice (const :tag "off" nil)
171 (regexp :format "%v")))
173 ;; Pseudo-MIME support
175 (defconst gnus-uu-ext-to-mime-list
176 '(("\\.gif$" "image/gif")
177 ("\\.jpe?g$" "image/jpeg")
178 ("\\.tiff?$" "image/tiff")
179 ("\\.xwd$" "image/xwd")
180 ("\\.pbm$" "image/pbm")
181 ("\\.pgm$" "image/pgm")
182 ("\\.ppm$" "image/ppm")
183 ("\\.xbm$" "image/xbm")
184 ("\\.pcx$" "image/pcx")
185 ("\\.tga$" "image/tga")
186 ("\\.ps$" "image/postscript")
187 ("\\.fli$" "video/fli")
188 ("\\.wav$" "audio/wav")
189 ("\\.aiff$" "audio/aiff")
190 ("\\.hcom$" "audio/hcom")
191 ("\\.voc$" "audio/voc")
192 ("\\.smp$" "audio/smp")
193 ("\\.mod$" "audio/mod")
194 ("\\.dvi$" "image/dvi")
195 ("\\.mpe?g$" "video/mpeg")
196 ("\\.au$" "audio/basic")
197 ("\\.\\(te?xt\\|doc\\|c\\|h\\)$" "text/plain")
198 ("\\.\\(c\\|h\\)$" "text/source")
199 ("read.*me" "text/plain")
200 ("\\.html$" "text/html")
201 ("\\.bat$" "text/bat")
202 ("\\.[1-6]$" "text/man")
203 ("\\.flc$" "video/flc")
204 ("\\.rle$" "video/rle")
205 ("\\.pfx$" "video/pfx")
206 ("\\.avi$" "video/avi")
207 ("\\.sme$" "video/sme")
208 ("\\.rpza$" "video/prza")
209 ("\\.dl$" "video/dl")
210 ("\\.qt$" "video/qt")
211 ("\\.rsrc$" "video/rsrc")
212 ("\\..*$" "unknown/unknown")))
214 ;; Various variables users may set
216 (defcustom gnus-uu-tmp-dir "/tmp/"
217 "*Variable saying where gnus-uu is to do its work.
218 Default is \"/tmp/\"."
222 (defcustom gnus-uu-do-not-unpack-archives nil
223 "*Non-nil means that gnus-uu won't peek inside archives looking for files to display.
225 :group 'gnus-extract-archive
228 (defcustom gnus-uu-ignore-default-view-rules nil
229 "*Non-nil means that gnus-uu will ignore the default viewing rules.
230 Only the user viewing rules will be consulted. Default is nil."
231 :group 'gnus-extract-view
234 (defcustom gnus-uu-grabbed-file-functions nil
235 "Functions run on each file after successful decoding.
236 They will be called with the name of the file as the argument.
237 Likely functions you can use in this list are `gnus-uu-grab-view'
238 and `gnus-uu-grab-move'."
240 :options '(gnus-uu-grab-view gnus-uu-grab-move)
243 (defcustom gnus-uu-ignore-default-archive-rules nil
244 "*Non-nil means that gnus-uu will ignore the default archive unpacking commands.
245 Only the user unpacking commands will be consulted. Default is nil."
246 :group 'gnus-extract-archive
249 (defcustom gnus-uu-kill-carriage-return t
250 "*Non-nil means that gnus-uu will strip all carriage returns from articles.
255 (defcustom gnus-uu-view-with-metamail nil
256 "*Non-nil means that files will be viewed with metamail.
257 The gnus-uu viewing functions will be ignored and gnus-uu will try
258 to guess at a content-type based on file name suffixes. Default
263 (defcustom gnus-uu-unmark-articles-not-decoded nil
264 "*Non-nil means that gnus-uu will mark articles that were unsuccessfully decoded as unread.
269 (defcustom gnus-uu-correct-stripped-uucode nil
270 "*Non-nil means that gnus-uu will *try* to fix uuencoded files that have had trailing spaces deleted.
275 (defcustom gnus-uu-save-in-digest nil
276 "*Non-nil means that gnus-uu, when asked to save without decoding, will save in digests.
277 If this variable is nil, gnus-uu will just save everything in a
278 file without any embellishments. The digesting almost conforms to RFC1153 -
279 no easy way to specify any meaningful volume and issue numbers were found,
280 so I simply dropped them."
284 (defcustom gnus-uu-digest-headers
285 '("^Date:" "^From:" "^To:" "^Cc:" "^Subject:" "^Message-ID:" "^Keywords:"
286 "^Summary:" "^References:")
287 "List of regexps to match headers included in digested messages.
288 The headers will be included in the sequence they are matched."
290 :type '(repeat regexp))
292 (defcustom gnus-uu-save-separate-articles nil
293 "*Non-nil means that gnus-uu will save articles in separate files."
297 (defcustom gnus-uu-be-dangerous 'ask
298 "*Specifies what to do if unusual situations arise during decoding.
299 If nil, be as conservative as possible. If t, ignore things that
300 didn't work, and overwrite existing files. Otherwise, ask each time."
302 :type '(choice (const :tag "conservative" nil)
303 (const :tag "ask" ask)
304 (const :tag "liberal" t)))
306 ;; Internal variables
308 (defvar gnus-uu-saved-article-name nil)
310 (defconst gnus-uu-begin-string "^begin[ \t]+[0-7][0-7][0-7][ \t]+\\(.*\\)$")
311 (defconst gnus-uu-end-string "^end[ \t]*$")
313 (defconst gnus-uu-body-line "^M")
315 (while (> (setq i (1- i)) 0)
316 (setq gnus-uu-body-line (concat gnus-uu-body-line "[^a-z]")))
317 (setq gnus-uu-body-line (concat gnus-uu-body-line ".?$")))
319 ;"^M.............................................................?$"
321 (defconst gnus-uu-shar-begin-string "^#! */bin/sh")
323 (defvar gnus-uu-shar-file-name nil)
324 (defconst gnus-uu-shar-name-marker "begin [0-7][0-7][0-7][ \t]+\\(\\(\\w\\|\\.\\)*\\b\\)")
326 (defconst gnus-uu-postscript-begin-string "^%!PS-")
327 (defconst gnus-uu-postscript-end-string "^%%EOF$")
329 (defvar gnus-uu-file-name nil)
330 (defconst gnus-uu-uudecode-process nil)
331 (defvar gnus-uu-binhex-article-name nil)
333 (defvar gnus-uu-work-dir nil)
335 (defconst gnus-uu-output-buffer-name " *Gnus UU Output*")
337 (defvar gnus-uu-default-dir gnus-article-save-directory)
338 (defvar gnus-uu-digest-from-subject nil)
342 (gnus-define-keys (gnus-uu-mark-map "P" gnus-summary-mark-map)
343 "p" gnus-summary-mark-as-processable
344 "u" gnus-summary-unmark-as-processable
345 "U" gnus-summary-unmark-all-processable
346 "v" gnus-uu-mark-over
347 "s" gnus-uu-mark-series
348 "r" gnus-uu-mark-region
349 "R" gnus-uu-mark-by-regexp
350 "t" gnus-uu-mark-thread
351 "T" gnus-uu-unmark-thread
353 "b" gnus-uu-mark-buffer
354 "S" gnus-uu-mark-sparse
355 "k" gnus-summary-kill-process-mark
356 "y" gnus-summary-yank-process-mark
357 "w" gnus-summary-save-process-mark
358 "i" gnus-uu-invert-processable)
360 (gnus-define-keys (gnus-uu-extract-map "X" gnus-summary-mode-map)
361 ;;"x" gnus-uu-extract-any
362 ;;"m" gnus-uu-extract-mime
363 "u" gnus-uu-decode-uu
364 "U" gnus-uu-decode-uu-and-save
365 "s" gnus-uu-decode-unshar
366 "S" gnus-uu-decode-unshar-and-save
367 "o" gnus-uu-decode-save
368 "O" gnus-uu-decode-save
369 "b" gnus-uu-decode-binhex
370 "B" gnus-uu-decode-binhex
371 "p" gnus-uu-decode-postscript
372 "P" gnus-uu-decode-postscript-and-save)
375 (gnus-uu-extract-view-map "v" gnus-uu-extract-map)
376 "u" gnus-uu-decode-uu-view
377 "U" gnus-uu-decode-uu-and-save-view
378 "s" gnus-uu-decode-unshar-view
379 "S" gnus-uu-decode-unshar-and-save-view
380 "o" gnus-uu-decode-save-view
381 "O" gnus-uu-decode-save-view
382 "b" gnus-uu-decode-binhex-view
383 "B" gnus-uu-decode-binhex-view
384 "p" gnus-uu-decode-postscript-view
385 "P" gnus-uu-decode-postscript-and-save-view)
390 (defun gnus-uu-decode-uu (&optional n)
391 "Uudecodes the current article."
393 (gnus-uu-decode-with-method 'gnus-uu-uustrip-article n))
395 (defun gnus-uu-decode-uu-and-save (n dir)
396 "Decodes and saves the resulting file."
398 (list current-prefix-arg
399 (file-name-as-directory
400 (read-file-name "Uudecode and save in dir: "
402 gnus-uu-default-dir t))))
403 (gnus-uu-decode-with-method 'gnus-uu-uustrip-article n dir nil nil t))
405 (defun gnus-uu-decode-unshar (&optional n)
406 "Unshars the current article."
408 (gnus-uu-decode-with-method 'gnus-uu-unshar-article n nil nil 'scan t))
410 (defun gnus-uu-decode-unshar-and-save (n dir)
411 "Unshars and saves the current article."
413 (list current-prefix-arg
414 (file-name-as-directory
415 (read-file-name "Unshar and save in dir: "
417 gnus-uu-default-dir t))))
418 (gnus-uu-decode-with-method 'gnus-uu-unshar-article n dir nil 'scan t))
420 (defun gnus-uu-decode-save (n file)
421 "Saves the current article."
423 (list current-prefix-arg
425 (if gnus-uu-save-separate-articles
426 "Save articles is dir: "
427 "Save articles in file: ")
429 gnus-uu-default-dir)))
430 (setq gnus-uu-saved-article-name file)
431 (gnus-uu-decode-with-method 'gnus-uu-save-article n nil t))
433 (defun gnus-uu-decode-binhex (n dir)
434 "Unbinhexes the current article."
436 (list current-prefix-arg
437 (file-name-as-directory
438 (read-file-name "Unbinhex and save in dir: "
440 gnus-uu-default-dir))))
441 (setq gnus-uu-binhex-article-name
442 (make-temp-name (concat gnus-uu-work-dir "binhex")))
443 (gnus-uu-decode-with-method 'gnus-uu-binhex-article n dir))
445 (defun gnus-uu-decode-uu-view (&optional n)
446 "Uudecodes and views the current article."
448 (let ((gnus-view-pseudos (or gnus-view-pseudos 'automatic)))
449 (gnus-uu-decode-uu n)))
451 (defun gnus-uu-decode-uu-and-save-view (n dir)
452 "Decodes, views and saves the resulting file."
454 (list current-prefix-arg
455 (read-file-name "Uudecode, view and save in dir: "
457 gnus-uu-default-dir t)))
458 (let ((gnus-view-pseudos (or gnus-view-pseudos 'automatic)))
459 (gnus-uu-decode-uu-and-save n dir)))
461 (defun gnus-uu-decode-unshar-view (&optional n)
462 "Unshars and views the current article."
464 (let ((gnus-view-pseudos (or gnus-view-pseudos 'automatic)))
465 (gnus-uu-decode-unshar n)))
467 (defun gnus-uu-decode-unshar-and-save-view (n dir)
468 "Unshars and saves the current article."
470 (list current-prefix-arg
471 (read-file-name "Unshar, view and save in dir: "
473 gnus-uu-default-dir t)))
474 (let ((gnus-view-pseudos (or gnus-view-pseudos 'automatic)))
475 (gnus-uu-decode-unshar-and-save n dir)))
477 (defun gnus-uu-decode-save-view (n file)
478 "Saves and views the current article."
480 (list current-prefix-arg
481 (read-file-name (if gnus-uu-save-separate-articles
482 "Save articles is dir: "
483 "Save articles in file: ")
484 gnus-uu-default-dir gnus-uu-default-dir)))
485 (let ((gnus-view-pseudos (or gnus-view-pseudos 'automatic)))
486 (gnus-uu-decode-save n file)))
488 (defun gnus-uu-decode-binhex-view (n file)
489 "Unbinhexes and views the current article."
491 (list current-prefix-arg
492 (read-file-name "Unbinhex, view and save in dir: "
493 gnus-uu-default-dir gnus-uu-default-dir)))
494 (setq gnus-uu-binhex-article-name
495 (make-temp-name (concat gnus-uu-work-dir "binhex")))
496 (let ((gnus-view-pseudos (or gnus-view-pseudos 'automatic)))
497 (gnus-uu-decode-binhex n file)))
500 ;; Digest and forward articles
502 (defun gnus-uu-digest-mail-forward (&optional n post)
503 "Digests and forwards all articles in this series."
505 (let ((gnus-uu-save-in-digest t)
506 (file (make-temp-name (nnheader-concat gnus-uu-tmp-dir "forward")))
507 buf subject from newsgroups)
508 (gnus-setup-message 'forward
509 (setq gnus-uu-digest-from-subject nil)
510 (gnus-uu-decode-save n file)
511 (setq buf (switch-to-buffer (get-buffer-create " *gnus-uu-forward*")))
512 (gnus-add-current-to-buffer-list)
515 (let ((fs gnus-uu-digest-from-subject))
518 subject (gnus-simplify-subject-fuzzy (cdar fs))
520 (while (and fs (or from subject))
522 (unless (string= from (caar fs))
525 (unless (string= (gnus-simplify-subject-fuzzy (cdar fs))
530 (setq subject "Digested Articles"))
533 (if (gnus-news-group-p gnus-newsgroup-name)
536 (goto-char (point-min))
537 (when (re-search-forward "^Subject: ")
538 (delete-region (point) (gnus-point-at-eol))
540 (goto-char (point-min))
541 (when (re-search-forward "^From: ")
542 (delete-region (point) (gnus-point-at-eol))
544 (message-forward post))
547 (setq gnus-uu-digest-from-subject nil)))
549 (defun gnus-uu-digest-post-forward (&optional n)
550 "Digest and forward to a newsgroup."
552 (gnus-uu-digest-mail-forward n t))
556 (defun gnus-uu-mark-by-regexp (regexp &optional unmark)
557 "Ask for a regular expression and set the process mark on all articles that match."
558 (interactive (list (read-from-minibuffer "Mark (regexp): ")))
559 (gnus-set-global-variables)
560 (let ((articles (gnus-uu-find-articles-matching regexp)))
563 (gnus-summary-remove-process-mark (pop articles))
564 (gnus-summary-set-process-mark (pop articles))))
566 (gnus-summary-position-point))
568 (defun gnus-uu-unmark-by-regexp (regexp &optional unmark)
569 "Ask for a regular expression and remove the process mark on all articles that match."
570 (interactive (list (read-from-minibuffer "Mark (regexp): ")))
571 (gnus-uu-mark-by-regexp regexp t))
573 (defun gnus-uu-mark-series ()
574 "Mark the current series with the process mark."
576 (gnus-set-global-variables)
577 (let ((articles (gnus-uu-find-articles-matching)))
579 (gnus-summary-set-process-mark (car articles))
580 (setq articles (cdr articles)))
582 (gnus-summary-position-point))
584 (defun gnus-uu-mark-region (beg end &optional unmark)
585 "Set the process mark on all articles between point and mark."
587 (gnus-set-global-variables)
590 (while (< (point) end)
592 (gnus-summary-remove-process-mark (gnus-summary-article-number))
593 (gnus-summary-set-process-mark (gnus-summary-article-number)))
595 (gnus-summary-position-point))
597 (defun gnus-uu-unmark-region (beg end)
598 "Remove the process mark from all articles between point and mark."
600 (gnus-uu-mark-region beg end t))
602 (defun gnus-uu-mark-buffer ()
603 "Set the process mark on all articles in the buffer."
605 (gnus-uu-mark-region (point-min) (point-max)))
607 (defun gnus-uu-unmark-buffer ()
608 "Remove the process mark on all articles in the buffer."
610 (gnus-uu-mark-region (point-min) (point-max) t))
612 (defun gnus-uu-mark-thread ()
613 "Marks all articles downwards in this thread."
615 (gnus-set-global-variables)
616 (let ((level (gnus-summary-thread-level)))
617 (while (and (gnus-summary-set-process-mark (gnus-summary-article-number))
618 (zerop (gnus-summary-next-subject 1))
619 (> (gnus-summary-thread-level) level))))
620 (gnus-summary-position-point))
622 (defun gnus-uu-unmark-thread ()
623 "Unmarks all articles downwards in this thread."
625 (gnus-set-global-variables)
626 (let ((level (gnus-summary-thread-level)))
627 (while (and (gnus-summary-remove-process-mark
628 (gnus-summary-article-number))
629 (zerop (gnus-summary-next-subject 1))
630 (> (gnus-summary-thread-level) level))))
631 (gnus-summary-position-point))
633 (defun gnus-uu-invert-processable ()
634 "Invert the list of process-marked articles."
635 (let ((data gnus-newsgroup-data)
639 (if (memq (setq number (gnus-data-number (pop data)))
640 gnus-newsgroup-processable)
641 (gnus-summary-remove-process-mark number)
642 (gnus-summary-set-process-mark number)))))
643 (gnus-summary-position-point))
645 (defun gnus-uu-mark-over (&optional score)
646 "Mark all articles with a score over SCORE (the prefix.)"
648 (let ((score (gnus-score-default score))
649 (data gnus-newsgroup-data))
652 (when (> (or (cdr (assq (gnus-data-number (car data))
653 gnus-newsgroup-scored))
654 gnus-summary-default-score 0)
656 (gnus-summary-set-process-mark (caar data)))
657 (setq data (cdr data))))
658 (gnus-summary-position-point)))
660 (defun gnus-uu-mark-sparse ()
661 "Mark all series that have some articles marked."
663 (gnus-set-global-variables)
664 (let ((marked (nreverse gnus-newsgroup-processable))
665 subject articles total headers)
667 (error "No articles marked with the process mark"))
668 (setq gnus-newsgroup-processable nil)
671 (and (vectorp (setq headers
672 (gnus-summary-article-header (car marked))))
673 (setq subject (mail-header-subject headers)
674 articles (gnus-uu-find-articles-matching
675 (gnus-uu-reginize-string subject))
676 total (nconc total articles)))
678 (gnus-summary-set-process-mark (car articles))
679 (setcdr marked (delq (car articles) (cdr marked)))
680 (setq articles (cdr articles)))
681 (setq marked (cdr marked)))
682 (setq gnus-newsgroup-processable (nreverse total)))
683 (gnus-summary-position-point)))
685 (defun gnus-uu-mark-all ()
686 "Mark all articles in \"series\" order."
688 (gnus-set-global-variables)
689 (setq gnus-newsgroup-processable nil)
691 (let ((data gnus-newsgroup-data)
694 (when (and (not (memq (setq number (gnus-data-number (car data)))
695 gnus-newsgroup-processable))
696 (vectorp (gnus-data-header (car data))))
697 (gnus-summary-goto-subject number)
698 (gnus-uu-mark-series))
699 (setq data (cdr data)))))
700 (gnus-summary-position-point))
702 ;; All PostScript functions written by Erik Selberg <speed@cs.washington.edu>.
704 (defun gnus-uu-decode-postscript (&optional n)
705 "Gets postscript of the current article."
707 (gnus-uu-decode-with-method 'gnus-uu-decode-postscript-article n))
709 (defun gnus-uu-decode-postscript-view (&optional n)
710 "Gets and views the current article."
712 (let ((gnus-view-pseudos (or gnus-view-pseudos 'automatic)))
713 (gnus-uu-decode-postscript n)))
715 (defun gnus-uu-decode-postscript-and-save (n dir)
716 "Extracts postscript and saves the current article."
718 (list current-prefix-arg
719 (file-name-as-directory
720 (read-file-name "Save in dir: "
722 gnus-uu-default-dir t))))
723 (gnus-uu-decode-with-method 'gnus-uu-decode-postscript-article
726 (defun gnus-uu-decode-postscript-and-save-view (n dir)
727 "Decodes, views and saves the resulting file."
729 (list current-prefix-arg
730 (read-file-name "Where do you want to save the file(s)? "
732 gnus-uu-default-dir t)))
733 (let ((gnus-view-pseudos (or gnus-view-pseudos 'automatic)))
734 (gnus-uu-decode-postscript-and-save n dir)))
737 ;; Internal functions.
739 (defun gnus-uu-decode-with-method (method n &optional save not-insert
741 (gnus-uu-initialize scan)
743 (setq gnus-uu-default-dir save))
744 ;; Create the directory we save to.
745 (when (and scan cdir save
746 (not (file-exists-p save)))
747 (make-directory save t))
748 (let ((articles (gnus-uu-get-list-of-articles n))
750 (setq files (gnus-uu-grab-articles articles method t))
751 (let ((gnus-current-article (car articles)))
753 (setq files (gnus-uu-scan-directory gnus-uu-work-dir))))
755 (gnus-uu-save-files files save))
756 (when (eq gnus-uu-do-not-unpack-archives nil)
757 (setq files (gnus-uu-unpack-files files)))
758 (setq files (nreverse (gnus-uu-get-actions files)))
759 (or not-insert (not gnus-insert-pseudo-articles)
760 (gnus-summary-insert-pseudos files save))))
762 (defun gnus-uu-scan-directory (dir &optional rec)
763 "Return a list of all files under DIR."
764 (let ((files (directory-files dir t))
766 (while (setq file (pop files))
767 (unless (member (file-name-nondirectory file) '("." ".."))
768 (push (list (cons 'name file)
769 (cons 'article gnus-current-article))
771 (when (file-directory-p file)
772 (setq out (nconc (gnus-uu-scan-directory file t) out)))))
777 (defun gnus-uu-save-files (files dir)
779 (let ((len (length files))
780 (reg (concat "^" (regexp-quote gnus-uu-work-dir)))
781 to-file file fromdir)
782 (while (setq file (cdr (assq 'name (pop files))))
783 (when (file-exists-p file)
784 (string-match reg file)
785 (setq fromdir (substring file (match-end 0)))
786 (if (file-directory-p file)
787 (gnus-make-directory (concat dir fromdir))
788 (setq to-file (concat dir fromdir))
789 (when (or (not (file-exists-p to-file))
790 (eq gnus-uu-be-dangerous t)
791 (and gnus-uu-be-dangerous
792 (gnus-y-or-n-p (format "%s exists; overwrite? "
794 (copy-file file to-file t t)))))
795 (gnus-message 5 "Saved %d file%s" len (if (= len 1) "" "s"))))
797 ;; Functions for saving and possibly digesting articles without
800 ;; Function called by gnus-uu-grab-articles to treat each article.
801 (defun gnus-uu-save-article (buffer in-state)
803 (gnus-uu-save-separate-articles
807 (concat gnus-uu-saved-article-name gnus-current-article))
808 (cond ((eq in-state 'first) (list gnus-uu-saved-article-name 'begin))
809 ((eq in-state 'first-and-last) (list gnus-uu-saved-article-name
811 ((eq in-state 'last) (list 'end))
812 (t (list 'middle)))))
813 ((not gnus-uu-save-in-digest)
816 (write-region (point-min) (point-max) gnus-uu-saved-article-name t)
817 (cond ((eq in-state 'first) (list gnus-uu-saved-article-name 'begin))
818 ((eq in-state 'first-and-last) (list gnus-uu-saved-article-name
820 ((eq in-state 'last) (list 'end))
821 (t (list 'middle)))))
823 (let ((header (gnus-summary-article-header)))
824 (push (cons (mail-header-from header)
825 (mail-header-subject header))
826 gnus-uu-digest-from-subject))
827 (let ((name (file-name-nondirectory gnus-uu-saved-article-name))
828 (delim (concat "^" (make-string 30 ?-) "$"))
829 beg subj headers headline sorthead body end-string state)
830 (if (or (eq in-state 'first)
831 (eq in-state 'first-and-last))
833 (setq state (list 'begin))
834 (save-excursion (set-buffer (get-buffer-create "*gnus-uu-body*"))
837 (set-buffer (get-buffer-create "*gnus-uu-pre*"))
840 "Date: %s\nFrom: %s\nSubject: %s Digest\n\nTopics:\n"
841 (current-time-string) name name))))
842 (when (not (eq in-state 'end))
843 (setq state (list 'middle))))
845 (set-buffer (get-buffer "*gnus-uu-body*"))
846 (goto-char (setq beg (point-max)))
850 (let (buffer-read-only)
851 (gnus-set-text-properties (point-min) (point-max) nil)
852 ;; These two are necessary for XEmacs 19.12 fascism.
853 (put-text-property (point-min) (point-max) 'invisible nil)
854 (put-text-property (point-min) (point-max) 'intangible nil))
855 (goto-char (point-min))
856 (re-search-forward "\n\n")
857 ;; Quote all 30-dash lines.
859 (while (re-search-forward delim nil t)
863 (setq body (buffer-substring (1- (point)) (point-max)))
864 (narrow-to-region (point-min) (point))
865 (if (not (setq headers gnus-uu-digest-headers))
866 (setq sorthead (buffer-substring (point-min) (point-max)))
868 (setq headline (car headers))
869 (setq headers (cdr headers))
870 (goto-char (point-min))
871 (while (re-search-forward headline nil t)
876 (or (and (re-search-forward "^[^ \t]" nil t)
878 (progn (forward-line 1) (point)))))))))
880 (insert sorthead) (goto-char (point-max))
881 (insert body) (goto-char (point-max))
882 (insert (concat "\n" (make-string 30 ?-) "\n\n"))
884 (when (re-search-forward "^Subject: \\(.*\\)$" nil t)
885 (setq subj (buffer-substring (match-beginning 1) (match-end 1)))
887 (set-buffer (get-buffer "*gnus-uu-pre*"))
888 (insert (format " %s\n" subj)))))
889 (when (or (eq in-state 'last)
890 (eq in-state 'first-and-last))
892 (set-buffer (get-buffer "*gnus-uu-pre*"))
893 (insert (format "\n\n%s\n\n" (make-string 70 ?-)))
894 (gnus-write-buffer gnus-uu-saved-article-name))
896 (set-buffer (get-buffer "*gnus-uu-body*"))
897 (goto-char (point-max))
899 (concat (setq end-string (format "End of %s Digest" name))
901 (insert (concat (make-string (length end-string) ?*) "\n"))
903 (point-min) (point-max) gnus-uu-saved-article-name t))
904 (kill-buffer (get-buffer "*gnus-uu-pre*"))
905 (kill-buffer (get-buffer "*gnus-uu-body*"))
907 (if (memq 'begin state)
908 (cons gnus-uu-saved-article-name state)
911 ;; Binhex treatment - not very advanced.
913 (defconst gnus-uu-binhex-body-line
914 "^[^:]...............................................................$")
915 (defconst gnus-uu-binhex-begin-line
916 "^:...............................................................$")
917 (defconst gnus-uu-binhex-end-line
920 (defun gnus-uu-binhex-article (buffer in-state)
921 (let (state start-char)
925 (goto-char (point-min))
926 (when (not (re-search-forward gnus-uu-binhex-begin-line nil t))
927 (when (not (re-search-forward gnus-uu-binhex-body-line nil t))
928 (setq state (list 'wrong-type))))
930 (if (memq 'wrong-type state)
933 (setq start-char (point))
934 (if (looking-at gnus-uu-binhex-begin-line)
936 (setq state (list 'begin))
937 (write-region 1 1 gnus-uu-binhex-article-name))
938 (setq state (list 'middle)))
939 (goto-char (point-max))
940 (re-search-backward (concat gnus-uu-binhex-body-line "\\|"
941 gnus-uu-binhex-end-line)
943 (when (looking-at gnus-uu-binhex-end-line)
944 (setq state (if (memq 'begin state)
949 (when (file-exists-p gnus-uu-binhex-article-name)
950 (append-to-file start-char (point) gnus-uu-binhex-article-name))))
951 (if (memq 'begin state)
952 (cons gnus-uu-binhex-article-name state)
957 (defun gnus-uu-decode-postscript-article (process-buffer in-state)
958 (let ((state (list 'ok))
959 start-char end-char file-name)
961 (set-buffer process-buffer)
962 (goto-char (point-min))
963 (if (not (re-search-forward gnus-uu-postscript-begin-string nil t))
964 (setq state (list 'wrong-type))
966 (setq start-char (point))
967 (if (not (re-search-forward gnus-uu-postscript-end-string nil t))
968 (setq state (list 'wrong-type))
969 (setq end-char (point))
970 (set-buffer (get-buffer-create gnus-uu-output-buffer-name))
971 (insert-buffer-substring process-buffer start-char end-char)
972 (setq file-name (concat gnus-uu-work-dir
973 (cdr gnus-article-current) ".ps"))
974 (write-region (point-min) (point-max) file-name)
975 (setq state (list file-name 'begin 'end)))))
981 (defun gnus-uu-get-actions (files)
985 (setq name (cdr (assq 'name (car files))))
987 (setq action (gnus-uu-get-action name))
988 (setcar files (nconc (list (if (string= action "gnus-uu-archive")
989 (cons 'action "file")
990 (cons 'action action))
991 (cons 'execute (gnus-uu-command
994 (setq files (cdr files)))
997 (defun gnus-uu-get-action (file-name)
1000 (gnus-uu-choose-action
1003 gnus-uu-user-view-rules
1004 (if gnus-uu-ignore-default-view-rules
1006 gnus-uu-default-view-rules)
1007 gnus-uu-user-view-rules-end)))
1008 (when (and (not (string= (or action "") "gnus-uu-archive"))
1009 gnus-uu-view-with-metamail)
1011 (gnus-uu-choose-action file-name gnus-uu-ext-to-mime-list))
1012 (setq action (format "metamail -d -b -c \"%s\"" action))))
1016 ;; Functions for treating subjects and collecting series.
1018 (defun gnus-uu-reginize-string (string)
1019 ;; Takes a string and puts a \ in front of every special character;
1020 ;; ignores any leading "version numbers" thingies that they use in
1021 ;; the comp.binaries groups, and either replaces anything that looks
1022 ;; like "2/3" with "[0-9]+/[0-9]+" or, if it can't find something
1023 ;; like that, replaces the last two numbers with "[0-9]+". This, in
1024 ;; my experience, should get most postings of a series.
1026 (vernum "v[0-9]+[a-z][0-9]+:")
1029 (set-buffer (get-buffer-create gnus-uu-output-buffer-name))
1030 (buffer-disable-undo (current-buffer))
1032 (insert (regexp-quote string))
1035 (setq case-fold-search nil)
1036 (goto-char (point-min))
1037 (when (looking-at vernum)
1038 (replace-match vernum t t)
1039 (setq beg (length vernum)))
1042 (if (re-search-forward "[ \t]*[0-9]+/[0-9]+" nil t)
1043 (replace-match " [0-9]+/[0-9]+")
1046 (if (re-search-forward "[0-9]+[ \t]*of[ \t]*[0-9]+" nil t)
1047 (replace-match "[0-9]+ of [0-9]+")
1050 (if (re-search-backward "\\([^0-9]\\)[0-9]+\\([^0-9]+\\)[0-9]+"
1052 (replace-match "\\1[0-9]+\\2[0-9]+" t nil nil nil))))
1055 (while (re-search-forward "[ \t]+" nil t)
1056 (replace-match "[ \t]*" t t))
1058 (buffer-substring 1 (point-max)))))
1060 (defun gnus-uu-get-list-of-articles (n)
1061 ;; If N is non-nil, the article numbers of the N next articles
1062 ;; will be returned.
1063 ;; If any articles have been marked as processable, they will be
1065 ;; Failing that, articles that have subjects that are part of the
1066 ;; same "series" as the current will be returned.
1070 (setq n (prefix-numeric-value n))
1071 (let ((backward (< n 0))
1075 (push (gnus-summary-article-number)
1077 (gnus-summary-search-forward nil nil backward))
1079 (nreverse articles)))
1080 (gnus-newsgroup-processable
1081 (reverse gnus-newsgroup-processable))
1083 (gnus-uu-find-articles-matching)))))
1085 (defun gnus-uu-string< (l1 l2)
1086 (string< (car l1) (car l2)))
1088 (defun gnus-uu-find-articles-matching
1089 (&optional subject only-unread do-not-translate)
1090 ;; Finds all articles that matches the regexp SUBJECT. If it is
1091 ;; nil, the current article name will be used. If ONLY-UNREAD is
1092 ;; non-nil, only unread articles are chosen. If DO-NOT-TRANSLATE is
1093 ;; non-nil, article names are not equalized before sorting.
1094 (let ((subject (or subject
1095 (gnus-uu-reginize-string (gnus-summary-article-subject))))
1100 ;; Collect all subjects matching subject.
1101 (let ((case-fold-search t)
1102 (data gnus-newsgroup-data)
1106 (and (not (gnus-data-pseudo-p d))
1107 (or (not only-unread)
1108 (= (setq mark (gnus-data-mark d))
1110 (= mark gnus-ticked-mark)
1111 (= mark gnus-dormant-mark))
1112 (setq subj (mail-header-subject (gnus-data-header d)))
1113 (string-match subject subj)
1114 (push (cons subj (gnus-data-number d))
1115 list-of-subjects))))
1117 ;; Expand numbers, sort, and return the list of article
1119 (mapcar (lambda (sub) (cdr sub))
1120 (sort (gnus-uu-expand-numbers
1122 (not do-not-translate))
1123 'gnus-uu-string<))))))
1125 (defun gnus-uu-expand-numbers (string-list &optional translate)
1126 ;; Takes a list of strings and "expands" all numbers in all the
1127 ;; strings. That is, this function makes all numbers equal length by
1128 ;; prepending lots of zeroes before each number. This is to ease later
1129 ;; sorting to find out what sequence the articles are supposed to be
1130 ;; decoded in. Returns the list of expanded strings.
1131 (let ((out-list string-list)
1134 (set-buffer (get-buffer-create gnus-uu-output-buffer-name))
1135 (buffer-disable-undo (current-buffer))
1138 (insert (caar string-list))
1139 ;; Translate multiple spaces to one space.
1140 (goto-char (point-min))
1141 (while (re-search-forward "[ \t]+" nil t)
1142 (replace-match " "))
1143 ;; Translate all characters to "a".
1144 (goto-char (point-min))
1146 (while (re-search-forward "[A-Za-z]" nil t)
1147 (replace-match "a" t t)))
1149 (goto-char (point-min))
1150 (while (re-search-forward "[0-9]+" nil t)
1153 (string-to-int (buffer-substring
1154 (match-beginning 0) (match-end 0))))))
1155 (setq string (buffer-substring 1 (point-max)))
1156 (setcar (car string-list) string)
1157 (setq string-list (cdr string-list))))
1161 ;; `gnus-uu-grab-articles' is the general multi-article treatment
1162 ;; function. It takes a list of articles to be grabbed and a function
1163 ;; to apply to each article.
1165 ;; The function to be called should take two parameters. The first
1166 ;; parameter is the article buffer. The function should leave the
1167 ;; result, if any, in this buffer. Most treatment functions will just
1168 ;; generate files...
1170 ;; The second parameter is the state of the list of articles, and can
1171 ;; have four values: `first', `middle', `last' and `first-and-last'.
1173 ;; The function should return a list. The list may contain the
1174 ;; following symbols:
1175 ;; `error' if an error occurred
1176 ;; `begin' if the beginning of an encoded file has been received
1177 ;; If the list returned contains a `begin', the first element of
1178 ;; the list *must* be a string with the file name of the decoded
1180 ;; `end' if the end of an encoded file has been received
1181 ;; `middle' if the article was a body part of an encoded file
1182 ;; `wrong-type' if the article was not a part of an encoded file
1183 ;; `ok', which can be used everything is ok
1185 (defvar gnus-uu-has-been-grabbed nil)
1187 (defun gnus-uu-unmark-list-of-grabbed (&optional dont-unmark-last-article)
1189 (if (not (and gnus-uu-has-been-grabbed
1190 gnus-uu-unmark-articles-not-decoded))
1192 (when dont-unmark-last-article
1193 (setq art (car gnus-uu-has-been-grabbed))
1194 (setq gnus-uu-has-been-grabbed (cdr gnus-uu-has-been-grabbed)))
1195 (while gnus-uu-has-been-grabbed
1196 (gnus-summary-tick-article (car gnus-uu-has-been-grabbed) t)
1197 (setq gnus-uu-has-been-grabbed (cdr gnus-uu-has-been-grabbed)))
1198 (when dont-unmark-last-article
1199 (setq gnus-uu-has-been-grabbed (list art))))))
1201 ;; This function takes a list of articles and a function to apply to
1202 ;; each article grabbed.
1204 ;; This function returns a list of files decoded if the grabbing and
1205 ;; the process-function has been successful and nil otherwise.
1206 (defun gnus-uu-grab-articles (articles process-function
1207 &optional sloppy limit no-errors)
1208 (let ((state 'first)
1209 (gnus-asynchronous nil)
1210 has-been-begin article result-file result-files process-state
1211 gnus-summary-display-article-function
1212 gnus-article-display-hook gnus-article-prepare-hook
1213 article-series files)
1215 (while (and articles
1216 (not (memq 'error process-state))
1218 (not (memq 'end process-state))))
1220 (setq article (pop articles))
1221 (push article article-series)
1224 (if (eq state 'first)
1225 (setq state 'first-and-last)
1226 (setq state 'last)))
1228 (let ((part (gnus-uu-part-number article)))
1229 (gnus-message 6 "Getting article %d%s..."
1230 article (if (string= part "") "" (concat ", " part))))
1231 (gnus-summary-display-article article)
1233 ;; Push the article to the processing function.
1235 (set-buffer gnus-original-article-buffer)
1236 (let ((buffer-read-only nil))
1238 (set-buffer gnus-summary-buffer)
1240 (funcall process-function
1241 gnus-original-article-buffer state)))))
1243 (gnus-summary-remove-process-mark article)
1245 ;; If this is the beginning of a decoded file, we push it
1247 (when (or (memq 'begin process-state)
1248 (and (or (eq state 'first)
1249 (eq state 'first-and-last))
1250 (memq 'ok process-state)))
1251 (when has-been-begin
1252 ;; If there is a `result-file' here, that means that the
1253 ;; file was unsuccessfully decoded, so we delete it.
1254 (when (and result-file
1255 (file-exists-p result-file)
1256 (not gnus-uu-be-dangerous)
1257 (or (eq gnus-uu-be-dangerous t)
1259 (format "Delete unsuccessfully decoded file %s"
1261 (delete-file result-file)))
1262 (when (memq 'begin process-state)
1263 (setq result-file (car process-state)))
1264 (setq has-been-begin t))
1266 ;; Check whether we have decoded one complete file.
1267 (when (memq 'end process-state)
1268 (setq article-series nil)
1269 (setq has-been-begin nil)
1270 (if (stringp result-file)
1271 (setq files (list result-file))
1272 (setq files result-file))
1273 (setq result-file (car files))
1275 (push (list (cons 'name (pop files))
1276 (cons 'article article))
1278 ;; Allow user-defined functions to be run on this file.
1279 (when gnus-uu-grabbed-file-functions
1280 (let ((funcs gnus-uu-grabbed-file-functions))
1281 (unless (listp funcs)
1282 (setq funcs (list funcs)))
1284 (funcall (pop funcs) result-file))))
1285 (setq result-file nil)
1286 ;; Check whether we have decoded enough articles.
1287 (and limit (= (length result-files) limit)
1288 (setq articles nil)))
1290 ;; If this is the last article to be decoded, and
1291 ;; we still haven't reached the end, then we delete
1292 ;; the partially decoded file.
1293 (and (or (eq state 'last) (eq state 'first-and-last))
1294 (not (memq 'end process-state))
1296 (file-exists-p result-file)
1297 (not gnus-uu-be-dangerous)
1298 (or (eq gnus-uu-be-dangerous t)
1299 (gnus-y-or-n-p (format "Delete incomplete file %s? " result-file)))
1300 (delete-file result-file))
1302 ;; If this was a file of the wrong sort, then
1303 (when (and (or (memq 'wrong-type process-state)
1304 (memq 'error process-state))
1305 gnus-uu-unmark-articles-not-decoded)
1306 (gnus-summary-tick-article article t))
1308 ;; Set the new series state.
1309 (if (and (not has-been-begin)
1311 (or (memq 'end process-state)
1312 (memq 'middle process-state)))
1314 (setq process-state (list 'error))
1315 (gnus-message 2 "No begin part at the beginning")
1317 (setq state 'middle)))
1319 ;; When there are no result-files, then something must be wrong.
1323 ((not has-been-begin)
1324 (gnus-message 2 "Wrong type file"))
1325 ((memq 'error process-state)
1326 (gnus-message 2 "An error occurred during decoding"))
1327 ((not (or (memq 'ok process-state)
1328 (memq 'end process-state)))
1329 (gnus-message 2 "End of articles reached before end of file")))
1330 ;; Make unsuccessfully decoded articles unread.
1331 (when gnus-uu-unmark-articles-not-decoded
1332 (while article-series
1333 (gnus-summary-tick-article (pop article-series) t))))
1337 (defun gnus-uu-grab-view (file)
1338 "View FILE using the gnus-uu methods."
1339 (let ((action (gnus-uu-get-action file)))
1340 (gnus-execute-command
1341 (if (string-match "%" action)
1342 (format action file)
1343 (concat action " " file))
1344 (eq gnus-view-pseudos 'not-confirm))))
1346 (defun gnus-uu-grab-move (file)
1347 "Move FILE to somewhere."
1348 (when gnus-uu-default-dir
1349 (let ((to-file (concat (file-name-as-directory gnus-uu-default-dir)
1350 (file-name-nondirectory file))))
1351 (rename-file file to-file)
1352 (unless (file-exists-p file)
1353 (make-symbolic-link to-file file)))))
1355 (defun gnus-uu-part-number (article)
1356 (let* ((header (gnus-summary-article-header article))
1357 (subject (and header (mail-header-subject header))))
1359 (string-match "[0-9]+ */[0-9]+\\|[0-9]+ * of *[0-9]+" subject))
1360 (match-string 0 subject)
1363 (defun gnus-uu-uudecode-sentinel (process event)
1364 (delete-process (get-process process)))
1366 (defun gnus-uu-uustrip-article (process-buffer in-state)
1367 ;; Uudecodes a file asynchronously.
1369 (set-buffer process-buffer)
1370 (let ((state (list 'wrong-type))
1371 process-connection-type case-fold-search buffer-read-only
1373 (goto-char (point-min))
1375 ;; Deal with ^M at the end of the lines.
1376 (when gnus-uu-kill-carriage-return
1378 (while (search-forward "\r" nil t)
1379 (delete-backward-char 1))))
1381 (while (or (re-search-forward gnus-uu-begin-string nil t)
1382 (re-search-forward gnus-uu-body-line nil t))
1383 (setq state (list 'ok))
1384 ;; Ok, we are at the first uucoded line.
1386 (setq start-char (point))
1388 (if (not (looking-at gnus-uu-begin-string))
1389 (setq state (list 'middle))
1390 ;; This is the beginning of an uuencoded article.
1391 ;; We replace certain characters that could make things messy.
1392 (setq gnus-uu-file-name
1393 (let ((nnheader-file-name-translation-alist
1394 '((?/ . ?,) (? . ?_) (?* . ?_) (?$ . ?_))))
1395 (nnheader-translate-file-chars (match-string 1))))
1396 (replace-match (concat "begin 644 " gnus-uu-file-name) t t)
1398 ;; Remove any non gnus-uu-body-line right after start.
1400 (while (and (not (eobp))
1401 (not (looking-at gnus-uu-body-line)))
1404 ;; If a process is running, we kill it.
1405 (when (and gnus-uu-uudecode-process
1406 (memq (process-status gnus-uu-uudecode-process)
1408 (delete-process gnus-uu-uudecode-process)
1409 (gnus-uu-unmark-list-of-grabbed t))
1411 ;; Start a new uudecoding process.
1412 (let ((cdir default-directory))
1415 (cd gnus-uu-work-dir)
1416 (setq gnus-uu-uudecode-process
1419 (get-buffer-create gnus-uu-output-buffer-name)
1420 shell-file-name shell-command-switch
1421 (format "cd %s %s uudecode" gnus-uu-work-dir
1422 gnus-shell-command-separator))))
1424 (set-process-sentinel
1425 gnus-uu-uudecode-process 'gnus-uu-uudecode-sentinel)
1426 (setq state (list 'begin))
1427 (push (concat gnus-uu-work-dir gnus-uu-file-name) files))
1429 ;; We look for the end of the thing to be decoded.
1430 (if (re-search-forward gnus-uu-end-string nil t)
1432 (goto-char (point-max))
1433 (re-search-backward gnus-uu-body-line nil t))
1437 (when gnus-uu-uudecode-process
1438 (when (memq (process-status gnus-uu-uudecode-process) '(run stop))
1439 ;; Try to correct mishandled uucode.
1440 (when gnus-uu-correct-stripped-uucode
1441 (gnus-uu-check-correct-stripped-uucode start-char (point)))
1443 ;; Send the text to the process.
1445 (process-send-region
1446 gnus-uu-uudecode-process start-char (point))
1449 (delete-process gnus-uu-uudecode-process)
1450 (gnus-message 2 "gnus-uu: Couldn't uudecode")
1451 (setq state (list 'wrong-type)))))
1453 (if (memq 'end state)
1455 ;; Send an EOF, just in case.
1457 (process-send-eof gnus-uu-uudecode-process))
1458 (while (memq (process-status gnus-uu-uudecode-process)
1460 (accept-process-output gnus-uu-uudecode-process 1)))
1461 (when (or (not gnus-uu-uudecode-process)
1462 (not (memq (process-status gnus-uu-uudecode-process)
1464 (setq state (list 'wrong-type)))))))
1466 (if (memq 'begin state)
1467 (cons (if (= (length files) 1) (car files) files) state)
1470 ;; This function is used by `gnus-uu-grab-articles' to treat
1471 ;; a shared article.
1472 (defun gnus-uu-unshar-article (process-buffer in-state)
1473 (let ((state (list 'ok))
1476 (set-buffer process-buffer)
1477 (goto-char (point-min))
1478 (if (not (re-search-forward gnus-uu-shar-begin-string nil t))
1479 (setq state (list 'wrong-type))
1481 (setq start-char (point))
1482 (call-process-region
1483 start-char (point-max) shell-file-name nil
1484 (get-buffer-create gnus-uu-output-buffer-name) nil
1485 shell-command-switch
1486 (concat "cd " gnus-uu-work-dir " "
1487 gnus-shell-command-separator " sh"))))
1490 ;; Returns the name of what the shar file is going to unpack.
1491 (defun gnus-uu-find-name-in-shar ()
1492 (let ((oldpoint (point))
1494 (goto-char (point-min))
1495 (when (re-search-forward gnus-uu-shar-name-marker nil t)
1496 (setq res (buffer-substring (match-beginning 1) (match-end 1))))
1497 (goto-char oldpoint)
1500 ;; `gnus-uu-choose-action' chooses what action to perform given the name
1501 ;; and `gnus-uu-file-action-list'. Returns either nil if no action is
1502 ;; found, or the name of the command to run if such a rule is found.
1503 (defun gnus-uu-choose-action (file-name file-action-list &optional no-ignore)
1504 (let ((action-list (copy-sequence file-action-list))
1505 (case-fold-search t)
1510 (and gnus-uu-ignore-files-by-name
1511 (string-match gnus-uu-ignore-files-by-name file-name)))
1513 (and gnus-uu-ignore-files-by-type
1514 (string-match gnus-uu-ignore-files-by-type
1515 (or (gnus-uu-choose-action
1516 file-name gnus-uu-ext-to-mime-list t)
1518 (while (not (or (eq action-list ()) action))
1519 (setq rule (car action-list))
1520 (setq action-list (cdr action-list))
1521 (when (string-match (car rule) file-name)
1522 (setq action (cadr rule)))))
1525 (defun gnus-uu-treat-archive (file-path)
1526 ;; Unpacks an archive. Returns t if unpacking is successful.
1527 (let ((did-unpack t)
1529 (setq action (gnus-uu-choose-action
1530 file-path (append gnus-uu-user-archive-rules
1531 (if gnus-uu-ignore-default-archive-rules
1533 gnus-uu-default-archive-rules))))
1536 (error "No unpackers for the file %s" file-path))
1538 (string-match "/[^/]*$" file-path)
1539 (setq dir (substring file-path 0 (match-beginning 0)))
1541 (when (member action gnus-uu-destructive-archivers)
1542 (copy-file file-path (concat file-path "~") t))
1544 (setq command (format "cd %s ; %s" dir (gnus-uu-command action file-path)))
1547 (set-buffer (get-buffer-create gnus-uu-output-buffer-name))
1550 (gnus-message 5 "Unpacking: %s..." (gnus-uu-command action file-path))
1552 (if (= 0 (call-process shell-file-name nil
1553 (get-buffer-create gnus-uu-output-buffer-name)
1554 nil shell-command-switch command))
1556 (gnus-message 2 "Error during unpacking of archive")
1557 (setq did-unpack nil))
1559 (when (member action gnus-uu-destructive-archivers)
1560 (rename-file (concat file-path "~") file-path t))
1564 (defun gnus-uu-dir-files (dir)
1565 (let ((dirs (directory-files dir t "[^/][^\\.][^\\.]?$"))
1568 (if (file-directory-p (setq file (car dirs)))
1569 (setq files (append files (gnus-uu-dir-files file)))
1571 (setq dirs (cdr dirs)))
1574 (defun gnus-uu-unpack-files (files &optional ignore)
1575 ;; Go through FILES and look for files to unpack.
1576 (let* ((totfiles (gnus-uu-ls-r gnus-uu-work-dir))
1580 (setq file (cdr (assq 'name (car files))))
1581 (when (and (not (member file ignore))
1582 (equal (gnus-uu-get-action (file-name-nondirectory file))
1584 (push file did-unpack)
1585 (unless (gnus-uu-treat-archive file)
1586 (gnus-message 2 "Error during unpacking of %s" file))
1587 (let* ((newfiles (gnus-uu-ls-r gnus-uu-work-dir))
1590 (unless (member (car nfiles) totfiles)
1591 (push (list (cons 'name (car nfiles))
1592 (cons 'original file))
1594 (setq nfiles (cdr nfiles)))
1595 (setq totfiles newfiles)))
1596 (setq files (cdr files)))
1598 (gnus-uu-unpack-files ofiles (append did-unpack ignore))
1601 (defun gnus-uu-ls-r (dir)
1602 (let* ((files (gnus-uu-directory-files dir t))
1605 (when (file-directory-p (car files))
1606 (setq ofiles (delete (car files) ofiles))
1607 (setq ofiles (append ofiles (gnus-uu-ls-r (car files)))))
1608 (setq files (cdr files)))
1613 (defun gnus-uu-directory-files (dir &optional full)
1614 (let (files out file)
1615 (setq files (directory-files dir full))
1617 (setq file (car files))
1618 (setq files (cdr files))
1619 (unless (member (file-name-nondirectory file) '("." ".."))
1621 (setq out (nreverse out))
1624 (defun gnus-uu-check-correct-stripped-uucode (start end)
1626 (let (found beg length)
1627 (if (not gnus-uu-correct-stripped-uucode)
1631 (if (re-search-forward " \\|`" end t)
1636 (when (looking-at "\n")
1641 (if (looking-at (concat gnus-uu-begin-string "\\|"
1642 gnus-uu-end-string))
1648 (setq length (- (point) beg)))
1653 (when (not (= length (- (point) beg)))
1654 (insert (make-string (- length (- (point) beg)) ? ))))
1655 (forward-line 1)))))))
1657 (defvar gnus-uu-tmp-alist nil)
1659 (defun gnus-uu-initialize (&optional scan)
1662 (when (setq entry (assoc gnus-newsgroup-name gnus-uu-tmp-alist))
1663 (if (file-exists-p (cdr entry))
1664 (setq gnus-uu-work-dir (cdr entry))
1665 (setq gnus-uu-tmp-alist (delq entry gnus-uu-tmp-alist))
1668 (setq gnus-uu-tmp-dir (file-name-as-directory
1669 (expand-file-name gnus-uu-tmp-dir)))
1670 (if (not (file-directory-p gnus-uu-tmp-dir))
1671 (error "Temp directory %s doesn't exist" gnus-uu-tmp-dir)
1672 (when (not (file-writable-p gnus-uu-tmp-dir))
1673 (error "Temp directory %s can't be written to"
1676 (setq gnus-uu-work-dir
1677 (make-temp-name (concat gnus-uu-tmp-dir "gnus")))
1678 (gnus-make-directory gnus-uu-work-dir)
1679 (set-file-modes gnus-uu-work-dir 448)
1680 (setq gnus-uu-work-dir (file-name-as-directory gnus-uu-work-dir))
1681 (push (cons gnus-newsgroup-name gnus-uu-work-dir)
1682 gnus-uu-tmp-alist))))
1685 ;; Kills the temporary uu buffers, kills any processes, etc.
1686 (defun gnus-uu-clean-up ()
1688 (and gnus-uu-uudecode-process
1689 (memq (process-status (or gnus-uu-uudecode-process "nevair"))
1691 (delete-process gnus-uu-uudecode-process))
1692 (when (setq buf (get-buffer gnus-uu-output-buffer-name))
1693 (kill-buffer buf))))
1695 (defun gnus-quote-arg-for-sh-or-csh (arg)
1696 (let ((pos 0) new-pos accum)
1697 ;; *** bug: we don't handle newline characters properly
1698 (while (setq new-pos (string-match "[!`\"$\\& \t{}]" arg pos))
1699 (push (substring arg pos new-pos) accum)
1701 (push (list (aref arg new-pos)) accum)
1702 (setq pos (1+ new-pos)))
1705 (apply 'concat (nconc (nreverse accum) (list (substring arg pos)))))))
1707 ;; Inputs an action and a filename and returns a full command, making sure
1708 ;; that the filename will be treated as a single argument when the shell
1709 ;; executes the command.
1710 (defun gnus-uu-command (action file)
1711 (let ((quoted-file (gnus-quote-arg-for-sh-or-csh file)))
1712 (if (string-match "%s" action)
1713 (format action quoted-file)
1714 (concat action " " quoted-file))))
1716 (defun gnus-uu-delete-work-dir (&optional dir)
1717 "Delete recursively all files and directories under `gnus-uu-work-dir'."
1719 (gnus-message 7 "Deleting directory %s..." dir)
1720 (setq dir gnus-uu-work-dir))
1722 (file-exists-p dir))
1723 (let ((files (directory-files dir t nil t))
1725 (while (setq file (pop files))
1726 (unless (member (file-name-nondirectory file) '("." ".."))
1727 (if (file-directory-p file)
1728 (gnus-uu-delete-work-dir file)
1729 (gnus-message 9 "Deleting file %s..." file)
1730 (delete-file file))))
1731 (delete-directory dir)))
1732 (gnus-message 7 ""))
1736 (add-hook 'gnus-exit-group-hook 'gnus-uu-clean-up)
1737 (add-hook 'gnus-exit-group-hook 'gnus-uu-delete-work-dir)
1742 ;;; uuencoded posting
1745 ;; Any function that is to be used as and encoding method will take two
1746 ;; parameters: PATH-NAME and FILE-NAME. (E.g. "/home/gaga/spiral.jpg"
1747 ;; and "spiral.jpg", respectively.) The function should return nil if
1748 ;; the encoding wasn't successful.
1749 (defcustom gnus-uu-post-encode-method 'gnus-uu-post-encode-uuencode
1750 "Function used for encoding binary files.
1751 There are three functions supplied with gnus-uu for encoding files:
1752 `gnus-uu-post-encode-uuencode', which does straight uuencoding;
1753 `gnus-uu-post-encode-mime', which encodes with base64 and adds MIME
1754 headers; and `gnus-uu-post-encode-mime-uuencode', which encodes with
1755 uuencode and adds MIME headers."
1756 :group 'gnus-extract-post
1757 :type '(radio (function-item gnus-uu-post-encode-uuencode)
1758 (function-item gnus-uu-post-encode-mime)
1759 (function-item gnus-uu-post-encode-mime-uuencode)
1760 (function :tag "Other")))
1762 (defcustom gnus-uu-post-include-before-composing nil
1763 "Non-nil means that gnus-uu will ask for a file to encode before you compose the article.
1764 If this variable is t, you can either include an encoded file with
1765 \\[gnus-uu-post-insert-binary-in-article] or have one included for you when you post the article."
1766 :group 'gnus-extract-post
1769 (defcustom gnus-uu-post-length 990
1770 "Maximum length of an article.
1771 The encoded file will be split into how many articles it takes to
1772 post the entire file."
1773 :group 'gnus-extract-post
1776 (defcustom gnus-uu-post-threaded nil
1777 "Non-nil means that gnus-uu will post the encoded file in a thread.
1778 This may not be smart, as no other decoder I have seen are able to
1779 follow threads when collecting uuencoded articles. (Well, I have seen
1780 one package that does that - gnus-uu, but somehow, I don't think that
1781 counts...) Default is nil."
1782 :group 'gnus-extract-post
1785 (defcustom gnus-uu-post-separate-description t
1786 "Non-nil means that the description will be posted in a separate article.
1787 The first article will typically be numbered (0/x). If this variable
1788 is nil, the description the user enters will be included at the
1789 beginning of the first article, which will be numbered (1/x). Default
1791 :group 'gnus-extract-post
1794 (defvar gnus-uu-post-binary-separator "--binary follows this line--")
1795 (defvar gnus-uu-post-message-id nil)
1796 (defvar gnus-uu-post-inserted-file-name nil)
1797 (defvar gnus-uu-winconf-post-news nil)
1799 (defun gnus-uu-post-news ()
1800 "Compose an article and post an encoded file."
1802 (setq gnus-uu-post-inserted-file-name nil)
1803 (setq gnus-uu-winconf-post-news (current-window-configuration))
1805 (gnus-summary-post-news)
1807 (use-local-map (copy-keymap (current-local-map)))
1808 (local-set-key "\C-c\C-c" 'gnus-summary-edit-article-done)
1809 (local-set-key "\C-c\C-c" 'gnus-uu-post-news-inews)
1810 (local-set-key "\C-c\C-s" 'gnus-uu-post-news-inews)
1811 (local-set-key "\C-c\C-i" 'gnus-uu-post-insert-binary-in-article)
1813 (when gnus-uu-post-include-before-composing
1814 (save-excursion (setq gnus-uu-post-inserted-file-name
1815 (gnus-uu-post-insert-binary)))))
1817 (defun gnus-uu-post-insert-binary-in-article ()
1818 "Inserts an encoded file in the buffer.
1819 The user will be asked for a file name."
1822 (setq gnus-uu-post-inserted-file-name (gnus-uu-post-insert-binary))))
1824 ;; Encodes with uuencode and substitutes all spaces with backticks.
1825 (defun gnus-uu-post-encode-uuencode (path file-name)
1826 (when (gnus-uu-post-encode-file "uuencode" path file-name)
1827 (goto-char (point-min))
1829 (while (re-search-forward " " nil t)
1830 (replace-match "`"))
1833 ;; Encodes with uuencode and adds MIME headers.
1834 (defun gnus-uu-post-encode-mime-uuencode (path file-name)
1835 (when (gnus-uu-post-encode-uuencode path file-name)
1836 (gnus-uu-post-make-mime file-name "x-uue")
1839 ;; Encodes with base64 and adds MIME headers
1840 (defun gnus-uu-post-encode-mime (path file-name)
1841 (when (gnus-uu-post-encode-file "mmencode" path file-name)
1842 (gnus-uu-post-make-mime file-name "base64")
1845 ;; Adds MIME headers.
1846 (defun gnus-uu-post-make-mime (file-name encoding)
1847 (goto-char (point-min))
1848 (insert (format "Content-Type: %s; name=\"%s\"\n"
1849 (gnus-uu-choose-action file-name gnus-uu-ext-to-mime-list)
1851 (insert (format "Content-Transfer-Encoding: %s\n\n" encoding))
1853 (set-buffer gnus-message-buffer)
1854 (goto-char (point-min))
1855 (re-search-forward (concat "^" (regexp-quote mail-header-separator) "$"))
1857 (narrow-to-region 1 (point))
1858 (unless (mail-fetch-field "mime-version")
1860 (insert "MIME-Version: 1.0\n"))
1863 ;; Encodes a file PATH with COMMAND, leaving the result in the
1865 (defun gnus-uu-post-encode-file (command path file-name)
1866 (= 0 (call-process shell-file-name nil t nil shell-command-switch
1867 (format "%s %s %s" command path file-name))))
1869 (defun gnus-uu-post-news-inews ()
1870 "Posts the composed news article and encoded file.
1871 If no file has been included, the user will be asked for a file."
1876 (if gnus-uu-post-inserted-file-name
1877 (setq file-name gnus-uu-post-inserted-file-name)
1878 (setq file-name (gnus-uu-post-insert-binary)))
1880 (if gnus-uu-post-threaded
1881 (let ((message-required-news-headers
1882 (if (memq 'Message-ID message-required-news-headers)
1883 message-required-news-headers
1884 (cons 'Message-ID message-required-news-headers)))
1885 gnus-inews-article-hook)
1887 (setq gnus-inews-article-hook (if (listp gnus-inews-article-hook)
1888 gnus-inews-article-hook
1889 (list gnus-inews-article-hook)))
1893 (goto-char (point-min))
1894 (if (re-search-forward "^Message-ID: \\(.*\\)$" nil t)
1895 (setq gnus-uu-post-message-id
1897 (match-beginning 1) (match-end 1)))
1898 (setq gnus-uu-post-message-id nil))))
1899 gnus-inews-article-hook)
1900 (gnus-uu-post-encoded file-name t))
1901 (gnus-uu-post-encoded file-name nil)))
1902 (setq gnus-uu-post-inserted-file-name nil)
1903 (when gnus-uu-winconf-post-news
1904 (set-window-configuration gnus-uu-winconf-post-news)))
1906 ;; Asks for a file to encode, encodes it and inserts the result in
1907 ;; the current buffer. Returns the file name the user gave.
1908 (defun gnus-uu-post-insert-binary ()
1909 (let ((uuencode-buffer-name "*uuencode buffer*")
1910 file-path uubuf file-name)
1912 (setq file-path (read-file-name
1913 "What file do you want to encode? "))
1914 (when (not (file-exists-p file-path))
1915 (error "%s: No such file" file-path))
1917 (goto-char (point-max))
1918 (insert (format "\n%s\n" gnus-uu-post-binary-separator))
1920 (when (string-match "^~/" file-path)
1921 (setq file-path (concat "$HOME" (substring file-path 1))))
1922 (if (string-match "/[^/]*$" file-path)
1923 (setq file-name (substring file-path (1+ (match-beginning 0))))
1924 (setq file-name file-path))
1928 (set-buffer (setq uubuf
1929 (get-buffer-create uuencode-buffer-name)))
1931 (funcall gnus-uu-post-encode-method file-path file-name))
1932 (insert-buffer-substring uubuf)
1933 (error "Encoding unsuccessful"))
1934 (kill-buffer uubuf))
1937 ;; Posts the article and all of the encoded file.
1938 (defun gnus-uu-post-encoded (file-name &optional threaded)
1939 (let ((send-buffer-name "*uuencode send buffer*")
1940 (encoded-buffer-name "*encoded buffer*")
1941 (top-string "[ cut here %s (%s %d/%d) %s gnus-uu ]")
1942 (separator (concat mail-header-separator "\n\n"))
1943 uubuf length parts header i end beg
1944 beg-line minlen buf post-buf whole-len beg-binary end-binary)
1946 (setq post-buf (current-buffer))
1948 (goto-char (point-min))
1949 (when (not (re-search-forward
1950 (if gnus-uu-post-separate-description
1951 (concat "^" (regexp-quote gnus-uu-post-binary-separator)
1953 (concat "^" (regexp-quote mail-header-separator) "$"))
1955 (error "Internal error: No binary/header separator"))
1958 (setq beg-binary (point))
1959 (setq end-binary (point-max))
1962 (set-buffer (setq uubuf (get-buffer-create encoded-buffer-name)))
1964 (insert-buffer-substring post-buf beg-binary end-binary)
1965 (goto-char (point-min))
1966 (setq length (count-lines 1 (point-max)))
1967 (setq parts (/ length gnus-uu-post-length))
1968 (when (not (< (% length gnus-uu-post-length) 4))
1969 (setq parts (1+ parts))))
1971 (when gnus-uu-post-separate-description
1973 (kill-region (point) (point-max))
1975 (goto-char (point-min))
1977 (concat "^" (regexp-quote mail-header-separator) "$") nil t)
1979 (setq header (buffer-substring 1 (point)))
1981 (goto-char (point-min))
1982 (if (not gnus-uu-post-separate-description)
1984 (when (and (not threaded) (re-search-forward "^Subject: " nil t))
1986 (insert (format " (0/%d)" parts)))
1992 (while (not (> i parts))
1993 (set-buffer (get-buffer-create send-buffer-name))
1996 (when (and threaded gnus-uu-post-message-id)
1997 (insert (format "References: %s\n" gnus-uu-post-message-id)))
2000 (- 62 (length (format top-string "" file-name i parts ""))))
2001 (when (> 1 (setq minlen (/ whole-len 2)))
2006 (make-string minlen ?-)
2009 (if (= 0 (% whole-len 2)) (1- minlen) minlen) ?-)))
2011 (goto-char (point-min))
2012 (if (not (re-search-forward "^Subject: " nil t))
2017 (insert (format " (%d/%d)" i parts)))
2018 (when (or (and (= i 2) gnus-uu-post-separate-description)
2019 (and (= i 1) (not gnus-uu-post-separate-description)))
2020 (replace-match "Subject: Re: "))))
2022 (goto-char (point-max))
2027 (goto-char (point-max))
2028 (forward-line gnus-uu-post-length))
2029 (when (and (= (1+ i) parts) (< (count-lines (point) (point-max)) 4))
2032 (insert-buffer-substring uubuf beg end)
2037 (goto-char (point-min))
2039 (concat "^" (regexp-quote mail-header-separator) "$") nil t)
2042 (when (re-search-forward
2043 (concat "^" (regexp-quote gnus-uu-post-binary-separator) "$")
2049 (let (message-sent-message-via)
2052 (when (setq buf (get-buffer send-buffer-name))
2054 (when (setq buf (get-buffer encoded-buffer-name))
2057 (when (not gnus-uu-post-separate-description)
2058 (set-buffer-modified-p nil)
2059 (when (fboundp 'bury-buffer)
2064 ;; gnus-uu.el ends here