(redisplay): Limit prev change to pause != 0.
[bpt/emacs.git] / lisp / gnus-uu.el
CommitLineData
f919f65c 1;;; gnus-uu.el --- extract, view or save (uu)encoded files from gnus
e399bdd5
RS
2;; Copyright (C) 1985, 1986, 1987, 1993, 1994 Free Software Foundation, Inc.
3
f919f65c
RS
4;; Author: Lars Ingebrigtsen <larsi@ifi.uio.no>
5;; Created: 2 Oct 1993
ccfd5a00
RS
6;; Version: v2.7.2
7;; Last Modified: 1994/05/03
e399bdd5
RS
8;; Keyword: news
9
10;; This file is part of GNU Emacs.
11
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)
15;; any later version.
16
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.
21
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.
25
26;;; Commentary:
27
f919f65c
RS
28;; All gnus-uu commands start with `C-c C-v'.
29;;
ccfd5a00 30;; Short user manual for this package:
f919f65c 31;;
ccfd5a00
RS
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.
f919f65c 34;;
ccfd5a00
RS
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.
f919f65c 38;;
ccfd5a00
RS
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.
f919f65c 43;;
ccfd5a00
RS
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.
47;;
f919f65c
RS
48;;
49;;
50;; History
51;;
52;; v1.0: First version released Oct 2 1992.
53;;
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.
57;;
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.
66;;
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
70;; gnu.emacs.sources.
71;;
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.
76;;
0822af61
RS
77;; v2.5: First version copyrighted by FSF. Changed lots of
78;; documentation strings.
f919f65c 79;;
0822af61
RS
80;; v2.5.1: Added uuencode/posting code to post binary files.
81;;
ccfd5a00
RS
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.
0822af61 86;;
ccfd5a00
RS
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.
f919f65c 91;;
ccfd5a00
RS
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...
f919f65c 95;;
ccfd5a00
RS
96;; V2.7.2: New functions for digesting and forwarding articles added
97;; on the suggestion of Per Abrahamsen. Also added a function for
98;; marking threads.
f919f65c 99
e399bdd5
RS
100;;; Code:
101
f919f65c 102(require 'gnus)
0822af61 103(require 'gnuspost)
f919f65c
RS
104
105;; Binding of keys to the gnus-uu functions.
106
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)
110
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)
117
118(define-key gnus-uu-ctl-map "\C-b" 'gnus-uu-decode-and-show-in-buffer)
119
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)
ccfd5a00
RS
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)
f919f65c
RS
126
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)
133
ccfd5a00
RS
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)
136
f919f65c
RS
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)
139
140(define-key gnus-uu-ctl-map "\C-l" 'gnus-uu-edit-begin-line)
141
ccfd5a00
RS
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)
f919f65c 146
ccfd5a00
RS
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)
151
152(define-key gnus-uu-ctl-map "p" 'gnus-uu-post-news)
f919f65c 153
0822af61
RS
154;; Dummy function gnus-uu
155
156(defun gnus-uu ()
157 "gnus-uu is a package for uudecoding and viewing articles.
158
ccfd5a00
RS
159
160Keymap overview:
161
0822af61
RS
162By default, all gnus-uu keystrokes begin with `C-c C-v'.
163
164There four decoding commands categories:
165All commands for viewing are `C-c C-v C-LETTER'.
166All commands for saving are `C-c C-v LETTER'.
167All commands for marked viewing are `C-c C-v C-M-LETTER'.
168All commands for marked saving are `C-c C-v M-LETTER'.
169
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
176
ccfd5a00
RS
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
179
0822af61
RS
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
182
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
ccfd5a00
RS
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
187
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
0822af61
RS
190
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
ccfd5a00 195\\[gnus-uu-mark-thread]\tMark articles in this thread
0822af61
RS
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
202
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
ccfd5a00
RS
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
0822af61
RS
210\\[gnus-uu-toggle-any-variable]\tToggle any of the things above
211
ccfd5a00
RS
212\\[gnus-uu-post-news]\tPost an uuencoded article
213
214Function description:
215
216`gnus-uu-decode-and-view' will try to find all articles in the same
217series, uudecode them and view the resulting file(s).
218
219gnus-uu guesses what articles are in the series according to the
220following simplish rule: The subjects must be (nearly) identical,
221except for the last two numbers of the line. (Spaces are largely
222ignored, however.)
223
224For example: If you choose a subject called
225 \"cat.gif (2/3)\"
226gnus-uu will find all the articles that matches
227 \"^cat.gif ([0-9]+/[0-9]+).*$\".
228
229Subjects that are nonstandard, like
230 \"cat.gif (2/3) Part 6 of a series\",
231will not be properly recognized by any of the automatic viewing
232commands, and you have to mark the articles manually with '#'.
233
234`gnus-uu-decode-and-save' will do the same as
235`gnus-uu-decode-and-view', except that it will not display the
236resulting file, but save it instead.
237
238`gnus-uu-shar-and-view' and `gnus-uu-shar-and-save' are the \"shar\"
239equivalents to the uudecode functions. Instead of feeding the articles
240to uudecode, they are run through /bin/sh. Most shar files can be
241viewed and/or saved with the normal uudecode commands, which is much
242safer, as no foreign code is run.
243
244Instead of having windows popping up automatically, it can be handy to
245view files interactivly, especially when viewing archives. Use
246`gnus-uu-toggle-interactive-mode' to toggle interactive mode.
247
248`gnus-uu-mark-article' marks an article for later
249decoding/unsharing/saving/viewing. The files will be decoded in the
250sequence they were marked. To decode the files after you've marked the
251articles you are interested in, type the corresponding key strokes as
252the normal decoding commands, but put a `M-' in the last
253keystroke. For instance, to perform a standard uudecode and view, you
254would 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
256same way; marked uudecode and save is then `C-c C-v M-v'.
257
258`gnus-uu-unmark-article' will remove the mark from a previosly marked
259article.
260
261`gnus-uu-unmark-all-articles' will remove the mark from all marked
262articles.
263
264`gnus-uu-mark-by-regexp' will prompt for a regular expression and mark
265all articles matching that regular expression.
266
267`gnus-uu-mark-thread' will mark all articles downward in the current
268thread.
269
270There's an additional way to reach the decoding functions to make
271future expansions easier: `gnus-uu-multi-decode-and-view' and the
272corresponding save, marked view and marked save functions. You will be
273prompted for a decoding method, like uudecode, shar, binhex or plain
274save. Note that methods like binhex and save doesn't have view modes;
275even if you issue a view command (`C-c C-v C-m' and \"binhex\"),
276gnus-uu will just save the resulting binhex file.
277
278`gnus-uu-decode-and-show-in-buffer' will decode the current article
279and display the results in an emacs buffer. This might be useful if
280there's jsut some text in the current article that has been uuencoded
281by some perverse poster.
282
283`gnus-uu-decode-and-save-all-articles' looks at all the articles in
284the current newsgroup and tries to uudecode everything it can
285find. The user will be prompted for a directory where the resulting
286files (if any) will be
287saved. `gnus-uu-decode-and-save-unread-articles' does only checks
288unread articles.
289
290`gnus-uu-decode-and-view-all-articles' does the same as the function
291above, only viewing files instead of saving them.
292
293`gnus-uu-edit-begin-line' lets you edit the begin line of an uuencoded
294file in the current article. Useful to change a corrupted begin line.
295
296
297When using the view commands, `gnus-uu-decode-and-view' for instance,
298gnus-uu will (normally, see below) try to view the file according to
299the rules given in `gnus-uu-default-view-rules' and
300`gnus-uu-user-view-rules'. If it recognizes the file, it will display
301it immediately. If the file is some sort of archive, gnus-uu will
302attempt to unpack the archive and see if any of the files in the
303archive can be viewed. For instance, if you have a gzipped tar file
304\"pics.tar.gz\" containing the files \"pic1.jpg\" and \"pic2.gif\",
305gnus-uu will uncompress and detar the main file, and then view the two
306pictures. This unpacking process is recursive, so if the archive
307contains archives of archives, it'll all be unpacked.
308
309If the view command doesn't recognise the file type, or can't view it
310because you don't have the viewer, or can't view *any* of the files in
311the archive, the user will be asked if she wishes to have the file
312saved somewhere. Note that if the decoded file is an archive, and
313gnus-uu manages to view some of the files in the archive, it won't
314tell the user that there were some files that were unviewable. Try
315interactive view for a different approach.
316
317
318Note that gnus-uu adds a function to `gnus-exit-group-hook' to clear
319the list of marked articles and check for any generated files that
320might have escaped deletion if the user typed `C-g' during viewing.
321
322
323`gnus-uu-toggle-asynchronous' toggles the `gnus-uu-asynchronous'
324variable.
325
326`gnus-uu-toggle-query' toggles the `gnus-uu-ask-before-view'
327variable.
328
329`gnus-uu-toggle-always-ask' toggles the `gnus-uu-view-and-save'
330variable.
331
332`gnus-uu-toggle-kill-carriage-return' toggles the
333`gnus-uu-kill-carriage-return' variable.
334
335`gnus-uu-toggle-interactive-view' toggles interactive mode. If it is
336turned on, gnus-uu won't view files immediately, but will give you a
337buffer with the default commands and files and let you edit the
338commands and execute them at leisure.
339
340`gnus-uu-toggle-correct-stripped-articles' toggles whether to check
341and correct uuencoded articles that may have had trailing spaces
342stripped by mailers.
343
344`gnus-uu-toggle-view-with-metamail' toggles whether to skip the
345gnus-uu viewing methods and just guess at an content-type based on the
346file name suffix and feed it to metamail.
347
348`gnus-uu-toggle-any-variable' is an interface to the toggle commands
349listed above.
350
351
352Customization
0822af61
RS
353
354 Rule Variables
355
356 gnus-uu uses \"rule\" variables to decide how to view a file. All
357 these variables are of the form
358
359 (list '(regexp1 command2)
360 '(regexp2 command2)
361 ...)
362
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
366 say something like:
367
368 (setq gnus-uu-user-view-rules
369 (list '(\"\\\\.au$\" \"sox %s -t .aiff > /dev/audio\")))
370
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.
374
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.
378
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.
382
383 `gnus-uu-user-archive-rules`
384 This variable can be used to say what comamnds should be used to
385 unpack archives.
386
387
388 Other Variables
389
390 `gnus-uu-tmp-dir'
391 Where gnus-uu does its work.
392
393 `gnus-uu-do-not-unpack-archives'
394 Non-nil means that gnus-uu won't peek inside archives looking for
395 files to dispay.
396
397 `gnus-uu-view-and-save'
398 Non-nil means that the user will always be asked to save a file
399 after viewing it.
400
ccfd5a00
RS
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'
409 variable.
0822af61
RS
410
411 `gnus-uu-ask-before-view'
412 Non-nil means that gnus-uu will ask you before viewing each file
413
414 `gnus-uu-ignore-default-view-rules'
415 Non-nil means that gnus-uu will ignore the default viewing rules.
416
417 `gnus-uu-ignore-default-archive-rules'
418 Non-nil means that gnus-uu will ignore the default archive
419 unpacking commands.
420
421 `gnus-uu-kill-carriage-return'
422 Non-nil means that gnus-uu will strip all carriage returns from
423 articles.
424
425 `gnus-uu-unmark-articles-not-decoded'
426 Non-nil means that gnus-uu will mark articles that were
427 unsuccessfully decoded as unread.
428
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.
432
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.
436
437 `gnus-uu-use-interactive-view'
ccfd5a00
RS
438 Non-nil means that gnus-uu will use interactive viewing mode.
439
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
444 viewing.
445
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
452 dropped them.
453
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
458 post the article.
459
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.
463
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
470 nil.
471
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.
478"
0822af61
RS
479 (interactive)
480 )
481
f919f65c
RS
482;; Default viewing action rules
483
0822af61 484(defvar gnus-uu-default-view-rules
f919f65c
RS
485 (list
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")
f919f65c
RS
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")
492 '("\\.mod$" "str32")
493 '("\\.ps$" "ghostview")
494 '("\\.dvi$" "xdvi")
ccfd5a00 495 '("\\.[1-6]$" "xterm -e man -l")
f919f65c
RS
496 '("\\.html$" "xmosaic")
497 '("\\.mpe?g$" "mpeg_play")
ccfd5a00
RS
498 '("\\.fli$" "xflick")
499 '("\\.flc$" "xanim")
500 '("\\.\\(tar\\|arj\\|zip\\|zoo\\|arc\\|gz\\|Z\\|lzh\\|ar\\|lha\\)$"
f919f65c
RS
501 "gnus-uu-archive"))
502
0822af61
RS
503 "Default actions to be taken when the user asks to view a file.
504To change the behaviour, you can either edit this variable or set
505`gnus-uu-user-view-rules' to something useful.
f919f65c
RS
506
507For example:
508
509To make gnus-uu use 'xli' to display JPEG and GIF files, put the
510following in your .emacs file
511
512 (setq gnus-uu-user-view-rules (list '(\"jpg$\\\\|gif$\" \"xli\")))
513
0822af61
RS
514Both these variables are lists of lists with two string elements. The
515first string is a regular expression. If the file name matches this
516regular expression, the command in the second string is executed with
517the file as an argument.
f919f65c
RS
518
519If the command string contains \"%s\", the file name will be inserted
520at that point in the command string. If there's no \"%s\" in the
0822af61
RS
521command string, the file name will be appended to the command string
522before executing.
523
524There are several user variables to tailor the behaviour of gnus-uu to
525your needs. First we have `gnus-uu-user-view-rules', which is the
526variable gnus-uu first consults when trying to decide how to view a
527file. If this variable contains no matches, gnus-uu examines the
528default rule vaiable provided in this package. If gnus-uu finds no
529match here, it uses `gnus-uu-user-view-rules-end' to try to make a
530match.
531
532Unless, 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.")
f919f65c
RS
535
536(defvar gnus-uu-user-view-rules nil
0822af61
RS
537 "Variable detailing what actions are to be taken to view a file.
538See the documentation on the `gnus-uu-default-view-rules' variable for
f919f65c
RS
539details.")
540
541(defvar gnus-uu-user-view-rules-end nil
0822af61
RS
542 "Variable saying what actions are to be taken if no rule matched the file name.
543See the documentation on the `gnus-uu-default-view-rules' variable for
544details.")
f919f65c
RS
545
546(defvar gnus-uu-user-interactive-view-rules nil
0822af61
RS
547 "Variable detailing what actions are to be taken to view a file when using interactive mode.
548See the documentation on the `gnus-uu-default-view-rules' variable for
549details.")
f919f65c
RS
550
551(defvar gnus-uu-user-interactive-view-rules-end nil
0822af61
RS
552 "Variable saying what actions are to be taken if no rule matched the file name when using interactive mode.
553See the documentation on the `gnus-uu-default-view-rules' variable for
554details.")
f919f65c 555
0822af61 556(defvar gnus-uu-default-interactive-view-rules-begin
f919f65c 557 (list
ccfd5a00
RS
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")
f919f65c
RS
560 ))
561
ccfd5a00
RS
562(defvar gnus-uu-default-interactive-view-rules-end
563 (list
564 '(".*" "file")))
f919f65c
RS
565
566;; Default unpacking commands
567
0822af61 568(defvar gnus-uu-default-archive-rules
f919f65c 569 (list '("\\.tar$" "tar xf")
ccfd5a00 570 '("\\.zip$" "unzip -o")
f919f65c
RS
571 '("\\.ar$" "ar x")
572 '("\\.arj$" "unarj x")
573 '("\\.zoo$" "zoo -e")
ccfd5a00 574 '("\\.\\(lzh\\|lha\\)$" "lha x")
f919f65c
RS
575 '("\\.Z$" "uncompress")
576 '("\\.gz$" "gunzip")
577 '("\\.arc$" "arc -x"))
0822af61
RS
578 )
579
ccfd5a00
RS
580(defvar gnus-uu-destructive-archivers
581 (list "uncompress" "gunzip"))
582
0822af61
RS
583(defvar gnus-uu-user-archive-rules nil
584 "A list that can be set to override the default archive unpacking commands.
585To use, for instance, 'untar' to unpack tar files and 'zip -x' to
586unpack zip files, say the following:
587 (setq gnus-uu-user-archive-rules
588 (list '(\"\\\\.tar$\" \"untar\")
589 '(\"\\\\.zip$\" \"zip -x\")))"
590 )
f919f65c 591
ccfd5a00
RS
592;; Pseudo-MIME support
593
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")))
f919f65c
RS
620
621;; Various variables users may set
622
623(defvar gnus-uu-tmp-dir "/tmp/"
0822af61
RS
624 "Variable saying where gnus-uu is to do its work.
625Default is \"/tmp/\".")
f919f65c
RS
626
627(defvar gnus-uu-do-not-unpack-archives nil
0822af61
RS
628 "Non-nil means that gnus-uu won't peek inside archives looking for files to dispay.
629Default is nil.")
f919f65c
RS
630
631(defvar gnus-uu-view-and-save nil
0822af61
RS
632 "Non-nil means that the user will always be asked to save a file after viewing it.
633If the variable is nil, the suer will only be asked to save if the
634viewing is unsuccessful. Default is nil.")
f919f65c
RS
635
636(defvar gnus-uu-asynchronous nil
0822af61
RS
637 "Non-nil means that files will be viewed asynchronously.
638Default is nil.")
f919f65c
RS
639
640(defvar gnus-uu-ask-before-view nil
0822af61
RS
641 "Non-nil means that gnus-uu will ask you before viewing each file.
642Especially useful when `gnus-uu-asynchronous' is set. Default is
643nil.")
f919f65c
RS
644
645(defvar gnus-uu-ignore-default-view-rules nil
0822af61
RS
646 "Non-nil means that gnus-uu will ignore the default viewing rules.
647Only the user viewing rules will be consulted. Default is nil.")
f919f65c 648
0822af61
RS
649(defvar gnus-uu-ignore-default-archive-rules nil
650 "Non-nil means that gnus-uu will ignore the default archive unpacking commands.
651Only the user unpacking commands will be consulted. Default is nil.")
f919f65c
RS
652
653(defvar gnus-uu-kill-carriage-return t
0822af61
RS
654 "Non-nil means that gnus-uu will strip all carriage returns from articles.
655Default is t.")
f919f65c 656
ccfd5a00
RS
657(defvar gnus-uu-view-with-metamail nil
658 "Non-nil means that files will be viewed with metamail.
659The gnus-uu viewing functions will be ignored and gnus-uu will try
660to guess at a content-type based on file name suffixes. Default
661it nil.")
662
f919f65c 663(defvar gnus-uu-unmark-articles-not-decoded nil
0822af61
RS
664 "Non-nil means that gnus-uu will mark articles that were unsuccessfully decoded as unread.
665Default is nil.")
f919f65c
RS
666
667(defvar gnus-uu-output-window-height 20
0822af61
RS
668 "This variable says how tall the output buffer window is to be when using interactive view mode.
669Change it at your convenience. Default is 20.")
f919f65c
RS
670
671(defvar gnus-uu-correct-stripped-uucode nil
0822af61
RS
672 "Non-nil means that gnus-uu will *try* to fix uuencoded files that have had traling spaces deleted.
673Default is nil.")
f919f65c
RS
674
675(defvar gnus-uu-use-interactive-view nil
0822af61
RS
676 "Non-nil means that gnus-uu will use interactive viewing mode.
677Gnus-uu will create a special buffer where the user may choose
678interactively which files to view and how. Default is nil.")
f919f65c 679
ccfd5a00
RS
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.
682If this variable is nil, gnus-uu will just save everything in a
683file without any embellishments. The digesting almost conforms to RFC1153 -
684no easy way to specify any meaningful volume and issue numbers were found,
685so I simply dropped them.")
686
f919f65c
RS
687
688;; Internal variables
689
0822af61 690(defconst gnus-uu-begin-string "^begin[ \t]+[0-7][0-7][0-7][ \t]+\\(.*\\)$")
f919f65c 691(defconst gnus-uu-end-string "^end[ \t]*$")
ccfd5a00
RS
692
693(defconst gnus-uu-body-line "^M")
694(let ((i 61))
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 ".?$")))
698
699;"^M.............................................................?$"
700
0822af61 701(defconst gnus-uu-shar-begin-string "^#! */bin/sh")
f919f65c 702
0822af61
RS
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\\)")
f919f65c
RS
705(defvar gnus-uu-shar-directory nil)
706
707(defvar gnus-uu-file-name nil)
708(defconst gnus-uu-uudecode-process nil)
709
710(defvar gnus-uu-interactive-file-list nil)
711(defvar gnus-uu-marked-article-list nil)
712(defvar gnus-uu-generated-file-list nil)
ccfd5a00 713(defvar gnus-uu-work-dir nil)
f919f65c
RS
714
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*")
718
0822af61 719(defconst gnus-uu-error-during-unarching nil)
f919f65c
RS
720
721;; Interactive functions
722
723;; UUdecode and view
724
725(defun gnus-uu-decode-and-view ()
726 "UUdecodes and 'views' (if possible) the resulting file.
0822af61
RS
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
730viewed, the user is asked if she would like to save the file instead."
731 (interactive)
f919f65c
RS
732 (gnus-uu-decode-and-view-or-save t nil))
733
734(defun gnus-uu-decode-and-save ()
0822af61 735 "Decodes and saves the resulting file."
f919f65c
RS
736 (interactive)
737 (gnus-uu-decode-and-view-or-save nil nil))
738
739(defun gnus-uu-marked-decode-and-view ()
0822af61
RS
740 "Decodes and views articles marked.
741The marked equivalent to `gnus-uu-decode-and-view'."
f919f65c
RS
742 (interactive)
743 (gnus-uu-decode-and-view-or-save t t))
744
745(defun gnus-uu-marked-decode-and-save ()
0822af61
RS
746 "Decodes and saves articles marked.
747The marked equivalent to `gnus-uu-decode-and-save'."
f919f65c
RS
748 (interactive)
749 (gnus-uu-decode-and-view-or-save nil t))
750
751
752;; Unshar and view
753
754(defun gnus-uu-shar-and-view ()
0822af61
RS
755 "Unshars and views articles.
756The shar equivalent of `gnus-uu-decode-and-view'."
f919f65c
RS
757 (interactive)
758 (gnus-uu-unshar-and-view-or-save t nil))
759
760(defun gnus-uu-shar-and-save ()
0822af61
RS
761 "Unshars and saves files.
762The shar equivalent to `gnus-uu-decode-and-save'."
f919f65c
RS
763 (interactive)
764 (gnus-uu-unshar-and-view-or-save nil nil))
765
766(defun gnus-uu-marked-shar-and-view ()
0822af61
RS
767 "Unshars and views articles marked.
768The marked equivalent to `gnus-uu-shar-and-view'."
f919f65c
RS
769 (interactive)
770 (gnus-uu-unshar-and-view-or-save t t))
771
772(defun gnus-uu-marked-shar-and-save ()
0822af61
RS
773 "Unshars and saves articles marked.
774The marked equivalent to `gnus-uu-shar-and-save'."
f919f65c
RS
775 (interactive)
776 (gnus-uu-unshar-and-view-or-save nil t))
777
ccfd5a00 778;; Threaded decode
f919f65c 779
ccfd5a00
RS
780(defun gnus-uu-threaded-decode-and-view ()
781 "Decodes and saves the resulting file."
782 (interactive)
783 (gnus-uu-threaded-decode-and-view-or-save t))
f919f65c 784
ccfd5a00
RS
785(defun gnus-uu-threaded-decode-and-save ()
786 "Decodes and saves the resulting file."
f919f65c 787 (interactive)
ccfd5a00 788 (gnus-uu-threaded-decode-and-view-or-save nil))
f919f65c 789
ccfd5a00
RS
790(defun gnus-uu-threaded-multi-decode-and-view ()
791 "Decodes and saves the resulting file."
792 (interactive)
793 (gnus-uu-threaded-multi-decode-and-view-or-save t))
794
795(defun gnus-uu-threaded-multi-decode-and-save ()
796 "Decodes and saves the resulting file."
797 (interactive)
798 (gnus-uu-threaded-multi-decode-and-view-or-save nil))
799
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))
804
805(defun gnus-uu-threaded-multi-decode-and-view-or-save (view)
806 (let (type)
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))
811
812 (gnus-uu-unmark-all-articles)
813 (gnus-uu-mark-thread)
814
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)))))
820
f919f65c
RS
821
822;; Toggle commands
823
824(defun gnus-uu-toggle-asynchronous ()
825 "This function toggles asynchronous viewing."
826 (interactive)
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")))
830
831(defun gnus-uu-toggle-query ()
832 "This function toggles whether to ask before viewing or not."
833 (interactive)
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")))
837
838(defun gnus-uu-toggle-always-ask ()
0822af61 839 "This function toggles whether to always ask to save a file after viewing."
f919f65c
RS
840 (interactive)
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")))
844
845(defun gnus-uu-toggle-interactive-view ()
846 "This function toggles whether to use interactive view."
847 (interactive)
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")))
851
852(defun gnus-uu-toggle-unmark-undecoded ()
853 "This function toggles whether to unmark articles not decoded."
854 (interactive)
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")))
859
860(defun gnus-uu-toggle-kill-carriage-return ()
861 "This function toggles the stripping of carriage returns from the articles."
862 (interactive)
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")))
866
ccfd5a00
RS
867(defun gnus-uu-toggle-view-with-metamail ()
868 "This function toggles whether to view files with metamail."
869 (interactive)
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")))
873
f919f65c
RS
874(defun gnus-uu-toggle-correct-stripped-uucode ()
875 "This function toggles whether to correct stripped uucode."
876 (interactive)
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")))
881
882(defun gnus-uu-toggle-any-variable ()
883 "This function ask what variable the user wants to toggle."
884 (interactive)
885 (let (rep)
ccfd5a00 886 (message "(a)sync, (q)uery, (p)ask, (k)ill CR, (i)nteract, (u)nmark, (c)orrect, (m)eta")
f919f65c
RS
887 (setq rep (read-char))
888 (if (= rep ?a)
889 (gnus-uu-toggle-asynchronous))
890 (if (= rep ?q)
891 (gnus-uu-toggle-query))
892 (if (= rep ?p)
893 (gnus-uu-toggle-always-ask))
894 (if (= rep ?k)
895 (gnus-uu-toggle-kill-carriage-return))
896 (if (= rep ?u)
897 (gnus-uu-toggle-unmark-undecoded))
898 (if (= rep ?c)
899 (gnus-uu-toggle-correct-stripped-uucode))
ccfd5a00
RS
900 (if (= rep ?m)
901 (gnus-uu-toggle-view-with-metamail))
f919f65c
RS
902 (if (= rep ?i)
903 (gnus-uu-toggle-interactive-view))))
904
905
ccfd5a00
RS
906;; Misc interactive functions
907
908(defun gnus-uu-decode-and-show-in-buffer ()
909 "Uudecodes the current article and displays the result in a buffer.
910Might be useful if someone has, for instance, some text uuencoded in
911their sigs. (Stranger things have happened.)"
912 (interactive)
913 (gnus-uu-initialize)
914 (let ((uu-buffer (get-buffer-create gnus-uu-output-buffer-name))
915 file-name)
916 (save-excursion
917 (and
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))
922 (progn
923 (save-excursion
924 (set-buffer uu-buffer)
925 (erase-buffer)
926 (insert-file-contents file-name))
927 (set-window-buffer (get-buffer-window gnus-article-buffer)
928 uu-buffer)
929 (message "Showing file %s in buffer" file-name)
930 (delete-file file-name))))))
f919f65c
RS
931
932(defun gnus-uu-edit-begin-line ()
933 "Edit the begin line of the current article."
934 (interactive)
935 (let ((buffer-read-only nil)
936 begin b)
937 (save-excursion
ccfd5a00 938 (gnus-summary-select-article)
f919f65c
RS
939 (set-buffer gnus-article-buffer)
940 (goto-line 1)
941 (if (not (re-search-forward "begin " nil t))
ccfd5a00 942 (error "No begin line in the current article")
f919f65c
RS
943 (beginning-of-line)
944 (setq b (point))
945 (end-of-line)
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)))))
951
ccfd5a00 952
f919f65c
RS
953;; Multi functions
954
955(defun gnus-uu-multi-decode-and-view ()
0822af61
RS
956 "Choose a method of decoding and then decode and view.
957This function lets the user decide what method to use for decoding.
958Other than that, it's equivalent to the other decode-and-view
959functions."
f919f65c
RS
960 (interactive)
961 (gnus-uu-multi-decode-and-view-or-save t nil))
962
963(defun gnus-uu-multi-decode-and-save ()
0822af61
RS
964 "Choose a method of decoding and then decode and save.
965This function lets the user decide what method to use for decoding.
966Other than that, it's equivalent to the other decode-and-save
967functions."
f919f65c
RS
968 (interactive)
969 (gnus-uu-multi-decode-and-view-or-save nil nil))
970
971(defun gnus-uu-marked-multi-decode-and-view ()
0822af61
RS
972 "Choose a method of decoding and then decode and view the marked articles.
973This function lets the user decide what method to use for decoding.
f919f65c
RS
974Other than that, it's equivalent to the other marked decode-and-view
975functions."
976 (interactive)
977 (gnus-uu-multi-decode-and-view-or-save t t))
978
979(defun gnus-uu-marked-multi-decode-and-save ()
0822af61
RS
980 "Choose a method of decoding and then decode and save the marked articles.
981This function lets the user decide what method to use for decoding.
f919f65c
RS
982Other than that, it's equivalent to the other marked decode-and-save
983functions."
984 (interactive)
985 (gnus-uu-multi-decode-and-view-or-save t t))
986
987(defun gnus-uu-multi-decode-and-view-or-save (view marked)
ccfd5a00
RS
988 (let (type)
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)))))
0822af61 997
ccfd5a00
RS
998
999;; "All articles" commands
f919f65c
RS
1000
1001(defconst gnus-uu-rest-of-articles nil)
0822af61 1002(defvar gnus-uu-current-save-dir nil)
f919f65c 1003
ccfd5a00
RS
1004(defun gnus-uu-decode-and-view-all-articles (&optional unread)
1005 "Try to decode all articles and view the result."
1006 (interactive)
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))
1012
1013(defun gnus-uu-decode-and-view-all-unread-articles (&optional unread)
1014 "Try to decode all unread articles and view the result."
1015 (interactive)
1016 (gnus-uu-decode-and-view-all-articles t))
1017
f919f65c 1018(defun gnus-uu-decode-and-save-all-unread-articles ()
0822af61
RS
1019 "Try to decode all unread articles and saves the result.
1020This function reads all unread articles in the current group and sees
1021whether it can uudecode the articles. The user will be prompted for an
1022directory to put the resulting (if any) files."
f919f65c
RS
1023 (interactive)
1024 (gnus-uu-decode-and-save-articles t t))
1025
1026(defun gnus-uu-decode-and-save-all-articles ()
0822af61
RS
1027 "Try to decode all articles and saves the result.
1028Does the same as `gnus-uu-decode-and-save-all-unread-articles', except
f919f65c
RS
1029that it grabs all articles visible, unread or not."
1030 (interactive)
1031 (gnus-uu-decode-and-save-articles nil t))
1032
f919f65c 1033(defun gnus-uu-decode-and-save-articles (&optional unread unmark)
ccfd5a00
RS
1034 (let ((gnus-uu-unmark-articles-not-decoded t)
1035 dir)
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."))))
f919f65c
RS
1043
1044
1045;; Work functions
1046
ccfd5a00
RS
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)
f919f65c 1050 (gnus-uu-initialize)
ccfd5a00 1051 (let (decoded)
f919f65c
RS
1052 (save-excursion
1053 (if (gnus-uu-decode-and-strip nil marked)
1054 (progn
1055 (setq decoded t)
f919f65c 1056 (if view
ccfd5a00
RS
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)))))
f919f65c
RS
1061
1062 (gnus-uu-summary-next-subject)
1063
0822af61
RS
1064 (if gnus-uu-error-during-unarching
1065 (gnus-uu-clean-up)
1066 (if (and gnus-uu-use-interactive-view view decoded)
1067 (gnus-uu-do-interactive)))
f919f65c 1068
ccfd5a00 1069 (if (or (not view) (not gnus-uu-use-interactive-view) (not decoded))
f919f65c
RS
1070 (gnus-uu-clean-up))))
1071
0822af61 1072; Unshars and views/saves marked/unmarked articles.
f919f65c 1073(defun gnus-uu-unshar-and-view-or-save (view marked)
f919f65c
RS
1074 (gnus-uu-initialize)
1075 (let (tar-file files decoded)
1076 (save-excursion
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)
1082 (progn
1083 (setq decoded t)
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)
1088 (progn
1089 (setq tar-file
1090 (concat
1091 (make-temp-name (concat gnus-uu-tmp-dir "gnusuuar"))
1092 ".tar"))
1093 (gnus-uu-add-file tar-file)
ccfd5a00
RS
1094 (call-process
1095 "sh" nil
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))
f919f65c
RS
1100 (if view
1101 (gnus-uu-view-file tar-file)
1102 (gnus-uu-save-file tar-file)))
1103 (if view
1104 (gnus-uu-view-file (elt files 2))
1105 (gnus-uu-save-file (elt files 2)))))))
1106
1107 (gnus-uu-summary-next-subject)
1108
1109 (if (and gnus-uu-use-interactive-view view decoded)
1110 (gnus-uu-do-interactive))
1111
1112 (if (or (not gnus-uu-use-interactive-view) (not decoded))
1113 (gnus-uu-clean-up))))
1114
1115
ccfd5a00
RS
1116;; Functions for saving and possibly digesting articles without
1117;; any decoding.
1118
f919f65c 1119(defconst gnus-uu-saved-article-name nil)
ccfd5a00
RS
1120
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)
f919f65c
RS
1127 (let (list-of-articles)
1128 (save-excursion
ccfd5a00 1129 (gnus-uu-initialize)
f919f65c
RS
1130 (if (not marked)
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))
ccfd5a00 1134
f919f65c 1135 (if (not list-of-articles)
ccfd5a00
RS
1136 (error "No list of articles"))
1137
1138 (setq gnus-uu-saved-article-name
1139 (concat gnus-uu-work-dir
1140 (if no-save
1141 gnus-newsgroup-name
f919f65c 1142 (read-file-name "Enter file name: " gnus-newsgroup-name
ccfd5a00
RS
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)
1146 (not no-save))
1147 (gnus-uu-save-file gnus-uu-saved-article-name)
1148 gnus-uu-saved-article-name))))
1149
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)
1153 (save-excursion
1154 (set-buffer buffer)
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)
1163 (match-end 1)))
1164 (if (or (eq in-state 'first)
1165 (eq in-state 'first-and-last))
1166 (progn
1167 (setq state (list 'begin))
1168 (save-excursion (set-buffer (get-buffer-create "*gnus-uu-body*"))
1169 (erase-buffer))
1170 (save-excursion
1171 (set-buffer (get-buffer-create "*gnus-uu-pre*"))
1172 (erase-buffer)
1173 (insert (format
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))))
1178 (save-excursion
1179 (set-buffer (get-buffer "*gnus-uu-body*"))
1180 (goto-char (setq beg (point-max)))
1181 (save-excursion
1182 (save-restriction
1183 (set-buffer buffer)
1184 (goto-char 1)
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:"))
1190 (while headers
1191 (setq headline (car headers))
1192 (setq headers (cdr headers))
1193 (goto-char 1)
1194 (if (re-search-forward (concat "^" headline ".*$") nil t)
1195 (setq sorthead
1196 (concat sorthead (buffer-substring
1197 (match-beginning 0)
1198 (match-end 0)) "\n"))))
1199 (widen)))
1200 (insert sorthead)(goto-char (point-max))
1201 (insert body)(goto-char (point-max))
1202 (insert (concat "\n" (make-string 30 ?-) "\n\n"))
1203 (goto-char beg)
1204 (if (re-search-forward "^Subject: \\(.*\\)$" nil t)
1205 (progn
1206 (setq subj (buffer-substring (match-beginning 1) (match-end 1)))
1207 (save-excursion
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))
1212 (progn
1213 (save-excursion
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))
1217 (save-excursion
1218 (set-buffer (get-buffer "*gnus-uu-body*"))
1219 (goto-char (point-max))
1220 (insert
1221 (concat (setq end-string (format "End of %s Digest" name))
1222 "\n"))
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)
1230 state))))
1231
1232
1233;; Digest and forward articles
1234
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)
1239
1240(defun gnus-uu-digest-and-forward (&optional marked)
1241 "Digests and forwards all articles in this series."
1242 (interactive)
1243 (let ((gnus-uu-save-in-digest t)
1244 file buf)
1245 (setq file (gnus-uu-save-articles nil marked t))
1246 (switch-to-buffer (setq buf (get-buffer-create "*gnus-uu-forward*")))
1247 (erase-buffer)
1248 (delete-other-windows)
1249 (erase-buffer)
1250 (insert-file file)
1251 (goto-char 1)
1252 (bury-buffer buf)
1253 (funcall gnus-mail-forward-method)))
f919f65c 1254
ccfd5a00
RS
1255(defun gnus-uu-marked-digest-and-forward (&optional marked)
1256 "Digests and forwards all marked articles."
1257 (interactive)
1258 (gnus-uu-digest-and-forward t))
f919f65c 1259
f919f65c 1260
ccfd5a00 1261;; Binhex treatment - not very advanced.
f919f65c 1262
f919f65c 1263(defconst gnus-uu-binhex-body-line
ccfd5a00 1264 "^[^:]...............................................................$")
f919f65c
RS
1265(defconst gnus-uu-binhex-begin-line
1266 "^:...............................................................$")
1267(defconst gnus-uu-binhex-end-line
1268 ":$")
1269(defvar gnus-uu-binhex-article-name nil)
1270
ccfd5a00
RS
1271; This just concatenates and strips stuff from binhexed articles.
1272; No actual unbinhexing takes place. VIEW is ignored.
f919f65c 1273(defun gnus-uu-binhex-and-save (view marked)
ccfd5a00 1274 (gnus-uu-initialize)
f919f65c
RS
1275 (let (list-of-articles)
1276 (save-excursion
1277 (if (not marked)
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))
f919f65c 1281 (if (not list-of-articles)
ccfd5a00
RS
1282 (error "No list of articles"))
1283
1284 (setq gnus-uu-binhex-article-name
1285 (concat gnus-uu-work-dir
1286 (read-file-name "Enter binhex file name: "
1287 gnus-newsgroup-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))
f919f65c
RS
1294
1295(defun gnus-uu-binhex-article (buffer in-state)
ccfd5a00 1296 (let (state start-char)
f919f65c
RS
1297 (save-excursion
1298 (set-buffer buffer)
ccfd5a00 1299 (widen)
f919f65c 1300 (goto-char 1)
ccfd5a00
RS
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))))
1304
1305 (if (memq 'wrong-type state)
1306 ()
f919f65c
RS
1307 (beginning-of-line)
1308 (setq start-char (point))
1309 (if (looking-at gnus-uu-binhex-begin-line)
ccfd5a00
RS
1310 (progn
1311 (setq state (list 'begin))
1312 (write-region 1 1 gnus-uu-binhex-article-name))
1313 (setq state (list 'middle)))
f919f65c
RS
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)
ccfd5a00
RS
1318 (setq state (if (memq 'begin state)
1319 (cons 'end state)
1320 (list 'end))))
f919f65c
RS
1321 (beginning-of-line)
1322 (forward-line 1)
ccfd5a00
RS
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)
1327 state)))
f919f65c
RS
1328
1329
1330;; Internal view commands
1331
0822af61
RS
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.
1336;
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."
1339;
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.
1344
1345; `gnus-uu-view-file' returns t if viewing is successful.
f919f65c 1346
0822af61 1347(defun gnus-uu-view-file (file-name &optional dont-ask)
f919f65c 1348 (let (action did-view
ccfd5a00
RS
1349 (didnt-want t)
1350 (do-view t))
1351
1352 (setq action (gnus-uu-get-action file-name))
1353
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)
1358
1359 (if action
1360 (progn
1361
1362 (if gnus-uu-ask-before-view
1363 (setq didnt-want
1364 (or (not (setq do-view
1365 (y-or-n-p
1366 (format "Do you want to view %s? "
1367 file-name))))
1368 didnt-want)))
1369
1370 (if do-view
1371 (setq did-view
1372 (if gnus-uu-asynchronous
1373 (gnus-uu-call-asynchronous file-name action)
1374 (gnus-uu-call-synchronous file-name action)))))
1375
1376 (if (and (not dont-ask) (not gnus-uu-use-interactive-view))
1377 (progn
1378 (if (and
1379 didnt-want
1380 (or (not action)
1381 (and (string= action "gnus-uu-archive")
1382 (not did-view))))
1383 (progn
1384 (message
1385 (format "Could find no rule for %s" file-name))
1386 (sit-for 2)))
1387 (and (or (not did-view) gnus-uu-view-and-save)
1388 (y-or-n-p
1389 (format "Do you want to save the file %s? "
1390 file-name))
1391 (gnus-uu-save-file file-name)))))
1392
1393 (if (and (file-exists-p file-name)
1394 (not gnus-uu-use-interactive-view)
1395 (or
1396 (not (and gnus-uu-asynchronous did-view))
1397 (string= action "gnus-uu-archive")))
1398 (delete-file file-name)))
1399
1400 did-view))
1401
1402(defun gnus-uu-get-action (file-name)
1403 (let (action)
f919f65c 1404 (setq action
ccfd5a00 1405 (gnus-uu-choose-action
f919f65c
RS
1406 file-name
1407 (append
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)
ccfd5a00 1412 (if (or gnus-uu-ignore-default-view-rules
f919f65c
RS
1413 (not gnus-uu-use-interactive-view))
1414 ()
1415 gnus-uu-default-interactive-view-rules-begin)
1416 (if gnus-uu-ignore-default-view-rules
1417 nil
1418 gnus-uu-default-view-rules)
ccfd5a00
RS
1419 (if gnus-uu-use-interactive-view
1420 (append gnus-uu-user-interactive-view-rules-end
1421 (if gnus-uu-ignore-default-view-rules
1422 ()
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)
1427 (if (setq action
1428 (gnus-uu-choose-action file-name gnus-uu-ext-to-mime-list))
1429 (setq action (format "metamail -d -b -c \"%s\"" action))))
1430 action))
f919f65c 1431
0822af61
RS
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.
f919f65c 1435(defun gnus-uu-call-synchronous (file-name action)
f919f65c
RS
1436 (let (did-view command)
1437 (save-excursion
1438 (set-buffer (get-buffer-create gnus-uu-output-buffer-name))
1439 (erase-buffer)
0822af61 1440 (setq command (gnus-uu-command action file-name))
ccfd5a00 1441 (message "Viewing with '%s'" command)
f919f65c
RS
1442 (if (not (= 0 (call-process "sh" nil t nil "-c" command)))
1443 (progn
1444 (goto-char 1)
1445 (while (re-search-forward "\n" nil t)
1446 (replace-match " "))
1447 (message (concat "Error: " (buffer-substring 1 (point-max))))
1448 (sit-for 2))
1449 (message "")
1450 (setq did-view t)))
1451 did-view))
1452
0822af61
RS
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.
f919f65c 1459(defun gnus-uu-call-asynchronous (file-name action)
f919f65c
RS
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))
ccfd5a00 1464 (setq tmp-file (concat gnus-uu-work-dir file))
f919f65c
RS
1465 (if (string= tmp-file file-name)
1466 ()
1467 (rename-file file-name tmp-file t)
1468 (setq file-name tmp-file))
1469
0822af61 1470 (setq command (gnus-uu-command action file-name))
f919f65c 1471 (setq command (format "%s ; rm -f %s" command file-name))
ccfd5a00 1472 (message "Viewing with %s" command)
0822af61 1473 (start-process "gnus-uu-view" nil "sh" "-c" command)
f919f65c
RS
1474 t))
1475
0822af61
RS
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.
f919f65c 1482(defun gnus-uu-decode-and-strip (&optional shar use-marked)
f919f65c
RS
1483 (let (list-of-articles)
1484 (save-excursion
1485
1486 (if use-marked
ccfd5a00
RS
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))
f919f65c
RS
1491 (setq list-of-articles (gnus-uu-get-list-of-articles)))
1492
1493 (and list-of-articles
ccfd5a00
RS
1494 (gnus-uu-grab-articles
1495 list-of-articles
1496 (if shar 'gnus-uu-unshar-article 'gnus-uu-uustrip-article-as)
1497 t)))))
f919f65c 1498
0822af61
RS
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."
f919f65c 1505(defun gnus-uu-reginize-string (string)
f919f65c 1506 (let ((count 2)
0822af61 1507 (vernum "v[0-9]+[a-z][0-9]+:")
f919f65c
RS
1508 reg beg)
1509 (save-excursion
1510 (set-buffer (get-buffer-create gnus-uu-output-buffer-name))
1511 (erase-buffer)
1512 (insert (regexp-quote string))
1513 (setq beg 1)
1514
1515 (setq case-fold-search nil)
1516 (goto-char 1)
1517 (if (looking-at vernum)
1518 (progn
1519 (replace-match vernum t t)
1520 (setq beg (length vernum))))
1521
1522 (goto-char beg)
1523 (if (re-search-forward "[ \t]*[0-9]+/[0-9]+" nil t)
1524 (replace-match " [0-9]+/[0-9]+")
1525
1526 (goto-char beg)
1527 (if (re-search-forward "[0-9]+[ \t]*of[ \t]*[0-9]+" nil t)
1528 (replace-match "[0-9]+ of [0-9]+")
1529
1530 (end-of-line)
1531 (while (and (re-search-backward "[0-9]" nil t) (> count 0))
1532 (while (and
1533 (looking-at "[0-9]")
1534 (< 1 (goto-char (1- (point))))))
1535 (re-search-forward "[0-9]+" nil t)
1536 (replace-match "[0-9]+")
1537 (backward-char 5)
1538 (setq count (1- count)))))
1539
1540 (goto-char beg)
1541 (while (re-search-forward "[ \t]+" nil t)
1542 (replace-match "[ \t]*" t t))
1543
1544 (buffer-substring 1 (point-max)))))
1545
0822af61 1546; Finds all articles that matches the regular expression given.
ccfd5a00
RS
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)
f919f65c
RS
1553 (let (beg end reg-subject list-of-subjects list-of-numbers art-num)
1554 (save-excursion
1555
1556; If the subject is not given, this function looks at the current subject
1557; and takes that.
1558
1559 (if subject
1560 (setq reg-subject subject)
1561 (end-of-line)
1562 (setq end (point))
1563 (beginning-of-line)
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))
1567 (setq reg-subject
1568 (concat "\\[.*\\] " (gnus-uu-reginize-string subject)))))
1569
1570; (message reg-subject)(sleep-for 2)
1571
1572 (if reg-subject
1573 (progn
1574
1575; Collect all subjects matching reg-subject.
1576
1577 (let ((case-fold-search t))
f919f65c
RS
1578 (goto-char 1)
1579 (while (re-search-forward reg-subject nil t)
1580 (beginning-of-line)
1581 (setq beg (point))
1582 (if (or (not only-unread) (looking-at " \\|-"))
1583 (progn
1584 (end-of-line)
1585 (setq list-of-subjects (cons
1586 (buffer-substring beg (point))
1587 list-of-subjects)))
1588 (end-of-line))))
1589
1590; Expand all numbers in all the subjects: (hi9 -> hi0009, etc).
1591
ccfd5a00
RS
1592 (setq list-of-subjects (gnus-uu-expand-numbers
1593 list-of-subjects
1594 (not do-not-translate)))
f919f65c
RS
1595
1596; Sort the subjects.
1597
1598 (setq list-of-subjects (sort list-of-subjects 'gnus-uu-string<))
1599
1600; Get the article numbers from the sorted list of subjects.
1601
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)))
1607
ccfd5a00 1608 (setq list-of-numbers (nreverse list-of-numbers))))
f919f65c
RS
1609
1610 list-of-numbers)))
1611
0822af61
RS
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.
ccfd5a00 1617(defun gnus-uu-expand-numbers (string-list &optional translate)
f919f65c
RS
1618 (let (string out-list pos num)
1619 (save-excursion
1620 (set-buffer (get-buffer-create gnus-uu-output-buffer-name))
1621 (while string-list
1622 (erase-buffer)
1623 (setq string (car string-list))
1624 (setq string-list (cdr string-list))
1625 (insert string)
1626 (goto-char 1)
1627 (while (re-search-forward "[ \t]+" nil t)
1628 (replace-match " "))
1629 (goto-char 1)
ccfd5a00
RS
1630 (if translate
1631 (while (re-search-forward "[A-Za-z]" nil t)
1632 (replace-match "a" t t)))
f919f65c
RS
1633
1634 (goto-char 1)
1635 (if (not (search-forward "] " nil t))
1636 ()
1637 (while (re-search-forward "[0-9]+" nil t)
1638 (replace-match
1639 (format "%06d"
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)))))
1644 out-list))
1645
0822af61
RS
1646; Used in a sort for finding out what string is bigger, but ignoring
1647; everything before the subject part.
f919f65c 1648(defun gnus-uu-string< (string1 string2)
f919f65c
RS
1649 (string< (substring string1 (string-match "\\] " string1))
1650 (substring string2 (string-match "\\] " string2))))
1651
1652
1653;; gnus-uu-grab-article
0822af61
RS
1654;
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'.
1658;
ccfd5a00
RS
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
1663; generate files...
0822af61
RS
1664;
1665; The second parameter is the state of the list of articles, and can
ccfd5a00 1666; have four values: `first', `middle', `last' and `first-and-last'.
0822af61 1667;
ccfd5a00
RS
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
1674; file.
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
f919f65c
RS
1679
1680(defvar gnus-uu-has-been-grabbed nil)
1681
1682(defun gnus-uu-unmark-list-of-grabbed (&optional dont-unmark-last-article)
1683 (let (art)
ccfd5a00
RS
1684 (if (not (and gnus-uu-has-been-grabbed
1685 gnus-uu-unmark-articles-not-decoded))
f919f65c
RS
1686 ()
1687 (if dont-unmark-last-article
1688 (progn
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
0822af61 1695 (setq gnus-uu-has-been-grabbed (list art))))))
f919f65c
RS
1696
1697
0822af61
RS
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'.
1701;
ccfd5a00
RS
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)
f919f65c
RS
1705 (let ((result-buffer (get-buffer-create gnus-uu-result-buffer))
1706 (state 'first)
f919f65c 1707 (wrong-type t)
ccfd5a00
RS
1708 has-been-begin has-been-end
1709 article result-file result-files process-state)
f919f65c
RS
1710
1711 (save-excursion
1712 (set-buffer result-buffer)
1713 (erase-buffer))
1714 (setq gnus-uu-has-been-grabbed nil)
ccfd5a00 1715
f919f65c 1716 (while (and list-of-articles
ccfd5a00
RS
1717 (not (memq 'error process-state))
1718 (or sloppy
1719 (not (memq 'end process-state))))
1720
f919f65c
RS
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))
1724
ccfd5a00
RS
1725 (if (eq list-of-articles ())
1726 (if (eq state 'first)
1727 (setq state 'first-and-last)
1728 (setq state 'last)))
f919f65c 1729
ccfd5a00 1730 (message "Getting article %d" article)
f919f65c
RS
1731 (if (not (= (or gnus-current-article 0) article))
1732 (gnus-summary-display-article article))
1733 (gnus-summary-mark-as-read article)
1734
ccfd5a00 1735 (save-excursion (set-buffer gnus-article-buffer) (widen))
f919f65c
RS
1736
1737 (setq process-state (funcall process-function gnus-article-buffer state))
1738
ccfd5a00 1739; (message "process-state er %s" process-state)(sleep-for 3)
f919f65c 1740
ccfd5a00
RS
1741 (if (or (memq 'begin process-state)
1742 (and (or (eq state 'first) (eq state 'first-and-last))
1743 (memq 'ok process-state)))
1744 (progn
1745 (if has-been-begin
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)))
1750
1751 (if (memq 'end process-state)
1752 (progn
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)))
1757
1758 (if (not (memq 'wrong-type process-state))
f919f65c
RS
1759 (setq wrong-type nil)
1760 (if gnus-uu-unmark-articles-not-decoded
1761 (gnus-summary-mark-as-unread article t)))
1762
ccfd5a00 1763 (if sloppy (setq wrong-type nil))
f919f65c
RS
1764
1765 (if (and (not has-been-begin)
ccfd5a00
RS
1766 (not sloppy)
1767 (or (memq 'end process-state)
1768 (memq 'middle process-state)))
f919f65c 1769 (progn
ccfd5a00 1770 (setq process-state (list 'error))
f919f65c 1771 (message "No begin part at the beginning")
ccfd5a00 1772 (sleep-for 2))
f919f65c
RS
1773 (setq state 'middle)))
1774
ccfd5a00
RS
1775 (if result-files
1776 ()
1777 (if (not has-been-begin)
f919f65c 1778 (message "Wrong type file")
ccfd5a00
RS
1779 (if (memq 'error process-state)
1780 (setq result-files nil)
1781 (if (not (or (memq 'ok process-state)
1782 (memq 'end process-state)))
1783 (progn
1784 (message "End of articles reached before end of file")
1785 (setq result-files nil))
1786 (gnus-uu-unmark-list-of-grabbed)))))
1787 result-files))
f919f65c
RS
1788
1789(defun gnus-uu-uudecode-sentinel (process event)
f919f65c
RS
1790 (delete-process (get-process process)))
1791
ccfd5a00 1792; Uudecodes a file asynchronously.
f919f65c 1793(defun gnus-uu-uustrip-article-as (process-buffer in-state)
ccfd5a00 1794 (let ((state (list 'ok))
f919f65c 1795 (process-connection-type nil)
ccfd5a00 1796 start-char pst name-beg name-end)
f919f65c
RS
1797 (save-excursion
1798 (set-buffer process-buffer)
ccfd5a00
RS
1799 (let ((case-fold-search nil)
1800 (buffer-read-only nil))
f919f65c 1801
ccfd5a00 1802 (goto-char 1)
f919f65c 1803
ccfd5a00
RS
1804 (if gnus-uu-kill-carriage-return
1805 (progn
1806 (while (search-forward "\r" nil t)
1807 (delete-backward-char 1))
1808 (goto-char 1)))
f919f65c 1809
ccfd5a00
RS
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))))
1813
1814 (if (memq 'wrong-type state)
1815 ()
1816 (beginning-of-line)
1817 (setq start-char (point))
1818
1819 (if (looking-at gnus-uu-begin-string)
1820 (progn
1821 (setq name-end (match-end 1))
1822
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 "_"))
1830
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))
1836 (progn
1837 (delete-process gnus-uu-uudecode-process)
1838 (gnus-uu-unmark-list-of-grabbed t))))
1839 (setq gnus-uu-uudecode-process
1840 (start-process
1841 "*uudecode*"
1842 (get-buffer-create gnus-uu-output-buffer-name)
1843 "sh" "-c"
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)))
f919f65c 1850
ccfd5a00 1851 (goto-char (point-max))
0822af61 1852
ccfd5a00
RS
1853 (re-search-backward
1854 (concat gnus-uu-body-line "\\|" gnus-uu-end-string) nil t)
1855 (beginning-of-line)
f919f65c 1856
ccfd5a00
RS
1857 (if (looking-at gnus-uu-end-string)
1858 (setq state (cons 'end state)))
1859 (forward-line 1)
f919f65c 1860
ccfd5a00
RS
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))
1865 (progn
1866 (if gnus-uu-correct-stripped-uucode
1867 (progn
1868 (gnus-uu-check-correct-stripped-uucode
1869 start-char (point))
1870 (goto-char (point-max))
1871 (re-search-backward
1872 (concat gnus-uu-body-line "\\|"
1873 gnus-uu-end-string)
1874 nil t)
1875 (forward-line 1)))
1876 (condition-case err
1877 (process-send-region gnus-uu-uudecode-process
1878 start-char (point))
1879 (error
1880 (progn
1881 (message "gnus-uu: Couldn't uudecode")
1882 (sleep-for 2)
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)))))
1888
1889 (if (memq 'begin state)
1890 (cons (concat gnus-uu-work-dir gnus-uu-file-name) state)
1891 state))))
f919f65c 1892
0822af61
RS
1893; This function is used by `gnus-uu-grab-articles' to treat
1894; a shared article.
f919f65c 1895(defun gnus-uu-unshar-article (process-buffer in-state)
ccfd5a00 1896 (let ((state (list 'ok))
f919f65c
RS
1897 start-char)
1898 (save-excursion
1899 (set-buffer process-buffer)
1900 (goto-char 1)
1901 (if (not (re-search-forward gnus-uu-shar-begin-string nil t))
ccfd5a00 1902 (setq state (list 'wrong-type))
f919f65c
RS
1903 (beginning-of-line)
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"))))
1909 state))
1910
0822af61 1911; Returns the name of what the shar file is going to unpack.
f919f65c 1912(defun gnus-uu-find-name-in-shar ()
f919f65c
RS
1913 (let ((oldpoint (point))
1914 res)
1915 (goto-char 1)
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)
1919 res))
f919f65c 1920
0822af61 1921; Returns the article number of the given subject.
f919f65c 1922(defun gnus-uu-article-number (subject)
f919f65c
RS
1923 (let (end)
1924 (string-match "[0-9]+[^0-9]" subject 1)
1925 (setq end (match-end 0))
1926 (string-to-int
1927 (substring subject (string-match "[0-9]" subject 1) end))))
1928
0822af61
RS
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.
f919f65c 1932(defun gnus-uu-choose-action (file-name file-action-list)
f919f65c
RS
1933 (let ((action-list (copy-sequence file-action-list))
1934 rule action)
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)))))
1940 action))
1941
ccfd5a00
RS
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))
1945 (if default-dir
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" "") "? "))))
f919f65c 1950
ccfd5a00
RS
1951 (while files
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)
1957 ()
1958 (if (and (not ignore-existing) (file-exists-p (concat dir file-name)))
1959 (setq 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)))))
0822af61 1964
ccfd5a00 1965; Moves the file from the tmp directory to where the user wants it.
f919f65c 1966(defun gnus-uu-save-file (from-file-name &optional default-dir ignore-existing)
f919f65c
RS
1967 (let (dir file-name command)
1968 (string-match "/[^/]*$" from-file-name)
1969 (setq file-name (substring from-file-name (1+ (match-beginning 0))))
1970 (if default-dir
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)))
ccfd5a00
RS
1974 (setq file-name
1975 (read-file-name "File exist. Enter a new name: " dir
1976 (concat dir file-name) nil file-name))
f919f65c
RS
1977 (setq file-name (concat dir file-name)))
1978 (rename-file from-file-name file-name t)))
1979
f919f65c
RS
1980(defun gnus-uu-read-directory (prompt &optional default)
1981 (let (dir ok create)
1982 (while (not ok)
1983 (setq ok t)
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))
1991 (progn
1992 (setq ok nil)
1993 (message "%s is a file" dir)
1994 (sit-for 2)))
1995 (setq create ?o)
1996 (while (not (or (= create ?y) (= create ?n)))
1997 (message "%s: No such directory. Do you want to create it? (y/n)"
1998 dir)
1999 (setq create (read-char)))
2000 (if (= create ?y) (make-directory dir))))
2001 (setq gnus-uu-current-save-dir (concat dir "/"))))
2002
0822af61
RS
2003; Unpacks an archive and views all the files in it. Returns t if
2004; viewing one or more files is successful.
ccfd5a00
RS
2005(defun gnus-uu-treat-archive (file-path)
2006 (let ((did-unpack t)
2007 action command files file file-name dir)
f919f65c 2008 (setq action (gnus-uu-choose-action
ccfd5a00 2009 file-path (append gnus-uu-user-archive-rules
f919f65c
RS
2010 (if gnus-uu-ignore-default-archive-rules
2011 nil
2012 gnus-uu-default-archive-rules))))
f919f65c 2013
ccfd5a00 2014 (if (not action) (error "No unpackers for the file %s" file-path))
f919f65c 2015
ccfd5a00
RS
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)))
f919f65c 2019
ccfd5a00
RS
2020 (if (gnus-uu-string-in-list action gnus-uu-destructive-archivers)
2021 (copy-file file-path (concat file-path "~") t))
f919f65c 2022
ccfd5a00
RS
2023 (setq command (format "cd %s ; %s" dir (gnus-uu-command action file-path)))
2024
2025 (save-excursion
2026 (set-buffer (get-buffer-create gnus-uu-output-buffer-name))
2027 (erase-buffer))
2028
2029 (message "Unpacking: %s..." (gnus-uu-command action file-path))
2030
2031 (if (= 0 (call-process "sh" nil
2032 (get-buffer-create gnus-uu-output-buffer-name)
2033 nil "-c" command))
2034 (message "")
2035 (message "Error during unpacking of archive")
2036 (sleep-for 2)
2037 (setq did-unpack nil))
2038
2039 (if (gnus-uu-string-in-list action gnus-uu-destructive-archivers)
2040 (rename-file (concat file-path "~") file-path t))
2041
2042 did-unpack))
f919f65c 2043
0822af61
RS
2044; Tries to view all the files in the given directory. Returns t if
2045; viewing one or more files is successful.
ccfd5a00
RS
2046(defun gnus-uu-view-directory (dir &optional dont-delete-files not-top)
2047 (let ((first t)
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)
2052
2053 (while (gnus-uu-unpack-archives
2054 files (if not-top (list ".")
2055 (if first () ignore-files)))
2056 (setq first nil)
2057 (gnus-uu-add-file
2058 (setq files (directory-files dir t "[^/][^\\.][^\\.]?$"))))
2059
f919f65c
RS
2060 (while files
2061 (setq file (car files))
2062 (setq files (cdr files))
ccfd5a00 2063 (if (not (string= (or (gnus-uu-get-action file) "") "gnus-uu-archive"))
f919f65c
RS
2064 (progn
2065 (set-file-modes file 448)
2066 (if (file-directory-p file)
ccfd5a00
RS
2067 (setq did-view (or (gnus-uu-view-directory file
2068 dont-delete-files
2069 t)
f919f65c 2070 did-view))
ccfd5a00
RS
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)))
2074
f919f65c
RS
2075 (if (not dont-delete-files) (delete-directory dir))
2076 did-view))
2077
ccfd5a00
RS
2078(defun gnus-uu-unpack-archives (files &optional ignore)
2079 (let (path did-unpack)
2080 (while files
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)) "")
2086 "gnus-uu-archive")
2087 (progn
2088 (setq did-unpack t)
2089 (setq gnus-uu-error-during-unarching
2090 (not (gnus-uu-treat-archive path)))
2091 (if ignore (delete-file path))))))
2092 did-unpack))
2093
f919f65c
RS
2094
2095;; Manual marking
2096
2097(defun gnus-uu-enter-mark-in-list ()
2098 (let (article beg)
ccfd5a00
RS
2099 (save-excursion
2100 (beginning-of-line)
2101 (setq beg (point))
2102 (end-of-line)
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)))))
f919f65c 2108
ccfd5a00 2109(defun gnus-uu-mark-article (&optional dont-move)
f919f65c
RS
2110 "Marks the current article to be decoded later."
2111 (interactive)
2112 (gnus-uu-enter-mark-in-list)
2113 (gnus-summary-mark-as-read nil ?#)
2114 (gnus-summary-next-subject 1 nil))
2115
2116(defun gnus-uu-unmark-article ()
2117 "Unmarks the current article."
2118 (interactive)
2119 (let ((in (copy-sequence gnus-uu-marked-article-list))
2120 out article beg found
2121 (old-point (point)))
2122 (beginning-of-line)
2123 (setq beg (point))
2124 (end-of-line)
2125 (setq article (gnus-uu-article-number (buffer-substring beg (point))))
ccfd5a00 2126 (message "Removing article %d" article)
f919f65c
RS
2127 (while in
2128 (if (not (= (car in) article))
2129 (setq out (cons (car in) out))
2130 (setq found t)
ccfd5a00 2131 (message "Removing article %d" article))
f919f65c
RS
2132 (setq in (cdr in)))
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)))
f919f65c
RS
2137
2138(defun gnus-uu-unmark-all-articles ()
2139 "Removes the mark from all articles marked for decoding."
2140 (interactive)
ccfd5a00
RS
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))))
f919f65c
RS
2145
2146(defun gnus-uu-mark-by-regexp ()
0822af61 2147 "Asks for a regular expression and marks all articles that match."
f919f65c
RS
2148 (interactive)
2149 (let (exp)
ccfd5a00 2150 (setq exp (read-from-minibuffer "Mark (regexp): "))
f919f65c 2151 (setq gnus-uu-marked-article-list
ccfd5a00
RS
2152 (append gnus-uu-marked-article-list
2153 (reverse (gnus-uu-get-list-of-articles exp t))))
f919f65c
RS
2154 (message "")))
2155
ccfd5a00
RS
2156(defun gnus-uu-mark-thread ()
2157 "Marks all articles downwards in this thread."
2158 (interactive)
2159 (beginning-of-line)
2160 (let (level)
2161 (if (not (search-forward ":" nil t))
2162 ()
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))))
2172
2173
2174;; Various stuff
2175
2176(defun gnus-uu-string-in-list (string list)
2177 (while (and list
2178 (not (string= (car list) string))
2179 (setq list (cdr list))))
2180 list)
2181
2182(defun gnus-uu-name-from-path (path)
2183 (string-match "/[^/]*$" path)
2184 (substring path (1+ (match-beginning 0))))
2185
2186(defun gnus-uu-directory-files (dir)
2187 (let (files out file)
2188 (setq files (directory-files dir t))
2189 (while files
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)
2196 out))
f919f65c
RS
2197
2198(defun gnus-uu-check-correct-stripped-uucode (start end)
2199 (let (found beg length short)
2200 (if (not gnus-uu-correct-stripped-uucode)
2201 ()
2202 (goto-char start)
0822af61
RS
2203
2204 (if (re-search-forward " \\|`" end t)
2205 (progn
2206 (goto-char start)
2207 (while (not (eobp))
f919f65c 2208 (progn
0822af61
RS
2209 (if (looking-at "\n") (replace-match ""))
2210 (forward-line 1))))
2211
2212 (while (not (eobp))
2213 (if (looking-at (concat gnus-uu-begin-string "\\|"
2214 gnus-uu-end-string))
2215 ()
2216 (if (not found)
2217 (progn
2218 (beginning-of-line)
2219 (setq beg (point))
2220 (end-of-line)
2221 (setq length (- (point) beg))))
2222 (setq found t)
2223 (beginning-of-line)
2224 (setq beg (point))
2225 (end-of-line)
2226 (if (not (= length (- (point) beg)))
2227 (insert (make-string (- length (- (point) beg)) ? ))))
2228 (forward-line 1))))))
f919f65c
RS
2229
2230(defun gnus-uu-initialize ()
ccfd5a00
RS
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 "/"))
0822af61 2245 (setq gnus-uu-error-during-unarching nil)
ccfd5a00 2246 (setq gnus-uu-interactive-file-list nil))
f919f65c 2247
0822af61 2248; Kills the temporary uu buffers, kills any processes, etc.
f919f65c 2249(defun gnus-uu-clean-up ()
f919f65c 2250 (let (buf pst)
0822af61
RS
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)))
f919f65c
RS
2255 (and (not gnus-uu-asynchronous)
2256 (setq buf (get-buffer gnus-uu-output-buffer-name))
2257 (kill-buffer buf))
2258 (and (setq buf (get-buffer gnus-uu-result-buffer))
2259 (kill-buffer buf))))
2260
0822af61
RS
2261; `gnus-uu-check-for-generated-files' deletes any generated files that
2262; hasn't been deleted, if, for instance, the user terminated decoding
2263; with `C-g'.
f919f65c 2264(defun gnus-uu-check-for-generated-files ()
ccfd5a00 2265 (let (file dirs)
f919f65c
RS
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))
2270 (progn
2271 (if (file-directory-p file)
ccfd5a00 2272 (setq dirs (cons file dirs))
f919f65c 2273 (if (file-exists-p file)
ccfd5a00
RS
2274 (delete-file file))))))
2275 (setq dirs (nreverse dirs))
2276 (while dirs
2277 (setq file (car dirs))
2278 (setq dirs (cdr dirs))
2279 (if (file-directory-p file)
2280 (delete-directory file)))))
2281
2282; Add a file (or a list of files) to be checked (and deleted if it/they
2283; still exists upon exiting the newsgroup).
f919f65c 2284(defun gnus-uu-add-file (file)
ccfd5a00
RS
2285 (if (stringp 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))))
0822af61
RS
2290
2291; Go to the next unread subject. If there is no further unread
2292; subjects, go to the last subject in the buffer.
f919f65c 2293(defun gnus-uu-summary-next-subject ()
ccfd5a00
RS
2294 (let (opi)
2295 (if (not (gnus-summary-search-forward t))
2296 (progn
2297 (goto-char 1)
2298 (sit-for 0)
2299 (goto-char (point-max))
2300 (forward-line -1)
2301 (beginning-of-line)
2302 (search-forward ":" nil t)))
2303
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.
2308 (setq opi (point))
2309 (sit-for 0)
2310 (goto-char opi)
2311 (gnus-summary-recenter)))
f919f65c 2312
0822af61
RS
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)
2316 (let ((ofile ""))
2317 (while (string-match "`\\|\"\\|\\$\\|\\\\" file)
2318 (progn
2319 (setq ofile
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))))
2327
f919f65c
RS
2328
2329;; Initializing
f919f65c
RS
2330(add-hook 'gnus-exit-group-hook
2331 '(lambda ()
2332 (gnus-uu-clean-up)
2333 (setq gnus-uu-marked-article-list nil)
2334 (gnus-uu-check-for-generated-files)))
2335
2336
2337;; Interactive exec mode
2338
2339(defvar gnus-uu-output-window nil)
2340(defvar gnus-uu-mode-hook nil)
2341(defvar gnus-uu-mode-map nil)
2342
2343(defun gnus-uu-do-interactive ()
2344 (let (int-buffer out-buf)
2345 (set-buffer
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
2352 (setq out-buf
2353 (get-buffer-create gnus-uu-output-buffer-name)))
2354 (save-excursion (set-buffer out-buf) (erase-buffer))
2355 (goto-char 1)
2356 (forward-line 3)
2357 (run-hooks 'gnus-uu-mode-hook)))
2358
f919f65c
RS
2359(defun gnus-uu-enter-interactive-file (action file)
2360 (let (command)
2361 (save-excursion
ccfd5a00
RS
2362 (set-buffer (get-buffer-create gnus-uu-interactive-buffer-name))
2363 (if (not gnus-uu-interactive-file-list)
2364 (progn
2365 (erase-buffer)
2366 (gnus-uu-mode)
2367 (insert
2368 "# Press return to execute a command.
2369# Press `C-c C-c' to exit interactive view.
2370
2371")))
f919f65c
RS
2372 (setq gnus-uu-interactive-file-list
2373 (cons file gnus-uu-interactive-file-list))
0822af61 2374 (setq command (gnus-uu-command action file))
f919f65c
RS
2375 (insert (format "%s\n" command)))))
2376
f919f65c 2377(defun gnus-uu-interactive-execute ()
0822af61 2378 "Executes the command on the current line in interactive mode."
f919f65c
RS
2379 (interactive)
2380 (let (beg out-buf command)
2381 (beginning-of-line)
2382 (setq beg (point))
2383 (end-of-line)
2384 (setq command (buffer-substring beg (point)))
2385 (setq out-buf (get-buffer-create gnus-uu-output-buffer-name))
2386 (save-excursion
2387 (set-buffer out-buf)
2388 (erase-buffer)
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)
2394 (message ""))
2395 (forward-line 1)
2396 (beginning-of-line)))
2397
f919f65c 2398(defun gnus-uu-interactive-end ()
0822af61 2399 "This function exits interactive view mode and returns to summary mode."
f919f65c
RS
2400 (interactive)
2401 (let (buf)
2402 (delete-window gnus-uu-output-window)
2403 (gnus-uu-clean-up)
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)))
2409
f919f65c
RS
2410(if gnus-uu-mode-map
2411 ()
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))
2423
f919f65c 2424(defun gnus-uu-interactive-save-original-file ()
0822af61 2425 "Saves the file from whence the file on the current line came from."
f919f65c
RS
2426 (interactive)
2427 (let (file)
2428 (if (file-exists-p
ccfd5a00 2429 (setq file (concat gnus-uu-work-dir
f919f65c 2430 (or gnus-uu-file-name gnus-uu-shar-file-name))))
ccfd5a00
RS
2431 (progn
2432 (gnus-uu-save-file file)
2433 (message "Saved file %s"
2434 (or gnus-uu-file-name gnus-uu-shar-file-name)))
f919f65c
RS
2435 (message "Already saved."))))
2436
f919f65c 2437(defun gnus-uu-interactive-save-current-file-silent ()
0822af61 2438 "Saves the file referred to on the current line in the current directory."
f919f65c
RS
2439 (interactive)
2440 (gnus-uu-interactive-save-current-file t))
2441
2442(defun gnus-uu-interactive-save-current-file (&optional dont-ask silent)
2443 "Saves the file referred to on the current line."
2444 (interactive)
2445 (let (files beg line file)
2446 (setq files (copy-sequence gnus-uu-interactive-file-list))
2447 (beginning-of-line)
2448 (setq beg (point))
2449 (end-of-line)
2450 (setq line (buffer-substring beg (point)))
2451 (while (and files
2452 (not (string-match
2453 (concat "" (regexp-quote (setq file (car files))) "")
2454 line)))
2455 (setq files (cdr files)))
2456 (beginning-of-line)
2457 (forward-line 1)
2458 (if (not files)
2459 (if (not silent)
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)))))
2463
f919f65c 2464(defun gnus-uu-interactive-save-all-files ()
0822af61 2465 "Saves all files referred to in the interactive buffer."
f919f65c
RS
2466 (interactive)
2467 (let (dir)
2468 (goto-char 1)
2469 (setq dir (gnus-uu-read-directory "Where do you want the files? "))
2470 (while (not (eobp))
2471 (gnus-uu-interactive-save-current-file t t))))
2472
2473(defun gnus-uu-mode ()
2474 "Major mode for editing view commands in gnus-uu.
2475
f919f65c 2476Commands:
0822af61
RS
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
f919f65c 2481 where to put it
0822af61
RS
2482\\[gnus-uu-interactive-save-all-files] Save all files
2483\\[gnus-uu-interactive-save-original-file] Save the original file: If the files
f919f65c
RS
2484 originated in an archive, the archive
2485 file is saved.
2486"
2487 (interactive)
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)
2492)
2493
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)
2504
ccfd5a00
RS
2505
2506;; Major mode for posting encoded articles.
2507
2508(require 'sendmail)
2509(require 'rnews)
2510
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.
2517There 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
2520headers; and `gnus-uu-post-encode-mime-uuencode', which encodes with
2521uuencode and adds MIME headers.")
2522
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.
2525If 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.")
2527
2528(defvar gnus-uu-post-length 990
2529 "Maximum length of an article.
2530The encoded file will be split into how many articles it takes to
2531post the entire file.")
2532
2533(defvar gnus-uu-post-threaded nil
2534 "Non-nil means that gnus-uu will post the encoded file in a thread.
2535This may not be smart, as no other decoder I have seen are able to
2536follow threads when collecting uuencoded articles. (Well, I have seen
2537one package that does that - gnus-uu, but somehow, I don't think that
2538counts...) Default is nil.")
2539
2540(defvar gnus-uu-post-separate-description t
2541 "Non-nil means that the description will be posted in a separate article.
2542The first article will typically be numbered (0/x). If this variable
2543is nil, the description the user enters will be included at the
2544beginning of the first article, which will be numbered (1/x). Default
2545is t.")
2546
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)
2551
2552; The following map and mode was taken from rnewspost.el and edited
2553; somewhat.
2554(defvar gnus-uu-post-reply-mode-map () "Mode map used by gnus-uu-post-reply.")
2555(or gnus-uu-post-reply-mode-map
2556 (progn
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)
2565
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)
2584 ))
2585
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.
2589First-time posters are asked to please read the articles in newsgroup:
2590 news.announce.newusers .
2591
2592Like news-reply-mode, which is like Text Mode, but with these
2593additional commands:
2594
2595\\<gnus-uu-post-reply-mode-map>\\[gnus-uu-post-news-inews] post the message.
2596C-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:
2600C-c C-y news-reply-yank-original (insert current message, in NEWS).
2601C-c C-q mail-fill-yanked-message (fill what was yanked).
2602C-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.
2604
2605This mode is almost identical to news-reply-mode, but has some
2606additional commands for treating encoded binary articles. In
2607particular, \\[gnus-uu-post-news-inews] will ask for a file to include, if
2608one hasn't been included already. It will post, first, the message
2609composed, and then it will post as many additional articles it takes
2610to post the entire encoded files.
2611
2612 Relevant Variables
2613
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.
2620
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
2625 post the article.
2626
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.
2630
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.
2637
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.
2644"
2645 (interactive)
2646 ;; require...
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 "$\\|"
2659 paragraph-start))
2660 (setq paragraph-separate (concat "^" mail-header-separator "$\\|"
2661 paragraph-separate))
2662 (run-hooks 'text-mode-hook 'gnus-uu-post-reply-mode-hook))
2663
2664(defun gnus-uu-post-news ()
2665 "Compose an article and post an encoded file."
2666 (interactive)
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))))))
2675
2676(defun gnus-uu-post-insert-binary-in-article ()
2677 "Inserts an encoded file in the buffer.
2678The user will be asked for a file name."
2679 (interactive)
2680 (if (not (eq (current-buffer) (get-buffer gnus-post-news-buffer)))
2681 (error "Not in post-news buffer"))
2682 (save-excursion
2683 (setq gnus-uu-post-inserted-file-name (gnus-uu-post-insert-binary))))
2684
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)
2688 (progn
2689 (goto-char 1)
2690 (forward-line 1)
2691 (while (re-search-forward " " nil t)
2692 (replace-match "`"))
2693 t)))
2694
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)
2698 (progn
2699 (gnus-uu-post-make-mime file-name "x-uue")
2700 t)))
2701
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)
2705 (progn
2706 (gnus-uu-post-make-mime file-name "base64")
2707 t)))
2708
2709; Adds MIME headers.
2710(defun gnus-uu-post-make-mime (file-name encoding)
2711 (goto-char 1)
2712 (insert (format "Content-Type: %s; name=\"%s\"\n"
2713 (gnus-uu-choose-action file-name gnus-uu-ext-to-mime-list)
2714 file-name))
2715 (insert (format "Content-Transfer-Encoding: %s\n\n" encoding))
2716 (save-restriction
2717 (set-buffer gnus-post-news-buffer)
2718 (goto-char 1)
2719 (re-search-forward mail-header-separator)
2720 (beginning-of-line)
2721 (forward-line -1)
2722 (narrow-to-region 1 (point))
2723 (or (mail-fetch-field "mime-version")
2724 (progn
2725 (widen)
2726 (insert "MIME-Version: 1.0\n")))
2727 (widen)))
2728
2729; Encodes a file PATH with COMMAND, leaving the result in the
2730; current buffer.
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))))
2734
2735(defun gnus-uu-post-news-inews ()
2736 "Posts the composed news article and encoded file.
2737If no file has been included, the user will be asked for a file."
2738 (interactive)
2739 (if (not (eq (current-buffer) (get-buffer gnus-post-news-buffer)))
2740 (error "Not in post news buffer"))
2741
2742 (let (file-name)
2743
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)))
2747
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)
2754
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
2759 (cons
2760 '(lambda ()
2761 (save-excursion
2762 (goto-char 1)
2763 (if (re-search-forward "^Message-ID: \\(.*\\)$" nil t)
2764 (setq gnus-uu-post-message-id
2765 (buffer-substring
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)))
2774
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)
2780
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))
2785
2786 (goto-char (point-max))
2787 (insert (format "\n%s\n" gnus-uu-post-binary-separator))
2788
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))
2794
2795 (unwind-protect
2796 (if (save-excursion
2797 (set-buffer (setq uubuf
2798 (get-buffer-create uuencode-buffer-name)))
2799 (erase-buffer)
2800 (funcall gnus-uu-post-encode-method file-path file-name))
2801 (insert-buffer uubuf)
2802 (error "Encoding unsuccessful"))
2803 (kill-buffer uubuf))
2804 file-name))
2805
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)
2814
2815 (setq post-buf (current-buffer))
2816
2817 (goto-char 1)
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"))
2823 (beginning-of-line)
2824 (forward-line 1)
2825 (setq beg-binary (point))
2826 (setq end-binary (point-max))
2827
2828 (save-excursion
2829 (set-buffer (setq uubuf (get-buffer-create encoded-buffer-name)))
2830 (erase-buffer)
2831 (insert-buffer-substring post-buf beg-binary end-binary)
2832 (goto-char 1)
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))))
2837
2838 (if gnus-uu-post-separate-description
2839 (forward-line -1))
2840 (kill-region (point) (point-max))
2841
2842 (goto-char 1)
2843 (search-forward mail-header-separator nil t)
2844 (beginning-of-line)
2845 (setq header (buffer-substring 1 (point)))
2846
2847 (goto-char 1)
2848 (if (not gnus-uu-post-separate-description)
2849 ()
2850 (if (and (not threaded) (re-search-forward "^Subject: " nil t))
2851 (progn
2852 (end-of-line)
2853 (insert (format " (0/%d)" parts))))
2854 (gnus-inews-news))
2855
2856 (save-excursion
2857 (setq i 1)
2858 (setq beg 1)
2859 (while (not (> i parts))
2860 (set-buffer (get-buffer-create send-buffer-name))
2861 (erase-buffer)
2862 (insert header)
2863 (if (and threaded gnus-uu-post-message-id)
2864 (insert (format "References: %s\n" gnus-uu-post-message-id)))
2865 (insert separator)
2866 (setq whole-len
2867 (- 62 (length (format top-string "" file-name i parts ""))))
2868 (if (> 1 (setq minlen (/ whole-len 2)))
2869 (setq minlen 1))
2870 (setq
2871 beg-line
2872 (format top-string
2873 (make-string minlen ?-)
2874 file-name i parts
2875 (make-string
2876 (if (= 0 (% whole-len 2)) (1- minlen) minlen) ?-)))
2877
2878 (goto-char 1)
2879 (if (not (re-search-forward "^Subject: " nil t))
2880 ()
2881 (if (not threaded)
2882 (progn
2883 (end-of-line)
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: "))))
2888
2889 (goto-char (point-max))
2890 (save-excursion
2891 (set-buffer uubuf)
2892 (goto-char beg)
2893 (if (= i parts)
2894 (goto-char (point-max))
2895 (forward-line gnus-uu-post-length))
2896 (setq end (point)))
2897 (insert-buffer-substring uubuf beg end)
2898 (insert beg-line)
2899 (insert "\n")
2900 (setq beg end)
2901 (setq i (1+ i))
2902 (goto-char 1)
2903 (re-search-forward mail-header-separator nil t)
2904 (beginning-of-line)
2905 (forward-line 2)
2906 (if (re-search-forward gnus-uu-post-binary-separator nil t)
2907 (progn
2908 (replace-match "")
2909 (forward-line 1)))
2910 (insert beg-line)
2911 (insert "\n")
2912 (gnus-inews-news)))
2913
2914 (and (setq buf (get-buffer send-buffer-name))
2915 (kill-buffer buf))
2916 (and (setq buf (get-buffer encoded-buffer-name))
2917 (kill-buffer buf))
2918
2919 (if (not gnus-uu-post-separate-description)
2920 (progn
2921 (set-buffer-modified-p nil)
2922 (and (fboundp 'bury-buffer) (bury-buffer))))))
2923
f919f65c
RS
2924(provide 'gnus-uu)
2925
e399bdd5 2926;; gnus-uu.el ends here
ccfd5a00 2927