1 ;;; gnus-uu.el --- extract (uu)encoded files in Gnus
2 ;; Copyright (C) 1985,86,87,93,94,95,96,97,98 Free Software Foundation, Inc.
4 ;; Author: Lars Magne Ingebrigtsen <larsi@gnus.org>
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.
29 (eval-when-compile (require 'cl))
36 (defgroup gnus-extract nil
37 "Extracting encoded files."
41 (defgroup gnus-extract-view nil
42 "Viewwing extracted files."
45 (defgroup gnus-extract-archive nil
46 "Extracting encoded archives."
49 (defgroup gnus-extract-post nil
50 "Extracting encoded archives."
51 :prefix "gnus-uu-post"
54 ;; Default viewing action rules
56 (defcustom gnus-uu-default-view-rules
57 '(("\\.te?xt$\\|\\.doc$\\|read.*me\\|\\.c?$\\|\\.h$\\|\\.bat$\\|\\.asm$\\|makefile" "cat %s | sed 's/\r$//'")
58 ("\\.pas$" "cat %s | sed 's/\r$//'")
59 ("\\.[1-9]$" "groff -mandoc -Tascii %s | sed s/\b.//g")
60 ("\\.\\(jpe?g\\|gif\\|tiff?\\|p[pgb]m\\|xwd\\|xbm\\|pcx\\)$" "xv")
61 ("\\.tga$" "tgatoppm %s | xv -")
62 ("\\.\\(wav\\|aiff\\|hcom\\|u[blw]\\|s[bfw]\\|voc\\|smp\\)$"
63 "sox -v .5 %s -t .au -u - > /dev/audio")
64 ("\\.au$" "cat %s > /dev/audio")
65 ("\\.midi?$" "playmidi -f")
67 ("\\.ps$" "ghostview")
69 ("\\.html$" "xmosaic")
70 ("\\.mpe?g$" "mpeg_play")
71 ("\\.\\(flc\\|fli\\|rle\\|iff\\|pfx\\|avi\\|sme\\|rpza\\|dl\\|qt\\|rsrc\\|mov\\)$" "xanim")
72 ("\\.\\(tar\\|arj\\|zip\\|zoo\\|arc\\|gz\\|Z\\|lzh\\|ar\\|lha\\)$"
74 "*Default actions to be taken when the user asks to view a file.
75 To change the behaviour, you can either edit this variable or set
76 `gnus-uu-user-view-rules' to something useful.
80 To make gnus-uu use 'xli' to display JPEG and GIF files, put the
81 following in your .emacs file:
83 (setq gnus-uu-user-view-rules '((\"jpg$\\\\|gif$\" \"xli\")))
85 Both these variables are lists of lists with two string elements. The
86 first string is a regular expression. If the file name matches this
87 regular expression, the command in the second string is executed with
88 the file as an argument.
90 If the command string contains \"%s\", the file name will be inserted
91 at that point in the command string. If there's no \"%s\" in the
92 command string, the file name will be appended to the command string
95 There are several user variables to tailor the behaviour of gnus-uu to
96 your needs. First we have `gnus-uu-user-view-rules', which is the
97 variable gnus-uu first consults when trying to decide how to view a
98 file. If this variable contains no matches, gnus-uu examines the
99 default rule variable provided in this package. If gnus-uu finds no
100 match here, it uses `gnus-uu-user-view-rules-end' to try to make a
102 :group 'gnus-extract-view
103 :type '(repeat (group regexp (string :tag "Command"))))
105 (defcustom gnus-uu-user-view-rules nil
106 "What actions are to be taken to view a file.
107 See the documentation on the `gnus-uu-default-view-rules' variable for
109 :group 'gnus-extract-view
110 :type '(repeat (group regexp (string :tag "Command"))))
112 (defcustom gnus-uu-user-view-rules-end
114 "*What actions are to be taken if no rule matched the file name.
115 See the documentation on the `gnus-uu-default-view-rules' variable for
117 :group 'gnus-extract-view
118 :type '(repeat (group regexp (string :tag "Command"))))
120 ;; Default unpacking commands
122 (defcustom gnus-uu-default-archive-rules
123 '(("\\.tar$" "tar xf")
124 ("\\.zip$" "unzip -o")
126 ("\\.arj$" "unarj x")
128 ("\\.\\(lzh\\|lha\\)$" "lha x")
129 ("\\.Z$" "uncompress")
131 ("\\.arc$" "arc -x"))
132 "*See `gnus-uu-user-archive-rules'."
133 :group 'gnus-extract-archive
134 :type '(repeat (group regexp (string :tag "Command"))))
136 (defvar gnus-uu-destructive-archivers
137 (list "uncompress" "gunzip"))
139 (defcustom gnus-uu-user-archive-rules nil
140 "A list that can be set to override the default archive unpacking commands.
141 To use, for instance, 'untar' to unpack tar files and 'zip -x' to
142 unpack zip files, say the following:
143 (setq gnus-uu-user-archive-rules
144 '((\"\\\\.tar$\" \"untar\")
145 (\"\\\\.zip$\" \"zip -x\")))"
146 :group 'gnus-extract-archive
147 :type '(repeat (group regexp (string :tag "Command"))))
149 (defcustom gnus-uu-ignore-files-by-name nil
150 "*A regular expression saying what files should not be viewed based on name.
151 If, for instance, you want gnus-uu to ignore all .au and .wav files,
152 you could say something like
154 (setq gnus-uu-ignore-files-by-name \"\\\\.au$\\\\|\\\\.wav$\")
156 Note that this variable can be used in conjunction with the
157 `gnus-uu-ignore-files-by-type' variable."
159 :type '(choice (const :tag "off" nil)
160 (regexp :format "%v")))
162 (defcustom gnus-uu-ignore-files-by-type nil
163 "*A regular expression saying what files that shouldn't be viewed, based on MIME file type.
164 If, for instance, you want gnus-uu to ignore all audio files and all mpegs,
165 you could say something like
167 (setq gnus-uu-ignore-files-by-type \"audio/\\\\|video/mpeg\")
169 Note that this variable can be used in conjunction with the
170 `gnus-uu-ignore-files-by-name' variable."
172 :type '(choice (const :tag "off" nil)
173 (regexp :format "%v")))
175 ;; Pseudo-MIME support
177 (defconst gnus-uu-ext-to-mime-list
178 '(("\\.gif$" "image/gif")
179 ("\\.jpe?g$" "image/jpeg")
180 ("\\.tiff?$" "image/tiff")
181 ("\\.xwd$" "image/xwd")
182 ("\\.pbm$" "image/pbm")
183 ("\\.pgm$" "image/pgm")
184 ("\\.ppm$" "image/ppm")
185 ("\\.xbm$" "image/xbm")
186 ("\\.pcx$" "image/pcx")
187 ("\\.tga$" "image/tga")
188 ("\\.ps$" "image/postscript")
189 ("\\.fli$" "video/fli")
190 ("\\.wav$" "audio/wav")
191 ("\\.aiff$" "audio/aiff")
192 ("\\.hcom$" "audio/hcom")
193 ("\\.voc$" "audio/voc")
194 ("\\.smp$" "audio/smp")
195 ("\\.mod$" "audio/mod")
196 ("\\.dvi$" "image/dvi")
197 ("\\.mpe?g$" "video/mpeg")
198 ("\\.au$" "audio/basic")
199 ("\\.\\(te?xt\\|doc\\|c\\|h\\)$" "text/plain")
200 ("\\.\\(c\\|h\\)$" "text/source")
201 ("read.*me" "text/plain")
202 ("\\.html$" "text/html")
203 ("\\.bat$" "text/bat")
204 ("\\.[1-6]$" "text/man")
205 ("\\.flc$" "video/flc")
206 ("\\.rle$" "video/rle")
207 ("\\.pfx$" "video/pfx")
208 ("\\.avi$" "video/avi")
209 ("\\.sme$" "video/sme")
210 ("\\.rpza$" "video/prza")
211 ("\\.dl$" "video/dl")
212 ("\\.qt$" "video/qt")
213 ("\\.rsrc$" "video/rsrc")
214 ("\\..*$" "unknown/unknown")))
216 ;; Various variables users may set
218 (defcustom gnus-uu-tmp-dir "/tmp/"
219 "*Variable saying where gnus-uu is to do its work.
220 Default is \"/tmp/\"."
224 (defcustom gnus-uu-do-not-unpack-archives nil
225 "*Non-nil means that gnus-uu won't peek inside archives looking for files to display.
227 :group 'gnus-extract-archive
230 (defcustom gnus-uu-ignore-default-view-rules nil
231 "*Non-nil means that gnus-uu will ignore the default viewing rules.
232 Only the user viewing rules will be consulted. Default is nil."
233 :group 'gnus-extract-view
236 (defcustom gnus-uu-grabbed-file-functions nil
237 "Functions run on each file after successful decoding.
238 They will be called with the name of the file as the argument.
239 Likely functions you can use in this list are `gnus-uu-grab-view'
240 and `gnus-uu-grab-move'."
242 :options '(gnus-uu-grab-view gnus-uu-grab-move)
245 (defcustom gnus-uu-ignore-default-archive-rules nil
246 "*Non-nil means that gnus-uu will ignore the default archive unpacking commands.
247 Only the user unpacking commands will be consulted. Default is nil."
248 :group 'gnus-extract-archive
251 (defcustom gnus-uu-kill-carriage-return t
252 "*Non-nil means that gnus-uu will strip all carriage returns from articles.
257 (defcustom gnus-uu-view-with-metamail nil
258 "*Non-nil means that files will be viewed with metamail.
259 The gnus-uu viewing functions will be ignored and gnus-uu will try
260 to guess at a content-type based on file name suffixes. Default
265 (defcustom gnus-uu-unmark-articles-not-decoded nil
266 "*Non-nil means that gnus-uu will mark articles that were unsuccessfully decoded as unread.
271 (defcustom gnus-uu-correct-stripped-uucode nil
272 "*Non-nil means that gnus-uu will *try* to fix uuencoded files that have had trailing spaces deleted.
277 (defcustom gnus-uu-save-in-digest nil
278 "*Non-nil means that gnus-uu, when asked to save without decoding, will save in digests.
279 If this variable is nil, gnus-uu will just save everything in a
280 file without any embellishments. The digesting almost conforms to RFC1153 -
281 no easy way to specify any meaningful volume and issue numbers were found,
282 so I simply dropped them."
286 (defcustom gnus-uu-pre-uudecode-hook nil
287 "Hook run before sending a message to uudecode."
291 (defcustom gnus-uu-digest-headers
292 '("^Date:" "^From:" "^To:" "^Cc:" "^Subject:" "^Message-ID:" "^Keywords:"
293 "^Summary:" "^References:" "^Content-Type:" "^Content-Transfer-Encoding:")
294 "*List of regexps to match headers included in digested messages.
295 The headers will be included in the sequence they are matched."
297 :type '(repeat regexp))
299 (defcustom gnus-uu-save-separate-articles nil
300 "*Non-nil means that gnus-uu will save articles in separate files."
304 (defcustom gnus-uu-be-dangerous 'ask
305 "*Specifies what to do if unusual situations arise during decoding.
306 If nil, be as conservative as possible. If t, ignore things that
307 didn't work, and overwrite existing files. Otherwise, ask each time."
309 :type '(choice (const :tag "conservative" nil)
310 (const :tag "ask" ask)
311 (const :tag "liberal" t)))
313 ;; Internal variables
315 (defvar gnus-uu-saved-article-name nil)
317 (defvar gnus-uu-begin-string "^begin[ \t]+[0-7][0-7][0-7][ \t]+\\(.*\\)$")
318 (defvar gnus-uu-end-string "^end[ \t]*$")
320 (defvar gnus-uu-body-line "^M")
322 (while (> (setq i (1- i)) 0)
323 (setq gnus-uu-body-line (concat gnus-uu-body-line "[^a-z]")))
324 (setq gnus-uu-body-line (concat gnus-uu-body-line ".?$")))
326 ;"^M.............................................................?$"
328 (defvar gnus-uu-shar-begin-string "^#! */bin/sh")
330 (defvar gnus-uu-shar-file-name nil)
331 (defvar gnus-uu-shar-name-marker "begin [0-7][0-7][0-7][ \t]+\\(\\(\\w\\|\\.\\)*\\b\\)")
333 (defvar gnus-uu-postscript-begin-string "^%!PS-")
334 (defvar gnus-uu-postscript-end-string "^%%EOF$")
336 (defvar gnus-uu-file-name nil)
337 (defvar gnus-uu-uudecode-process nil)
338 (defvar gnus-uu-binhex-article-name nil)
340 (defvar gnus-uu-work-dir nil)
342 (defvar gnus-uu-output-buffer-name " *Gnus UU Output*")
344 (defvar gnus-uu-default-dir gnus-article-save-directory)
345 (defvar gnus-uu-digest-from-subject nil)
349 (gnus-define-keys (gnus-uu-mark-map "P" gnus-summary-mark-map)
350 "p" gnus-summary-mark-as-processable
351 "u" gnus-summary-unmark-as-processable
352 "U" gnus-summary-unmark-all-processable
353 "v" gnus-uu-mark-over
354 "s" gnus-uu-mark-series
355 "r" gnus-uu-mark-region
356 "g" gnus-uu-unmark-region
357 "R" gnus-uu-mark-by-regexp
358 "G" gnus-uu-unmark-by-regexp
359 "t" gnus-uu-mark-thread
360 "T" gnus-uu-unmark-thread
362 "b" gnus-uu-mark-buffer
363 "S" gnus-uu-mark-sparse
364 "k" gnus-summary-kill-process-mark
365 "y" gnus-summary-yank-process-mark
366 "w" gnus-summary-save-process-mark
367 "i" gnus-uu-invert-processable)
369 (gnus-define-keys (gnus-uu-extract-map "X" gnus-summary-mode-map)
370 ;;"x" gnus-uu-extract-any
371 ;;"m" gnus-uu-extract-mime
372 "u" gnus-uu-decode-uu
373 "U" gnus-uu-decode-uu-and-save
374 "s" gnus-uu-decode-unshar
375 "S" gnus-uu-decode-unshar-and-save
376 "o" gnus-uu-decode-save
377 "O" gnus-uu-decode-save
378 "b" gnus-uu-decode-binhex
379 "B" gnus-uu-decode-binhex
380 "p" gnus-uu-decode-postscript
381 "P" gnus-uu-decode-postscript-and-save)
384 (gnus-uu-extract-view-map "v" gnus-uu-extract-map)
385 "u" gnus-uu-decode-uu-view
386 "U" gnus-uu-decode-uu-and-save-view
387 "s" gnus-uu-decode-unshar-view
388 "S" gnus-uu-decode-unshar-and-save-view
389 "o" gnus-uu-decode-save-view
390 "O" gnus-uu-decode-save-view
391 "b" gnus-uu-decode-binhex-view
392 "B" gnus-uu-decode-binhex-view
393 "p" gnus-uu-decode-postscript-view
394 "P" gnus-uu-decode-postscript-and-save-view)
399 (defun gnus-uu-decode-uu (&optional n)
400 "Uudecodes the current article."
402 (gnus-uu-decode-with-method 'gnus-uu-uustrip-article n))
404 (defun gnus-uu-decode-uu-and-save (n dir)
405 "Decodes and saves the resulting file."
407 (list current-prefix-arg
408 (file-name-as-directory
409 (read-file-name "Uudecode and save in dir: "
411 gnus-uu-default-dir t))))
412 (gnus-uu-decode-with-method 'gnus-uu-uustrip-article n dir nil nil t))
414 (defun gnus-uu-decode-unshar (&optional n)
415 "Unshars the current article."
417 (gnus-uu-decode-with-method 'gnus-uu-unshar-article n nil nil 'scan t))
419 (defun gnus-uu-decode-unshar-and-save (n dir)
420 "Unshars and saves the current article."
422 (list current-prefix-arg
423 (file-name-as-directory
424 (read-file-name "Unshar and save in dir: "
426 gnus-uu-default-dir t))))
427 (gnus-uu-decode-with-method 'gnus-uu-unshar-article n dir nil 'scan t))
429 (defun gnus-uu-decode-save (n file)
430 "Saves the current article."
432 (list current-prefix-arg
434 (if gnus-uu-save-separate-articles
435 "Save articles is dir: "
436 "Save articles in file: ")
438 gnus-uu-default-dir)))
439 (setq gnus-uu-saved-article-name file)
440 (gnus-uu-decode-with-method 'gnus-uu-save-article n nil t))
442 (defun gnus-uu-decode-binhex (n dir)
443 "Unbinhexes the current article."
445 (list current-prefix-arg
446 (file-name-as-directory
447 (read-file-name "Unbinhex and save in dir: "
449 gnus-uu-default-dir))))
450 (setq gnus-uu-binhex-article-name
451 (make-temp-name (concat gnus-uu-work-dir "binhex")))
452 (gnus-uu-decode-with-method 'gnus-uu-binhex-article n dir))
454 (defun gnus-uu-decode-uu-view (&optional n)
455 "Uudecodes and views the current article."
457 (let ((gnus-view-pseudos (or gnus-view-pseudos 'automatic)))
458 (gnus-uu-decode-uu n)))
460 (defun gnus-uu-decode-uu-and-save-view (n dir)
461 "Decodes, views and saves the resulting file."
463 (list current-prefix-arg
464 (read-file-name "Uudecode, view and save in dir: "
466 gnus-uu-default-dir t)))
467 (let ((gnus-view-pseudos (or gnus-view-pseudos 'automatic)))
468 (gnus-uu-decode-uu-and-save n dir)))
470 (defun gnus-uu-decode-unshar-view (&optional n)
471 "Unshars and views the current article."
473 (let ((gnus-view-pseudos (or gnus-view-pseudos 'automatic)))
474 (gnus-uu-decode-unshar n)))
476 (defun gnus-uu-decode-unshar-and-save-view (n dir)
477 "Unshars and saves the current article."
479 (list current-prefix-arg
480 (read-file-name "Unshar, view and save in dir: "
482 gnus-uu-default-dir t)))
483 (let ((gnus-view-pseudos (or gnus-view-pseudos 'automatic)))
484 (gnus-uu-decode-unshar-and-save n dir)))
486 (defun gnus-uu-decode-save-view (n file)
487 "Saves and views the current article."
489 (list current-prefix-arg
490 (read-file-name (if gnus-uu-save-separate-articles
491 "Save articles is dir: "
492 "Save articles in file: ")
493 gnus-uu-default-dir gnus-uu-default-dir)))
494 (let ((gnus-view-pseudos (or gnus-view-pseudos 'automatic)))
495 (gnus-uu-decode-save n file)))
497 (defun gnus-uu-decode-binhex-view (n file)
498 "Unbinhexes and views the current article."
500 (list current-prefix-arg
501 (read-file-name "Unbinhex, view and save in dir: "
502 gnus-uu-default-dir gnus-uu-default-dir)))
503 (setq gnus-uu-binhex-article-name
504 (make-temp-name (concat gnus-uu-work-dir "binhex")))
505 (let ((gnus-view-pseudos (or gnus-view-pseudos 'automatic)))
506 (gnus-uu-decode-binhex n file)))
509 ;; Digest and forward articles
511 (defun gnus-uu-digest-mail-forward (&optional n post)
512 "Digests and forwards all articles in this series."
514 (let ((gnus-uu-save-in-digest t)
515 (file (make-temp-name (nnheader-concat gnus-uu-tmp-dir "forward")))
516 buf subject from newsgroups)
517 (gnus-setup-message 'forward
518 (setq gnus-uu-digest-from-subject nil)
519 (gnus-uu-decode-save n file)
520 (setq buf (switch-to-buffer (get-buffer-create " *gnus-uu-forward*")))
521 (gnus-add-current-to-buffer-list)
524 (let ((fs gnus-uu-digest-from-subject))
527 subject (gnus-simplify-subject-fuzzy (cdar fs))
529 (while (and fs (or from subject))
531 (unless (string= from (caar fs))
534 (unless (string= (gnus-simplify-subject-fuzzy (cdar fs))
539 (setq subject "Digested Articles"))
542 (if (gnus-news-group-p gnus-newsgroup-name)
545 (goto-char (point-min))
546 (when (re-search-forward "^Subject: ")
547 (delete-region (point) (gnus-point-at-eol))
549 (goto-char (point-min))
550 (when (re-search-forward "^From: ")
551 (delete-region (point) (gnus-point-at-eol))
553 (message-forward post))
556 (setq gnus-uu-digest-from-subject nil)))
558 (defun gnus-uu-digest-post-forward (&optional n)
559 "Digest and forward to a newsgroup."
561 (gnus-uu-digest-mail-forward n t))
565 (defun gnus-uu-mark-by-regexp (regexp &optional unmark)
566 "Ask for a regular expression and set the process mark on all articles that match."
567 (interactive (list (read-from-minibuffer "Mark (regexp): ")))
568 (let ((articles (gnus-uu-find-articles-matching regexp)))
571 (gnus-summary-remove-process-mark (pop articles))
572 (gnus-summary-set-process-mark (pop articles))))
574 (gnus-summary-position-point))
576 (defun gnus-uu-unmark-by-regexp (regexp &optional unmark)
577 "Ask for a regular expression and remove the process mark on all articles that match."
578 (interactive (list (read-from-minibuffer "Mark (regexp): ")))
579 (gnus-uu-mark-by-regexp regexp t))
581 (defun gnus-uu-mark-series ()
582 "Mark the current series with the process mark."
584 (let ((articles (gnus-uu-find-articles-matching)))
586 (gnus-summary-set-process-mark (car articles))
587 (setq articles (cdr articles)))
589 (gnus-summary-position-point))
591 (defun gnus-uu-mark-region (beg end &optional unmark)
592 "Set the process mark on all articles between point and mark."
596 (while (< (point) end)
598 (gnus-summary-remove-process-mark (gnus-summary-article-number))
599 (gnus-summary-set-process-mark (gnus-summary-article-number)))
601 (gnus-summary-position-point))
603 (defun gnus-uu-unmark-region (beg end)
604 "Remove the process mark from all articles between point and mark."
606 (gnus-uu-mark-region beg end t))
608 (defun gnus-uu-mark-buffer ()
609 "Set the process mark on all articles in the buffer."
611 (gnus-uu-mark-region (point-min) (point-max)))
613 (defun gnus-uu-unmark-buffer ()
614 "Remove the process mark on all articles in the buffer."
616 (gnus-uu-mark-region (point-min) (point-max) t))
618 (defun gnus-uu-mark-thread ()
619 "Marks all articles downwards in this thread."
621 (let ((level (gnus-summary-thread-level)))
622 (while (and (gnus-summary-set-process-mark (gnus-summary-article-number))
623 (zerop (gnus-summary-next-subject 1))
624 (> (gnus-summary-thread-level) level))))
625 (gnus-summary-position-point))
627 (defun gnus-uu-unmark-thread ()
628 "Unmarks all articles downwards in this thread."
630 (let ((level (gnus-summary-thread-level)))
631 (while (and (gnus-summary-remove-process-mark
632 (gnus-summary-article-number))
633 (zerop (gnus-summary-next-subject 1))
634 (> (gnus-summary-thread-level) level))))
635 (gnus-summary-position-point))
637 (defun gnus-uu-invert-processable ()
638 "Invert the list of process-marked articles."
640 (let ((data gnus-newsgroup-data)
644 (if (memq (setq number (gnus-data-number (pop data)))
645 gnus-newsgroup-processable)
646 (gnus-summary-remove-process-mark number)
647 (gnus-summary-set-process-mark number)))))
648 (gnus-summary-position-point))
650 (defun gnus-uu-mark-over (&optional score)
651 "Mark all articles with a score over SCORE (the prefix)."
653 (let ((score (gnus-score-default score))
654 (data gnus-newsgroup-data))
657 (when (> (or (cdr (assq (gnus-data-number (car data))
658 gnus-newsgroup-scored))
659 gnus-summary-default-score 0)
661 (gnus-summary-set-process-mark (caar data)))
662 (setq data (cdr data))))
663 (gnus-summary-position-point)))
665 (defun gnus-uu-mark-sparse ()
666 "Mark all series that have some articles marked."
668 (let ((marked (nreverse gnus-newsgroup-processable))
669 subject articles total headers)
671 (error "No articles marked with the process mark"))
672 (setq gnus-newsgroup-processable nil)
675 (and (vectorp (setq headers
676 (gnus-summary-article-header (car marked))))
677 (setq subject (mail-header-subject headers)
678 articles (gnus-uu-find-articles-matching
679 (gnus-uu-reginize-string subject))
680 total (nconc total articles)))
682 (gnus-summary-set-process-mark (car articles))
683 (setcdr marked (delq (car articles) (cdr marked)))
684 (setq articles (cdr articles)))
685 (setq marked (cdr marked)))
686 (setq gnus-newsgroup-processable (nreverse total)))
687 (gnus-summary-position-point)))
689 (defun gnus-uu-mark-all ()
690 "Mark all articles in \"series\" order."
692 (setq gnus-newsgroup-processable nil)
694 (let ((data gnus-newsgroup-data)
697 (when (and (not (memq (setq number (gnus-data-number (car data)))
698 gnus-newsgroup-processable))
699 (vectorp (gnus-data-header (car data))))
700 (gnus-summary-goto-subject number)
701 (gnus-uu-mark-series))
702 (setq data (cdr data)))))
703 (gnus-summary-position-point))
705 ;; All PostScript functions written by Erik Selberg <speed@cs.washington.edu>.
707 (defun gnus-uu-decode-postscript (&optional n)
708 "Gets postscript of the current article."
710 (gnus-uu-decode-with-method 'gnus-uu-decode-postscript-article n))
712 (defun gnus-uu-decode-postscript-view (&optional n)
713 "Gets and views the current article."
715 (let ((gnus-view-pseudos (or gnus-view-pseudos 'automatic)))
716 (gnus-uu-decode-postscript n)))
718 (defun gnus-uu-decode-postscript-and-save (n dir)
719 "Extracts postscript and saves the current article."
721 (list current-prefix-arg
722 (file-name-as-directory
723 (read-file-name "Save in dir: "
725 gnus-uu-default-dir t))))
726 (gnus-uu-decode-with-method 'gnus-uu-decode-postscript-article
729 (defun gnus-uu-decode-postscript-and-save-view (n dir)
730 "Decodes, views and saves the resulting file."
732 (list current-prefix-arg
733 (read-file-name "Where do you want to save the file(s)? "
735 gnus-uu-default-dir t)))
736 (let ((gnus-view-pseudos (or gnus-view-pseudos 'automatic)))
737 (gnus-uu-decode-postscript-and-save n dir)))
740 ;; Internal functions.
742 (defun gnus-uu-decode-with-method (method n &optional save not-insert
744 (gnus-uu-initialize scan)
746 (setq gnus-uu-default-dir save))
747 ;; Create the directory we save to.
748 (when (and scan cdir save
749 (not (file-exists-p save)))
750 (make-directory save t))
751 (let ((articles (gnus-uu-get-list-of-articles n))
753 (setq files (gnus-uu-grab-articles articles method t))
754 (let ((gnus-current-article (car articles)))
756 (setq files (gnus-uu-scan-directory gnus-uu-work-dir))))
758 (gnus-uu-save-files files save))
759 (when (eq gnus-uu-do-not-unpack-archives nil)
760 (setq files (gnus-uu-unpack-files files)))
761 (setq files (nreverse (gnus-uu-get-actions files)))
762 (or not-insert (not gnus-insert-pseudo-articles)
763 (gnus-summary-insert-pseudos files save))))
765 (defun gnus-uu-scan-directory (dir &optional rec)
766 "Return a list of all files under DIR."
767 (let ((files (directory-files dir t))
769 (while (setq file (pop files))
770 (unless (member (file-name-nondirectory file) '("." ".."))
771 (push (list (cons 'name file)
772 (cons 'article gnus-current-article))
774 (when (file-directory-p file)
775 (setq out (nconc (gnus-uu-scan-directory file t) out)))))
780 (defun gnus-uu-save-files (files dir)
782 (let ((len (length files))
783 (reg (concat "^" (regexp-quote gnus-uu-work-dir)))
784 to-file file fromdir)
785 (while (setq file (cdr (assq 'name (pop files))))
786 (when (file-exists-p file)
787 (string-match reg file)
788 (setq fromdir (substring file (match-end 0)))
789 (if (file-directory-p file)
790 (gnus-make-directory (concat dir fromdir))
791 (setq to-file (concat dir fromdir))
792 (when (or (not (file-exists-p to-file))
793 (eq gnus-uu-be-dangerous t)
794 (and gnus-uu-be-dangerous
795 (gnus-y-or-n-p (format "%s exists; overwrite? "
797 (copy-file file to-file t t)))))
798 (gnus-message 5 "Saved %d file%s" len (if (= len 1) "" "s"))))
800 ;; Functions for saving and possibly digesting articles without
803 ;; Function called by gnus-uu-grab-articles to treat each article.
804 (defun gnus-uu-save-article (buffer in-state)
806 (gnus-uu-save-separate-articles
810 (concat gnus-uu-saved-article-name gnus-current-article))
811 (cond ((eq in-state 'first) (list gnus-uu-saved-article-name 'begin))
812 ((eq in-state 'first-and-last) (list gnus-uu-saved-article-name
814 ((eq in-state 'last) (list 'end))
815 (t (list 'middle)))))
816 ((not gnus-uu-save-in-digest)
819 (write-region (point-min) (point-max) gnus-uu-saved-article-name t)
820 (cond ((eq in-state 'first) (list gnus-uu-saved-article-name 'begin))
821 ((eq in-state 'first-and-last) (list gnus-uu-saved-article-name
823 ((eq in-state 'last) (list 'end))
824 (t (list 'middle)))))
826 (let ((header (gnus-summary-article-header)))
827 (push (cons (mail-header-from header)
828 (mail-header-subject header))
829 gnus-uu-digest-from-subject))
830 (let ((name (file-name-nondirectory gnus-uu-saved-article-name))
831 (delim (concat "^" (make-string 30 ?-) "$"))
832 beg subj headers headline sorthead body end-string state)
833 (if (or (eq in-state 'first)
834 (eq in-state 'first-and-last))
836 (setq state (list 'begin))
837 (save-excursion (set-buffer (get-buffer-create "*gnus-uu-body*"))
840 (set-buffer (get-buffer-create "*gnus-uu-pre*"))
843 "Date: %s\nFrom: %s\nSubject: %s Digest\n\nTopics:\n"
844 (current-time-string) name name))))
845 (when (not (eq in-state 'end))
846 (setq state (list 'middle))))
848 (set-buffer "*gnus-uu-body*")
849 (goto-char (setq beg (point-max)))
853 (let (buffer-read-only)
854 (gnus-set-text-properties (point-min) (point-max) nil)
855 ;; These two are necessary for XEmacs 19.12 fascism.
856 (put-text-property (point-min) (point-max) 'invisible nil)
857 (put-text-property (point-min) (point-max) 'intangible nil))
858 (goto-char (point-min))
859 (re-search-forward "\n\n")
860 ;; Quote all 30-dash lines.
862 (while (re-search-forward "^-" nil t)
866 (setq body (buffer-substring (1- (point)) (point-max)))
867 (narrow-to-region (point-min) (point))
868 (if (not (setq headers gnus-uu-digest-headers))
869 (setq sorthead (buffer-substring (point-min) (point-max)))
871 (setq headline (car headers))
872 (setq headers (cdr headers))
873 (goto-char (point-min))
874 (while (re-search-forward headline nil t)
879 (or (and (re-search-forward "^[^ \t]" nil t)
881 (progn (forward-line 1) (point)))))))))
883 (insert sorthead) (goto-char (point-max))
884 (insert body) (goto-char (point-max))
885 (insert (concat "\n" (make-string 30 ?-) "\n\n"))
887 (when (re-search-forward "^Subject: \\(.*\\)$" nil t)
888 (setq subj (buffer-substring (match-beginning 1) (match-end 1)))
890 (set-buffer "*gnus-uu-pre*")
891 (insert (format " %s\n" subj)))))
892 (when (or (eq in-state 'last)
893 (eq in-state 'first-and-last))
895 (set-buffer "*gnus-uu-pre*")
896 (insert (format "\n\n%s\n\n" (make-string 70 ?-)))
897 (gnus-write-buffer gnus-uu-saved-article-name))
899 (set-buffer "*gnus-uu-body*")
900 (goto-char (point-max))
902 (concat (setq end-string (format "End of %s Digest" name))
904 (insert (concat (make-string (length end-string) ?*) "\n"))
906 (point-min) (point-max) gnus-uu-saved-article-name t))
907 (gnus-kill-buffer "*gnus-uu-pre*")
908 (gnus-kill-buffer "*gnus-uu-body*")
910 (if (memq 'begin state)
911 (cons gnus-uu-saved-article-name state)
914 ;; Binhex treatment - not very advanced.
916 (defvar gnus-uu-binhex-body-line
917 "^[^:]...............................................................$")
918 (defvar gnus-uu-binhex-begin-line
919 "^:...............................................................$")
920 (defvar gnus-uu-binhex-end-line
923 (defun gnus-uu-binhex-article (buffer in-state)
924 (let (state start-char)
928 (goto-char (point-min))
929 (when (not (re-search-forward gnus-uu-binhex-begin-line nil t))
930 (when (not (re-search-forward gnus-uu-binhex-body-line nil t))
931 (setq state (list 'wrong-type))))
933 (if (memq 'wrong-type state)
936 (setq start-char (point))
937 (if (looking-at gnus-uu-binhex-begin-line)
939 (setq state (list 'begin))
940 (write-region 1 1 gnus-uu-binhex-article-name))
941 (setq state (list 'middle)))
942 (goto-char (point-max))
943 (re-search-backward (concat gnus-uu-binhex-body-line "\\|"
944 gnus-uu-binhex-end-line)
946 (when (looking-at gnus-uu-binhex-end-line)
947 (setq state (if (memq 'begin state)
952 (when (file-exists-p gnus-uu-binhex-article-name)
953 (append-to-file start-char (point) gnus-uu-binhex-article-name))))
954 (if (memq 'begin state)
955 (cons gnus-uu-binhex-article-name state)
960 (defun gnus-uu-decode-postscript-article (process-buffer in-state)
961 (let ((state (list 'ok))
962 start-char end-char file-name)
964 (set-buffer process-buffer)
965 (goto-char (point-min))
966 (if (not (re-search-forward gnus-uu-postscript-begin-string nil t))
967 (setq state (list 'wrong-type))
969 (setq start-char (point))
970 (if (not (re-search-forward gnus-uu-postscript-end-string nil t))
971 (setq state (list 'wrong-type))
972 (setq end-char (point))
973 (set-buffer (get-buffer-create gnus-uu-output-buffer-name))
974 (insert-buffer-substring process-buffer start-char end-char)
975 (setq file-name (concat gnus-uu-work-dir
976 (cdr gnus-article-current) ".ps"))
977 (write-region (point-min) (point-max) file-name)
978 (setq state (list file-name 'begin 'end)))))
984 (defun gnus-uu-get-actions (files)
988 (setq name (cdr (assq 'name (car files))))
990 (setq action (gnus-uu-get-action name))
991 (setcar files (nconc (list (if (string= action "gnus-uu-archive")
992 (cons 'action "file")
993 (cons 'action action))
994 (cons 'execute (gnus-uu-command
997 (setq files (cdr files)))
1000 (defun gnus-uu-get-action (file-name)
1003 (gnus-uu-choose-action
1006 gnus-uu-user-view-rules
1007 (if gnus-uu-ignore-default-view-rules
1009 gnus-uu-default-view-rules)
1010 gnus-uu-user-view-rules-end)))
1011 (when (and (not (string= (or action "") "gnus-uu-archive"))
1012 gnus-uu-view-with-metamail)
1014 (gnus-uu-choose-action file-name gnus-uu-ext-to-mime-list))
1015 (setq action (format "metamail -d -b -c \"%s\"" action))))
1019 ;; Functions for treating subjects and collecting series.
1021 (defun gnus-uu-reginize-string (string)
1022 ;; Takes a string and puts a \ in front of every special character;
1023 ;; ignores any leading "version numbers" thingies that they use in
1024 ;; the comp.binaries groups, and either replaces anything that looks
1025 ;; like "2/3" with "[0-9]+/[0-9]+" or, if it can't find something
1026 ;; like that, replaces the last two numbers with "[0-9]+". This, in
1027 ;; my experience, should get most postings of a series.
1029 (vernum "v[0-9]+[a-z][0-9]+:")
1032 (set-buffer (get-buffer-create gnus-uu-output-buffer-name))
1033 (buffer-disable-undo (current-buffer))
1035 (insert (regexp-quote string))
1038 (setq case-fold-search nil)
1039 (goto-char (point-min))
1040 (when (looking-at vernum)
1041 (replace-match vernum t t)
1042 (setq beg (length vernum)))
1045 (if (re-search-forward "[ \t]*[0-9]+/[0-9]+" nil t)
1046 (replace-match " [0-9]+/[0-9]+")
1049 (if (re-search-forward "[0-9]+[ \t]*of[ \t]*[0-9]+" nil t)
1050 (replace-match "[0-9]+ of [0-9]+")
1053 (if (re-search-backward "\\([^0-9]\\)[0-9]+\\([^0-9]+\\)[0-9]+"
1055 (replace-match "\\1[0-9]+\\2[0-9]+" t nil nil nil))))
1058 (while (re-search-forward "[ \t]+" nil t)
1059 (replace-match "[ \t]*" t t))
1061 (buffer-substring 1 (point-max)))))
1063 (defun gnus-uu-get-list-of-articles (n)
1064 ;; If N is non-nil, the article numbers of the N next articles
1065 ;; will be returned.
1066 ;; If any articles have been marked as processable, they will be
1068 ;; Failing that, articles that have subjects that are part of the
1069 ;; same "series" as the current will be returned.
1073 (setq n (prefix-numeric-value n))
1074 (let ((backward (< n 0))
1078 (push (gnus-summary-article-number)
1080 (gnus-summary-search-forward nil nil backward))
1082 (nreverse articles)))
1083 (gnus-newsgroup-processable
1084 (reverse gnus-newsgroup-processable))
1086 (gnus-uu-find-articles-matching)))))
1088 (defun gnus-uu-string< (l1 l2)
1089 (string< (car l1) (car l2)))
1091 (defun gnus-uu-find-articles-matching
1092 (&optional subject only-unread do-not-translate)
1093 ;; Finds all articles that matches the regexp SUBJECT. If it is
1094 ;; nil, the current article name will be used. If ONLY-UNREAD is
1095 ;; non-nil, only unread articles are chosen. If DO-NOT-TRANSLATE is
1096 ;; non-nil, article names are not equalized before sorting.
1097 (let ((subject (or subject
1098 (gnus-uu-reginize-string (gnus-summary-article-subject))))
1103 ;; Collect all subjects matching subject.
1104 (let ((case-fold-search t)
1105 (data gnus-newsgroup-data)
1109 (and (not (gnus-data-pseudo-p d))
1110 (or (not only-unread)
1111 (= (setq mark (gnus-data-mark d))
1113 (= mark gnus-ticked-mark)
1114 (= mark gnus-dormant-mark))
1115 (setq subj (mail-header-subject (gnus-data-header d)))
1116 (string-match subject subj)
1117 (push (cons subj (gnus-data-number d))
1118 list-of-subjects))))
1120 ;; Expand numbers, sort, and return the list of article
1122 (mapcar (lambda (sub) (cdr sub))
1123 (sort (gnus-uu-expand-numbers
1125 (not do-not-translate))
1126 'gnus-uu-string<))))))
1128 (defun gnus-uu-expand-numbers (string-list &optional translate)
1129 ;; Takes a list of strings and "expands" all numbers in all the
1130 ;; strings. That is, this function makes all numbers equal length by
1131 ;; prepending lots of zeroes before each number. This is to ease later
1132 ;; sorting to find out what sequence the articles are supposed to be
1133 ;; decoded in. Returns the list of expanded strings.
1134 (let ((out-list string-list)
1137 (set-buffer (get-buffer-create gnus-uu-output-buffer-name))
1138 (buffer-disable-undo (current-buffer))
1141 (insert (caar string-list))
1142 ;; Translate multiple spaces to one space.
1143 (goto-char (point-min))
1144 (while (re-search-forward "[ \t]+" nil t)
1145 (replace-match " "))
1146 ;; Translate all characters to "a".
1147 (goto-char (point-min))
1149 (while (re-search-forward "[A-Za-z]" nil t)
1150 (replace-match "a" t t)))
1152 (goto-char (point-min))
1153 (while (re-search-forward "[0-9]+" nil t)
1156 (string-to-int (buffer-substring
1157 (match-beginning 0) (match-end 0))))))
1158 (setq string (buffer-substring 1 (point-max)))
1159 (setcar (car string-list) string)
1160 (setq string-list (cdr string-list))))
1164 ;; `gnus-uu-grab-articles' is the general multi-article treatment
1165 ;; function. It takes a list of articles to be grabbed and a function
1166 ;; to apply to each article.
1168 ;; The function to be called should take two parameters. The first
1169 ;; parameter is the article buffer. The function should leave the
1170 ;; result, if any, in this buffer. Most treatment functions will just
1171 ;; generate files...
1173 ;; The second parameter is the state of the list of articles, and can
1174 ;; have four values: `first', `middle', `last' and `first-and-last'.
1176 ;; The function should return a list. The list may contain the
1177 ;; following symbols:
1178 ;; `error' if an error occurred
1179 ;; `begin' if the beginning of an encoded file has been received
1180 ;; If the list returned contains a `begin', the first element of
1181 ;; the list *must* be a string with the file name of the decoded
1183 ;; `end' if the end of an encoded file has been received
1184 ;; `middle' if the article was a body part of an encoded file
1185 ;; `wrong-type' if the article was not a part of an encoded file
1186 ;; `ok', which can be used everything is ok
1188 (defvar gnus-uu-has-been-grabbed nil)
1190 (defun gnus-uu-unmark-list-of-grabbed (&optional dont-unmark-last-article)
1192 (if (not (and gnus-uu-has-been-grabbed
1193 gnus-uu-unmark-articles-not-decoded))
1195 (when dont-unmark-last-article
1196 (setq art (car gnus-uu-has-been-grabbed))
1197 (setq gnus-uu-has-been-grabbed (cdr gnus-uu-has-been-grabbed)))
1198 (while gnus-uu-has-been-grabbed
1199 (gnus-summary-tick-article (car gnus-uu-has-been-grabbed) t)
1200 (setq gnus-uu-has-been-grabbed (cdr gnus-uu-has-been-grabbed)))
1201 (when dont-unmark-last-article
1202 (setq gnus-uu-has-been-grabbed (list art))))))
1204 ;; This function takes a list of articles and a function to apply to
1205 ;; each article grabbed.
1207 ;; This function returns a list of files decoded if the grabbing and
1208 ;; the process-function has been successful and nil otherwise.
1209 (defun gnus-uu-grab-articles (articles process-function
1210 &optional sloppy limit no-errors)
1211 (let ((state 'first)
1212 (gnus-asynchronous nil)
1213 has-been-begin article result-file result-files process-state
1214 gnus-summary-display-article-function
1215 gnus-article-display-hook gnus-article-prepare-hook
1216 article-series files)
1218 (while (and articles
1219 (not (memq 'error process-state))
1221 (not (memq 'end process-state))))
1223 (setq article (pop articles))
1224 (push article article-series)
1227 (if (eq state 'first)
1228 (setq state 'first-and-last)
1229 (setq state 'last)))
1231 (let ((part (gnus-uu-part-number article)))
1232 (gnus-message 6 "Getting article %d%s..."
1233 article (if (string= part "") "" (concat ", " part))))
1234 (gnus-summary-display-article article)
1236 ;; Push the article to the processing function.
1238 (set-buffer gnus-original-article-buffer)
1239 (let ((buffer-read-only nil))
1241 (set-buffer gnus-summary-buffer)
1243 (funcall process-function
1244 gnus-original-article-buffer state)))))
1246 (gnus-summary-remove-process-mark article)
1248 ;; If this is the beginning of a decoded file, we push it
1250 (when (or (memq 'begin process-state)
1251 (and (or (eq state 'first)
1252 (eq state 'first-and-last))
1253 (memq 'ok process-state)))
1254 (when has-been-begin
1255 ;; If there is a `result-file' here, that means that the
1256 ;; file was unsuccessfully decoded, so we delete it.
1257 (when (and result-file
1258 (file-exists-p result-file)
1259 (not gnus-uu-be-dangerous)
1260 (or (eq gnus-uu-be-dangerous t)
1262 (format "Delete unsuccessfully decoded file %s"
1264 (delete-file result-file)))
1265 (when (memq 'begin process-state)
1266 (setq result-file (car process-state)))
1267 (setq has-been-begin t))
1269 ;; Check whether we have decoded one complete file.
1270 (when (memq 'end process-state)
1271 (setq article-series nil)
1272 (setq has-been-begin nil)
1273 (if (stringp result-file)
1274 (setq files (list result-file))
1275 (setq files result-file))
1276 (setq result-file (car files))
1278 (push (list (cons 'name (pop files))
1279 (cons 'article article))
1281 ;; Allow user-defined functions to be run on this file.
1282 (when gnus-uu-grabbed-file-functions
1283 (let ((funcs gnus-uu-grabbed-file-functions))
1284 (unless (listp funcs)
1285 (setq funcs (list funcs)))
1287 (funcall (pop funcs) result-file))))
1288 (setq result-file nil)
1289 ;; Check whether we have decoded enough articles.
1290 (and limit (= (length result-files) limit)
1291 (setq articles nil)))
1293 ;; If this is the last article to be decoded, and
1294 ;; we still haven't reached the end, then we delete
1295 ;; the partially decoded file.
1296 (and (or (eq state 'last) (eq state 'first-and-last))
1297 (not (memq 'end process-state))
1299 (file-exists-p result-file)
1300 (not gnus-uu-be-dangerous)
1301 (or (eq gnus-uu-be-dangerous t)
1302 (gnus-y-or-n-p (format "Delete incomplete file %s? " result-file)))
1303 (delete-file result-file))
1305 ;; If this was a file of the wrong sort, then
1306 (when (and (or (memq 'wrong-type process-state)
1307 (memq 'error process-state))
1308 gnus-uu-unmark-articles-not-decoded)
1309 (gnus-summary-tick-article article t))
1311 ;; Set the new series state.
1312 (if (and (not has-been-begin)
1314 (or (memq 'end process-state)
1315 (memq 'middle process-state)))
1317 (setq process-state (list 'error))
1318 (gnus-message 2 "No begin part at the beginning")
1320 (setq state 'middle)))
1322 ;; When there are no result-files, then something must be wrong.
1326 ((not has-been-begin)
1327 (gnus-message 2 "Wrong type file"))
1328 ((memq 'error process-state)
1329 (gnus-message 2 "An error occurred during decoding"))
1330 ((not (or (memq 'ok process-state)
1331 (memq 'end process-state)))
1332 (gnus-message 2 "End of articles reached before end of file")))
1333 ;; Make unsuccessfully decoded articles unread.
1334 (when gnus-uu-unmark-articles-not-decoded
1335 (while article-series
1336 (gnus-summary-tick-article (pop article-series) t))))
1340 (defun gnus-uu-grab-view (file)
1341 "View FILE using the gnus-uu methods."
1342 (let ((action (gnus-uu-get-action file)))
1343 (gnus-execute-command
1344 (if (string-match "%" action)
1345 (format action file)
1346 (concat action " " file))
1347 (eq gnus-view-pseudos 'not-confirm))))
1349 (defun gnus-uu-grab-move (file)
1350 "Move FILE to somewhere."
1351 (when gnus-uu-default-dir
1352 (let ((to-file (concat (file-name-as-directory gnus-uu-default-dir)
1353 (file-name-nondirectory file))))
1354 (rename-file file to-file)
1355 (unless (file-exists-p file)
1356 (make-symbolic-link to-file file)))))
1358 (defun gnus-uu-part-number (article)
1359 (let* ((header (gnus-summary-article-header article))
1360 (subject (and header (mail-header-subject header))))
1362 (string-match "[0-9]+ */[0-9]+\\|[0-9]+ * of *[0-9]+" subject))
1363 (match-string 0 subject)
1366 (defun gnus-uu-uudecode-sentinel (process event)
1367 (delete-process (get-process process)))
1369 (defun gnus-uu-uustrip-article (process-buffer in-state)
1370 ;; Uudecodes a file asynchronously.
1372 (set-buffer process-buffer)
1373 (let ((state (list 'wrong-type))
1374 process-connection-type case-fold-search buffer-read-only
1376 (goto-char (point-min))
1378 ;; Deal with ^M at the end of the lines.
1379 (when gnus-uu-kill-carriage-return
1381 (while (search-forward "\r" nil t)
1382 (delete-backward-char 1))))
1384 (while (or (re-search-forward gnus-uu-begin-string nil t)
1385 (re-search-forward gnus-uu-body-line nil t))
1386 (setq state (list 'ok))
1387 ;; Ok, we are at the first uucoded line.
1389 (setq start-char (point))
1391 (if (not (looking-at gnus-uu-begin-string))
1392 (setq state (list 'middle))
1393 ;; This is the beginning of a uuencoded article.
1394 ;; We replace certain characters that could make things messy.
1395 (setq gnus-uu-file-name
1396 (let ((nnheader-file-name-translation-alist
1397 '((?/ . ?,) (? . ?_) (?* . ?_) (?$ . ?_))))
1398 (nnheader-translate-file-chars (match-string 1))))
1399 (replace-match (concat "begin 644 " gnus-uu-file-name) t t)
1401 ;; Remove any non gnus-uu-body-line right after start.
1403 (while (and (not (eobp))
1404 (not (looking-at gnus-uu-body-line)))
1407 ;; If a process is running, we kill it.
1408 (when (and gnus-uu-uudecode-process
1409 (memq (process-status gnus-uu-uudecode-process)
1411 (delete-process gnus-uu-uudecode-process)
1412 (gnus-uu-unmark-list-of-grabbed t))
1414 ;; Start a new uudecoding process.
1415 (let ((cdir default-directory))
1418 (cd gnus-uu-work-dir)
1419 (setq gnus-uu-uudecode-process
1422 (get-buffer-create gnus-uu-output-buffer-name)
1423 shell-file-name shell-command-switch
1424 (format "cd %s %s uudecode" gnus-uu-work-dir
1425 gnus-shell-command-separator))))
1427 (set-process-sentinel
1428 gnus-uu-uudecode-process 'gnus-uu-uudecode-sentinel)
1429 (setq state (list 'begin))
1430 (push (concat gnus-uu-work-dir gnus-uu-file-name) files))
1432 ;; We look for the end of the thing to be decoded.
1433 (if (re-search-forward gnus-uu-end-string nil t)
1435 (goto-char (point-max))
1436 (re-search-backward gnus-uu-body-line nil t))