1 ;;; gnus-uu.el --- extract, view or save (uu)encoded files from gnus
2 ;; Copyright (C) 1985, 1986, 1987, 1993, 1994 Free Software Foundation, Inc.
4 ;; Author: Lars Ingebrigtsen <larsi@ifi.uio.no>
7 ;; Last Modified: 1994/05/03
10 ;; This file is part of GNU Emacs.
12 ;; GNU Emacs is free software; you can redistribute it and/or modify
13 ;; it under the terms of the GNU General Public License as published by
14 ;; the Free Software Foundation; either version 2, or (at your option)
17 ;; GNU Emacs is distributed in the hope that it will be useful,
18 ;; but WITHOUT ANY WARRANTY; without even the implied warranty of
19 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
20 ;; GNU General Public License for more details.
22 ;; You should have received a copy of the GNU General Public License
23 ;; along with GNU Emacs; see the file COPYING. If not, write to
24 ;; the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA.
28 ;; All gnus-uu commands start with `C-c C-v'.
30 ;; Short user manual for this package:
32 ;; Type `C-c C-v C-v' to decode and view all articles of the current
33 ;; series. The defaults should be reasonable for most systems.
35 ;; Type `C-c C-v C-i' to toggle interactive mode. When using
36 ;; interactive mode, gnus-uu will which display a buffer that will let
37 ;; you see the suggested commands to be executed.
39 ;; To post an uuencoded file, type `C-c C-v p', which will enter you
40 ;; into a buffer analogous to the one you will get when typing `a'. Do
41 ;; an `M-x describe-mode' in this buffer to get a description of what
42 ;; this buffer lets you do.
44 ;; Read the documentation of the `gnus-uu' dummy function for a more
45 ;; complete description of what this package does and how you can
46 ;; customize it to fit your needs.
52 ;; v1.0: First version released Oct 2 1992.
54 ;; v1.1: Changed `C-c C-r' to `C-c C-e' and `C-c C-p' to `C-c C-k'.
55 ;; Changed (setq gnus-exit-group-hook) to (add-hook). Removed
56 ;; checking for "Re:" for finding parts.
58 ;; v2.2: Fixed handling of currupted archives. Changed uudecoding to
59 ;; an asynchronous process to avoid loading tons of data into emacs
60 ;; buffers. No longer reads articles emacs already have aboard. Fixed
61 ;; a firmer support for shar files. Made regexp searches for files
62 ;; more convenient. Added `C-c C-l' for editing uucode begin
63 ;; lines. Added multi-system decoder entry point. Added interactive
64 ;; view mode. Added function for decoding and saving all uuencoded
65 ;; articles in the current newsgroup.
67 ;; v2.3: After suggestions I have changed all the gnus-uu key bindings
68 ;; to avoid hogging all the user keys (C-c LETTER). Also added
69 ;; (provide) and fixed some saving stuff. First posted version to
72 ;; v2.4: Fixed some more in the save-all category. Automatic fixing of
73 ;; uucode "begin" lines: names on the form of "dir/file" are
74 ;; translated into "dir-file". Added a function for fixing stripped
75 ;; uucode articles. Added binhex save.
77 ;; v2.5: First version copyrighted by FSF. Changed lots of
78 ;; documentation strings.
80 ;; v2.5.1: Added uuencode/posting code to post binary files.
82 ;; v2.6: Thread support. gnus-uu is now able to decode uuencoded files
83 ;; posted in threads. gnus-uu can also post in threads. I don't know
84 ;; if this ability is of much use - I've never seen anyone post
85 ;; uuencoded files in threads.
87 ;; v2.7: gnus-uu is now able to decode (and view/save) multiple
88 ;; encoded files in one big gulp. Also added pseudo-mime support
89 ;; (users can use metamail to view files), posting uuencoded/mime
90 ;; files and various other bits and pieces.
92 ;; v2.7.1: New functions for decoding/saving threads bound to `C-c
93 ;; C-v C-j'. Handy to save entire threads, not very useful for
94 ;; decoding, as nobody posts encoded files in threads...
96 ;; V2.7.2: New functions for digesting and forwarding articles added
97 ;; on the suggestion of Per Abrahamsen. Also added a function for
105 ;; Binding of keys to the gnus-uu functions.
107 (defvar gnus-uu-ctl-map nil)
108 (define-prefix-command 'gnus-uu-ctl-map)
109 (define-key gnus-summary-mode-map "\C-c\C-v" gnus-uu-ctl-map)
111 (define-key gnus-uu-ctl-map "\C-v" 'gnus-uu-decode-and-view)
112 (define-key gnus-uu-ctl-map "v" 'gnus-uu-decode-and-save)
113 (define-key gnus-uu-ctl-map "\C-s" 'gnus-uu-shar-and-view)
114 (define-key gnus-uu-ctl-map "s" 'gnus-uu-shar-and-save)
115 (define-key gnus-uu-ctl-map "\C-m" 'gnus-uu-multi-decode-and-view)
116 (define-key gnus-uu-ctl-map "m" 'gnus-uu-multi-decode-and-save)
118 (define-key gnus-uu-ctl-map "\C-b" 'gnus-uu-decode-and-show-in-buffer)
120 (define-key gnus-summary-mode-map "#" 'gnus-uu-mark-article)
121 (define-key gnus-summary-mode-map "\M-#" 'gnus-uu-unmark-article)
122 (define-key gnus-uu-ctl-map "\C-u" 'gnus-uu-unmark-all-articles)
123 (define-key gnus-uu-ctl-map "\C-r" 'gnus-uu-mark-by-regexp)
124 (define-key gnus-uu-ctl-map "r" 'gnus-uu-mark-by-regexp)
125 (define-key gnus-uu-ctl-map "t" 'gnus-uu-mark-thread)
127 (define-key gnus-uu-ctl-map "\M-\C-v" 'gnus-uu-marked-decode-and-view)
128 (define-key gnus-uu-ctl-map "\M-v" 'gnus-uu-marked-decode-and-save)
129 (define-key gnus-uu-ctl-map "\M-\C-s" 'gnus-uu-marked-shar-and-view)
130 (define-key gnus-uu-ctl-map "\M-s" 'gnus-uu-marked-shar-and-save)
131 (define-key gnus-uu-ctl-map "\M-\C-m" 'gnus-uu-marked-multi-decode-and-view)
132 (define-key gnus-uu-ctl-map "\M-m" 'gnus-uu-marked-multi-decode-and-save)
134 (define-key gnus-uu-ctl-map "f" 'gnus-uu-digest-and-forward)
135 (define-key gnus-uu-ctl-map "\M-f" 'gnus-uu-marked-digest-and-forward)
137 (define-key gnus-uu-ctl-map "\C-i" 'gnus-uu-toggle-interactive-view)
138 (define-key gnus-uu-ctl-map "\C-t" 'gnus-uu-toggle-any-variable)
140 (define-key gnus-uu-ctl-map "\C-l" 'gnus-uu-edit-begin-line)
142 (define-key gnus-uu-ctl-map "a" 'gnus-uu-decode-and-save-all-unread-articles)
143 (define-key gnus-uu-ctl-map "w" 'gnus-uu-decode-and-save-all-articles)
144 (define-key gnus-uu-ctl-map "\C-a" 'gnus-uu-decode-and-view-all-unread-articles)
145 (define-key gnus-uu-ctl-map "\C-w" 'gnus-uu-decode-and-view-all-articles)
147 (define-key gnus-uu-ctl-map "\C-h" 'gnus-uu-threaded-decode-and-view)
148 (define-key gnus-uu-ctl-map "h" 'gnus-uu-threaded-decode-and-save)
149 (define-key gnus-uu-ctl-map "\C-j" 'gnus-uu-threaded-multi-decode-and-view)
150 (define-key gnus-uu-ctl-map "j" 'gnus-uu-threaded-multi-decode-and-save)
152 (define-key gnus-uu-ctl-map "p" 'gnus-uu-post-news)
154 ;; Dummy function gnus-uu
157 "gnus-uu is a package for uudecoding and viewing articles.
162 By default, all gnus-uu keystrokes begin with `C-c C-v'.
164 There four decoding commands categories:
165 All commands for viewing are `C-c C-v C-LETTER'.
166 All commands for saving are `C-c C-v LETTER'.
167 All commands for marked viewing are `C-c C-v C-M-LETTER'.
168 All commands for marked saving are `C-c C-v M-LETTER'.
170 \\<gnus-summary-mode-map>\\[gnus-uu-decode-and-view]\tDecode and view articles
171 \\[gnus-uu-decode-and-save]\tDecode and save articles
172 \\[gnus-uu-shar-and-view]\tUnshar and view articles
173 \\[gnus-uu-shar-and-save]\tUnshar and save articles
174 \\[gnus-uu-multi-decode-and-view]\tChoose a decoding method, decode and view articles
175 \\[gnus-uu-multi-decode-and-save]\tChoose a decoding method, decode and save articles
177 \\[gnus-uu-threaded-multi-decode-and-view]\tDecode a thread and view
178 \\[gnus-uu-threaded-multi-decode-and-save]\tDecode a thread and save
180 \\[gnus-uu-decode-and-show-in-buffer]\tDecode the current article and view the result in a buffer
181 \\[gnus-uu-edit-begin-line]\tEdit the 'begin' line of an uuencoded article
183 \\[gnus-uu-decode-and-save-all-unread-articles]\tDecode and save all unread articles
184 \\[gnus-uu-decode-and-save-all-articles]\tDecode and save all articles
185 \\[gnus-uu-decode-and-view-all-unread-articles]\tDecode and view all unread articles
186 \\[gnus-uu-decode-and-view-all-articles]\tDecode and view all articles
188 \\[gnus-uu-digest-and-forward]\tDigest and forward a series of articles
189 \\[gnus-uu-marked-digest-and-forward]\tDigest and forward all marked articles
191 \\[gnus-uu-mark-article]\tMark the current article for decoding
192 \\[gnus-uu-unmark-article]\tUnmark the current article
193 \\[gnus-uu-unmark-all-articles]\tUnmark all articles
194 \\[gnus-uu-mark-by-regexp]\tMark articles for decoding by regexp
195 \\[gnus-uu-mark-thread]\tMark articles in this thread
196 \\[gnus-uu-marked-decode-and-view]\tDecode and view marked articles
197 \\[gnus-uu-marked-decode-and-save]\tDecode and save marked articles
198 \\[gnus-uu-marked-shar-and-view]\tUnshar and view marked articles
199 \\[gnus-uu-marked-shar-and-save]\tUnshar and save marked articles
200 \\[gnus-uu-marked-multi-decode-and-view]\tChoose decoding method, decode and view marked articles
201 \\[gnus-uu-marked-multi-decode-and-save]\tChoose decoding method, decode and save marked articles
203 \\[gnus-uu-toggle-asynchronous]\tToggle asynchronous viewing mode
204 \\[gnus-uu-toggle-query]\tToggle whether to ask before viewing a file
205 \\[gnus-uu-toggle-always-ask]\tToggle whether to ask to save a file after viewing
206 \\[gnus-uu-toggle-kill-carriage-return]\tToggle whether to strip trailing carriage returns
207 \\[gnus-uu-toggle-interactive-view]\tToggle whether to use interactive viewing mode
208 \\[gnus-uu-toggle-correct-stripped-articles]\tToggle whether to 'correct' articles
209 \\[gnus-uu-toggle-view-with-metamail]\tToggle whether to use metamail for viewing
210 \\[gnus-uu-toggle-any-variable]\tToggle any of the things above
212 \\[gnus-uu-post-news]\tPost an uuencoded article
214 Function description:
216 `gnus-uu-decode-and-view' will try to find all articles in the same
217 series, uudecode them and view the resulting file(s).
219 gnus-uu guesses what articles are in the series according to the
220 following simplish rule: The subjects must be (nearly) identical,
221 except for the last two numbers of the line. (Spaces are largely
224 For example: If you choose a subject called
226 gnus-uu will find all the articles that matches
227 \"^cat.gif ([0-9]+/[0-9]+).*$\".
229 Subjects that are nonstandard, like
230 \"cat.gif (2/3) Part 6 of a series\",
231 will not be properly recognized by any of the automatic viewing
232 commands, and you have to mark the articles manually with '#'.
234 `gnus-uu-decode-and-save' will do the same as
235 `gnus-uu-decode-and-view', except that it will not display the
236 resulting file, but save it instead.
238 `gnus-uu-shar-and-view' and `gnus-uu-shar-and-save' are the \"shar\"
239 equivalents to the uudecode functions. Instead of feeding the articles
240 to uudecode, they are run through /bin/sh. Most shar files can be
241 viewed and/or saved with the normal uudecode commands, which is much
242 safer, as no foreign code is run.
244 Instead of having windows popping up automatically, it can be handy to
245 view files interactivly, especially when viewing archives. Use
246 `gnus-uu-toggle-interactive-mode' to toggle interactive mode.
248 `gnus-uu-mark-article' marks an article for later
249 decoding/unsharing/saving/viewing. The files will be decoded in the
250 sequence they were marked. To decode the files after you've marked the
251 articles you are interested in, type the corresponding key strokes as
252 the normal decoding commands, but put a `M-' in the last
253 keystroke. For instance, to perform a standard uudecode and view, you
254 would type `C-c C-v C-v'. To perform a marked uudecode and view, say
255 `C-v C-v M-C-v'. All the other view and save commands are handled the
256 same way; marked uudecode and save is then `C-c C-v M-v'.
258 `gnus-uu-unmark-article' will remove the mark from a previosly marked
261 `gnus-uu-unmark-all-articles' will remove the mark from all marked
264 `gnus-uu-mark-by-regexp' will prompt for a regular expression and mark
265 all articles matching that regular expression.
267 `gnus-uu-mark-thread' will mark all articles downward in the current
270 There's an additional way to reach the decoding functions to make
271 future expansions easier: `gnus-uu-multi-decode-and-view' and the
272 corresponding save, marked view and marked save functions. You will be
273 prompted for a decoding method, like uudecode, shar, binhex or plain
274 save. Note that methods like binhex and save doesn't have view modes;
275 even if you issue a view command (`C-c C-v C-m' and \"binhex\"),
276 gnus-uu will just save the resulting binhex file.
278 `gnus-uu-decode-and-show-in-buffer' will decode the current article
279 and display the results in an emacs buffer. This might be useful if
280 there's jsut some text in the current article that has been uuencoded
281 by some perverse poster.
283 `gnus-uu-decode-and-save-all-articles' looks at all the articles in
284 the current newsgroup and tries to uudecode everything it can
285 find. The user will be prompted for a directory where the resulting
286 files (if any) will be
287 saved. `gnus-uu-decode-and-save-unread-articles' does only checks
290 `gnus-uu-decode-and-view-all-articles' does the same as the function
291 above, only viewing files instead of saving them.
293 `gnus-uu-edit-begin-line' lets you edit the begin line of an uuencoded
294 file in the current article. Useful to change a corrupted begin line.
297 When using the view commands, `gnus-uu-decode-and-view' for instance,
298 gnus-uu will (normally, see below) try to view the file according to
299 the rules given in `gnus-uu-default-view-rules' and
300 `gnus-uu-user-view-rules'. If it recognizes the file, it will display
301 it immediately. If the file is some sort of archive, gnus-uu will
302 attempt to unpack the archive and see if any of the files in the
303 archive can be viewed. For instance, if you have a gzipped tar file
304 \"pics.tar.gz\" containing the files \"pic1.jpg\" and \"pic2.gif\",
305 gnus-uu will uncompress and detar the main file, and then view the two
306 pictures. This unpacking process is recursive, so if the archive
307 contains archives of archives, it'll all be unpacked.
309 If the view command doesn't recognise the file type, or can't view it
310 because you don't have the viewer, or can't view *any* of the files in
311 the archive, the user will be asked if she wishes to have the file
312 saved somewhere. Note that if the decoded file is an archive, and
313 gnus-uu manages to view some of the files in the archive, it won't
314 tell the user that there were some files that were unviewable. Try
315 interactive view for a different approach.
318 Note that gnus-uu adds a function to `gnus-exit-group-hook' to clear
319 the list of marked articles and check for any generated files that
320 might have escaped deletion if the user typed `C-g' during viewing.
323 `gnus-uu-toggle-asynchronous' toggles the `gnus-uu-asynchronous'
326 `gnus-uu-toggle-query' toggles the `gnus-uu-ask-before-view'
329 `gnus-uu-toggle-always-ask' toggles the `gnus-uu-view-and-save'
332 `gnus-uu-toggle-kill-carriage-return' toggles the
333 `gnus-uu-kill-carriage-return' variable.
335 `gnus-uu-toggle-interactive-view' toggles interactive mode. If it is
336 turned on, gnus-uu won't view files immediately, but will give you a
337 buffer with the default commands and files and let you edit the
338 commands and execute them at leisure.
340 `gnus-uu-toggle-correct-stripped-articles' toggles whether to check
341 and correct uuencoded articles that may have had trailing spaces
344 `gnus-uu-toggle-view-with-metamail' toggles whether to skip the
345 gnus-uu viewing methods and just guess at an content-type based on the
346 file name suffix and feed it to metamail.
348 `gnus-uu-toggle-any-variable' is an interface to the toggle commands
356 gnus-uu uses \"rule\" variables to decide how to view a file. All
357 these variables are of the form
359 (list '(regexp1 command2)
363 `gnus-uu-user-view-rules'
364 This variable is consulted first when viewing files. If you wish
365 to use, for instance, sox to convert an .au sound file, you could
368 (setq gnus-uu-user-view-rules
369 (list '(\"\\\\.au$\" \"sox %s -t .aiff > /dev/audio\")))
371 `gnus-uu-user-view-rules-end'
372 This variable is consulted if gnus-uu couldn't make any matches
373 from the user and default view rules.
375 `gnus-uu-user-interactive-view-rules'
376 This is the variable used instead of `gnus-uu-user-view-rules'
377 when in interactive mode.
379 `gnus-uu-user-interactive-view-rules-end'
380 This variable is used instead of `gnus-uu-user-view-rules-end'
381 when in interactive mode.
383 `gnus-uu-user-archive-rules`
384 This variable can be used to say what comamnds should be used to
391 Where gnus-uu does its work.
393 `gnus-uu-do-not-unpack-archives'
394 Non-nil means that gnus-uu won't peek inside archives looking for
397 `gnus-uu-view-and-save'
398 Non-nil means that the user will always be asked to save a file
401 `gnus-uu-asynchronous'
402 Non-nil means that files will be viewed asynchronously. This can
403 be useful if you're viewing long .mod files, for instance, which
404 often takes several minutes. Note, however, that since gnus-uu
405 doesn't ask, and if you are viewing an archive with lots of
406 viewable files, you'll get them all up more or less at once,
407 which can be confusing, to say the least. To get gnus-uu to ask
408 you before viewing a file, set the `gnus-uu-ask-before-view'
411 `gnus-uu-ask-before-view'
412 Non-nil means that gnus-uu will ask you before viewing each file
414 `gnus-uu-ignore-default-view-rules'
415 Non-nil means that gnus-uu will ignore the default viewing rules.
417 `gnus-uu-ignore-default-archive-rules'
418 Non-nil means that gnus-uu will ignore the default archive
421 `gnus-uu-kill-carriage-return'
422 Non-nil means that gnus-uu will strip all carriage returns from
425 `gnus-uu-unmark-articles-not-decoded'
426 Non-nil means that gnus-uu will mark articles that were
427 unsuccessfully decoded as unread.
429 `gnus-uu-output-window-height'
430 This variable says how tall the output buffer window is to be
431 when using interactive view mode.
433 `gnus-uu-correct-stripped-uucode'
434 Non-nil means that gnus-uu will *try* to fix uuencoded files that
435 have had traling spaces deleted.
437 `gnus-uu-use-interactive-view'
438 Non-nil means that gnus-uu will use interactive viewing mode.
440 `gnus-uu-view-with-metamail'
441 Non-nil means that gnus-uu will ignore the viewing commands
442 defined by the rule variables and just fudge a MIME content type
443 based on the file name. The result will be fed to metamail for
446 `gnus-uu-save-in-digest'
447 Non-nil means that gnus-uu, when asked to save without decoding,
448 will save in digests. If this variable is nil, gnus-uu will just
449 save everything in a file without any embellishments. The
450 digesting almost conforms to RFC1153 - no easy way to specify any
451 meaningful volume and issue numbers were found, so I simply
454 `gnus-uu-post-include-before-composing'
455 Non-nil means that gnus-uu will ask for a file to encode before
456 you compose the article. If this variable is t, you can either
457 include an encoded file with \\<gnus-uu-post-reply-mode-map>\\[gnus-uu-post-insert-binary-in-article] or have one included for you when you
460 `gnus-uu-post-length'
461 Maximum length of an article. The encoded file will be split
462 into how many articles it takes to post the entire file.
464 `gnus-uu-post-threaded'
465 Non-nil means that gnus-uu will post the encoded file in a
466 thread. This may not be smart, as no other decoder I have seen
467 are able to follow threads when collecting uuencoded
468 articles. (Well, I have seen one package that does that -
469 gnus-uu, but somehow, I don't think that counts...) Default is
472 `gnus-uu-post-separate-description'
473 Non-nil means that the description will be posted in a separate
474 article. The first article will typically be numbered (0/x). If
475 this variable is nil, the description the user enters will be
476 included at the beginning of the first article, which will be
477 numbered (1/x). Default is t.
482 ;; Default viewing action rules
484 (defvar gnus-uu-default-view-rules
486 '("\\.\\(jpe?g\\|gif\\|tiff?\\|p[pgb]m\\|xwd\\|xbm\\|pcx\\)$" "xv")
487 '("\\.tga$" "tgatoppm %s | xv -")
488 '("\\.te?xt$\\|\\.doc$\\|read.*me" "xterm -e less")
489 '("\\.\\(wav\\|aiff\\|hcom\\|u[blw]\\|s[bfw]\\|voc\\|smp\\)$"
490 "sox -v .5 %s -t .au -u - > /dev/audio")
491 '("\\.au$" "cat %s > /dev/audio")
493 '("\\.ps$" "ghostview")
495 '("\\.[1-6]$" "xterm -e man -l")
496 '("\\.html$" "xmosaic")
497 '("\\.mpe?g$" "mpeg_play")
498 '("\\.fli$" "xflick")
500 '("\\.\\(tar\\|arj\\|zip\\|zoo\\|arc\\|gz\\|Z\\|lzh\\|ar\\|lha\\)$"
503 "Default actions to be taken when the user asks to view a file.
504 To change the behaviour, you can either edit this variable or set
505 `gnus-uu-user-view-rules' to something useful.
509 To make gnus-uu use 'xli' to display JPEG and GIF files, put the
510 following in your .emacs file
512 (setq gnus-uu-user-view-rules (list '(\"jpg$\\\\|gif$\" \"xli\")))
514 Both these variables are lists of lists with two string elements. The
515 first string is a regular expression. If the file name matches this
516 regular expression, the command in the second string is executed with
517 the file as an argument.
519 If the command string contains \"%s\", the file name will be inserted
520 at that point in the command string. If there's no \"%s\" in the
521 command string, the file name will be appended to the command string
524 There are several user variables to tailor the behaviour of gnus-uu to
525 your needs. First we have `gnus-uu-user-view-rules', which is the
526 variable gnus-uu first consults when trying to decide how to view a
527 file. If this variable contains no matches, gnus-uu examines the
528 default rule vaiable provided in this package. If gnus-uu finds no
529 match here, it uses `gnus-uu-user-view-rules-end' to try to make a
532 Unless, of course, you are using the interactive view mode. Then
533 `gnus-uu-user-interactive-view-rules' and
534 `gnus-uu-user-interactive-view-rules-end' will be used instead.")
536 (defvar gnus-uu-user-view-rules nil
537 "Variable detailing what actions are to be taken to view a file.
538 See the documentation on the `gnus-uu-default-view-rules' variable for
541 (defvar gnus-uu-user-view-rules-end nil
542 "Variable saying what actions are to be taken if no rule matched the file name.
543 See the documentation on the `gnus-uu-default-view-rules' variable for
546 (defvar gnus-uu-user-interactive-view-rules nil
547 "Variable detailing what actions are to be taken to view a file when using interactive mode.
548 See the documentation on the `gnus-uu-default-view-rules' variable for
551 (defvar gnus-uu-user-interactive-view-rules-end nil
552 "Variable saying what actions are to be taken if no rule matched the file name when using interactive mode.
553 See the documentation on the `gnus-uu-default-view-rules' variable for
556 (defvar gnus-uu-default-interactive-view-rules-begin
558 '("\\.te?xt$\\|\\.doc$\\|read.*me\\|\\.c?$\\|\\.h$\\|\\.bat$\\|\\.asm$\\|makefile" "cat %s | sed s/\r//g")
559 '("\\.pas$" "cat %s | sed s/\r//g")
562 (defvar gnus-uu-default-interactive-view-rules-end
566 ;; Default unpacking commands
568 (defvar gnus-uu-default-archive-rules
569 (list '("\\.tar$" "tar xf")
570 '("\\.zip$" "unzip -o")
572 '("\\.arj$" "unarj x")
573 '("\\.zoo$" "zoo -e")
574 '("\\.\\(lzh\\|lha\\)$" "lha x")
575 '("\\.Z$" "uncompress")
577 '("\\.arc$" "arc -x"))
580 (defvar gnus-uu-destructive-archivers
581 (list "uncompress" "gunzip"))
583 (defvar gnus-uu-user-archive-rules nil
584 "A list that can be set to override the default archive unpacking commands.
585 To use, for instance, 'untar' to unpack tar files and 'zip -x' to
586 unpack zip files, say the following:
587 (setq gnus-uu-user-archive-rules
588 (list '(\"\\\\.tar$\" \"untar\")
589 '(\"\\\\.zip$\" \"zip -x\")))"
592 ;; Pseudo-MIME support
594 (defconst gnus-uu-ext-to-mime-list
595 (list '("\\.gif$" "image/gif")
596 '("\\.jpe?g$" "image/jpeg")
597 '("\\.tiff?$" "image/tiff")
598 '("\\.xwd$" "image/xwd")
599 '("\\.pbm$" "image/pbm")
600 '("\\.pgm$" "image/pgm")
601 '("\\.ppm$" "image/ppm")
602 '("\\.xbm$" "image/xbm")
603 '("\\.pcx$" "image/pcx")
604 '("\\.tga$" "image/tga")
605 '("\\.ps$" "image/postscript")
606 '("\\.fli$" "video/xflick")
607 '("\\.wav$" "audio/wav")
608 '("\\.aiff$" "audio/aiff")
609 '("\\.hcom$" "audio/hcom")
610 '("\\.voc$" "audio/voc")
611 '("\\.smp$" "audio/smp")
612 '("\\.mod$" "audio/mod")
613 '("\\.dvi$" "image/dvi")
614 '("\\.mpe?g$" "video/mpeg")
615 '("\\.au$" "audio/basic")
616 '("\\.\\(te?xt\\|doc\\|c\\|h\\)$" "text/plain")
617 '("read.*me" "text/plain")
618 '("\\.html$" "text/html")
619 '("\\..*$" "unknown/unknown")))
621 ;; Various variables users may set
623 (defvar gnus-uu-tmp-dir "/tmp/"
624 "Variable saying where gnus-uu is to do its work.
625 Default is \"/tmp/\".")
627 (defvar gnus-uu-do-not-unpack-archives nil
628 "Non-nil means that gnus-uu won't peek inside archives looking for files to dispay.
631 (defvar gnus-uu-view-and-save nil
632 "Non-nil means that the user will always be asked to save a file after viewing it.
633 If the variable is nil, the suer will only be asked to save if the
634 viewing is unsuccessful. Default is nil.")
636 (defvar gnus-uu-asynchronous nil
637 "Non-nil means that files will be viewed asynchronously.
640 (defvar gnus-uu-ask-before-view nil
641 "Non-nil means that gnus-uu will ask you before viewing each file.
642 Especially useful when `gnus-uu-asynchronous' is set. Default is
645 (defvar gnus-uu-ignore-default-view-rules nil
646 "Non-nil means that gnus-uu will ignore the default viewing rules.
647 Only the user viewing rules will be consulted. Default is nil.")
649 (defvar gnus-uu-ignore-default-archive-rules nil
650 "Non-nil means that gnus-uu will ignore the default archive unpacking commands.
651 Only the user unpacking commands will be consulted. Default is nil.")
653 (defvar gnus-uu-kill-carriage-return t
654 "Non-nil means that gnus-uu will strip all carriage returns from articles.
657 (defvar gnus-uu-view-with-metamail nil
658 "Non-nil means that files will be viewed with metamail.
659 The gnus-uu viewing functions will be ignored and gnus-uu will try
660 to guess at a content-type based on file name suffixes. Default
663 (defvar gnus-uu-unmark-articles-not-decoded nil
664 "Non-nil means that gnus-uu will mark articles that were unsuccessfully decoded as unread.
667 (defvar gnus-uu-output-window-height 20
668 "This variable says how tall the output buffer window is to be when using interactive view mode.
669 Change it at your convenience. Default is 20.")
671 (defvar gnus-uu-correct-stripped-uucode nil
672 "Non-nil means that gnus-uu will *try* to fix uuencoded files that have had traling spaces deleted.
675 (defvar gnus-uu-use-interactive-view nil
676 "Non-nil means that gnus-uu will use interactive viewing mode.
677 Gnus-uu will create a special buffer where the user may choose
678 interactively which files to view and how. Default is nil.")
680 (defvar gnus-uu-save-in-digest nil
681 "Non-nil means that gnus-uu, when asked to save without decoding, will save in digests.
682 If this variable is nil, gnus-uu will just save everything in a
683 file without any embellishments. The digesting almost conforms to RFC1153 -
684 no easy way to specify any meaningful volume and issue numbers were found,
685 so I simply dropped them.")
688 ;; Internal variables
690 (defconst gnus-uu-begin-string "^begin[ \t]+[0-7][0-7][0-7][ \t]+\\(.*\\)$")
691 (defconst gnus-uu-end-string "^end[ \t]*$")
693 (defconst gnus-uu-body-line "^M")
695 (while (> (setq i (1- i)) 0)
696 (setq gnus-uu-body-line (concat gnus-uu-body-line "[^a-z]")))
697 (setq gnus-uu-body-line (concat gnus-uu-body-line ".?$")))
699 ;"^M.............................................................?$"
701 (defconst gnus-uu-shar-begin-string "^#! */bin/sh")
703 (defvar gnus-uu-shar-file-name nil)
704 (defconst gnus-uu-shar-name-marker "begin [0-7][0-7][0-7][ \t]+\\(\\(\\w\\|\\.\\)*\\b\\)")
705 (defvar gnus-uu-shar-directory nil)
707 (defvar gnus-uu-file-name nil)
708 (defconst gnus-uu-uudecode-process nil)
710 (defvar gnus-uu-interactive-file-list nil)
711 (defvar gnus-uu-marked-article-list nil)
712 (defvar gnus-uu-generated-file-list nil)
713 (defvar gnus-uu-work-dir nil)
715 (defconst gnus-uu-interactive-buffer-name "*gnus-uu interactive*")
716 (defconst gnus-uu-output-buffer-name "*Gnus UU Output*")
717 (defconst gnus-uu-result-buffer "*Gnus UU Result Buffer*")
719 (defconst gnus-uu-error-during-unarching nil)
721 ;; Interactive functions
725 (defun gnus-uu-decode-and-view ()
726 "UUdecodes and 'views' (if possible) the resulting file.
727 'Viewing' can be any action at all, as defined in the
728 `gnus-uu-file-action-list' variable. Running 'xv' on gifs and 'cat
729 >/dev/audio' on au files are popular actions. If the file can't be
730 viewed, the user is asked if she would like to save the file instead."
732 (gnus-uu-decode-and-view-or-save t nil))
734 (defun gnus-uu-decode-and-save ()
735 "Decodes and saves the resulting file."
737 (gnus-uu-decode-and-view-or-save nil nil))
739 (defun gnus-uu-marked-decode-and-view ()
740 "Decodes and views articles marked.
741 The marked equivalent to `gnus-uu-decode-and-view'."
743 (gnus-uu-decode-and-view-or-save t t))
745 (defun gnus-uu-marked-decode-and-save ()
746 "Decodes and saves articles marked.
747 The marked equivalent to `gnus-uu-decode-and-save'."
749 (gnus-uu-decode-and-view-or-save nil t))
754 (defun gnus-uu-shar-and-view ()
755 "Unshars and views articles.
756 The shar equivalent of `gnus-uu-decode-and-view'."
758 (gnus-uu-unshar-and-view-or-save t nil))
760 (defun gnus-uu-shar-and-save ()
761 "Unshars and saves files.
762 The shar equivalent to `gnus-uu-decode-and-save'."
764 (gnus-uu-unshar-and-view-or-save nil nil))
766 (defun gnus-uu-marked-shar-and-view ()
767 "Unshars and views articles marked.
768 The marked equivalent to `gnus-uu-shar-and-view'."
770 (gnus-uu-unshar-and-view-or-save t t))
772 (defun gnus-uu-marked-shar-and-save ()
773 "Unshars and saves articles marked.
774 The marked equivalent to `gnus-uu-shar-and-save'."
776 (gnus-uu-unshar-and-view-or-save nil t))
780 (defun gnus-uu-threaded-decode-and-view ()
781 "Decodes and saves the resulting file."
783 (gnus-uu-threaded-decode-and-view-or-save t))
785 (defun gnus-uu-threaded-decode-and-save ()
786 "Decodes and saves the resulting file."
788 (gnus-uu-threaded-decode-and-view-or-save nil))
790 (defun gnus-uu-threaded-multi-decode-and-view ()
791 "Decodes and saves the resulting file."
793 (gnus-uu-threaded-multi-decode-and-view-or-save t))
795 (defun gnus-uu-threaded-multi-decode-and-save ()
796 "Decodes and saves the resulting file."
798 (gnus-uu-threaded-multi-decode-and-view-or-save nil))
800 (defun gnus-uu-threaded-decode-and-view-or-save (&optional view)
801 (gnus-uu-unmark-all-articles)
802 (gnus-uu-mark-thread)
803 (gnus-uu-decode-and-view-or-save view t))
805 (defun gnus-uu-threaded-multi-decode-and-view-or-save (view)
807 (message "Decode type: [u]udecode, (s)har, s(a)ve, (b)inhex: ")
808 (setq type (read-char))
809 (if (not (or (= type ?u) (= type ?s) (= type ?b) (= type ?a)))
810 (error "No such decoding method '%c'" type))
812 (gnus-uu-unmark-all-articles)
813 (gnus-uu-mark-thread)
815 (if (= type ?\r) (setq type ?u))
816 (cond ((= type ?u) (gnus-uu-decode-and-view-or-save view t))
817 ((= type ?s) (gnus-uu-unshar-and-view-or-save view t))
818 ((= type ?b) (gnus-uu-binhex-and-save view t))
819 ((= type ?a) (gnus-uu-save-articles view t)))))
824 (defun gnus-uu-toggle-asynchronous ()
825 "This function toggles asynchronous viewing."
827 (if (setq gnus-uu-asynchronous (not gnus-uu-asynchronous))
828 (message "gnus-uu will now view files asynchronously")
829 (message "gnus-uu will now view files synchronously")))
831 (defun gnus-uu-toggle-query ()
832 "This function toggles whether to ask before viewing or not."
834 (if (setq gnus-uu-ask-before-view (not gnus-uu-ask-before-view))
835 (message "gnus-uu will now ask before viewing")
836 (message "gnus-uu will now view without asking first")))
838 (defun gnus-uu-toggle-always-ask ()
839 "This function toggles whether to always ask to save a file after viewing."
841 (if (setq gnus-uu-view-and-save (not gnus-uu-view-and-save))
842 (message "gnus-uu will now ask to save the file after viewing")
843 (message "gnus-uu will now not ask to save after successful viewing")))
845 (defun gnus-uu-toggle-interactive-view ()
846 "This function toggles whether to use interactive view."
848 (if (setq gnus-uu-use-interactive-view (not gnus-uu-use-interactive-view))
849 (message "gnus-uu will now use interactive view")
850 (message "gnus-uu will now use non-interactive view")))
852 (defun gnus-uu-toggle-unmark-undecoded ()
853 "This function toggles whether to unmark articles not decoded."
855 (if (setq gnus-uu-unmark-articles-not-decoded
856 (not gnus-uu-unmark-articles-not-decoded))
857 (message "gnus-uu will now unmark articles not decoded")
858 (message "gnus-uu will now not unmark articles not decoded")))
860 (defun gnus-uu-toggle-kill-carriage-return ()
861 "This function toggles the stripping of carriage returns from the articles."
863 (if (setq gnus-uu-kill-carriage-return (not gnus-uu-kill-carriage-return))
864 (message "gnus-uu will now strip carriage returns")
865 (message "gnus-uu won't strip carriage returns")))
867 (defun gnus-uu-toggle-view-with-metamail ()
868 "This function toggles whether to view files with metamail."
870 (if (setq gnus-uu-view-with-metamail (not gnus-uu-view-with-metamail))
871 (message "gnus-uu will now view with metamail")
872 (message "gnus-uu will now view with the gnus-uu viewing functions")))
874 (defun gnus-uu-toggle-correct-stripped-uucode ()
875 "This function toggles whether to correct stripped uucode."
877 (if (setq gnus-uu-correct-stripped-uucode
878 (not gnus-uu-correct-stripped-uucode))
879 (message "gnus-uu will now correct stripped uucode")
880 (message "gnus-uu won't check and correct stripped uucode")))
882 (defun gnus-uu-toggle-any-variable ()
883 "This function ask what variable the user wants to toggle."
886 (message "(a)sync, (q)uery, (p)ask, (k)ill CR, (i)nteract, (u)nmark, (c)orrect, (m)eta")
887 (setq rep (read-char))
889 (gnus-uu-toggle-asynchronous))
891 (gnus-uu-toggle-query))
893 (gnus-uu-toggle-always-ask))
895 (gnus-uu-toggle-kill-carriage-return))
897 (gnus-uu-toggle-unmark-undecoded))
899 (gnus-uu-toggle-correct-stripped-uucode))
901 (gnus-uu-toggle-view-with-metamail))
903 (gnus-uu-toggle-interactive-view))))
906 ;; Misc interactive functions
908 (defun gnus-uu-decode-and-show-in-buffer ()
909 "Uudecodes the current article and displays the result in a buffer.
910 Might be useful if someone has, for instance, some text uuencoded in
911 their sigs. (Stranger things have happened.)"
914 (let ((uu-buffer (get-buffer-create gnus-uu-output-buffer-name))
918 (gnus-summary-select-article)
919 (gnus-uu-grab-articles (list gnus-current-article)
920 'gnus-uu-uustrip-article-as)
921 (setq file-name (concat gnus-uu-work-dir gnus-uu-file-name))
924 (set-buffer uu-buffer)
926 (insert-file-contents file-name))
927 (set-window-buffer (get-buffer-window gnus-article-buffer)
929 (message "Showing file %s in buffer" file-name)
930 (delete-file file-name))))))
932 (defun gnus-uu-edit-begin-line ()
933 "Edit the begin line of the current article."
935 (let ((buffer-read-only nil)
938 (gnus-summary-select-article)
939 (set-buffer gnus-article-buffer)
941 (if (not (re-search-forward "begin " nil t))
942 (error "No begin line in the current article")
946 (setq begin (buffer-substring b (point)))
947 (setq begin (read-string "" begin))
948 (setq buffer-read-only nil)
949 (delete-region b (point))
950 (insert-string begin)))))
955 (defun gnus-uu-multi-decode-and-view ()
956 "Choose a method of decoding and then decode and view.
957 This function lets the user decide what method to use for decoding.
958 Other than that, it's equivalent to the other decode-and-view
961 (gnus-uu-multi-decode-and-view-or-save t nil))
963 (defun gnus-uu-multi-decode-and-save ()
964 "Choose a method of decoding and then decode and save.
965 This function lets the user decide what method to use for decoding.
966 Other than that, it's equivalent to the other decode-and-save
969 (gnus-uu-multi-decode-and-view-or-save nil nil))
971 (defun gnus-uu-marked-multi-decode-and-view ()
972 "Choose a method of decoding and then decode and view the marked articles.
973 This function lets the user decide what method to use for decoding.
974 Other than that, it's equivalent to the other marked decode-and-view
977 (gnus-uu-multi-decode-and-view-or-save t t))
979 (defun gnus-uu-marked-multi-decode-and-save ()
980 "Choose a method of decoding and then decode and save the marked articles.
981 This function lets the user decide what method to use for decoding.
982 Other than that, it's equivalent to the other marked decode-and-save
985 (gnus-uu-multi-decode-and-view-or-save t t))
987 (defun gnus-uu-multi-decode-and-view-or-save (view marked)
989 (message "[u]udecode, (s)har, s(a)ve, (b)inhex: ")
990 (setq type (read-char))
991 (if (= type ?\r) (setq type ?u))
992 (cond ((= type ?u) (gnus-uu-decode-and-view-or-save view marked))
993 ((= type ?s) (gnus-uu-unshar-and-view-or-save view marked))
994 ((= type ?b) (gnus-uu-binhex-and-save view marked))
995 ((= type ?a) (gnus-uu-save-articles view marked))
996 (t (error "Unknown decode method '%c'." type)))))
999 ;; "All articles" commands
1001 (defconst gnus-uu-rest-of-articles nil)
1002 (defvar gnus-uu-current-save-dir nil)
1004 (defun gnus-uu-decode-and-view-all-articles (&optional unread)
1005 "Try to decode all articles and view the result."
1007 (if (not (setq gnus-uu-marked-article-list
1008 (nreverse (gnus-uu-get-list-of-articles
1009 "^." nil unread t))))
1010 (error "No%s articles to be decoded" (if unread " unread" "")))
1011 (gnus-uu-decode-and-view-or-save t t))
1013 (defun gnus-uu-decode-and-view-all-unread-articles (&optional unread)
1014 "Try to decode all unread articles and view the result."
1016 (gnus-uu-decode-and-view-all-articles t))
1018 (defun gnus-uu-decode-and-save-all-unread-articles ()
1019 "Try to decode all unread articles and saves the result.
1020 This function reads all unread articles in the current group and sees
1021 whether it can uudecode the articles. The user will be prompted for an
1022 directory to put the resulting (if any) files."
1024 (gnus-uu-decode-and-save-articles t t))
1026 (defun gnus-uu-decode-and-save-all-articles ()
1027 "Try to decode all articles and saves the result.
1028 Does the same as `gnus-uu-decode-and-save-all-unread-articles', except
1029 that it grabs all articles visible, unread or not."
1031 (gnus-uu-decode-and-save-articles nil t))
1033 (defun gnus-uu-decode-and-save-articles (&optional unread unmark)
1034 (let ((gnus-uu-unmark-articles-not-decoded t)
1036 (if (not (setq gnus-uu-marked-article-list
1037 (nreverse (gnus-uu-get-list-of-articles
1038 "^." nil unread t))))
1039 (error "No%s articles to be decoded." (if unread " unread" ""))
1040 (setq dir (gnus-uu-read-directory "Where do you want the files? "))
1041 (gnus-uu-decode-and-view-or-save nil t dir)
1042 (message "Saved."))))
1047 ; All the interactive uudecode/view/save/marked functions are interfaces
1048 ; to this function, which does the rest.
1049 (defun gnus-uu-decode-and-view-or-save (view marked &optional save-dir)
1050 (gnus-uu-initialize)
1053 (if (gnus-uu-decode-and-strip nil marked)
1057 (gnus-uu-view-directory gnus-uu-work-dir
1058 gnus-uu-use-interactive-view)
1059 (gnus-uu-save-directory gnus-uu-work-dir save-dir save-dir)
1060 (gnus-uu-check-for-generated-files)))))
1062 (gnus-uu-summary-next-subject)
1064 (if gnus-uu-error-during-unarching
1066 (if (and gnus-uu-use-interactive-view view decoded)
1067 (gnus-uu-do-interactive)))
1069 (if (or (not view) (not gnus-uu-use-interactive-view) (not decoded))
1070 (gnus-uu-clean-up))))
1072 ; Unshars and views/saves marked/unmarked articles.
1073 (defun gnus-uu-unshar-and-view-or-save (view marked)
1074 (gnus-uu-initialize)
1075 (let (tar-file files decoded)
1077 (setq gnus-uu-shar-directory
1078 (make-temp-name (concat gnus-uu-tmp-dir "gnusuush")))
1079 (make-directory gnus-uu-shar-directory)
1080 (gnus-uu-add-file gnus-uu-shar-directory)
1081 (if (gnus-uu-decode-and-strip t marked)
1084 (setq files (directory-files gnus-uu-shar-directory t))
1085 (setq gnus-uu-generated-file-list
1086 (append files gnus-uu-generated-file-list))
1087 (if (> (length files) 3)
1091 (make-temp-name (concat gnus-uu-tmp-dir "gnusuuar"))
1093 (gnus-uu-add-file tar-file)
1096 (get-buffer-create gnus-uu-output-buffer-name) nil "-c"
1097 (format "cd %s ; tar cf %s * ; cd .. ; rm -r %s"
1098 gnus-uu-shar-directory tar-file
1099 gnus-uu-shar-directory))
1101 (gnus-uu-view-file tar-file)
1102 (gnus-uu-save-file tar-file)))
1104 (gnus-uu-view-file (elt files 2))
1105 (gnus-uu-save-file (elt files 2)))))))
1107 (gnus-uu-summary-next-subject)
1109 (if (and gnus-uu-use-interactive-view view decoded)
1110 (gnus-uu-do-interactive))
1112 (if (or (not gnus-uu-use-interactive-view) (not decoded))
1113 (gnus-uu-clean-up))))
1116 ;; Functions for saving and possibly digesting articles without
1119 (defconst gnus-uu-saved-article-name nil)
1121 ; VIEW isn't used, but is here anyway, to provide similar interface to
1122 ; the other related functions. If MARKED is non-nil, the list of
1123 ; marked articles is used. If NO-SAVE is non-nil, the articles aren't
1124 ; actually saved in a permanent location, but the collecting is done
1125 ; and a temporary file with the result is returned.
1126 (defun gnus-uu-save-articles (view marked &optional no-save)
1127 (let (list-of-articles)
1129 (gnus-uu-initialize)
1131 (setq list-of-articles (gnus-uu-get-list-of-articles))
1132 (setq list-of-articles (reverse gnus-uu-marked-article-list))
1133 (setq gnus-uu-marked-article-list nil))
1135 (if (not list-of-articles)
1136 (error "No list of articles"))
1138 (setq gnus-uu-saved-article-name
1139 (concat gnus-uu-work-dir
1142 (read-file-name "Enter file name: " gnus-newsgroup-name
1143 gnus-newsgroup-name))))
1144 (gnus-uu-add-file gnus-uu-saved-article-name)
1145 (if (and (gnus-uu-grab-articles list-of-articles 'gnus-uu-save-article t)
1147 (gnus-uu-save-file gnus-uu-saved-article-name)
1148 gnus-uu-saved-article-name))))
1150 ; Function called by gnus-uu-grab-articles to treat each article.
1151 (defun gnus-uu-save-article (buffer in-state)
1152 (if (not gnus-uu-save-in-digest)
1155 (write-region 1 (point-max) gnus-uu-saved-article-name t)
1156 (cond ((eq in-state 'first) (list gnus-uu-saved-article-name 'begin))
1157 ((eq in-state 'first-and-last) (list gnus-uu-saved-article-name 'begin 'end))
1158 ((eq in-state 'last) (list 'end))
1159 (t (list 'middle))))
1160 (let (beg subj name headers headline sorthead body end-string state)
1161 (string-match "/\\([^/]*\\)$" gnus-uu-saved-article-name)
1162 (setq name (substring gnus-uu-saved-article-name (match-beginning 1)
1164 (if (or (eq in-state 'first)
1165 (eq in-state 'first-and-last))
1167 (setq state (list 'begin))
1168 (save-excursion (set-buffer (get-buffer-create "*gnus-uu-body*"))
1171 (set-buffer (get-buffer-create "*gnus-uu-pre*"))
1174 "Date: %s\nFrom: %s\nSubject: %s Digest\n\nTopics:\n"
1175 (current-time-string) name name))))
1176 (if (not (eq in-state 'end))
1177 (setq state (list 'middle))))
1179 (set-buffer (get-buffer "*gnus-uu-body*"))
1180 (goto-char (setq beg (point-max)))
1185 (re-search-forward "\n\n")
1186 (setq body (buffer-substring (1- (point)) (point-max)))
1187 (narrow-to-region 1 (point))
1188 (setq headers (list "Date:" "From:" "To:" "Cc:" "Subject:"
1189 "Message-ID:" "Keywords:" "Summary:"))
1191 (setq headline (car headers))
1192 (setq headers (cdr headers))
1194 (if (re-search-forward (concat "^" headline ".*$") nil t)
1196 (concat sorthead (buffer-substring
1198 (match-end 0)) "\n"))))
1200 (insert sorthead)(goto-char (point-max))
1201 (insert body)(goto-char (point-max))
1202 (insert (concat "\n" (make-string 30 ?-) "\n\n"))
1204 (if (re-search-forward "^Subject: \\(.*\\)$" nil t)
1206 (setq subj (buffer-substring (match-beginning 1) (match-end 1)))
1208 (set-buffer (get-buffer "*gnus-uu-pre*"))
1209 (insert (format " %s\n" subj))))))
1210 (if (or (eq in-state 'last)
1211 (eq in-state 'first-and-last))
1214 (set-buffer (get-buffer "*gnus-uu-pre*"))
1215 (insert (format "\n\n%s\n\n" (make-string 70 ?-)))
1216 (write-region 1 (point-max) gnus-uu-saved-article-name))
1218 (set-buffer (get-buffer "*gnus-uu-body*"))
1219 (goto-char (point-max))
1221 (concat (setq end-string (format "End of %s Digest" name))
1223 (insert (concat (make-string (length end-string) ?*) "\n"))
1224 (write-region 1 (point-max) gnus-uu-saved-article-name t))
1225 (kill-buffer (get-buffer "*gnus-uu-pre*"))
1226 (kill-buffer (get-buffer "*gnus-uu-body*"))
1227 (setq state (cons 'end state))))
1228 (if (memq 'begin state)
1229 (cons gnus-uu-saved-article-name state)
1233 ;; Digest and forward articles
1235 (autoload 'gnus-mail-forward-using-mail "gnusmail"
1236 "Forward the current message to another user." t)
1237 (autoload 'gnus-mail-forward-using-mhe "gnusmail"
1238 "Forward the current message to another user." t)
1240 (defun gnus-uu-digest-and-forward (&optional marked)
1241 "Digests and forwards all articles in this series."
1243 (let ((gnus-uu-save-in-digest t)
1245 (setq file (gnus-uu-save-articles nil marked t))
1246 (switch-to-buffer (setq buf (get-buffer-create "*gnus-uu-forward*")))
1248 (delete-other-windows)
1253 (funcall gnus-mail-forward-method)))
1255 (defun gnus-uu-marked-digest-and-forward (&optional marked)
1256 "Digests and forwards all marked articles."
1258 (gnus-uu-digest-and-forward t))
1261 ;; Binhex treatment - not very advanced.
1263 (defconst gnus-uu-binhex-body-line
1264 "^[^:]...............................................................$")
1265 (defconst gnus-uu-binhex-begin-line
1266 "^:...............................................................$")
1267 (defconst gnus-uu-binhex-end-line
1269 (defvar gnus-uu-binhex-article-name nil)
1271 ; This just concatenates and strips stuff from binhexed articles.
1272 ; No actual unbinhexing takes place. VIEW is ignored.
1273 (defun gnus-uu-binhex-and-save (view marked)
1274 (gnus-uu-initialize)
1275 (let (list-of-articles)
1278 (setq list-of-articles (gnus-uu-get-list-of-articles))
1279 (setq list-of-articles (reverse gnus-uu-marked-article-list))
1280 (setq gnus-uu-marked-article-list nil))
1281 (if (not list-of-articles)
1282 (error "No list of articles"))
1284 (setq gnus-uu-binhex-article-name
1285 (concat gnus-uu-work-dir
1286 (read-file-name "Enter binhex file name: "
1288 gnus-newsgroup-name)))
1289 (gnus-uu-add-file gnus-uu-binhex-article-name)
1290 (if (gnus-uu-grab-articles list-of-articles 'gnus-uu-binhex-article t)
1291 (gnus-uu-save-file gnus-uu-binhex-article-name))))
1292 (gnus-uu-check-for-generated-files)
1293 (gnus-uu-summary-next-subject))
1295 (defun gnus-uu-binhex-article (buffer in-state)
1296 (let (state start-char)
1301 (if (not (re-search-forward gnus-uu-binhex-begin-line nil t))
1302 (if (not (re-search-forward gnus-uu-binhex-body-line nil t))
1303 (setq state (list 'wrong-type))))
1305 (if (memq 'wrong-type state)
1308 (setq start-char (point))
1309 (if (looking-at gnus-uu-binhex-begin-line)
1311 (setq state (list 'begin))
1312 (write-region 1 1 gnus-uu-binhex-article-name))
1313 (setq state (list 'middle)))
1314 (goto-char (point-max))
1315 (re-search-backward (concat gnus-uu-binhex-body-line "\\|"
1316 gnus-uu-binhex-end-line) nil t)
1317 (if (looking-at gnus-uu-binhex-end-line)
1318 (setq state (if (memq 'begin state)
1323 (if (file-exists-p gnus-uu-binhex-article-name)
1324 (append-to-file start-char (point) gnus-uu-binhex-article-name))))
1325 (if (memq 'begin state)
1326 (cons gnus-uu-binhex-article-name state)
1330 ;; Internal view commands
1332 ; This function takes two parameters. The first is name of the file to
1333 ; be viewed. `gnus-uu-view-file' will look for an action associated
1334 ; with the file type of the file. If it finds an appropriate action,
1335 ; the file will be attempted displayed.
1337 ; The second parameter specifies if the user is to be asked whether to
1338 ; save the file if viewing is unsuccessful. t means "do not ask."
1340 ; Note that the file given will be deleted by this function, one way
1341 ; or another. If `gnus-uu-asynchronous' is set, it won't be deleted
1342 ; right away, but sometime later. If the user is offered to save the
1343 ; file, it'll be moved to wherever the user wants it.
1345 ; `gnus-uu-view-file' returns t if viewing is successful.
1347 (defun gnus-uu-view-file (file-name &optional dont-ask)
1348 (let (action did-view
1352 (setq action (gnus-uu-get-action file-name))
1354 ; Do interactive view if that is wanted and it is not an archive
1355 (if (and gnus-uu-use-interactive-view
1356 (not (string= (or action "") "gnus-uu-archive")))
1357 (gnus-uu-enter-interactive-file (or action "") file-name)
1362 (if gnus-uu-ask-before-view
1364 (or (not (setq do-view
1366 (format "Do you want to view %s? "
1372 (if gnus-uu-asynchronous
1373 (gnus-uu-call-asynchronous file-name action)
1374 (gnus-uu-call-synchronous file-name action)))))
1376 (if (and (not dont-ask) (not gnus-uu-use-interactive-view))
1381 (and (string= action "gnus-uu-archive")
1385 (format "Could find no rule for %s" file-name))
1387 (and (or (not did-view) gnus-uu-view-and-save)
1389 (format "Do you want to save the file %s? "
1391 (gnus-uu-save-file file-name)))))
1393 (if (and (file-exists-p file-name)
1394 (not gnus-uu-use-interactive-view)
1396 (not (and gnus-uu-asynchronous did-view))
1397 (string= action "gnus-uu-archive")))
1398 (delete-file file-name)))
1402 (defun gnus-uu-get-action (file-name)
1405 (gnus-uu-choose-action
1408 (if (and gnus-uu-use-interactive-view
1409 gnus-uu-user-interactive-view-rules)
1410 gnus-uu-user-interactive-view-rules
1411 gnus-uu-user-view-rules)
1412 (if (or gnus-uu-ignore-default-view-rules
1413 (not gnus-uu-use-interactive-view))
1415 gnus-uu-default-interactive-view-rules-begin)
1416 (if gnus-uu-ignore-default-view-rules
1418 gnus-uu-default-view-rules)
1419 (if gnus-uu-use-interactive-view
1420 (append gnus-uu-user-interactive-view-rules-end
1421 (if gnus-uu-ignore-default-view-rules
1423 gnus-uu-default-interactive-view-rules-end))
1424 gnus-uu-user-view-rules-end))))
1425 (if (and (not (string= (or action "") "gnus-uu-archive"))
1426 gnus-uu-view-with-metamail)
1428 (gnus-uu-choose-action file-name gnus-uu-ext-to-mime-list))
1429 (setq action (format "metamail -d -b -c \"%s\"" action))))
1432 ; `gnus-uu-call-synchronous' takes two parameters: The name of the
1433 ; file to be displayed and the command to display it with. Returns t
1434 ; on success and nil if the file couldn't be displayed.
1435 (defun gnus-uu-call-synchronous (file-name action)
1436 (let (did-view command)
1438 (set-buffer (get-buffer-create gnus-uu-output-buffer-name))
1440 (setq command (gnus-uu-command action file-name))
1441 (message "Viewing with '%s'" command)
1442 (if (not (= 0 (call-process "sh" nil t nil "-c" command)))
1445 (while (re-search-forward "\n" nil t)
1446 (replace-match " "))
1447 (message (concat "Error: " (buffer-substring 1 (point-max))))
1453 ; `gnus-uu-call-asyncronous' takes two parameters: The name of the
1454 ; file to be displayed and the command to display it with. Since the
1455 ; view command is executed asynchronously, it's kinda hard to decide
1456 ; whether the command succeded or not, so this function always returns
1457 ; t. It also adds "; rm -f file-name" to the end of the execution
1458 ; string, so the file will be removed after viewing has ended.
1459 (defun gnus-uu-call-asynchronous (file-name action)
1460 (let (command file tmp-file start)
1461 (while (string-match "/" file-name start)
1462 (setq start (1+ (match-beginning 0))))
1463 (setq file (substring file-name start))
1464 (setq tmp-file (concat gnus-uu-work-dir file))
1465 (if (string= tmp-file file-name)
1467 (rename-file file-name tmp-file t)
1468 (setq file-name tmp-file))
1470 (setq command (gnus-uu-command action file-name))
1471 (setq command (format "%s ; rm -f %s" command file-name))
1472 (message "Viewing with %s" command)
1473 (start-process "gnus-uu-view" nil "sh" "-c" command)
1476 ; `gnus-uu-decode-and-strip' does all the main work. It finds out what
1477 ; articles to grab, grabs them, strips the result and decodes. If any
1478 ; of these operations fail, it returns nil, t otherwise. If shar is
1479 ; t, it will pass this on to `gnus-uu-grab-articles', which will
1480 ; (probably) unshar the articles. If use-marked is non-nil, it won't
1481 ; try to find articles, but use the marked list.
1482 (defun gnus-uu-decode-and-strip (&optional shar use-marked)
1483 (let (list-of-articles)
1487 (if (not gnus-uu-marked-article-list)
1488 (message "No articles marked")
1489 (setq list-of-articles (reverse gnus-uu-marked-article-list))
1490 (gnus-uu-unmark-all-articles))
1491 (setq list-of-articles (gnus-uu-get-list-of-articles)))
1493 (and list-of-articles
1494 (gnus-uu-grab-articles
1496 (if shar 'gnus-uu-unshar-article 'gnus-uu-uustrip-article-as)
1499 ; Takes a string and puts a \ in front of every special character;
1500 ; ignores any leading "version numbers" thingies that they use in the
1501 ; comp.binaries groups, and either replaces anything that looks like
1502 ; "2/3" with "[0-9]+/[0-9]+" or, if it can't find something like that,
1503 ; replaces the last two numbers with "[0-9]+". This, in my experience,
1504 ; should get most postings of a series."
1505 (defun gnus-uu-reginize-string (string)
1507 (vernum "v[0-9]+[a-z][0-9]+:")
1510 (set-buffer (get-buffer-create gnus-uu-output-buffer-name))
1512 (insert (regexp-quote string))
1515 (setq case-fold-search nil)
1517 (if (looking-at vernum)
1519 (replace-match vernum t t)
1520 (setq beg (length vernum))))
1523 (if (re-search-forward "[ \t]*[0-9]+/[0-9]+" nil t)
1524 (replace-match " [0-9]+/[0-9]+")
1527 (if (re-search-forward "[0-9]+[ \t]*of[ \t]*[0-9]+" nil t)
1528 (replace-match "[0-9]+ of [0-9]+")
1531 (while (and (re-search-backward "[0-9]" nil t) (> count 0))
1533 (looking-at "[0-9]")
1534 (< 1 (goto-char (1- (point))))))
1535 (re-search-forward "[0-9]+" nil t)
1536 (replace-match "[0-9]+")
1538 (setq count (1- count)))))
1541 (while (re-search-forward "[ \t]+" nil t)
1542 (replace-match "[ \t]*" t t))
1544 (buffer-substring 1 (point-max)))))
1546 ; Finds all articles that matches the regular expression given.
1547 ; Returns the resulting list. SUBJECT is the regular expression to be
1548 ; matched. If it is nil, the current article name will be used. If
1549 ; MARK-ARTICLES is non-nil, articles found are marked. If ONLY-UNREAD
1550 ; is non-nil, only unread articles are chose. If DO-NOT-TRANSLATE is
1551 ; non-nil, article names are not equialized before sorting.
1552 (defun gnus-uu-get-list-of-articles (&optional subject mark-articles only-unread do-not-translate)
1553 (let (beg end reg-subject list-of-subjects list-of-numbers art-num)
1556 ; If the subject is not given, this function looks at the current subject
1560 (setq reg-subject subject)
1564 (if (not (re-search-forward "\\] " end t))
1565 (progn (message "No valid subject chosen") (sit-for 2))
1566 (setq subject (buffer-substring (point) end))
1568 (concat "\\[.*\\] " (gnus-uu-reginize-string subject)))))
1570 ; (message reg-subject)(sleep-for 2)
1575 ; Collect all subjects matching reg-subject.
1577 (let ((case-fold-search t))
1579 (while (re-search-forward reg-subject nil t)
1582 (if (or (not only-unread) (looking-at " \\|-"))
1585 (setq list-of-subjects (cons
1586 (buffer-substring beg (point))
1590 ; Expand all numbers in all the subjects: (hi9 -> hi0009, etc).
1592 (setq list-of-subjects (gnus-uu-expand-numbers
1594 (not do-not-translate)))
1596 ; Sort the subjects.
1598 (setq list-of-subjects (sort list-of-subjects 'gnus-uu-string<))
1600 ; Get the article numbers from the sorted list of subjects.
1602 (while list-of-subjects
1603 (setq art-num (gnus-uu-article-number (car list-of-subjects)))
1604 (if mark-articles (gnus-summary-mark-as-read art-num ?#))
1605 (setq list-of-numbers (cons art-num list-of-numbers))
1606 (setq list-of-subjects (cdr list-of-subjects)))
1608 (setq list-of-numbers (nreverse list-of-numbers))))
1612 ; Takes a list of strings and "expands" all numbers in all the
1613 ; strings. That is, this function makes all numbers equal length by
1614 ; prepending lots of zeroes before each number. This is to ease later
1615 ; sorting to find out what sequence the articles are supposed to be
1616 ; decoded in. Returns the list of expanded strings.
1617 (defun gnus-uu-expand-numbers (string-list &optional translate)
1618 (let (string out-list pos num)
1620 (set-buffer (get-buffer-create gnus-uu-output-buffer-name))
1623 (setq string (car string-list))
1624 (setq string-list (cdr string-list))
1627 (while (re-search-forward "[ \t]+" nil t)
1628 (replace-match " "))
1631 (while (re-search-forward "[A-Za-z]" nil t)
1632 (replace-match "a" t t)))
1635 (if (not (search-forward "] " nil t))
1637 (while (re-search-forward "[0-9]+" nil t)
1640 (string-to-int (buffer-substring
1641 (match-beginning 0) (match-end 0))))))
1642 (setq string (buffer-substring 1 (point-max)))
1643 (setq out-list (cons string out-list)))))
1646 ; Used in a sort for finding out what string is bigger, but ignoring
1647 ; everything before the subject part.
1648 (defun gnus-uu-string< (string1 string2)
1649 (string< (substring string1 (string-match "\\] " string1))
1650 (substring string2 (string-match "\\] " string2))))
1653 ;; gnus-uu-grab-article
1655 ; This is the general multi-article treatment function. It takes a
1656 ; list of articles to be grabbed and a function to apply to each
1657 ; article. It puts the result in `gnus-uu-result-buffer'.
1659 ; The function to be called should take two parameters. The first
1660 ; parameter is the article buffer. The function should leave the
1661 ; result, if any, in this buffer. This result is then appended on to
1662 ; the `gnus-uu-result-buffer'. Most treatment functions will just
1665 ; The second parameter is the state of the list of articles, and can
1666 ; have four values: `first', `middle', `last' and `first-and-last'.
1668 ; The function should return a list. The list may contain the
1669 ; following symbols:
1670 ; `error' if an error occurred
1671 ; `begin' if the beginning of an encoded file has been received
1672 ; If the list returned contains a `begin', the first element of
1673 ; the list *must* be a string with the file name of the decoded
1675 ; `end' if the the end of an encoded file has been received
1676 ; `middle' if the article was a body part of an encoded file
1677 ; `wrong-type' if the article was not a part of an encoded file
1678 ; `ok', which can be used everything is ok
1680 (defvar gnus-uu-has-been-grabbed nil)
1682 (defun gnus-uu-unmark-list-of-grabbed (&optional dont-unmark-last-article)
1684 (if (not (and gnus-uu-has-been-grabbed
1685 gnus-uu-unmark-articles-not-decoded))
1687 (if dont-unmark-last-article
1689 (setq art (car gnus-uu-has-been-grabbed))
1690 (setq gnus-uu-has-been-grabbed (cdr gnus-uu-has-been-grabbed))))
1691 (while gnus-uu-has-been-grabbed
1692 (gnus-summary-mark-as-unread (car gnus-uu-has-been-grabbed) t)
1693 (setq gnus-uu-has-been-grabbed (cdr gnus-uu-has-been-grabbed)))
1694 (if dont-unmark-last-article
1695 (setq gnus-uu-has-been-grabbed (list art))))))
1698 ; This function takes a list of articles and a function to apply to
1699 ; each article grabbed. The result of the function is appended on to
1700 ; `gnus-uu-result-buffer'.
1702 ; This function returns a list of files decoded if the grabbing and
1703 ; the process-function has been successful and nil otherwise.
1704 (defun gnus-uu-grab-articles (list-of-articles process-function &optional sloppy)
1705 (let ((result-buffer (get-buffer-create gnus-uu-result-buffer))
1708 has-been-begin has-been-end
1709 article result-file result-files process-state)
1712 (set-buffer result-buffer)
1714 (setq gnus-uu-has-been-grabbed nil)
1716 (while (and list-of-articles
1717 (not (memq 'error process-state))
1719 (not (memq 'end process-state))))
1721 (setq article (car list-of-articles))
1722 (setq list-of-articles (cdr list-of-articles))
1723 (setq gnus-uu-has-been-grabbed (cons article gnus-uu-has-been-grabbed))
1725 (if (eq list-of-articles ())
1726 (if (eq state 'first)
1727 (setq state 'first-and-last)
1728 (setq state 'last)))
1730 (message "Getting article %d" article)
1731 (if (not (= (or gnus-current-article 0) article))
1732 (gnus-summary-display-article article))
1733 (gnus-summary-mark-as-read article)
1735 (save-excursion (set-buffer gnus-article-buffer) (widen))
1737 (setq process-state (funcall process-function gnus-article-buffer state))
1739 ; (message "process-state er %s" process-state)(sleep-for 3)
1741 (if (or (memq 'begin process-state)
1742 (and (or (eq state 'first) (eq state 'first-and-last))
1743 (memq 'ok process-state)))
1746 (if (file-exists-p result-file) (delete-file result-file)))
1747 (setq result-file (car process-state))
1748 (setq has-been-begin t)
1749 (setq has-been-end nil)))
1751 (if (memq 'end process-state)
1753 (setq gnus-uu-has-been-grabbed nil)
1754 (setq result-files (cons result-file result-files))
1755 (setq has-been-end t)
1756 (setq has-been-begin nil)))
1758 (if (not (memq 'wrong-type process-state))
1759 (setq wrong-type nil)
1760 (if gnus-uu-unmark-articles-not-decoded
1761 (gnus-summary-mark-as-unread article t)))
1763 (if sloppy (setq wrong-type nil))
1765 (if (and (not has-been-begin)
1767 (or (memq 'end process-state)
1768 (memq 'middle process-state)))
1770 (setq process-state (list 'error))
1771 (message "No begin part at the beginning")
1773 (setq state 'middle)))
1777 (if (not has-been-begin)
1778 (message "Wrong type file")
1779 (if (memq 'error process-state)
1780 (setq result-files nil)
1781 (if (not (or (memq 'ok process-state)
1782 (memq 'end process-state)))
1784 (message "End of articles reached before end of file")
1785 (setq result-files nil))
1786 (gnus-uu-unmark-list-of-grabbed)))))
1789 (defun gnus-uu-uudecode-sentinel (process event)
1790 (delete-process (get-process process)))
1792 ; Uudecodes a file asynchronously.
1793 (defun gnus-uu-uustrip-article-as (process-buffer in-state)
1794 (let ((state (list 'ok))
1795 (process-connection-type nil)
1796 start-char pst name-beg name-end)
1798 (set-buffer process-buffer)
1799 (let ((case-fold-search nil)
1800 (buffer-read-only nil))
1804 (if gnus-uu-kill-carriage-return
1806 (while (search-forward "\r" nil t)
1807 (delete-backward-char 1))
1810 (if (not (re-search-forward gnus-uu-begin-string nil t))
1811 (if (not (re-search-forward gnus-uu-body-line nil t))
1812 (setq state (list 'wrong-type))))
1814 (if (memq 'wrong-type state)
1817 (setq start-char (point))
1819 (if (looking-at gnus-uu-begin-string)
1821 (setq name-end (match-end 1))
1823 ; Replace any slashes and spaces in file names before decoding
1824 (goto-char (setq name-beg (match-beginning 1)))
1825 (while (re-search-forward "/" name-end t)
1826 (replace-match "-"))
1827 (goto-char name-beg)
1828 (while (re-search-forward " " name-end t)
1829 (replace-match "_"))
1831 (setq gnus-uu-file-name (buffer-substring name-beg name-end))
1832 (and gnus-uu-uudecode-process
1833 (setq pst (process-status
1834 (or gnus-uu-uudecode-process "nevair")))
1835 (if (or (eq pst 'stop) (eq pst 'run))
1837 (delete-process gnus-uu-uudecode-process)
1838 (gnus-uu-unmark-list-of-grabbed t))))
1839 (setq gnus-uu-uudecode-process
1842 (get-buffer-create gnus-uu-output-buffer-name)
1844 (format "cd %s ; uudecode" gnus-uu-work-dir)))
1845 (set-process-sentinel
1846 gnus-uu-uudecode-process 'gnus-uu-uudecode-sentinel)
1847 (setq state (list 'begin))
1848 (gnus-uu-add-file (concat gnus-uu-work-dir gnus-uu-file-name)))
1849 (setq state (list 'middle)))
1851 (goto-char (point-max))
1854 (concat gnus-uu-body-line "\\|" gnus-uu-end-string) nil t)
1857 (if (looking-at gnus-uu-end-string)
1858 (setq state (cons 'end state)))
1861 (and gnus-uu-uudecode-process
1862 (setq pst (process-status
1863 (or gnus-uu-uudecode-process "nevair")))
1864 (if (or (eq pst 'run) (eq pst 'stop))
1866 (if gnus-uu-correct-stripped-uucode
1868 (gnus-uu-check-correct-stripped-uucode
1870 (goto-char (point-max))
1872 (concat gnus-uu-body-line "\\|"
1877 (process-send-region gnus-uu-uudecode-process
1881 (message "gnus-uu: Couldn't uudecode")
1883 (setq state (list 'wrong-type))
1884 (delete-process gnus-uu-uudecode-process)))))
1885 (setq state (list 'wrong-type))))
1886 (if (not gnus-uu-uudecode-process)
1887 (setq state (list 'wrong-type)))))
1889 (if (memq 'begin state)
1890 (cons (concat gnus-uu-work-dir gnus-uu-file-name) state)
1893 ; This function is used by `gnus-uu-grab-articles' to treat
1895 (defun gnus-uu-unshar-article (process-buffer in-state)
1896 (let ((state (list 'ok))
1899 (set-buffer process-buffer)
1901 (if (not (re-search-forward gnus-uu-shar-begin-string nil t))
1902 (setq state (list 'wrong-type))
1904 (setq start-char (point))
1905 (call-process-region
1906 start-char (point-max) "sh" nil
1907 (get-buffer-create gnus-uu-output-buffer-name) nil
1908 "-c" (concat "cd " gnus-uu-shar-directory " ; sh"))))
1911 ; Returns the name of what the shar file is going to unpack.
1912 (defun gnus-uu-find-name-in-shar ()
1913 (let ((oldpoint (point))
1916 (if (re-search-forward gnus-uu-shar-name-marker nil t)
1917 (setq res (buffer-substring (match-beginning 1) (match-end 1))))
1918 (goto-char oldpoint)
1921 ; Returns the article number of the given subject.
1922 (defun gnus-uu-article-number (subject)
1924 (string-match "[0-9]+[^0-9]" subject 1)
1925 (setq end (match-end 0))
1927 (substring subject (string-match "[0-9]" subject 1) end))))
1929 ; `gnus-uu-choose-action' chooses what action to perform given the name
1930 ; and `gnus-uu-file-action-list'. Returns either nil if no action is
1931 ; found, or the name of the command to run if such a rule is found.
1932 (defun gnus-uu-choose-action (file-name file-action-list)
1933 (let ((action-list (copy-sequence file-action-list))
1935 (while (not (or (eq action-list ()) action))
1936 (setq rule (car action-list))
1937 (setq action-list (cdr action-list))
1938 (if (string-match (car rule) file-name)
1939 (setq action (car (cdr rule)))))
1942 (defun gnus-uu-save-directory (from-dir &optional default-dir ignore-existing)
1943 (let (dir file-name command files file)
1944 (setq files (directory-files from-dir t))
1946 (setq dir default-dir)
1947 (setq dir (gnus-uu-read-directory
1948 (concat "Where do you want the file"
1949 (if (< 3 (length files)) "s" "") "? "))))
1952 (setq file (car files))
1953 (setq files (cdr files))
1954 (string-match "/[^/]*$" file)
1955 (setq file-name (substring file (1+ (match-beginning 0))))
1956 (if (string-match "^\\.\\.?$" file-name)
1958 (if (and (not ignore-existing) (file-exists-p (concat dir file-name)))
1960 (read-file-name "File exists. Enter a new name: " dir
1961 (concat dir file-name) nil file-name))
1962 (setq file-name (concat dir file-name)))
1963 (rename-file file file-name t)))))
1965 ; Moves the file from the tmp directory to where the user wants it.
1966 (defun gnus-uu-save-file (from-file-name &optional default-dir ignore-existing)
1967 (let (dir file-name command)
1968 (string-match "/[^/]*$" from-file-name)
1969 (setq file-name (substring from-file-name (1+ (match-beginning 0))))
1971 (setq dir default-dir)
1972 (setq dir (gnus-uu-read-directory "Where do you want the file? ")))
1973 (if (and (not ignore-existing) (file-exists-p (concat dir file-name)))
1975 (read-file-name "File exist. Enter a new name: " dir
1976 (concat dir file-name) nil file-name))
1977 (setq file-name (concat dir file-name)))
1978 (rename-file from-file-name file-name t)))
1980 (defun gnus-uu-read-directory (prompt &optional default)
1981 (let (dir ok create)
1984 (setq dir (if default default
1985 (read-file-name prompt gnus-uu-current-save-dir
1986 gnus-uu-current-save-dir)))
1987 (while (string-match "/$" dir)
1988 (setq dir (substring dir 0 (match-beginning 0))))
1989 (if (file-exists-p dir)
1990 (if (not (file-directory-p dir))
1993 (message "%s is a file" dir)
1996 (while (not (or (= create ?y) (= create ?n)))
1997 (message "%s: No such directory. Do you want to create it? (y/n)"
1999 (setq create (read-char)))
2000 (if (= create ?y) (make-directory dir))))
2001 (setq gnus-uu-current-save-dir (concat dir "/"))))
2003 ; Unpacks an archive and views all the files in it. Returns t if
2004 ; viewing one or more files is successful.
2005 (defun gnus-uu-treat-archive (file-path)
2006 (let ((did-unpack t)
2007 action command files file file-name dir)
2008 (setq action (gnus-uu-choose-action
2009 file-path (append gnus-uu-user-archive-rules
2010 (if gnus-uu-ignore-default-archive-rules
2012 gnus-uu-default-archive-rules))))
2014 (if (not action) (error "No unpackers for the file %s" file-path))
2016 (string-match "/[^/]*$" file-path)
2017 (setq file-name (substring file-path (1+ (match-beginning 0))))
2018 (setq dir (substring file-path 0 (match-beginning 0)))
2020 (if (gnus-uu-string-in-list action gnus-uu-destructive-archivers)
2021 (copy-file file-path (concat file-path "~") t))
2023 (setq command (format "cd %s ; %s" dir (gnus-uu-command action file-path)))
2026 (set-buffer (get-buffer-create gnus-uu-output-buffer-name))
2029 (message "Unpacking: %s..." (gnus-uu-command action file-path))
2031 (if (= 0 (call-process "sh" nil
2032 (get-buffer-create gnus-uu-output-buffer-name)
2035 (message "Error during unpacking of archive")
2037 (setq did-unpack nil))
2039 (if (gnus-uu-string-in-list action gnus-uu-destructive-archivers)
2040 (rename-file (concat file-path "~") file-path t))
2044 ; Tries to view all the files in the given directory. Returns t if
2045 ; viewing one or more files is successful.
2046 (defun gnus-uu-view-directory (dir &optional dont-delete-files not-top)
2048 files file did-view ignore-files)
2049 (setq files (directory-files dir t "[^/][^\\.][^\\.]?$"))
2050 (gnus-uu-add-file files)
2051 (setq ignore-files files)
2053 (while (gnus-uu-unpack-archives
2054 files (if not-top (list ".")
2055 (if first () ignore-files)))
2058 (setq files (directory-files dir t "[^/][^\\.][^\\.]?$"))))
2061 (setq file (car files))
2062 (setq files (cdr files))
2063 (if (not (string= (or (gnus-uu-get-action file) "") "gnus-uu-archive"))
2065 (set-file-modes file 448)
2066 (if (file-directory-p file)
2067 (setq did-view (or (gnus-uu-view-directory file
2071 (setq did-view (or (gnus-uu-view-file file t) did-view)))))
2072 (if (and (not dont-delete-files) (file-exists-p file))
2073 (delete-file file)))
2075 (if (not dont-delete-files) (delete-directory dir))
2078 (defun gnus-uu-unpack-archives (files &optional ignore)
2079 (let (path did-unpack)
2081 (setq path (car files))
2082 (setq files (cdr files))
2083 (if (not (gnus-uu-string-in-list path ignore))
2084 (if (string= (or (gnus-uu-get-action
2085 (gnus-uu-name-from-path path)) "")
2089 (setq gnus-uu-error-during-unarching
2090 (not (gnus-uu-treat-archive path)))
2091 (if ignore (delete-file path))))))
2097 (defun gnus-uu-enter-mark-in-list ()
2103 (setq article (gnus-uu-article-number
2104 (buffer-substring beg (point))))
2105 (message "Adding article %d to list" article)
2106 (setq gnus-uu-marked-article-list
2107 (cons article gnus-uu-marked-article-list)))))
2109 (defun gnus-uu-mark-article (&optional dont-move)
2110 "Marks the current article to be decoded later."
2112 (gnus-uu-enter-mark-in-list)
2113 (gnus-summary-mark-as-read nil ?#)
2114 (gnus-summary-next-subject 1 nil))
2116 (defun gnus-uu-unmark-article ()
2117 "Unmarks the current article."
2119 (let ((in (copy-sequence gnus-uu-marked-article-list))
2120 out article beg found
2121 (old-point (point)))
2125 (setq article (gnus-uu-article-number (buffer-substring beg (point))))
2126 (message "Removing article %d" article)
2128 (if (not (= (car in) article))
2129 (setq out (cons (car in) out))
2131 (message "Removing article %d" article))
2133 (if (not found) (message "Not a marked article."))
2134 (setq gnus-uu-marked-article-list (reverse out))
2135 (gnus-summary-mark-as-unread nil t)
2136 (gnus-summary-next-subject 1 nil)))
2138 (defun gnus-uu-unmark-all-articles ()
2139 "Removes the mark from all articles marked for decoding."
2141 (while gnus-uu-marked-article-list
2142 (gnus-summary-goto-subject (car gnus-uu-marked-article-list))
2143 (gnus-summary-mark-as-unread nil t)
2144 (setq gnus-uu-marked-article-list (cdr gnus-uu-marked-article-list))))
2146 (defun gnus-uu-mark-by-regexp ()
2147 "Asks for a regular expression and marks all articles that match."
2150 (setq exp (read-from-minibuffer "Mark (regexp): "))
2151 (setq gnus-uu-marked-article-list
2152 (append gnus-uu-marked-article-list
2153 (reverse (gnus-uu-get-list-of-articles exp t))))
2156 (defun gnus-uu-mark-thread ()
2157 "Marks all articles downwards in this thread."
2161 (if (not (search-forward ":" nil t))
2163 (setq level (current-column))
2164 (gnus-uu-enter-mark-in-list)
2165 (gnus-summary-mark-as-read nil ?#)
2166 (gnus-summary-search-forward)
2167 (while (< level (current-column))
2168 (gnus-uu-enter-mark-in-list)
2169 (gnus-summary-mark-as-read nil ?#)
2170 (gnus-summary-search-forward))
2171 (gnus-summary-search-backward))))
2176 (defun gnus-uu-string-in-list (string list)
2178 (not (string= (car list) string))
2179 (setq list (cdr list))))
2182 (defun gnus-uu-name-from-path (path)
2183 (string-match "/[^/]*$" path)
2184 (substring path (1+ (match-beginning 0))))
2186 (defun gnus-uu-directory-files (dir)
2187 (let (files out file)
2188 (setq files (directory-files dir t))
2190 (setq file (car files))
2191 (setq files (cdr files))
2192 (if (not (string-match "/\\.\\.?$" file))
2193 (setq out (cons file out))))
2194 (setq out (reverse out))
2195 (message "dir-files %s er %s" dir out)(sleep-for 2)
2198 (defun gnus-uu-check-correct-stripped-uucode (start end)
2199 (let (found beg length short)
2200 (if (not gnus-uu-correct-stripped-uucode)
2204 (if (re-search-forward " \\|`" end t)
2209 (if (looking-at "\n") (replace-match ""))
2213 (if (looking-at (concat gnus-uu-begin-string "\\|"
2214 gnus-uu-end-string))
2221 (setq length (- (point) beg))))
2226 (if (not (= length (- (point) beg)))
2227 (insert (make-string (- length (- (point) beg)) ? ))))
2228 (forward-line 1))))))
2230 (defun gnus-uu-initialize ()
2231 (gnus-uu-check-for-generated-files)
2232 (setq gnus-uu-tmp-dir (expand-file-name gnus-uu-tmp-dir))
2233 (if (string-match "[^/]$" gnus-uu-tmp-dir)
2234 (setq gnus-uu-tmp-dir (concat gnus-uu-tmp-dir "/")))
2235 (if (not (file-directory-p gnus-uu-tmp-dir))
2236 (error "Temp directory %s doesn't exist" gnus-uu-tmp-dir)
2237 (if (not (file-writable-p gnus-uu-tmp-dir))
2238 (error "Temp directory %s can't be written to" gnus-uu-tmp-dir)))
2239 (setq gnus-uu-work-dir
2240 (concat gnus-uu-tmp-dir (make-temp-name "gnus")))
2241 (gnus-uu-add-file gnus-uu-work-dir)
2242 (if (not (file-directory-p gnus-uu-work-dir))
2243 (make-directory gnus-uu-work-dir))
2244 (setq gnus-uu-work-dir (concat gnus-uu-work-dir "/"))
2245 (setq gnus-uu-error-during-unarching nil)
2246 (setq gnus-uu-interactive-file-list nil))
2248 ; Kills the temporary uu buffers, kills any processes, etc.
2249 (defun gnus-uu-clean-up ()
2251 (and gnus-uu-uudecode-process
2252 (setq pst (process-status (or gnus-uu-uudecode-process "nevair")))
2253 (if (or (eq pst 'stop) (eq pst 'run))
2254 (delete-process gnus-uu-uudecode-process)))
2255 (and (not gnus-uu-asynchronous)
2256 (setq buf (get-buffer gnus-uu-output-buffer-name))
2258 (and (setq buf (get-buffer gnus-uu-result-buffer))
2259 (kill-buffer buf))))
2261 ; `gnus-uu-check-for-generated-files' deletes any generated files that
2262 ; hasn't been deleted, if, for instance, the user terminated decoding
2264 (defun gnus-uu-check-for-generated-files ()
2266 (while gnus-uu-generated-file-list
2267 (setq file (car gnus-uu-generated-file-list))
2268 (setq gnus-uu-generated-file-list (cdr gnus-uu-generated-file-list))
2269 (if (not (string-match "/\\.[\\.]?$" file))
2271 (if (file-directory-p file)
2272 (setq dirs (cons file dirs))
2273 (if (file-exists-p file)
2274 (delete-file file))))))
2275 (setq dirs (nreverse dirs))
2277 (setq file (car dirs))
2278 (setq dirs (cdr dirs))
2279 (if (file-directory-p file)
2280 (delete-directory file)))))
2282 ; Add a file (or a list of files) to be checked (and deleted if it/they
2283 ; still exists upon exiting the newsgroup).
2284 (defun gnus-uu-add-file (file)
2286 (setq gnus-uu-generated-file-list
2287 (cons file gnus-uu-generated-file-list))
2288 (setq gnus-uu-generated-file-list
2289 (append file gnus-uu-generated-file-list))))
2291 ; Go to the next unread subject. If there is no further unread
2292 ; subjects, go to the last subject in the buffer.
2293 (defun gnus-uu-summary-next-subject ()
2295 (if (not (gnus-summary-search-forward t))
2299 (goto-char (point-max))
2302 (search-forward ":" nil t)))
2304 ; You may well find all this a bit puzzling - so do I, but I seem
2305 ; to have to do something like this to move to the next unread article,
2306 ; as `sit-for' seems to do some rather strange things here. Might
2307 ; be a bug in my head, probably.
2311 (gnus-summary-recenter)))
2313 ; Inputs an action and a file and returns a full command, putting
2314 ; ticks round the file name and escaping any ticks in the file name.
2315 (defun gnus-uu-command (action file)
2317 (while (string-match "`\\|\"\\|\\$\\|\\\\" file)
2320 (concat ofile (substring file 0 (match-beginning 0)) "\\"
2321 (substring file (match-beginning 0) (match-end 0))))
2322 (setq file (substring file (1+ (match-beginning 0))))))
2323 (setq ofile (concat "\"" ofile file "\""))
2324 (if (string-match "%s" action)
2325 (format action ofile)
2326 (concat action " " ofile))))
2330 (add-hook 'gnus-exit-group-hook
2333 (setq gnus-uu-marked-article-list nil)
2334 (gnus-uu-check-for-generated-files)))
2337 ;; Interactive exec mode
2339 (defvar gnus-uu-output-window nil)
2340 (defvar gnus-uu-mode-hook nil)
2341 (defvar gnus-uu-mode-map nil)
2343 (defun gnus-uu-do-interactive ()
2344 (let (int-buffer out-buf)
2346 (setq int-buffer (get-buffer gnus-uu-interactive-buffer-name)))
2347 (switch-to-buffer-other-window int-buffer)
2348 (pop-to-buffer int-buffer)
2349 (setq gnus-uu-output-window
2350 (split-window nil (- (window-height) gnus-uu-output-window-height)))
2351 (set-window-buffer gnus-uu-output-window
2353 (get-buffer-create gnus-uu-output-buffer-name)))
2354 (save-excursion (set-buffer out-buf) (erase-buffer))
2357 (run-hooks 'gnus-uu-mode-hook)))
2359 (defun gnus-uu-enter-interactive-file (action file)
2362 (set-buffer (get-buffer-create gnus-uu-interactive-buffer-name))
2363 (if (not gnus-uu-interactive-file-list)
2368 "# Press return to execute a command.
2369 # Press `C-c C-c' to exit interactive view.
2372 (setq gnus-uu-interactive-file-list
2373 (cons file gnus-uu-interactive-file-list))
2374 (setq command (gnus-uu-command action file))
2375 (insert (format "%s\n" command)))))
2377 (defun gnus-uu-interactive-execute ()
2378 "Executes the command on the current line in interactive mode."
2380 (let (beg out-buf command)
2384 (setq command (buffer-substring beg (point)))
2385 (setq out-buf (get-buffer-create gnus-uu-output-buffer-name))
2387 (set-buffer out-buf)
2389 (insert (format "$ %s \n\n" command)))
2390 (message "Executing...")
2391 (if gnus-uu-asynchronous
2392 (start-process "gnus-uu-view" out-buf "sh" "-c" command)
2393 (call-process "sh" nil out-buf nil "-c" command)
2396 (beginning-of-line)))
2398 (defun gnus-uu-interactive-end ()
2399 "This function exits interactive view mode and returns to summary mode."
2402 (delete-window gnus-uu-output-window)
2404 (if (not gnus-uu-asynchronous) (gnus-uu-check-for-generated-files))
2405 (setq buf (get-buffer gnus-uu-interactive-buffer-name))
2406 (if gnus-article-buffer (switch-to-buffer gnus-article-buffer))
2407 (if buf (kill-buffer buf))
2408 (pop-to-buffer gnus-summary-buffer)))
2410 (if gnus-uu-mode-map
2412 (setq gnus-uu-mode-map (make-sparse-keymap))
2413 (define-key gnus-uu-mode-map "\C-c\C-x" 'gnus-uu-interactive-execute)
2414 (define-key gnus-uu-mode-map "\C-c\C-v" 'gnus-uu-interactive-execute)
2415 (define-key gnus-uu-mode-map "\C-m" 'gnus-uu-interactive-execute)
2416 (define-key gnus-uu-mode-map "\C-c\C-c" 'gnus-uu-interactive-end)
2417 (define-key gnus-uu-mode-map "\C-cs"
2418 'gnus-uu-interactive-save-current-file)
2419 (define-key gnus-uu-mode-map "\C-c\C-s"
2420 'gnus-uu-interactive-save-current-file-silent)
2421 (define-key gnus-uu-mode-map "\C-c\C-w" 'gnus-uu-interactive-save-all-files)
2422 (define-key gnus-uu-mode-map "\C-c\C-o" 'gnus-uu-interactive-save-original-file))
2424 (defun gnus-uu-interactive-save-original-file ()
2425 "Saves the file from whence the file on the current line came from."
2429 (setq file (concat gnus-uu-work-dir
2430 (or gnus-uu-file-name gnus-uu-shar-file-name))))
2432 (gnus-uu-save-file file)
2433 (message "Saved file %s"
2434 (or gnus-uu-file-name gnus-uu-shar-file-name)))
2435 (message "Already saved."))))
2437 (defun gnus-uu-interactive-save-current-file-silent ()
2438 "Saves the file referred to on the current line in the current directory."
2440 (gnus-uu-interactive-save-current-file t))
2442 (defun gnus-uu-interactive-save-current-file (&optional dont-ask silent)
2443 "Saves the file referred to on the current line."
2445 (let (files beg line file)
2446 (setq files (copy-sequence gnus-uu-interactive-file-list))
2450 (setq line (buffer-substring beg (point)))
2453 (concat "" (regexp-quote (setq file (car files))) "")
2455 (setq files (cdr files)))
2460 (progn (message "Could not find file") (sit-for 2)))
2461 (gnus-uu-save-file file (if dont-ask gnus-uu-current-save-dir nil) silent)
2462 (delete-region beg (point)))))
2464 (defun gnus-uu-interactive-save-all-files ()
2465 "Saves all files referred to in the interactive buffer."
2469 (setq dir (gnus-uu-read-directory "Where do you want the files? "))
2471 (gnus-uu-interactive-save-current-file t t))))
2473 (defun gnus-uu-mode ()
2474 "Major mode for editing view commands in gnus-uu.
2477 \\<gnus-uu-mode-map>Return, C-c C-v, C-c C-x Execute the current command
2478 \\[gnus-uu-interactive-end] End interactive mode
2479 \\[gnus-uu-interactive-save-current-file] Save the current file
2480 \\[gnus-uu-interactive-save-current-file-silent] Save the current file without asking
2482 \\[gnus-uu-interactive-save-all-files] Save all files
2483 \\[gnus-uu-interactive-save-original-file] Save the original file: If the files
2484 originated in an archive, the archive
2488 (kill-all-local-variables)
2489 (use-local-map gnus-uu-mode-map)
2490 (setq mode-name "gnus-uu")
2491 (setq major-mode 'gnus-uu-mode)
2494 (define-key gnus-uu-mode-map "\C-c\C-x" 'gnus-uu-interactive-execute)
2495 (define-key gnus-uu-mode-map "\C-c\C-v" 'gnus-uu-interactive-execute)
2496 (define-key gnus-uu-mode-map "\C-m" 'gnus-uu-interactive-execute)
2497 (define-key gnus-uu-mode-map "\C-c\C-c" 'gnus-uu-interactive-end)
2498 (define-key gnus-uu-mode-map "\C-cs"
2499 'gnus-uu-interactive-save-current-file)
2500 (define-key gnus-uu-mode-map "\C-c\C-s"
2501 'gnus-uu-interactive-save-current-file-silent)
2502 (define-key gnus-uu-mode-map "\C-c\C-a" 'gnus-uu-interactive-save-all-files)
2503 (define-key gnus-uu-mode-map "\C-c\C-o" 'gnus-uu-interactive-save-original-file)
2506 ;; Major mode for posting encoded articles.
2511 ; Any function that is to be used as and encoding method will take two
2512 ; parameters: PATH-NAME and FILE-NAME. (E.g. "/home/gaga/spiral.jpg"
2513 ; and "spiral.jpg", respectively.) The function should return nil if
2514 ; the encoding wasn't successful.
2515 (defvar gnus-uu-post-encode-method 'gnus-uu-post-encode-uuencode
2516 "Function used for encoding binary files.
2517 There are three functions supplied with gnus-uu for encoding files:
2518 `gnus-uu-post-encode-uuencode', which does straight uuencoding;
2519 `gnus-uu-post-encode-mime', which encodes with base64 and adds MIME
2520 headers; and `gnus-uu-post-encode-mime-uuencode', which encodes with
2521 uuencode and adds MIME headers.")
2523 (defvar gnus-uu-post-include-before-composing nil
2524 "Non-nil means that gnus-uu will ask for a file to encode before you compose the article.
2525 If this variable is t, you can either include an encoded file with
2526 \\<gnus-uu-post-reply-mode-map>\\[gnus-uu-post-insert-binary-in-article] or have one included for you when you post the article.")
2528 (defvar gnus-uu-post-length 990
2529 "Maximum length of an article.
2530 The encoded file will be split into how many articles it takes to
2531 post the entire file.")
2533 (defvar gnus-uu-post-threaded nil
2534 "Non-nil means that gnus-uu will post the encoded file in a thread.
2535 This may not be smart, as no other decoder I have seen are able to
2536 follow threads when collecting uuencoded articles. (Well, I have seen
2537 one package that does that - gnus-uu, but somehow, I don't think that
2538 counts...) Default is nil.")
2540 (defvar gnus-uu-post-separate-description t
2541 "Non-nil means that the description will be posted in a separate article.
2542 The first article will typically be numbered (0/x). If this variable
2543 is nil, the description the user enters will be included at the
2544 beginning of the first article, which will be numbered (1/x). Default
2547 (defconst gnus-uu-post-binary-separator "--binary follows this line--")
2548 (defvar gnus-uu-post-message-id nil)
2549 (defvar gnus-uu-post-inserted-file-name nil)
2550 (defvar gnus-uu-winconf-post-news nil)
2552 ; The following map and mode was taken from rnewspost.el and edited
2554 (defvar gnus-uu-post-reply-mode-map () "Mode map used by gnus-uu-post-reply.")
2555 (or gnus-uu-post-reply-mode-map
2557 (setq gnus-uu-post-reply-mode-map (make-keymap))
2558 (define-key gnus-uu-post-reply-mode-map "\C-c?" 'describe-mode)
2559 (define-key gnus-uu-post-reply-mode-map "\C-c\C-f\C-d"
2560 'news-reply-distribution)
2561 (define-key gnus-uu-post-reply-mode-map "\C-c\C-f\C-k"
2562 'news-reply-keywords)
2563 (define-key gnus-uu-post-reply-mode-map "\C-c\C-f\C-n"
2564 'news-reply-newsgroups)
2566 (define-key gnus-uu-post-reply-mode-map "\C-c\C-f\C-f"
2567 'news-reply-followup-to)
2568 (define-key gnus-uu-post-reply-mode-map "\C-c\C-f\C-s" 'mail-subject)
2569 (define-key gnus-uu-post-reply-mode-map "\C-c\C-f\C-a"
2570 'gnus-uu-post-reply-summary)
2571 (define-key gnus-uu-post-reply-mode-map "\C-c\C-r"
2572 'news-caesar-buffer-body)
2573 (define-key gnus-uu-post-reply-mode-map "\C-c\C-w" 'news-reply-signature)
2574 (define-key gnus-uu-post-reply-mode-map "\C-c\C-y"
2575 'news-reply-yank-original)
2576 (define-key gnus-uu-post-reply-mode-map "\C-c\C-q"
2577 'mail-fill-yanked-message)
2578 (define-key gnus-uu-post-reply-mode-map "\C-c\C-c"
2579 'gnus-uu-post-news-inews)
2580 (define-key gnus-uu-post-reply-mode-map "\C-c\C-s"
2581 'gnus-uu-post-news-inews)
2582 (define-key gnus-uu-post-reply-mode-map "\C-c\C-i"
2583 'gnus-uu-post-insert-binary-in-article)
2586 ; This mode was taken from rnewspost.el and modified slightly.
2587 (defun gnus-uu-post-reply-mode ()
2588 "Major mode for editing binary news to be posted on USENET.
2589 First-time posters are asked to please read the articles in newsgroup:
2590 news.announce.newusers .
2592 Like news-reply-mode, which is like Text Mode, but with these
2593 additional commands:
2595 \\<gnus-uu-post-reply-mode-map>\\[gnus-uu-post-news-inews] post the message.
2596 C-c C-f move to a header field (and create it if there isn't):
2597 C-c C-f C-n move to Newsgroups: C-c C-f C-s move to Subj:
2598 C-c C-f C-f move to Followup-To: C-c C-f C-k move to Keywords:
2599 C-c C-f C-d move to Distribution: C-c C-f C-a move to Summary:
2600 C-c C-y news-reply-yank-original (insert current message, in NEWS).
2601 C-c C-q mail-fill-yanked-message (fill what was yanked).
2602 C-c C-r caesar rotate all letters by 13 places in the article's body (rot13).
2603 \\[gnus-uu-post-insert-binary-in-article] encode and include a file in this article.
2605 This mode is almost identical to news-reply-mode, but has some
2606 additional commands for treating encoded binary articles. In
2607 particular, \\[gnus-uu-post-news-inews] will ask for a file to include, if
2608 one hasn't been included already. It will post, first, the message
2609 composed, and then it will post as many additional articles it takes
2610 to post the entire encoded files.
2614 `gnus-uu-post-encode-method'
2615 There are three functions supplied with gnus-uu for encoding files:
2616 `gnus-uu-post-encode-uuencode', which does straight uuencoding;
2617 `gnus-uu-post-encode-mime', which encodes with base64 and adds MIME
2618 headers; and `gnus-uu-post-encode-mime-uuencode', which encodes with
2619 uuencode and adds MIME headers.
2621 `gnus-uu-post-include-before-composing'
2622 Non-nil means that gnus-uu will ask for a file to encode before you
2623 compose the article. If this variable is t, you can either include
2624 an encoded file with `C-c C-i' or have one included for you when you
2627 `gnus-uu-post-length'
2628 Maximum length of an article. The encoded file will be split into how
2629 many articles it takes to post the entire file.
2631 `gnus-uu-post-separate-description'
2632 Non-nil means that the description will be posted in a separate
2633 article. The first article will typically be numbered (0/x). If
2634 this variable is nil, the description the user enters will be
2635 included at the beginning of the first article, which will be
2636 numbered (1/x). Default is t.
2638 `gnus-uu-post-threaded'
2639 Non-nil means that gnus-uu will post the encoded file in a thread.
2640 This may not be smart, as no other decoder I have seen are able to
2641 follow threads when collecting uuencoded articles. (Well, I have seen
2642 one package that does that - gnus-uu, but somehow, I don't think that
2643 counts...) Default is nil.
2647 (or (fboundp 'mail-setup) (load "sendmail"))
2648 (kill-all-local-variables)
2649 (make-local-variable 'mail-reply-buffer)
2650 (setq mail-reply-buffer nil)
2651 (set-syntax-table text-mode-syntax-table)
2652 (use-local-map gnus-uu-post-reply-mode-map)
2653 (setq local-abbrev-table text-mode-abbrev-table)
2654 (setq major-mode 'gnus-uu-post-reply-mode)
2655 (setq mode-name "Gnus UU News")
2656 (make-local-variable 'paragraph-separate)
2657 (make-local-variable 'paragraph-start)
2658 (setq paragraph-start (concat "^" mail-header-separator "$\\|"
2660 (setq paragraph-separate (concat "^" mail-header-separator "$\\|"
2661 paragraph-separate))
2662 (run-hooks 'text-mode-hook 'gnus-uu-post-reply-mode-hook))
2664 (defun gnus-uu-post-news ()
2665 "Compose an article and post an encoded file."
2667 (setq gnus-uu-post-inserted-file-name nil)
2668 (setq gnus-uu-winconf-post-news (current-window-configuration))
2669 (let (news-reply-mode)
2670 (fset 'news-reply-mode 'gnus-uu-post-reply-mode)
2671 (gnus-summary-post-news)
2672 (if gnus-uu-post-include-before-composing
2673 (save-excursion (setq gnus-uu-post-inserted-file-name
2674 (gnus-uu-post-insert-binary))))))
2676 (defun gnus-uu-post-insert-binary-in-article ()
2677 "Inserts an encoded file in the buffer.
2678 The user will be asked for a file name."
2680 (if (not (eq (current-buffer) (get-buffer gnus-post-news-buffer)))
2681 (error "Not in post-news buffer"))
2683 (setq gnus-uu-post-inserted-file-name (gnus-uu-post-insert-binary))))
2685 ; Encodes with uuencode and substitutes all spaces with backticks.
2686 (defun gnus-uu-post-encode-uuencode (path file-name)
2687 (if (gnus-uu-post-encode-file "uuencode" path file-name)
2691 (while (re-search-forward " " nil t)
2692 (replace-match "`"))
2695 ; Encodes with uuencode and adds MIME headers.
2696 (defun gnus-uu-post-encode-mime-uuencode (path file-name)
2697 (if (gnus-uu-post-encode-uuencode path file-name)
2699 (gnus-uu-post-make-mime file-name "x-uue")
2702 ; Encodes with base64 and adds MIME headers
2703 (defun gnus-uu-post-encode-mime (path file-name)
2704 (if (gnus-uu-post-encode-file "mmencode" path file-name)
2706 (gnus-uu-post-make-mime file-name "base64")
2709 ; Adds MIME headers.
2710 (defun gnus-uu-post-make-mime (file-name encoding)
2712 (insert (format "Content-Type: %s; name=\"%s\"\n"
2713 (gnus-uu-choose-action file-name gnus-uu-ext-to-mime-list)
2715 (insert (format "Content-Transfer-Encoding: %s\n\n" encoding))
2717 (set-buffer gnus-post-news-buffer)
2719 (re-search-forward mail-header-separator)
2722 (narrow-to-region 1 (point))
2723 (or (mail-fetch-field "mime-version")
2726 (insert "MIME-Version: 1.0\n")))
2729 ; Encodes a file PATH with COMMAND, leaving the result in the
2731 (defun gnus-uu-post-encode-file (command path file-name)
2732 (= 0 (call-process "sh" nil t nil "-c"
2733 (format "%s %s %s" command path file-name))))
2735 (defun gnus-uu-post-news-inews ()
2736 "Posts the composed news article and encoded file.
2737 If no file has been included, the user will be asked for a file."
2739 (if (not (eq (current-buffer) (get-buffer gnus-post-news-buffer)))
2740 (error "Not in post news buffer"))
2744 (if gnus-uu-post-inserted-file-name
2745 (setq file-name gnus-uu-post-inserted-file-name)
2746 (setq file-name (gnus-uu-post-insert-binary)))
2748 (if gnus-uu-post-threaded
2749 (let ((gnus-required-headers
2750 (if (memq 'Message-ID gnus-required-headers)
2751 gnus-required-headers
2752 (cons 'Message-ID gnus-required-headers)))
2753 gnus-inews-article-hook elem)
2755 (setq gnus-inews-article-hook (if (listp gnus-inews-article-hook)
2756 gnus-inews-article-hook
2757 (list gnus-inews-article-hook)))
2758 (setq gnus-inews-article-hook
2763 (if (re-search-forward "^Message-ID: \\(.*\\)$" nil t)
2764 (setq gnus-uu-post-message-id
2766 (match-beginning 1) (match-end 1)))
2767 (setq gnus-uu-post-message-id nil))))
2768 gnus-inews-article-hook))
2769 (gnus-uu-post-encoded file-name t))
2770 (gnus-uu-post-encoded file-name nil)))
2771 (setq gnus-uu-post-inserted-file-name nil)
2772 (and gnus-uu-winconf-post-news
2773 (set-window-configuration gnus-uu-winconf-post-news)))
2775 ; Asks for a file to encode, encodes it and inserts the result in
2776 ; the current buffer. Returns the file name the user gave.
2777 (defun gnus-uu-post-insert-binary ()
2778 (let ((uuencode-buffer-name "*uuencode buffer*")
2779 file-path post-buf uubuf file-name)
2781 (setq file-path (read-file-name
2782 "What file do you want to encode? "))
2783 (if (not (file-exists-p file-path))
2784 (error "%s: No such file" file-path))
2786 (goto-char (point-max))
2787 (insert (format "\n%s\n" gnus-uu-post-binary-separator))
2789 (if (string-match "^~/" file-path)
2790 (setq file-path (concat "$HOME" (substring file-path 1))))
2791 (if (string-match "/[^/]*$" file-path)
2792 (setq file-name (substring file-path (1+ (match-beginning 0))))
2793 (setq file-name file-path))
2797 (set-buffer (setq uubuf
2798 (get-buffer-create uuencode-buffer-name)))
2800 (funcall gnus-uu-post-encode-method file-path file-name))
2801 (insert-buffer uubuf)
2802 (error "Encoding unsuccessful"))
2803 (kill-buffer uubuf))
2806 ; Posts the article and all of the encoded file.
2807 (defun gnus-uu-post-encoded (file-name &optional threaded)
2808 (let ((send-buffer-name "*uuencode send buffer*")
2809 (encoded-buffer-name "*encoded buffer*")
2810 (top-string "[ cut here %s (%s %d/%d) %s gnus-uu ]")
2811 (separator (concat mail-header-separator "\n\n"))
2812 file uubuf length parts header i end beg
2813 beg-line minlen buf post-buf whole-len beg-binary end-binary)
2815 (setq post-buf (current-buffer))
2818 (if (not (re-search-forward
2819 (if gnus-uu-post-separate-description
2820 gnus-uu-post-binary-separator
2821 mail-header-separator) nil t))
2822 (error "Internal error: No binary/header separator"))
2825 (setq beg-binary (point))
2826 (setq end-binary (point-max))
2829 (set-buffer (setq uubuf (get-buffer-create encoded-buffer-name)))
2831 (insert-buffer-substring post-buf beg-binary end-binary)
2833 (setq length (count-lines 1 (point-max)))
2834 (setq parts (/ length gnus-uu-post-length))
2835 (if (not (< (% length gnus-uu-post-length) 4))
2836 (setq parts (1+ parts))))
2838 (if gnus-uu-post-separate-description
2840 (kill-region (point) (point-max))
2843 (search-forward mail-header-separator nil t)
2845 (setq header (buffer-substring 1 (point)))
2848 (if (not gnus-uu-post-separate-description)
2850 (if (and (not threaded) (re-search-forward "^Subject: " nil t))
2853 (insert (format " (0/%d)" parts))))
2859 (while (not (> i parts))
2860 (set-buffer (get-buffer-create send-buffer-name))
2863 (if (and threaded gnus-uu-post-message-id)
2864 (insert (format "References: %s\n" gnus-uu-post-message-id)))
2867 (- 62 (length (format top-string "" file-name i parts ""))))
2868 (if (> 1 (setq minlen (/ whole-len 2)))
2873 (make-string minlen ?-)
2876 (if (= 0 (% whole-len 2)) (1- minlen) minlen) ?-)))
2879 (if (not (re-search-forward "^Subject: " nil t))
2884 (insert (format " (%d/%d)" i parts)))
2885 (if (or (and (= i 2) gnus-uu-post-separate-description)
2886 (and (= i 1) (not gnus-uu-post-separate-description)))
2887 (replace-match "Subject: Re: "))))
2889 (goto-char (point-max))
2894 (goto-char (point-max))
2895 (forward-line gnus-uu-post-length))
2897 (insert-buffer-substring uubuf beg end)
2903 (re-search-forward mail-header-separator nil t)
2906 (if (re-search-forward gnus-uu-post-binary-separator nil t)
2914 (and (setq buf (get-buffer send-buffer-name))
2916 (and (setq buf (get-buffer encoded-buffer-name))
2919 (if (not gnus-uu-post-separate-description)
2921 (set-buffer-modified-p nil)
2922 (and (fboundp 'bury-buffer) (bury-buffer))))))
2926 ;; gnus-uu.el ends here