aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorRichard M. Stallman1994-05-03 06:05:48 +0000
committerRichard M. Stallman1994-05-03 06:05:48 +0000
commitccfd5a004a57edde76ab26fc5c29c92765f5b92d (patch)
treeda00b01e10e6c4732555b9b6ea7b45ed79bd4a3a
parent165af501cfdc5b4df4b72c189e2dd19e237f43db (diff)
downloademacs-ccfd5a004a57edde76ab26fc5c29c92765f5b92d.tar.gz
emacs-ccfd5a004a57edde76ab26fc5c29c92765f5b92d.zip
Removed some keystrokes for obscure toggle commands:
C-c C-v C-a, C-c C-v C-p, C-c C-v C-q and C-c C-v C-k. (gnus-uu-decode-and-save-all-unread-articles-and-mark): Fn deleted. (gnus-uu-decode-and-save-all-articles-and-mark): Fn deleted. (gnus-uu-do-sloppy-uudecode): Variable deleted. (gnus-uu-decode-and-save-articles): Rewritten. (gnus-uu-grab-articles, gnus-uu-uustrip-article-as): Rewritten to properly handle multiple encoded files in one gulp. (gnus-uu-uustrip-article-as): Replace spaces in file names with underscores before giving the file to uudecode. (gnus-uu-save-in-digest): Doc fix. (gnus-uu-save-articles, gnus-uu-save-article, gnus-uu-digest-and-forward, gnus-uu-marked-digest-and-forward): Changed old functions and added new functions to digest and forward articles. (gnus-uu-mark-thread): New function to mark a thread for later treatment. (gnus-uu-mark-by-regexp): Changed to add articles instead of clearing before adding. (gnus-uu-check-for-generated-files): First delete files, then directories. (gnus-uu-edit-begin-line, gnus-uu-decode-and-show-in-buffer): Select the current article before starting work. (gnus-uu-decode-and-view-all-unread-articles) (gnus-uu-decode-and-view-all-articles): Two new functions for decoding and viewing all (unread) articles in a newsgroup. (gnus-uu-view-directory, gnus-uu-unpack-archives, gnus-uu-treat-archive): gnus-uu will now treat archives in archives (etc) properly when viewing. (gnus-uu-threaded-multi-decode-and-save, gnus-uu-threaded-multi-decode-and-view): New interactive functions for decoding/saving threads. Bound to `C-c C-v C-j'. (gnus-uu-save-article): Added RFC1153-compliant digest saving. (gnus-uu-initialize): Does some checks and expands relative temp dir names. (gnus-uu-decode-and-show-in-buffer) (gnus-uu-decode-and-strip, gnus-uu-grab-articles) (gnus-uu-decode-and-view-or-save): Allow multiple encoded files to be decoded (and viewed) in one fell swoop. (gnus-uu-work-dir): New variable. (gnus-uu-view-file): Changed to work with metamail. (gnus-uu-get-action, gnus-uu-toggle-view-with-metamail): New functions. (gnus-uu-ext-to-mime, gnus-uu-view-with-metamail): New variables. (gnus-uu-ctl-map): Add C-a binding. (gnus-uu-summary-next-subject): Ensures that the next unread article is moved to. (gnus-uu-default-interactive-view-rules-end): New variable to provide a "catch-all" when using interactive mode. (gnus-uu-get-action): Changed viewing rules in interactive mode. (gnus-uu-uustrip-article-as): Disabled case-fold-search and changed gnus-uu-body-line to be more restrictive. (gnus-uu-multi-decode-and-view-or-save, gnus-uu-uustrip-article-as): Changed hard returns to \r. (gnus-uu-post-reply-mode): New mode for sending encoded files. (gnus-uu-post-news, gnus-uu-post-insert-binary-in-article) (gnus-uu-post-encode-uuencode, gnus-uu-post-encode-mime-uuencode) (gnus-uu-post-encode-mime, gnus-uu-post-make-mime) (gnus-uu-post-encode-file, gnus-uu-post-news-inews) (gnus-uu-post-insert-binary, gnus-uu-post-encoded): New functions. (gnus-uu-post-encode-method, gnus-uu-post-include-before-composing) (gnus-uu-post-threaded, gnus-uu-post-binary-separator): New variables.
-rw-r--r--lisp/gnus-uu.el2447
1 files changed, 1506 insertions, 941 deletions
diff --git a/lisp/gnus-uu.el b/lisp/gnus-uu.el
index e4006a45675..838bbc21cb8 100644
--- a/lisp/gnus-uu.el
+++ b/lisp/gnus-uu.el
@@ -1,11 +1,10 @@
1;;; gnus-uu.el --- extract, view or save (uu)encoded files from gnus 1;;; gnus-uu.el --- extract, view or save (uu)encoded files from gnus
2
3;; Copyright (C) 1985, 1986, 1987, 1993, 1994 Free Software Foundation, Inc. 2;; Copyright (C) 1985, 1986, 1987, 1993, 1994 Free Software Foundation, Inc.
4 3
5;; Author: Lars Ingebrigtsen <larsi@ifi.uio.no> 4;; Author: Lars Ingebrigtsen <larsi@ifi.uio.no>
6;; Created: 2 Oct 1993 5;; Created: 2 Oct 1993
7;; Version: v2.5.2 6;; Version: v2.7.2
8;; Last Modified: 1994/04/13 7;; Last Modified: 1994/05/03
9;; Keyword: news 8;; Keyword: news
10 9
11;; This file is part of GNU Emacs. 10;; This file is part of GNU Emacs.
@@ -28,230 +27,24 @@
28 27
29;; All gnus-uu commands start with `C-c C-v'. 28;; All gnus-uu commands start with `C-c C-v'.
30;; 29;;
31;; Typing `C-c C-v C-v' (`gnus-uu-decode-and-view') in the summary 30;; Short user manual for this package:
32;; buffer will try to find all articles in the same series, uudecode
33;; them and view the resulting file(s).
34;;
35;; gnus-uu guesses what articles are in the series according to the
36;; following simple rule: The subjects must be identical, except for
37;; the last two numbers of the line.
38;;
39;; For example: If you choose a subject called "cat.gif (2/3)" gnus-uu
40;; will find all the articles that matches "^cat.gif
41;; ([0-9]+/[0-9]+).*$". Subjects that are nonstandard, like "cat.gif
42;; (2/3) Part 6 of a series", will not be properly recognized by 'C-c
43;; C-v C-v', and you have to mark the articles manually with '#'.
44;;
45;; Typing `C-c C-v v' (`gnus-uu-decode-and-save') will do the same as
46;; `C-c C-v C-v', except that it will not display the resulting file,
47;; but save it instead.
48;;
49;; Typing `C-c C-v s' (`gnus-uu-shar-and-save') does the same as `C-c
50;; C-v v', and `C-c C-v C-s' (`gnus-uu-shar-and-view') does the same
51;; as `C-c C-v C-v', except that they unshar files instead, i. e. run
52;; them through /bin/sh. Most shar files can be viewed and/or saved
53;; with the normal uudecode commands, which is much safer, as no
54;; foreign code is run.
55;;
56;; `#' (`gnus-uu-mark-article') marks an article for later
57;; decoding/unsharing/saving/viewing. The files will be decoded in the
58;; sequence they were marked. To decode the files after you've marked
59;; the articles you are interested in, type the corresponding key
60;; strokes as the normal decoding commands, but put a `M-' in the last
61;; keystroke. For instance, to perform a standard uudecode and view,
62;; you would type `C-c C-v C-v'. To perform a marked uudecode and
63;; view, say `C-v C-v M-C-v'. All the other view and save commands are
64;; handled the same way; marked uudecode and save is then `C-c C-v
65;; M-v'.
66;;
67;; `M-#' (`gnus-uu-unmark-article') will remove the mark from a
68;; previosly marked article.
69;;
70;; `C-c C-v C-u' (`gnus-uu-unmark-all-articles') will remove the mark from
71;; all marked articles.
72;;
73;; `C-c C-v C-r' (`gnus-uu-mark-by-regexp') will prompt for a regular
74;; expression and mark (forward) all articles matching that regular
75;; expression.
76;;
77;; There's an additional way to reach the decoding functions to make
78;; future expansions easier: `C-c C-v C-m'
79;; (`gnus-uu-multi-decode-and-view') and the corresponding save, marked
80;; view and marked save keystrokes, `C-c C-v m', `C-c C-v M-C-m' and
81;; `C-c C-v M-m' respectively. You will be prompted for decoding
82;; method, like uudecode, shar, binhex or plain save. Note that
83;; methods like binhex and save doesn't have view modes; even if you
84;; issue a view command (`C-c C-v C-m' and "binhex"), gnus-uu will
85;; just save the resulting binhex file.
86;;
87;; `C-c C-v C-b' (`gnus-uu-decode-and-show-in-buffer') will decode the
88;; current article and display the results in an emacs buffer. This
89;; might be useful if there's jsut some text in the current article
90;; that has been uuencoded by some perverse poster.
91;;
92;; `C-c C-v a' (`gnus-uu-decode-and-save-all-articles') looks at all the
93;; articles in the current newsgroup and tries to uudecode everything
94;; it can find. The user will be prompted for a directory where the
95;; resulting files (if any) will be stored. `C-c C-v M-a' only looks
96;; at unread article. `C-c C-v w' does the same as `C-c C-v a', but
97;; also marks as read all articles it has peeked through, even if they
98;; weren't uuencoded articles. `C-c C-v M-w' is, as you might have
99;; guessed, similar to `C-c C-v M-a'.
100;;
101;; `C-c C-v C-l' (`gnus-uu-edit-begin-line') lets you edit the begin
102;; line of the current buffer. Useful to change an incorrect suffix or
103;; an incorrect begin line.
104;;
105;;
106;; When using the view commands, `C-c C-v C-v' for instance, gnus-uu
107;; will (normally, see below) try to view the file according to the
108;; rules given in `gnus-uu-default-view-rules' and
109;; `gnus-uu-user-view-rules'. If it recognises the file, it will
110;; display it immediately. If the file is some sort of archive,
111;; gnus-uu will attempt to unpack the archive and see if any of the
112;; files in the archive can be viewed. For instance, if you have a
113;; gzipped tar file "pics.tar.gz" containing the files "pic1.jpg" and
114;; "pic2.gif", gnus-uu will uncompress and detar the main file, and
115;; then view the two pictures. This unpacking process is recursive, so
116;; if the archive contains archives of archives, it'll all be
117;; unpacked.
118;;
119;; If the view command doesn't recognise the file type, or can't view
120;; it because you don't have the viewer, or can't view *any* of the
121;; files in the archive, the user will be asked if she wishes to have
122;; the file saved somewhere. Note that if the decoded file is an
123;; archive, and gnus-uu manages to view some of the files in the
124;; archive, it won't tell the user that there were some files that
125;; were unviewable. See "Interactive view" for a different approach.
126;;
127;;
128;; Note that gnus-uu adds a function to `gnus-exit-group-hook' to
129;; clear the list of marked articles and check for any generated files
130;; that might have escaped deletion if the user typed `C-g'.
131;;
132;;
133;; `C-c C-v C-a' (`gnus-uu-toggle-asynchronous') toggles the
134;; `gnus-uu-asynchronous' variable. See below for explanation.
135;;
136;; `C-c C-v C-q' (`gnus-uu-toggle-query') toggles the
137;; `gnus-uu-ask-before-view' variable. See below for explanation.
138;;
139;; `C-c C-v C-p' (`gnus-uu-toggle-always-ask') toggles the
140;; `gnus-uu-view-and-save' variable. See below for explanation.
141;;
142;; `C-c C-v C-k' (`gnus-uu-toggle-kill-carriage-return') toggles the
143;; `gnus-uu-kill-carriage-return' variable. See below for explanation.
144;;
145;; `C-c C-v C-i' (`gnus-uu-toggle-interactive-view') toggles interactive
146;; mode. If it is turned on, gnus-uu won't view files immediately but
147;; give you a buffer with the default commands and files and lets you
148;; edit the commands and execute them at leisure.
149;;
150;; `C-c C-v C-t' (`gnus-uu-toggle-any-variable') is an interface to the
151;; five toggle commands listed above.
152;;
153;; `gnus-uu-toggle-correct-stripped-articles' toggles whether to check
154;; and correct uuencoded articles that may have had trailing spaces
155;; stripped by mailers.
156;;
157;; 31;;
158;; Customization 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.
159;; 34;;
160;; To load this file when starting gnus, put sumething like the 35;; Type `C-c C-v C-i' to toggle interactive mode. When using
161;; following in your .emacs file: 36;; interactive mode, gnus-uu will which display a buffer that will let
37;; you see the suggested commands to be executed.
162;; 38;;
163;; (setq gnus-group-mode-hook 39;; To post an uuencoded file, type `C-c C-v p', which will enter you
164;; '(lambda () (load "gnus-uu"))) 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.
165;; 43;;
166;; To make gnus-uu use, for instance, "xli" to view JPEGs and GIFs, 44;; Read the documentation of the `gnus-uu' dummy function for a more
167;; put this in your .emacs file: 45;; complete description of what this package does and how you can
168;; 46;; customize it to fit your needs.
169;; (setq gnus-uu-user-view-rules 47;;
170;; (list
171;; '("jpg$\\|gif$" "xli")
172;; ))
173;;
174;; This variable is a list where each list item is a list containing
175;; two strings. The first string is a regular expression. If the file
176;; name is matched by this expression, the command given in the
177;; second string is executed on this file. If the command contains
178;; "%s", the file will be inserted there in the command string. Eg.
179;; "giftoppm %s | xv -" will result in the file name being inserted at
180;; the "%s".
181;;
182;; If you don't want to display certain file types, like if you
183;; haven't got sound capabilities, you could put something like
184;;
185;; (setq gnus-uu-user-view-rules
186;; (list
187;; '("au$\\|voc$\\|wav$" nil)
188;; ))
189;;
190;; in your .emacs file.
191;;
192;; There's a similar variable called `gnus-uu-user-archive-rules'
193;; which gives a list of unarcers to use when looking inside archives
194;; for files to display.
195;;
196;; If you don't want gnus-uu to look inside archives for files to
197;; display, say
198;;
199;; (setq gnus-uu-do-not-unpack-archives t)
200;;
201;;
202;; If you want gnus-uu to ask you if you want to save a file after
203;; viewing, say
204;;
205;; (setq gnus-uu-view-and-save t)
206;;
207;;
208;; If you don't want to wait for the viewing command to finish before
209;; returning to emacs, say
210;;
211;; (setq gnus-uu-asynchronous t)
212;;
213;;
214;; This can be useful if you're viewing long .mod files, for instance,
215;; which often takes several minutes. Note, however, that since
216;; gnus-uu doesn't ask, and if you are viewing an archive with lots of
217;; viewable files, you'll get them all up more or less at once, which
218;; can be confusing, to say the least. To get gnus-uu to ask you
219;; before viewing a file, say
220;;
221;; (setq gnus-uu-ask-before-view t)
222;;
223;; You can set this variable even if you're not using asynchronous
224;; viewing, of course.
225;;
226;; If the articles has been posted by some numbscull with a PC (isn't
227;; that a bit redundant, though?) and there's lots of carriage returns
228;; everywhere, say
229;;
230;; (setq gnus-uu-kill-carriage-return t)
231;;
232;; If you want gnus-uu to ignore the default file rules when viewing,
233;; for instance if there's several file types that you can't view, set
234;; `gnus-uu-ignore-default-view-rules' to t. There's a similar
235;; variable to disable the default unarchive rule list,
236;; `gnus-uu-ignore-default-archive-rules'.
237;;
238;; If you want a more interactive approach to file viewing, say
239;;
240;; (setq gnus-uu-use-interactive-view t)
241;;
242;; If this variable is set, whenever you type `C-c C-v C-v' (or any of
243;; the other view commands), gnus-uu will present you with a buffer
244;; with the default actions and file names after decoding. You can
245;; edit the command lines and execute them in a convenient fashion.
246;; The output from the commands will be displayed in a small window at
247;; the bottom of the emacs window. End interactive mode by typing `C-c
248;; C-c' in the view window.
249;;
250;; If you want gnus-uu to unmark articles that you have asked to
251;; decode, but can't be decoded (if, for instance, the articles aren't
252;; uuencoded files or the posting is incomplete), say
253;;
254;; (setq gnus-uu-unmark-articles-not-decoded t)
255;; 48;;
256;; 49;;
257;; History 50;; History
@@ -286,45 +79,23 @@
286;; 79;;
287;; v2.5.1: Added uuencode/posting code to post binary files. 80;; v2.5.1: Added uuencode/posting code to post binary files.
288;; 81;;
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.
289;; 86;;
290;; Default keymap overview: 87;; v2.7: gnus-uu is now able to decode (and view/save) multiple
291;; 88;; encoded files in one big gulp. Also added pseudo-mime support
292;; All commands start with `C-c C-v'. The difference is in the third 89;; (users can use metamail to view files), posting uuencoded/mime
293;; keystroke. All view commands are `C-LETTER'. All save commands are 90;; files and various other bits and pieces.
294;; just `LETTER'. All marked commands are the same as the unmarked
295;; commands, except that they have `M-' before in the last keystroke.
296;;
297;; `C-c C-v C-v' gnus-uu-decode-and-view
298;; `C-c C-v v' gnus-uu-decode-and-save
299;; `C-c C-v C-s' gnus-uu-shar-and-view
300;; `C-c C-v s' gnus-uu-shar-and-save
301;; `C-c C-v C-m' gnus-uu-multi-decode-and-view
302;; `C-c C-v m' gnus-uu-multi-decode-and-save
303;; 91;;
304;; `C-c C-v C-b' gnus-uu-decode-and-show-in-buffer 92;; v2.7.1: New functions for decoding/saving threads bound to `C-c
305;; `C-c C-v C-l' gnus-uu-edit-begin-line 93;; C-v C-j'. Handy to save entire threads, not very useful for
306;; `C-c C-v M-a' gnus-uu-decode-and-save-all-unread-articles 94;; decoding, as nobody posts encoded files in threads...
307;; `C-c C-v a' gnus-uu-decode-and-save-all-articles
308;; `C-c C-v M-w' gnus-uu-decode-and-save-all-unread-articles-and-mark
309;; `C-c C-v w' gnus-uu-decode-and-save-all-articles-and-mark
310;; 95;;
311;; `#' gnus-uu-mark-article 96;; V2.7.2: New functions for digesting and forwarding articles added
312;; `M-#' gnus-uu-unmark-article 97;; on the suggestion of Per Abrahamsen. Also added a function for
313;; `C-c C-v C-u' gnus-uu-unmark-all-articles 98;; marking threads.
314;; `C-c C-v C-r' gnus-uu-mark-by-regexp
315;; `C-c C-v M-C-v' gnus-uu-marked-decode-and-view
316;; `C-c C-v M-v' gnus-uu-marked-decode-and-save
317;; `C-c C-v M-C-s' gnus-uu-marked-shar-and-view
318;; `C-c C-v M-s' gnus-uu-marked-shar-and-save
319;; `C-c C-v M-C-m' gnus-uu-marked-multi-decode-and-view
320;; `C-c C-v M-m' gnus-uu-marked-multi-decode-and-save
321;;
322;; `C-c C-v C-a' gnus-uu-toggle-asynchronous
323;; `C-c C-v C-q' gnus-uu-toggle-query
324;; `C-c C-v C-p' gnus-uu-toggle-always-ask
325;; `C-c C-v C-k' gnus-uu-toggle-kill-carriage-return
326;; `C-c C-v C-i' gnus-uu-toggle-interactive-view
327;; `C-c C-v C-t' gnus-uu-toggle-any-variable
328 99
329;;; Code: 100;;; Code:
330 101
@@ -350,6 +121,8 @@
350(define-key gnus-summary-mode-map "\M-#" 'gnus-uu-unmark-article) 121(define-key gnus-summary-mode-map "\M-#" 'gnus-uu-unmark-article)
351(define-key gnus-uu-ctl-map "\C-u" 'gnus-uu-unmark-all-articles) 122(define-key gnus-uu-ctl-map "\C-u" 'gnus-uu-unmark-all-articles)
352(define-key gnus-uu-ctl-map "\C-r" 'gnus-uu-mark-by-regexp) 123(define-key gnus-uu-ctl-map "\C-r" 'gnus-uu-mark-by-regexp)
124(define-key gnus-uu-ctl-map "r" 'gnus-uu-mark-by-regexp)
125(define-key gnus-uu-ctl-map "t" 'gnus-uu-mark-thread)
353 126
354(define-key gnus-uu-ctl-map "\M-\C-v" 'gnus-uu-marked-decode-and-view) 127(define-key gnus-uu-ctl-map "\M-\C-v" 'gnus-uu-marked-decode-and-view)
355(define-key gnus-uu-ctl-map "\M-v" 'gnus-uu-marked-decode-and-save) 128(define-key gnus-uu-ctl-map "\M-v" 'gnus-uu-marked-decode-and-save)
@@ -358,28 +131,34 @@
358(define-key gnus-uu-ctl-map "\M-\C-m" 'gnus-uu-marked-multi-decode-and-view) 131(define-key gnus-uu-ctl-map "\M-\C-m" 'gnus-uu-marked-multi-decode-and-view)
359(define-key gnus-uu-ctl-map "\M-m" 'gnus-uu-marked-multi-decode-and-save) 132(define-key gnus-uu-ctl-map "\M-m" 'gnus-uu-marked-multi-decode-and-save)
360 133
361(define-key gnus-uu-ctl-map "\C-a" 'gnus-uu-toggle-asynchronous) 134(define-key gnus-uu-ctl-map "f" 'gnus-uu-digest-and-forward)
362(define-key gnus-uu-ctl-map "\C-q" 'gnus-uu-toggle-query) 135(define-key gnus-uu-ctl-map "\M-f" 'gnus-uu-marked-digest-and-forward)
363(define-key gnus-uu-ctl-map "\C-p" 'gnus-uu-toggle-always-ask) 136
364(define-key gnus-uu-ctl-map "\C-k" 'gnus-uu-toggle-kill-carriage-return)
365(define-key gnus-uu-ctl-map "\C-i" 'gnus-uu-toggle-interactive-view) 137(define-key gnus-uu-ctl-map "\C-i" 'gnus-uu-toggle-interactive-view)
366(define-key gnus-uu-ctl-map "\C-t" 'gnus-uu-toggle-any-variable) 138(define-key gnus-uu-ctl-map "\C-t" 'gnus-uu-toggle-any-variable)
367 139
368(define-key gnus-uu-ctl-map "\C-l" 'gnus-uu-edit-begin-line) 140(define-key gnus-uu-ctl-map "\C-l" 'gnus-uu-edit-begin-line)
369 141
370(define-key gnus-uu-ctl-map "\M-a" 'gnus-uu-decode-and-save-all-unread-articles) 142(define-key gnus-uu-ctl-map "a" 'gnus-uu-decode-and-save-all-unread-articles)
371(define-key gnus-uu-ctl-map "a" 'gnus-uu-decode-and-save-all-articles) 143(define-key gnus-uu-ctl-map "w" 'gnus-uu-decode-and-save-all-articles)
372(define-key gnus-uu-ctl-map "\M-w" 'gnus-uu-decode-and-save-all-unread-articles-and-mark) 144(define-key gnus-uu-ctl-map "\C-a" 'gnus-uu-decode-and-view-all-unread-articles)
373(define-key gnus-uu-ctl-map "w" 'gnus-uu-decode-and-save-all-articles-and-mark) 145(define-key gnus-uu-ctl-map "\C-w" 'gnus-uu-decode-and-view-all-articles)
374 146
375;(load "rnewspost") 147(define-key gnus-uu-ctl-map "\C-h" 'gnus-uu-threaded-decode-and-view)
376;(define-key news-reply-mode-map "\C-c\C-v" 'gnus-uu-uuencode-and-post) 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)
377 153
378;; Dummy function gnus-uu 154;; Dummy function gnus-uu
379 155
380(defun gnus-uu () 156(defun gnus-uu ()
381 "gnus-uu is a package for uudecoding and viewing articles. 157 "gnus-uu is a package for uudecoding and viewing articles.
382 158
159
160Keymap overview:
161
383By default, all gnus-uu keystrokes begin with `C-c C-v'. 162By default, all gnus-uu keystrokes begin with `C-c C-v'.
384 163
385There four decoding commands categories: 164There four decoding commands categories:
@@ -395,18 +174,25 @@ All commands for marked saving are `C-c C-v M-LETTER'.
395\\[gnus-uu-multi-decode-and-view]\tChoose a decoding method, decode and view articles 174\\[gnus-uu-multi-decode-and-view]\tChoose a decoding method, decode and view articles
396\\[gnus-uu-multi-decode-and-save]\tChoose a decoding method, decode and save articles 175\\[gnus-uu-multi-decode-and-save]\tChoose a decoding method, decode and save articles
397 176
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
398\\[gnus-uu-decode-and-show-in-buffer]\tDecode the current article and view the result in a buffer 180\\[gnus-uu-decode-and-show-in-buffer]\tDecode the current article and view the result in a buffer
399\\[gnus-uu-edit-begin-line]\tEdit the 'begin' line of an uuencoded article 181\\[gnus-uu-edit-begin-line]\tEdit the 'begin' line of an uuencoded article
400 182
401\\[gnus-uu-decode-and-save-all-unread-articles]\tDecode and save all unread articles 183\\[gnus-uu-decode-and-save-all-unread-articles]\tDecode and save all unread articles
402\\[gnus-uu-decode-and-save-all-articles]\tDecode and save all articles 184\\[gnus-uu-decode-and-save-all-articles]\tDecode and save all articles
403\\[gnus-uu-decode-and-save-all-unread-articles-and-mark]\tDecode and save all unread articles and catch up 185\\[gnus-uu-decode-and-view-all-unread-articles]\tDecode and view all unread articles
404\\[gnus-uu-decode-and-save-all-articles-and-mark]\tDecode and save all articles and catch up 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
405 190
406\\[gnus-uu-mark-article]\tMark the current article for decoding 191\\[gnus-uu-mark-article]\tMark the current article for decoding
407\\[gnus-uu-unmark-article]\tUnmark the current article 192\\[gnus-uu-unmark-article]\tUnmark the current article
408\\[gnus-uu-unmark-all-articles]\tUnmark all articles 193\\[gnus-uu-unmark-all-articles]\tUnmark all articles
409\\[gnus-uu-mark-by-regexp]\tMark articles for decoding by regexp 194\\[gnus-uu-mark-by-regexp]\tMark articles for decoding by regexp
195\\[gnus-uu-mark-thread]\tMark articles in this thread
410\\[gnus-uu-marked-decode-and-view]\tDecode and view marked articles 196\\[gnus-uu-marked-decode-and-view]\tDecode and view marked articles
411\\[gnus-uu-marked-decode-and-save]\tDecode and save marked articles 197\\[gnus-uu-marked-decode-and-save]\tDecode and save marked articles
412\\[gnus-uu-marked-shar-and-view]\tUnshar and view marked articles 198\\[gnus-uu-marked-shar-and-view]\tUnshar and view marked articles
@@ -419,9 +205,151 @@ All commands for marked saving are `C-c C-v M-LETTER'.
419\\[gnus-uu-toggle-always-ask]\tToggle whether to ask to save a file after viewing 205\\[gnus-uu-toggle-always-ask]\tToggle whether to ask to save a file after viewing
420\\[gnus-uu-toggle-kill-carriage-return]\tToggle whether to strip trailing carriage returns 206\\[gnus-uu-toggle-kill-carriage-return]\tToggle whether to strip trailing carriage returns
421\\[gnus-uu-toggle-interactive-view]\tToggle whether to use interactive viewing mode 207\\[gnus-uu-toggle-interactive-view]\tToggle whether to use interactive viewing mode
208\\[gnus-uu-toggle-correct-stripped-articles]\tToggle whether to 'correct' articles
209\\[gnus-uu-toggle-view-with-metamail]\tToggle whether to use metamail for viewing
422\\[gnus-uu-toggle-any-variable]\tToggle any of the things above 210\\[gnus-uu-toggle-any-variable]\tToggle any of the things above
423 211
424User configurable variables: 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
425 353
426 Rule Variables 354 Rule Variables
427 355
@@ -470,8 +398,15 @@ User configurable variables:
470 Non-nil means that the user will always be asked to save a file 398 Non-nil means that the user will always be asked to save a file
471 after viewing it. 399 after viewing it.
472 400
473 `gnus-uu-asynchronous' 401 `gnus-uu-asynchronous'
474 Non-nil means that files will be viewed asynchronously. 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.
475 410
476 `gnus-uu-ask-before-view' 411 `gnus-uu-ask-before-view'
477 Non-nil means that gnus-uu will ask you before viewing each file 412 Non-nil means that gnus-uu will ask you before viewing each file
@@ -500,7 +435,47 @@ User configurable variables:
500 have had traling spaces deleted. 435 have had traling spaces deleted.
501 436
502 `gnus-uu-use-interactive-view' 437 `gnus-uu-use-interactive-view'
503 Non-nil means that gnus-uu will use interactive viewing mode." 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"
504 (interactive) 479 (interactive)
505 ) 480 )
506 481
@@ -511,17 +486,18 @@ User configurable variables:
511 '("\\.\\(jpe?g\\|gif\\|tiff?\\|p[pgb]m\\|xwd\\|xbm\\|pcx\\)$" "xv") 486 '("\\.\\(jpe?g\\|gif\\|tiff?\\|p[pgb]m\\|xwd\\|xbm\\|pcx\\)$" "xv")
512 '("\\.tga$" "tgatoppm %s | xv -") 487 '("\\.tga$" "tgatoppm %s | xv -")
513 '("\\.te?xt$\\|\\.doc$\\|read.*me" "xterm -e less") 488 '("\\.te?xt$\\|\\.doc$\\|read.*me" "xterm -e less")
514 '("\\.fli$" "xflick")
515 '("\\.\\(wav\\|aiff\\|hcom\\|u[blw]\\|s[bfw]\\|voc\\|smp\\)$" 489 '("\\.\\(wav\\|aiff\\|hcom\\|u[blw]\\|s[bfw]\\|voc\\|smp\\)$"
516 "sox -v .5 %s -t .au -u - > /dev/audio") 490 "sox -v .5 %s -t .au -u - > /dev/audio")
517 '("\\.au$" "cat %s > /dev/audio") 491 '("\\.au$" "cat %s > /dev/audio")
518 '("\\.mod$" "str32") 492 '("\\.mod$" "str32")
519 '("\\.ps$" "ghostview") 493 '("\\.ps$" "ghostview")
520 '("\\.dvi$" "xdvi") 494 '("\\.dvi$" "xdvi")
521 '("\\.1$" "xterm -e man -l") 495 '("\\.[1-6]$" "xterm -e man -l")
522 '("\\.html$" "xmosaic") 496 '("\\.html$" "xmosaic")
523 '("\\.mpe?g$" "mpeg_play") 497 '("\\.mpe?g$" "mpeg_play")
524 '("\\.\\(tar\\|arj\\|zip\\|zoo\\|arc\\|gz\\|Z\\|lzh\\|ar\\)$" 498 '("\\.fli$" "xflick")
499 '("\\.flc$" "xanim")
500 '("\\.\\(tar\\|arj\\|zip\\|zoo\\|arc\\|gz\\|Z\\|lzh\\|ar\\|lha\\)$"
525 "gnus-uu-archive")) 501 "gnus-uu-archive"))
526 502
527 "Default actions to be taken when the user asks to view a file. 503 "Default actions to be taken when the user asks to view a file.
@@ -579,27 +555,31 @@ details.")
579 555
580(defvar gnus-uu-default-interactive-view-rules-begin 556(defvar gnus-uu-default-interactive-view-rules-begin
581 (list 557 (list
582 '("\\.te?xt$\\|\\.doc$\\|read.*me\\|\\.c?$\\|\\.h$\\|\\.bat$\\|\\.asm$\\|makefile" "cat %s | sed s/ 558 '("\\.te?xt$\\|\\.doc$\\|read.*me\\|\\.c?$\\|\\.h$\\|\\.bat$\\|\\.asm$\\|makefile" "cat %s | sed s/\r//g")
583//g") 559 '("\\.pas$" "cat %s | sed s/\r//g")
584 '("\\.pas$" "cat %s | sed s/
585//g")
586 )) 560 ))
587 561
562(defvar gnus-uu-default-interactive-view-rules-end
563 (list
564 '(".*" "file")))
588 565
589;; Default unpacking commands 566;; Default unpacking commands
590 567
591(defvar gnus-uu-default-archive-rules 568(defvar gnus-uu-default-archive-rules
592 (list '("\\.tar$" "tar xf") 569 (list '("\\.tar$" "tar xf")
593 '("\\.zip$" "unzip") 570 '("\\.zip$" "unzip -o")
594 '("\\.ar$" "ar x") 571 '("\\.ar$" "ar x")
595 '("\\.arj$" "unarj x") 572 '("\\.arj$" "unarj x")
596 '("\\.zoo$" "zoo -e") 573 '("\\.zoo$" "zoo -e")
597 '("\\.lzh$" "lha x") 574 '("\\.\\(lzh\\|lha\\)$" "lha x")
598 '("\\.Z$" "uncompress") 575 '("\\.Z$" "uncompress")
599 '("\\.gz$" "gunzip") 576 '("\\.gz$" "gunzip")
600 '("\\.arc$" "arc -x")) 577 '("\\.arc$" "arc -x"))
601 ) 578 )
602 579
580(defvar gnus-uu-destructive-archivers
581 (list "uncompress" "gunzip"))
582
603(defvar gnus-uu-user-archive-rules nil 583(defvar gnus-uu-user-archive-rules nil
604 "A list that can be set to override the default archive unpacking commands. 584 "A list that can be set to override the default archive unpacking commands.
605To use, for instance, 'untar' to unpack tar files and 'zip -x' to 585To use, for instance, 'untar' to unpack tar files and 'zip -x' to
@@ -609,6 +589,34 @@ unpack zip files, say the following:
609 '(\"\\\\.zip$\" \"zip -x\")))" 589 '(\"\\\\.zip$\" \"zip -x\")))"
610 ) 590 )
611 591
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")))
612 620
613;; Various variables users may set 621;; Various variables users may set
614 622
@@ -646,6 +654,12 @@ Only the user unpacking commands will be consulted. Default is nil.")
646 "Non-nil means that gnus-uu will strip all carriage returns from articles. 654 "Non-nil means that gnus-uu will strip all carriage returns from articles.
647Default is t.") 655Default is t.")
648 656
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
649(defvar gnus-uu-unmark-articles-not-decoded nil 663(defvar gnus-uu-unmark-articles-not-decoded nil
650 "Non-nil means that gnus-uu will mark articles that were unsuccessfully decoded as unread. 664 "Non-nil means that gnus-uu will mark articles that were unsuccessfully decoded as unread.
651Default is nil.") 665Default is nil.")
@@ -663,13 +677,27 @@ Default is nil.")
663Gnus-uu will create a special buffer where the user may choose 677Gnus-uu will create a special buffer where the user may choose
664interactively which files to view and how. Default is nil.") 678interactively which files to view and how. Default is nil.")
665 679
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
666 687
667;; Internal variables 688;; Internal variables
668 689
669(defconst gnus-uu-begin-string "^begin[ \t]+[0-7][0-7][0-7][ \t]+\\(.*\\)$") 690(defconst gnus-uu-begin-string "^begin[ \t]+[0-7][0-7][0-7][ \t]+\\(.*\\)$")
670(defconst gnus-uu-end-string "^end[ \t]*$") 691(defconst gnus-uu-end-string "^end[ \t]*$")
671(defconst gnus-uu-body-line 692
672"^M.............................................................?$") 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
673(defconst gnus-uu-shar-begin-string "^#! */bin/sh") 701(defconst gnus-uu-shar-begin-string "^#! */bin/sh")
674 702
675(defvar gnus-uu-shar-file-name nil) 703(defvar gnus-uu-shar-file-name nil)
@@ -682,6 +710,7 @@ interactively which files to view and how. Default is nil.")
682(defvar gnus-uu-interactive-file-list nil) 710(defvar gnus-uu-interactive-file-list nil)
683(defvar gnus-uu-marked-article-list nil) 711(defvar gnus-uu-marked-article-list nil)
684(defvar gnus-uu-generated-file-list nil) 712(defvar gnus-uu-generated-file-list nil)
713(defvar gnus-uu-work-dir nil)
685 714
686(defconst gnus-uu-interactive-buffer-name "*gnus-uu interactive*") 715(defconst gnus-uu-interactive-buffer-name "*gnus-uu interactive*")
687(defconst gnus-uu-output-buffer-name "*Gnus UU Output*") 716(defconst gnus-uu-output-buffer-name "*Gnus UU Output*")
@@ -746,31 +775,49 @@ The marked equivalent to `gnus-uu-shar-and-save'."
746 (interactive) 775 (interactive)
747 (gnus-uu-unshar-and-view-or-save nil t)) 776 (gnus-uu-unshar-and-view-or-save nil t))
748 777
778;; Threaded decode
749 779
750;; Decode and show in buffer 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))
751 784
752(defun gnus-uu-decode-and-show-in-buffer () 785(defun gnus-uu-threaded-decode-and-save ()
753 "Uudecodes the current article and displays the result in a buffer. 786 "Decodes and saves the resulting file."
754Might be useful if someone has, for instance, some text uuencoded in
755their sigs. (Stranger things have happened.)"
756 (interactive) 787 (interactive)
757 (let ((uu-buffer (get-buffer-create gnus-uu-output-buffer-name)) 788 (gnus-uu-threaded-decode-and-view-or-save nil))
758 list-of-articles file-name)
759 (save-excursion
760 (and
761 (setq list-of-articles (list gnus-current-article))
762 (gnus-uu-grab-articles list-of-articles 'gnus-uu-uustrip-article-as)
763 (setq file-name (gnus-uu-decode gnus-uu-tmp-dir))
764 (progn
765 (save-excursion
766 (set-buffer uu-buffer)
767 (erase-buffer)
768 (insert-file-contents file-name))
769 (set-window-buffer (get-buffer-window gnus-article-buffer)
770 uu-buffer)
771 (message (format "Showing file %s in buffer" file-name))
772 (delete-file file-name))))))
773 789
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
774 821
775;; Toggle commands 822;; Toggle commands
776 823
@@ -817,6 +864,13 @@ their sigs. (Stranger things have happened.)"
817 (message "gnus-uu will now strip carriage returns") 864 (message "gnus-uu will now strip carriage returns")
818 (message "gnus-uu won't strip carriage returns"))) 865 (message "gnus-uu won't strip carriage returns")))
819 866
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
820(defun gnus-uu-toggle-correct-stripped-uucode () 874(defun gnus-uu-toggle-correct-stripped-uucode ()
821 "This function toggles whether to correct stripped uucode." 875 "This function toggles whether to correct stripped uucode."
822 (interactive) 876 (interactive)
@@ -829,7 +883,7 @@ their sigs. (Stranger things have happened.)"
829 "This function ask what variable the user wants to toggle." 883 "This function ask what variable the user wants to toggle."
830 (interactive) 884 (interactive)
831 (let (rep) 885 (let (rep)
832 (message "(a)sync, (q)uery, (p)ask, (k)ill CR, (i)nteractive, (u)nmark, (c)orrect") 886 (message "(a)sync, (q)uery, (p)ask, (k)ill CR, (i)nteract, (u)nmark, (c)orrect, (m)eta")
833 (setq rep (read-char)) 887 (setq rep (read-char))
834 (if (= rep ?a) 888 (if (= rep ?a)
835 (gnus-uu-toggle-asynchronous)) 889 (gnus-uu-toggle-asynchronous))
@@ -843,11 +897,37 @@ their sigs. (Stranger things have happened.)"
843 (gnus-uu-toggle-unmark-undecoded)) 897 (gnus-uu-toggle-unmark-undecoded))
844 (if (= rep ?c) 898 (if (= rep ?c)
845 (gnus-uu-toggle-correct-stripped-uucode)) 899 (gnus-uu-toggle-correct-stripped-uucode))
900 (if (= rep ?m)
901 (gnus-uu-toggle-view-with-metamail))
846 (if (= rep ?i) 902 (if (= rep ?i)
847 (gnus-uu-toggle-interactive-view)))) 903 (gnus-uu-toggle-interactive-view))))
848 904
849 905
850;; Edit line 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))))))
851 931
852(defun gnus-uu-edit-begin-line () 932(defun gnus-uu-edit-begin-line ()
853 "Edit the begin line of the current article." 933 "Edit the begin line of the current article."
@@ -855,10 +935,11 @@ their sigs. (Stranger things have happened.)"
855 (let ((buffer-read-only nil) 935 (let ((buffer-read-only nil)
856 begin b) 936 begin b)
857 (save-excursion 937 (save-excursion
938 (gnus-summary-select-article)
858 (set-buffer gnus-article-buffer) 939 (set-buffer gnus-article-buffer)
859 (goto-line 1) 940 (goto-line 1)
860 (if (not (re-search-forward "begin " nil t)) 941 (if (not (re-search-forward "begin " nil t))
861 (progn (message "No begin line in the current article") (sit-for 2)) 942 (error "No begin line in the current article")
862 (beginning-of-line) 943 (beginning-of-line)
863 (setq b (point)) 944 (setq b (point))
864 (end-of-line) 945 (end-of-line)
@@ -868,6 +949,7 @@ their sigs. (Stranger things have happened.)"
868 (delete-region b (point)) 949 (delete-region b (point))
869 (insert-string begin))))) 950 (insert-string begin)))))
870 951
952
871;; Multi functions 953;; Multi functions
872 954
873(defun gnus-uu-multi-decode-and-view () 955(defun gnus-uu-multi-decode-and-view ()
@@ -903,131 +985,36 @@ functions."
903 (gnus-uu-multi-decode-and-view-or-save t t)) 985 (gnus-uu-multi-decode-and-view-or-save t t))
904 986
905(defun gnus-uu-multi-decode-and-view-or-save (view marked) 987(defun gnus-uu-multi-decode-and-view-or-save (view marked)
906 (let (decode-type) 988 (let (type)
907 (message "(u)udecode, (s)har, s(a)ve, (b)inhex: ") 989 (message "[u]udecode, (s)har, s(a)ve, (b)inhex: ")
908 (setq decode-type (read-char)) 990 (setq type (read-char))
909 (if (= decode-type ? 991 (if (= type ?\r) (setq type ?u))
910) (setq decode-type ?u)) 992 (cond ((= type ?u) (gnus-uu-decode-and-view-or-save view marked))
911 (if (= decode-type ?u) 993 ((= type ?s) (gnus-uu-unshar-and-view-or-save view marked))
912 (gnus-uu-decode-and-view-or-save view marked) 994 ((= type ?b) (gnus-uu-binhex-and-save view marked))
913 (if (= decode-type ?s) 995 ((= type ?a) (gnus-uu-save-articles view marked))
914 (gnus-uu-unshar-and-view-or-save view marked) 996 (t (error "Unknown decode method '%c'." type)))))
915 (if (= decode-type ?b)
916 (gnus-uu-binhex-and-save view marked)
917 (if (= decode-type ?a)
918 (gnus-uu-save-articles view marked)
919 (message (format "Unknown decode method '%c'." decode-type))
920 (sit-for 2)))))))
921
922
923;; uuencode and post
924
925(defconst gnus-uu-uuencode-post-length 90)
926
927(defun gnus-uu-post ()
928 (interactive)
929 (let ((uuencode-buffer-name "*uuencode buffer*")
930 (send-buffer-name "*uuencode send buffer*")
931 (top-string "[ cut here %s (%s %d/%d) %s gnus-uu ]")
932 file uubuf short-file length parts header i end beg
933 beg-line minlen buf post-buf whole-len)
934 (setq file (read-file-name
935 "What file do you want to uuencode and post? " "~/Unrd.jpg"))
936 (if (not (file-exists-p file))
937 (message "%s: No such file" file)
938 (save-excursion
939 (setq post-buf (current-buffer))
940 (set-buffer (setq uubuf (get-buffer-create uuencode-buffer-name)))
941 (erase-buffer)
942 (if (string-match "^~/" file)
943 (setq file (concat "$HOME" (substring file 1))))
944 (if (string-match "/[^/]*$" file)
945 (setq short-file (substring file (1+ (match-beginning 0))))
946 (setq short-file file))
947 (call-process "sh" nil uubuf nil "-c"
948 (format "uuencode %s %s" file short-file))
949 (goto-char 1)
950 (forward-line 1)
951 (while (re-search-forward " " nil t)
952 (replace-match "`"))
953 (setq length (count-lines 1 (point-max)))
954 (setq parts (/ length gnus-uu-uuencode-post-length))
955 (if (not (< (% length gnus-uu-uuencode-post-length) 4))
956 (setq parts (1+ parts)))
957 (message "Det er %d parts" parts))
958 (goto-char 1)
959 (search-forward mail-header-separator nil t)
960 (beginning-of-line)
961 (forward-line 1)
962 (setq header (buffer-substring 1 (point)))
963 (goto-char 1)
964 (if (re-search-forward "^Subject: " nil t)
965 (progn
966 (end-of-line)
967 (insert (format " (0/%d)" parts))))
968; (save-excursion
969; (set-buffer (get-buffer-create "*tull"))
970; (erase-buffer)
971; (goto-char (point-max))
972; (insert-buffer send-buffer-name))
973 (gnus-inews-news)
974 997
975 (save-excursion 998
976 (setq i 1) 999;; "All articles" commands
977 (setq beg 1)
978 (while (not (> i parts))
979 (set-buffer (get-buffer-create send-buffer-name))
980 (erase-buffer)
981 (insert header)
982 (insert "\n")
983 (setq whole-len
984 (- 62 (length (format top-string "" short-file i parts ""))))
985 (setq minlen (/ whole-len 2))
986 (setq
987 beg-line
988 (format top-string
989 (make-string minlen ?-)
990 short-file i parts
991 (make-string (if (= 0 (% whole-len 2)) (1- minlen) minlen) ?-)))
992 (insert beg-line)
993 (insert "\n")
994 (goto-char 1)
995 (if (re-search-forward "^Subject: " nil t)
996 (progn
997 (end-of-line)
998 (insert (format " (%d/%d)" i parts))))
999 (goto-char (point-max))
1000 (save-excursion
1001 (set-buffer uubuf)
1002 (goto-char beg)
1003 (if (= i parts)
1004 (goto-char (point-max))
1005 (forward-line gnus-uu-uuencode-post-length))
1006 (setq end (point)))
1007 (insert-buffer-substring uubuf beg end)
1008 (insert beg-line)
1009 (insert "\n")
1010 (setq beg end)
1011 (setq i (1+ i))
1012; (save-excursion
1013; (set-buffer (get-buffer-create "*tull"))
1014; (goto-char (point-max))
1015; (insert-buffer send-buffer-name))
1016 (gnus-inews-news)
1017 ))
1018 (and (setq buf (get-buffer send-buffer-name))
1019 (kill-buffer buf))
1020 (and (setq buf (get-buffer uuencode-buffer-name))
1021 (kill-buffer buf)))))
1022
1023
1024
1025;; Decode and all files
1026 1000
1027(defconst gnus-uu-rest-of-articles nil) 1001(defconst gnus-uu-rest-of-articles nil)
1028(defconst gnus-uu-do-sloppy-uudecode nil)
1029(defvar gnus-uu-current-save-dir nil) 1002(defvar gnus-uu-current-save-dir nil)
1030 1003
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
1031(defun gnus-uu-decode-and-save-all-unread-articles () 1018(defun gnus-uu-decode-and-save-all-unread-articles ()
1032 "Try to decode all unread articles and saves the result. 1019 "Try to decode all unread articles and saves the result.
1033This function reads all unread articles in the current group and sees 1020This function reads all unread articles in the current group and sees
@@ -1043,62 +1030,34 @@ that it grabs all articles visible, unread or not."
1043 (interactive) 1030 (interactive)
1044 (gnus-uu-decode-and-save-articles nil t)) 1031 (gnus-uu-decode-and-save-articles nil t))
1045 1032
1046(defun gnus-uu-decode-and-save-all-unread-articles-and-mark ()
1047 "Try to decode all unread articles and saves the result and marks everything as read.
1048Does the same as `gnus-uu-decode-and-save-all-unread-articles', except that
1049it marks everything as read, even if it couldn't decode the articles."
1050 (interactive)
1051 (gnus-uu-decode-and-save-articles t nil))
1052
1053(defun gnus-uu-decode-and-save-all-articles-and-mark ()
1054 "Try to decode all articles and saves the result and marks everything as read.
1055Does the same as `gnus-uu-decode-and-save-all-articles', except that
1056it marks everything as read, even if it couldn't decode the articles."
1057 (interactive)
1058 (gnus-uu-decode-and-save-articles nil nil))
1059
1060(defun gnus-uu-decode-and-save-articles (&optional unread unmark) 1033(defun gnus-uu-decode-and-save-articles (&optional unread unmark)
1061 (let ((gnus-uu-unmark-articles-not-decoded unmark) 1034 (let ((gnus-uu-unmark-articles-not-decoded t)
1062 (filest "") 1035 dir)
1063 where dir did unmark saved-list) 1036 (if (not (setq gnus-uu-marked-article-list
1064 (setq gnus-uu-do-sloppy-uudecode t) 1037 (nreverse (gnus-uu-get-list-of-articles
1065 (setq dir (gnus-uu-read-directory "Where do you want the files? ")) 1038 "^." nil unread t))))
1066 (message "Grabbing...") 1039 (error "No%s articles to be decoded." (if unread " unread" ""))
1067 (setq gnus-uu-rest-of-articles 1040 (setq dir (gnus-uu-read-directory "Where do you want the files? "))
1068 (gnus-uu-get-list-of-articles "^." nil unread)) 1041 (gnus-uu-decode-and-view-or-save nil t dir)
1069 (setq gnus-uu-file-name nil) 1042 (message "Saved."))))
1070 (while (and gnus-uu-rest-of-articles
1071 (gnus-uu-grab-articles gnus-uu-rest-of-articles
1072 'gnus-uu-uustrip-article-as))
1073 (if gnus-uu-file-name
1074 (progn
1075 (setq saved-list (cons gnus-uu-file-name saved-list))
1076 (rename-file (concat gnus-uu-tmp-dir gnus-uu-file-name)
1077 (concat dir gnus-uu-file-name) t)
1078 (setq did t)
1079 (setq gnus-uu-file-name nil))))
1080 (if (not did)
1081 ()
1082 (while saved-list
1083 (setq filest (concat filest " " (car saved-list)))
1084 (setq saved-list (cdr saved-list)))
1085 (message "Saved%s" filest)))
1086 (setq gnus-uu-do-sloppy-uudecode nil))
1087 1043
1088 1044
1089;; Work functions 1045;; Work functions
1090 1046
1091(defun gnus-uu-decode-and-view-or-save (view marked) 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)
1092 (gnus-uu-initialize) 1050 (gnus-uu-initialize)
1093 (let (file decoded) 1051 (let (decoded)
1094 (save-excursion 1052 (save-excursion
1095 (if (gnus-uu-decode-and-strip nil marked) 1053 (if (gnus-uu-decode-and-strip nil marked)
1096 (progn 1054 (progn
1097 (setq decoded t) 1055 (setq decoded t)
1098 (setq file (concat gnus-uu-tmp-dir gnus-uu-file-name))
1099 (if view 1056 (if view
1100 (gnus-uu-view-file file) 1057 (gnus-uu-view-directory gnus-uu-work-dir
1101 (gnus-uu-save-file file))))) 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)))))
1102 1061
1103 (gnus-uu-summary-next-subject) 1062 (gnus-uu-summary-next-subject)
1104 1063
@@ -1107,12 +1066,10 @@ it marks everything as read, even if it couldn't decode the articles."
1107 (if (and gnus-uu-use-interactive-view view decoded) 1066 (if (and gnus-uu-use-interactive-view view decoded)
1108 (gnus-uu-do-interactive))) 1067 (gnus-uu-do-interactive)))
1109 1068
1110 (if (or (not gnus-uu-use-interactive-view) (not decoded)) 1069 (if (or (not view) (not gnus-uu-use-interactive-view) (not decoded))
1111 (gnus-uu-clean-up)))) 1070 (gnus-uu-clean-up))))
1112 1071
1113
1114; Unshars and views/saves marked/unmarked articles. 1072; Unshars and views/saves marked/unmarked articles.
1115
1116(defun gnus-uu-unshar-and-view-or-save (view marked) 1073(defun gnus-uu-unshar-and-view-or-save (view marked)
1117 (gnus-uu-initialize) 1074 (gnus-uu-initialize)
1118 (let (tar-file files decoded) 1075 (let (tar-file files decoded)
@@ -1134,13 +1091,12 @@ it marks everything as read, even if it couldn't decode the articles."
1134 (make-temp-name (concat gnus-uu-tmp-dir "gnusuuar")) 1091 (make-temp-name (concat gnus-uu-tmp-dir "gnusuuar"))
1135 ".tar")) 1092 ".tar"))
1136 (gnus-uu-add-file tar-file) 1093 (gnus-uu-add-file tar-file)
1137 (call-process "sh" nil 1094 (call-process
1138 (get-buffer-create gnus-uu-output-buffer-name) 1095 "sh" nil
1139 nil "-c" 1096 (get-buffer-create gnus-uu-output-buffer-name) nil "-c"
1140 (format "cd %s ; tar cf %s * ; cd .. ; rm -r %s" 1097 (format "cd %s ; tar cf %s * ; cd .. ; rm -r %s"
1141 gnus-uu-shar-directory 1098 gnus-uu-shar-directory tar-file
1142 tar-file 1099 gnus-uu-shar-directory))
1143 gnus-uu-shar-directory))
1144 (if view 1100 (if view
1145 (gnus-uu-view-file tar-file) 1101 (gnus-uu-view-file tar-file)
1146 (gnus-uu-save-file tar-file))) 1102 (gnus-uu-save-file tar-file)))
@@ -1157,47 +1113,165 @@ it marks everything as read, even if it couldn't decode the articles."
1157 (gnus-uu-clean-up)))) 1113 (gnus-uu-clean-up))))
1158 1114
1159 1115
1116;; Functions for saving and possibly digesting articles without
1117;; any decoding.
1118
1160(defconst gnus-uu-saved-article-name nil) 1119(defconst gnus-uu-saved-article-name nil)
1161(defun gnus-uu-save-articles (view marked) 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)
1162 (let (list-of-articles) 1127 (let (list-of-articles)
1163 (save-excursion 1128 (save-excursion
1129 (gnus-uu-initialize)
1164 (if (not marked) 1130 (if (not marked)
1165 (setq list-of-articles (gnus-uu-get-list-of-articles)) 1131 (setq list-of-articles (gnus-uu-get-list-of-articles))
1166 (setq list-of-articles (reverse gnus-uu-marked-article-list)) 1132 (setq list-of-articles (reverse gnus-uu-marked-article-list))
1167 (setq gnus-uu-marked-article-list nil)) 1133 (setq gnus-uu-marked-article-list nil))
1134
1168 (if (not list-of-articles) 1135 (if (not list-of-articles)
1169 (progn 1136 (error "No list of articles"))
1170 (message "No list of articles") 1137
1171 (sit-for 2)) 1138 (setq gnus-uu-saved-article-name
1172 (setq gnus-uu-saved-article-name 1139 (concat gnus-uu-work-dir
1173 (concat gnus-uu-tmp-dir 1140 (if no-save
1141 gnus-newsgroup-name
1174 (read-file-name "Enter file name: " gnus-newsgroup-name 1142 (read-file-name "Enter file name: " gnus-newsgroup-name
1175 gnus-newsgroup-name))) 1143 gnus-newsgroup-name))))
1176 (gnus-uu-add-file gnus-uu-saved-article-name) 1144 (gnus-uu-add-file gnus-uu-saved-article-name)
1177 (if (gnus-uu-grab-articles list-of-articles 'gnus-uu-save-article) 1145 (if (and (gnus-uu-grab-articles list-of-articles 'gnus-uu-save-article t)
1178 (gnus-uu-save-file gnus-uu-saved-article-name)))))) 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)))
1179 1254
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))
1180 1259
1181(defun gnus-uu-save-article (buffer in-state)
1182 (save-excursion
1183 (set-buffer buffer)
1184 (call-process-region
1185 1 (point-max) "sh" nil (get-buffer-create gnus-uu-output-buffer-name)
1186 nil "-c" (concat "cat >> " gnus-uu-saved-article-name)))
1187 'ok)
1188 1260
1261;; Binhex treatment - not very advanced.
1189 1262
1190;; Binhex
1191(defconst gnus-uu-binhex-body-line 1263(defconst gnus-uu-binhex-body-line
1192 "^................................................................$") 1264 "^[^:]...............................................................$")
1193(defconst gnus-uu-binhex-begin-line 1265(defconst gnus-uu-binhex-begin-line
1194 "^:...............................................................$") 1266 "^:...............................................................$")
1195(defconst gnus-uu-binhex-end-line 1267(defconst gnus-uu-binhex-end-line
1196 ":$") 1268 ":$")
1197(defvar gnus-uu-binhex-article-name nil) 1269(defvar gnus-uu-binhex-article-name nil)
1198 1270
1199 1271; This just concatenates and strips stuff from binhexed articles.
1272; No actual unbinhexing takes place. VIEW is ignored.
1200(defun gnus-uu-binhex-and-save (view marked) 1273(defun gnus-uu-binhex-and-save (view marked)
1274 (gnus-uu-initialize)
1201 (let (list-of-articles) 1275 (let (list-of-articles)
1202 (save-excursion 1276 (save-excursion
1203 (if (not marked) 1277 (if (not marked)
@@ -1205,44 +1279,52 @@ it marks everything as read, even if it couldn't decode the articles."
1205 (setq list-of-articles (reverse gnus-uu-marked-article-list)) 1279 (setq list-of-articles (reverse gnus-uu-marked-article-list))
1206 (setq gnus-uu-marked-article-list nil)) 1280 (setq gnus-uu-marked-article-list nil))
1207 (if (not list-of-articles) 1281 (if (not list-of-articles)
1208 (progn 1282 (error "No list of articles"))
1209 (message "No list of articles") 1283
1210 (sit-for 2)) 1284 (setq gnus-uu-binhex-article-name
1211 (setq gnus-uu-binhex-article-name 1285 (concat gnus-uu-work-dir
1212 (concat gnus-uu-tmp-dir 1286 (read-file-name "Enter binhex file name: "
1213 (read-file-name "Enter binhex file name: " 1287 gnus-newsgroup-name
1214 gnus-newsgroup-name 1288 gnus-newsgroup-name)))
1215 gnus-newsgroup-name))) 1289 (gnus-uu-add-file gnus-uu-binhex-article-name)
1216 (gnus-uu-add-file gnus-uu-binhex-article-name) 1290 (if (gnus-uu-grab-articles list-of-articles 'gnus-uu-binhex-article t)
1217 (if (gnus-uu-grab-articles list-of-articles 'gnus-uu-binhex-article) 1291 (gnus-uu-save-file gnus-uu-binhex-article-name))))
1218 (gnus-uu-save-file gnus-uu-binhex-article-name)))))) 1292 (gnus-uu-check-for-generated-files)
1219 1293 (gnus-uu-summary-next-subject))
1220 1294
1221(defun gnus-uu-binhex-article (buffer in-state) 1295(defun gnus-uu-binhex-article (buffer in-state)
1222 (let ((state 'ok) 1296 (let (state start-char)
1223 start-char)
1224 (save-excursion 1297 (save-excursion
1225 (set-buffer buffer) 1298 (set-buffer buffer)
1299 (widen)
1226 (goto-char 1) 1300 (goto-char 1)
1227 (if (not (re-search-forward (concat gnus-uu-binhex-begin-line "\\|" 1301 (if (not (re-search-forward gnus-uu-binhex-begin-line nil t))
1228 gnus-uu-binhex-body-line) nil t)) 1302 (if (not (re-search-forward gnus-uu-binhex-body-line nil t))
1229 (setq state 'wrong-type) 1303 (setq state (list 'wrong-type))))
1304
1305 (if (memq 'wrong-type state)
1306 ()
1230 (beginning-of-line) 1307 (beginning-of-line)
1231 (setq start-char (point)) 1308 (setq start-char (point))
1232 (if (looking-at gnus-uu-binhex-begin-line) 1309 (if (looking-at gnus-uu-binhex-begin-line)
1233 (setq state 'begin) 1310 (progn
1234 (setq state 'middle)) 1311 (setq state (list 'begin))
1312 (write-region 1 1 gnus-uu-binhex-article-name))
1313 (setq state (list 'middle)))
1235 (goto-char (point-max)) 1314 (goto-char (point-max))
1236 (re-search-backward (concat gnus-uu-binhex-body-line "\\|" 1315 (re-search-backward (concat gnus-uu-binhex-body-line "\\|"
1237 gnus-uu-binhex-end-line) nil t) 1316 gnus-uu-binhex-end-line) nil t)
1238 (if (looking-at gnus-uu-binhex-end-line) 1317 (if (looking-at gnus-uu-binhex-end-line)
1239 (if (eq state 'begin) 1318 (setq state (if (memq 'begin state)
1240 (setq state 'begin-and-end) 1319 (cons 'end state)
1241 (setq state 'end))) 1320 (list 'end))))
1242 (beginning-of-line) 1321 (beginning-of-line)
1243 (forward-line 1) 1322 (forward-line 1)
1244 (append-to-file start-char (point) gnus-uu-binhex-article-name))) 1323 (if (file-exists-p gnus-uu-binhex-article-name)
1245 state)) 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)))
1246 1328
1247 1329
1248;; Internal view commands 1330;; Internal view commands
@@ -1264,89 +1346,99 @@ it marks everything as read, even if it couldn't decode the articles."
1264 1346
1265(defun gnus-uu-view-file (file-name &optional dont-ask) 1347(defun gnus-uu-view-file (file-name &optional dont-ask)
1266 (let (action did-view 1348 (let (action did-view
1267 (didnt-want t) 1349 (didnt-want t)
1268 (do-view 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)
1269 (setq action 1404 (setq action
1270 (gnus-uu-choose-action 1405 (gnus-uu-choose-action
1271 file-name 1406 file-name
1272 (append 1407 (append
1273 (if (and gnus-uu-use-interactive-view 1408 (if (and gnus-uu-use-interactive-view
1274 gnus-uu-user-interactive-view-rules) 1409 gnus-uu-user-interactive-view-rules)
1275 gnus-uu-user-interactive-view-rules 1410 gnus-uu-user-interactive-view-rules
1276 gnus-uu-user-view-rules) 1411 gnus-uu-user-view-rules)
1277 (if (or gnus-uu-ignore-default-view-rules 1412 (if (or gnus-uu-ignore-default-view-rules
1278 (not gnus-uu-use-interactive-view)) 1413 (not gnus-uu-use-interactive-view))
1279 () 1414 ()
1280 gnus-uu-default-interactive-view-rules-begin) 1415 gnus-uu-default-interactive-view-rules-begin)
1281 (if gnus-uu-ignore-default-view-rules 1416 (if gnus-uu-ignore-default-view-rules
1282 nil 1417 nil
1283 gnus-uu-default-view-rules) 1418 gnus-uu-default-view-rules)
1284 (if (and gnus-uu-use-interactive-view 1419 (if gnus-uu-use-interactive-view
1285 gnus-uu-user-interactive-view-rules-end) 1420 (append gnus-uu-user-interactive-view-rules-end
1286 gnus-uu-user-interactive-view-rules-end 1421 (if gnus-uu-ignore-default-view-rules
1287 gnus-uu-user-view-rules-end)))) 1422 ()
1288 1423 gnus-uu-default-interactive-view-rules-end))
1289 (if (and gnus-uu-use-interactive-view 1424 gnus-uu-user-view-rules-end))))
1290 (not (string= (or action "") "gnus-uu-archive"))) 1425 (if (and (not (string= (or action "") "gnus-uu-archive"))
1291 (gnus-uu-enter-interactive-file (or action "") file-name) 1426 gnus-uu-view-with-metamail)
1292 1427 (if (setq action
1293 (if action 1428 (gnus-uu-choose-action file-name gnus-uu-ext-to-mime-list))
1294 (if (string= action "gnus-uu-archive") 1429 (setq action (format "metamail -d -b -c \"%s\"" action))))
1295 (setq did-view (gnus-uu-treat-archive file-name)) 1430 action))
1296
1297 (if gnus-uu-ask-before-view
1298 (setq didnt-want
1299 (or (not
1300 (setq do-view
1301 (y-or-n-p
1302 (format "Do you want to view %s? "
1303 file-name))))
1304 didnt-want)))
1305
1306 (if do-view
1307 (setq did-view
1308 (if gnus-uu-asynchronous
1309 (gnus-uu-call-asynchronous file-name action)
1310 (gnus-uu-call-synchronous file-name action))))))
1311
1312 (if (and (not dont-ask) (not gnus-uu-use-interactive-view))
1313 (progn
1314 (if (and
1315 didnt-want
1316 (or (not action)
1317 (and (string= action "gnus-uu-archive")
1318 (not did-view))))
1319 (progn
1320 (message
1321 (format "Could find no rule for %s" file-name))
1322 (sit-for 2)))
1323 (and (or (not did-view) gnus-uu-view-and-save)
1324 (y-or-n-p
1325 (format "Do you want to save the file %s? "
1326 file-name))
1327 (gnus-uu-save-file file-name))))
1328
1329 (if (and (file-exists-p file-name)
1330 (not gnus-uu-use-interactive-view)
1331 (or
1332 (not (and gnus-uu-asynchronous did-view))
1333 (string= action "gnus-uu-archive")))
1334 (delete-file file-name)))
1335
1336 did-view))
1337
1338 1431
1339; `gnus-uu-call-synchronous' takes two parameters: The name of the 1432; `gnus-uu-call-synchronous' takes two parameters: The name of the
1340; file to be displayed and the command to display it with. Returns t 1433; file to be displayed and the command to display it with. Returns t
1341; on success and nil if the file couldn't be displayed. 1434; on success and nil if the file couldn't be displayed.
1342
1343(defun gnus-uu-call-synchronous (file-name action) 1435(defun gnus-uu-call-synchronous (file-name action)
1344 (let (did-view command) 1436 (let (did-view command)
1345 (save-excursion 1437 (save-excursion
1346 (set-buffer (get-buffer-create gnus-uu-output-buffer-name)) 1438 (set-buffer (get-buffer-create gnus-uu-output-buffer-name))
1347 (erase-buffer) 1439 (erase-buffer)
1348 (setq command (gnus-uu-command action file-name)) 1440 (setq command (gnus-uu-command action file-name))
1349 (message (format "Viewing with '%s'" command)) 1441 (message "Viewing with '%s'" command)
1350 (if (not (= 0 (call-process "sh" nil t nil "-c" command))) 1442 (if (not (= 0 (call-process "sh" nil t nil "-c" command)))
1351 (progn 1443 (progn
1352 (goto-char 1) 1444 (goto-char 1)
@@ -1364,13 +1456,12 @@ it marks everything as read, even if it couldn't decode the articles."
1364; whether the command succeded or not, so this function always returns 1456; whether the command succeded or not, so this function always returns
1365; t. It also adds "; rm -f file-name" to the end of the execution 1457; t. It also adds "; rm -f file-name" to the end of the execution
1366; string, so the file will be removed after viewing has ended. 1458; string, so the file will be removed after viewing has ended.
1367
1368(defun gnus-uu-call-asynchronous (file-name action) 1459(defun gnus-uu-call-asynchronous (file-name action)
1369 (let (command file tmp-file start) 1460 (let (command file tmp-file start)
1370 (while (string-match "/" file-name start) 1461 (while (string-match "/" file-name start)
1371 (setq start (1+ (match-beginning 0)))) 1462 (setq start (1+ (match-beginning 0))))
1372 (setq file (substring file-name start)) 1463 (setq file (substring file-name start))
1373 (setq tmp-file (concat gnus-uu-tmp-dir file)) 1464 (setq tmp-file (concat gnus-uu-work-dir file))
1374 (if (string= tmp-file file-name) 1465 (if (string= tmp-file file-name)
1375 () 1466 ()
1376 (rename-file file-name tmp-file t) 1467 (rename-file file-name tmp-file t)
@@ -1378,35 +1469,32 @@ it marks everything as read, even if it couldn't decode the articles."
1378 1469
1379 (setq command (gnus-uu-command action file-name)) 1470 (setq command (gnus-uu-command action file-name))
1380 (setq command (format "%s ; rm -f %s" command file-name)) 1471 (setq command (format "%s ; rm -f %s" command file-name))
1381 (message (format "Viewing with %s" command)) 1472 (message "Viewing with %s" command)
1382 (start-process "gnus-uu-view" nil "sh" "-c" command) 1473 (start-process "gnus-uu-view" nil "sh" "-c" command)
1383 t)) 1474 t))
1384 1475
1385
1386; `gnus-uu-decode-and-strip' does all the main work. It finds out what 1476; `gnus-uu-decode-and-strip' does all the main work. It finds out what
1387; articles to grab, grabs them, strips the result and decodes. If any 1477; articles to grab, grabs them, strips the result and decodes. If any
1388; of these operations fail, it returns nil, t otherwise. If shar is 1478; of these operations fail, it returns nil, t otherwise. If shar is
1389; t, it will pass this on to `gnus-uu-grab-articles', which will 1479; t, it will pass this on to `gnus-uu-grab-articles', which will
1390; (probably) unshar the articles. If use-marked is non-nil, it won't 1480; (probably) unshar the articles. If use-marked is non-nil, it won't
1391; try to find articles, but use the marked list. 1481; try to find articles, but use the marked list.
1392
1393(defun gnus-uu-decode-and-strip (&optional shar use-marked) 1482(defun gnus-uu-decode-and-strip (&optional shar use-marked)
1394 (let (list-of-articles) 1483 (let (list-of-articles)
1395 (save-excursion 1484 (save-excursion
1396 1485
1397 (if use-marked 1486 (if use-marked
1398 (progn (if (eq gnus-uu-marked-article-list ()) 1487 (if (not gnus-uu-marked-article-list)
1399 (message "No articles marked") 1488 (message "No articles marked")
1400 (setq list-of-articles (reverse gnus-uu-marked-article-list)) 1489 (setq list-of-articles (reverse gnus-uu-marked-article-list))
1401 (gnus-uu-unmark-all-articles))) 1490 (gnus-uu-unmark-all-articles))
1402 (setq list-of-articles (gnus-uu-get-list-of-articles))) 1491 (setq list-of-articles (gnus-uu-get-list-of-articles)))
1403 1492
1404 (and list-of-articles 1493 (and list-of-articles
1405 (gnus-uu-grab-articles list-of-articles 1494 (gnus-uu-grab-articles
1406 (if shar 1495 list-of-articles
1407 'gnus-uu-unshar-article 1496 (if shar 'gnus-uu-unshar-article 'gnus-uu-uustrip-article-as)
1408 'gnus-uu-uustrip-article-as)))))) 1497 t)))))
1409
1410 1498
1411; Takes a string and puts a \ in front of every special character; 1499; Takes a string and puts a \ in front of every special character;
1412; ignores any leading "version numbers" thingies that they use in the 1500; ignores any leading "version numbers" thingies that they use in the
@@ -1414,7 +1502,6 @@ it marks everything as read, even if it couldn't decode the articles."
1414; "2/3" with "[0-9]+/[0-9]+" or, if it can't find something like that, 1502; "2/3" with "[0-9]+/[0-9]+" or, if it can't find something like that,
1415; replaces the last two numbers with "[0-9]+". This, in my experience, 1503; replaces the last two numbers with "[0-9]+". This, in my experience,
1416; should get most postings of a series." 1504; should get most postings of a series."
1417
1418(defun gnus-uu-reginize-string (string) 1505(defun gnus-uu-reginize-string (string)
1419 (let ((count 2) 1506 (let ((count 2)
1420 (vernum "v[0-9]+[a-z][0-9]+:") 1507 (vernum "v[0-9]+[a-z][0-9]+:")
@@ -1456,11 +1543,13 @@ it marks everything as read, even if it couldn't decode the articles."
1456 1543
1457 (buffer-substring 1 (point-max))))) 1544 (buffer-substring 1 (point-max)))))
1458 1545
1459
1460; Finds all articles that matches the regular expression given. 1546; Finds all articles that matches the regular expression given.
1461; Returns the resulting list. 1547; Returns the resulting list. SUBJECT is the regular expression to be
1462 1548; matched. If it is nil, the current article name will be used. If
1463(defun gnus-uu-get-list-of-articles (&optional subject mark-articles only-unread) 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)
1464 (let (beg end reg-subject list-of-subjects list-of-numbers art-num) 1553 (let (beg end reg-subject list-of-subjects list-of-numbers art-num)
1465 (save-excursion 1554 (save-excursion
1466 1555
@@ -1486,7 +1575,6 @@ it marks everything as read, even if it couldn't decode the articles."
1486; Collect all subjects matching reg-subject. 1575; Collect all subjects matching reg-subject.
1487 1576
1488 (let ((case-fold-search t)) 1577 (let ((case-fold-search t))
1489 (setq case-fold-search t)
1490 (goto-char 1) 1578 (goto-char 1)
1491 (while (re-search-forward reg-subject nil t) 1579 (while (re-search-forward reg-subject nil t)
1492 (beginning-of-line) 1580 (beginning-of-line)
@@ -1501,7 +1589,9 @@ it marks everything as read, even if it couldn't decode the articles."
1501 1589
1502; Expand all numbers in all the subjects: (hi9 -> hi0009, etc). 1590; Expand all numbers in all the subjects: (hi9 -> hi0009, etc).
1503 1591
1504 (setq list-of-subjects (gnus-uu-expand-numbers list-of-subjects)) 1592 (setq list-of-subjects (gnus-uu-expand-numbers
1593 list-of-subjects
1594 (not do-not-translate)))
1505 1595
1506; Sort the subjects. 1596; Sort the subjects.
1507 1597
@@ -1515,23 +1605,16 @@ it marks everything as read, even if it couldn't decode the articles."
1515 (setq list-of-numbers (cons art-num list-of-numbers)) 1605 (setq list-of-numbers (cons art-num list-of-numbers))
1516 (setq list-of-subjects (cdr list-of-subjects))) 1606 (setq list-of-subjects (cdr list-of-subjects)))
1517 1607
1518 (setq list-of-numbers (nreverse list-of-numbers)) 1608 (setq list-of-numbers (nreverse list-of-numbers))))
1519
1520 (if (not list-of-numbers)
1521 (progn
1522 (message (concat "No subjects matched " subject))
1523 (sit-for 2)))))
1524 1609
1525 list-of-numbers))) 1610 list-of-numbers)))
1526 1611
1527
1528; Takes a list of strings and "expands" all numbers in all the 1612; Takes a list of strings and "expands" all numbers in all the
1529; strings. That is, this function makes all numbers equal length by 1613; strings. That is, this function makes all numbers equal length by
1530; prepending lots of zeroes before each number. This is to ease later 1614; prepending lots of zeroes before each number. This is to ease later
1531; sorting to find out what sequence the articles are supposed to be 1615; sorting to find out what sequence the articles are supposed to be
1532; decoded in. Returns the list of expanded strings. 1616; decoded in. Returns the list of expanded strings.
1533 1617(defun gnus-uu-expand-numbers (string-list &optional translate)
1534(defun gnus-uu-expand-numbers (string-list)
1535 (let (string out-list pos num) 1618 (let (string out-list pos num)
1536 (save-excursion 1619 (save-excursion
1537 (set-buffer (get-buffer-create gnus-uu-output-buffer-name)) 1620 (set-buffer (get-buffer-create gnus-uu-output-buffer-name))
@@ -1544,8 +1627,9 @@ it marks everything as read, even if it couldn't decode the articles."
1544 (while (re-search-forward "[ \t]+" nil t) 1627 (while (re-search-forward "[ \t]+" nil t)
1545 (replace-match " ")) 1628 (replace-match " "))
1546 (goto-char 1) 1629 (goto-char 1)
1547 (while (re-search-forward "[A-Za-z]" nil t) 1630 (if translate
1548 (replace-match "a" t t)) 1631 (while (re-search-forward "[A-Za-z]" nil t)
1632 (replace-match "a" t t)))
1549 1633
1550 (goto-char 1) 1634 (goto-char 1)
1551 (if (not (search-forward "] " nil t)) 1635 (if (not (search-forward "] " nil t))
@@ -1559,10 +1643,8 @@ it marks everything as read, even if it couldn't decode the articles."
1559 (setq out-list (cons string out-list))))) 1643 (setq out-list (cons string out-list)))))
1560 out-list)) 1644 out-list))
1561 1645
1562
1563; Used in a sort for finding out what string is bigger, but ignoring 1646; Used in a sort for finding out what string is bigger, but ignoring
1564; everything before the subject part. 1647; everything before the subject part.
1565
1566(defun gnus-uu-string< (string1 string2) 1648(defun gnus-uu-string< (string1 string2)
1567 (string< (substring string1 (string-match "\\] " string1)) 1649 (string< (substring string1 (string-match "\\] " string1))
1568 (substring string2 (string-match "\\] " string2)))) 1650 (substring string2 (string-match "\\] " string2))))
@@ -1574,30 +1656,33 @@ it marks everything as read, even if it couldn't decode the articles."
1574; list of articles to be grabbed and a function to apply to each 1656; list of articles to be grabbed and a function to apply to each
1575; article. It puts the result in `gnus-uu-result-buffer'. 1657; article. It puts the result in `gnus-uu-result-buffer'.
1576; 1658;
1577; The function to be called should take two parameters. The first is 1659; The function to be called should take two parameters. The first
1578; the buffer that has the article that should be treated. The function 1660; parameter is the article buffer. The function should leave the
1579; should leave the result in this buffer as well. This result is then 1661; result, if any, in this buffer. This result is then appended on to
1580; appended on to the `gnus-uu-result-buffer'. 1662; the `gnus-uu-result-buffer'. Most treatment functions will just
1663; generate files...
1581; 1664;
1582; The second parameter is the state of the list of articles, and can 1665; The second parameter is the state of the list of articles, and can
1583; have three values: 'start, 'middle and 'end. 1666; have four values: `first', `middle', `last' and `first-and-last'.
1584; 1667;
1585; The function can have several return values: 1668; The function should return a list. The list may contain the
1586; 'error if there was an error while treating. 1669; following symbols:
1587; 'end if the last article has been sighted. 1670; `error' if an error occurred
1588; 'begin-and-end if the article is both the beginning and 1671; `begin' if the beginning of an encoded file has been received
1589; the end. All these three return values results in 1672; If the list returned contains a `begin', the first element of
1590; `gnus-uu-grab-articles' stopping traversing of the list 1673; the list *must* be a string with the file name of the decoded
1591; of articles. 1674; file.
1592; 'middle if the article is a "middle" article. 1675; `end' if the the end of an encoded file has been received
1593; 'ok if everything is ok. 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
1594 1679
1595(defvar gnus-uu-has-been-grabbed nil) 1680(defvar gnus-uu-has-been-grabbed nil)
1596 1681
1597(defun gnus-uu-unmark-list-of-grabbed (&optional dont-unmark-last-article) 1682(defun gnus-uu-unmark-list-of-grabbed (&optional dont-unmark-last-article)
1598 (let (art) 1683 (let (art)
1599 (if (or (not gnus-uu-has-been-grabbed) 1684 (if (not (and gnus-uu-has-been-grabbed
1600 (not gnus-uu-unmark-articles-not-decoded)) 1685 gnus-uu-unmark-articles-not-decoded))
1601 () 1686 ()
1602 (if dont-unmark-last-article 1687 (if dont-unmark-last-article
1603 (progn 1688 (progn
@@ -1614,200 +1699,207 @@ it marks everything as read, even if it couldn't decode the articles."
1614; each article grabbed. The result of the function is appended on to 1699; each article grabbed. The result of the function is appended on to
1615; `gnus-uu-result-buffer'. 1700; `gnus-uu-result-buffer'.
1616; 1701;
1617; This function returns t if the grabbing and the process-function 1702; This function returns a list of files decoded if the grabbing and
1618; has been successful and nil otherwise." 1703; the process-function has been successful and nil otherwise.
1619 1704(defun gnus-uu-grab-articles (list-of-articles process-function &optional sloppy)
1620(defun gnus-uu-grab-articles (list-of-articles process-function)
1621 (let ((result-buffer (get-buffer-create gnus-uu-result-buffer)) 1705 (let ((result-buffer (get-buffer-create gnus-uu-result-buffer))
1622 (state 'first) 1706 (state 'first)
1623 (process-state 'ok)
1624 (result t)
1625 (wrong-type t) 1707 (wrong-type t)
1626 (has-been-begin nil) 1708 has-been-begin has-been-end
1627 (article nil)) 1709 article result-file result-files process-state)
1628 1710
1629 (save-excursion 1711 (save-excursion
1630 (set-buffer result-buffer) 1712 (set-buffer result-buffer)
1631 (erase-buffer)) 1713 (erase-buffer))
1632 (setq gnus-uu-has-been-grabbed nil) 1714 (setq gnus-uu-has-been-grabbed nil)
1715
1633 (while (and list-of-articles 1716 (while (and list-of-articles
1634 (not (eq process-state 'end)) 1717 (not (memq 'error process-state))
1635 (not (eq process-state 'begin-and-end)) 1718 (or sloppy
1636 (not (eq process-state 'error))) 1719 (not (memq 'end process-state))))
1720
1637 (setq article (car list-of-articles)) 1721 (setq article (car list-of-articles))
1638 (setq list-of-articles (cdr list-of-articles)) 1722 (setq list-of-articles (cdr list-of-articles))
1639 (setq gnus-uu-has-been-grabbed (cons article gnus-uu-has-been-grabbed)) 1723 (setq gnus-uu-has-been-grabbed (cons article gnus-uu-has-been-grabbed))
1640 1724
1641 (if (eq list-of-articles ()) (setq state 'last)) 1725 (if (eq list-of-articles ())
1726 (if (eq state 'first)
1727 (setq state 'first-and-last)
1728 (setq state 'last)))
1642 1729
1643 (message (format "Getting article %d" article)) 1730 (message "Getting article %d" article)
1644 (if (not (= (or gnus-current-article 0) article)) 1731 (if (not (= (or gnus-current-article 0) article))
1645 (gnus-summary-display-article article)) 1732 (gnus-summary-display-article article))
1646 (gnus-summary-mark-as-read article) 1733 (gnus-summary-mark-as-read article)
1647 1734
1648 (save-excursion 1735 (save-excursion (set-buffer gnus-article-buffer) (widen))
1649 (set-buffer gnus-article-buffer)
1650 (widen))
1651 1736
1652 (setq process-state (funcall process-function gnus-article-buffer state)) 1737 (setq process-state (funcall process-function gnus-article-buffer state))
1653 1738
1654 (if (or (eq process-state 'begin) (eq process-state 'begin-and-end) 1739; (message "process-state er %s" process-state)(sleep-for 3)
1655 (eq process-state 'ok))
1656 (setq has-been-begin t))
1657 1740
1658 (if (not (eq process-state 'wrong-type)) 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))
1659 (setq wrong-type nil) 1759 (setq wrong-type nil)
1660 (if gnus-uu-unmark-articles-not-decoded 1760 (if gnus-uu-unmark-articles-not-decoded
1661 (gnus-summary-mark-as-unread article t))) 1761 (gnus-summary-mark-as-unread article t)))
1662 1762
1663 (if gnus-uu-do-sloppy-uudecode 1763 (if sloppy (setq wrong-type nil))
1664 (setq wrong-type nil))
1665 1764
1666 (if (and (not has-been-begin) 1765 (if (and (not has-been-begin)
1667 (not gnus-uu-do-sloppy-uudecode) 1766 (not sloppy)
1668 (or (eq process-state 'end) 1767 (or (memq 'end process-state)
1669 (eq process-state 'middle))) 1768 (memq 'middle process-state)))
1670 (progn 1769 (progn
1671 (setq process-state 'error) 1770 (setq process-state (list 'error))
1672 (message "No begin part at the beginning") 1771 (message "No begin part at the beginning")
1673 (sit-for 2)) 1772 (sleep-for 2))
1674 (setq state 'middle))) 1773 (setq state 'middle)))
1675 1774
1676 (if (and (not has-been-begin) (not gnus-uu-do-sloppy-uudecode)) 1775 (if result-files
1677 (progn 1776 ()
1678 (setq result nil) 1777 (if (not has-been-begin)
1679 (message "Wrong type file") 1778 (message "Wrong type file")
1680 (sit-for 2)) 1779 (if (memq 'error process-state)
1681 (if (eq process-state 'error) 1780 (setq result-files nil)
1682 (setq result nil) 1781 (if (not (or (memq 'ok process-state)
1683 (if (not (or (eq process-state 'ok) 1782 (memq 'end process-state)))
1684 (eq process-state 'end) 1783 (progn
1685 (eq process-state 'begin-and-end))) 1784 (message "End of articles reached before end of file")
1686 (progn 1785 (setq result-files nil))
1687 (if (not gnus-uu-do-sloppy-uudecode) 1786 (gnus-uu-unmark-list-of-grabbed)))))
1688 (progn 1787 result-files))
1689 (message "End of articles reached before end of file")
1690 (sit-for 2)))
1691 (gnus-uu-unmark-list-of-grabbed)
1692 (setq result nil)))))
1693 (setq gnus-uu-rest-of-articles list-of-articles)
1694 result))
1695
1696 1788
1697(defun gnus-uu-uudecode-sentinel (process event) 1789(defun gnus-uu-uudecode-sentinel (process event)
1698; (message "Process '%s' has received event '%s'" process event)
1699; (sit-for 2)
1700 (delete-process (get-process process))) 1790 (delete-process (get-process process)))
1701 1791
1702 1792; Uudecodes a file asynchronously.
1703(defun gnus-uu-uustrip-article-as (process-buffer in-state) 1793(defun gnus-uu-uustrip-article-as (process-buffer in-state)
1704 (let ((state 'ok) 1794 (let ((state (list 'ok))
1705 (process-connection-type nil) 1795 (process-connection-type nil)
1706 start-char pst name-beg name-end buf-state) 1796 start-char pst name-beg name-end)
1707 (save-excursion 1797 (save-excursion
1708 (set-buffer process-buffer) 1798 (set-buffer process-buffer)
1709 (setq buf-state buffer-read-only) 1799 (let ((case-fold-search nil)
1710 (setq buffer-read-only nil) 1800 (buffer-read-only nil))
1711 1801
1712 (goto-char 1) 1802 (goto-char 1)
1713 1803
1714 (if gnus-uu-kill-carriage-return 1804 (if gnus-uu-kill-carriage-return
1715 (progn 1805 (progn
1716 (while (search-forward " 1806 (while (search-forward "\r" nil t)
1717" nil t) 1807 (delete-backward-char 1))
1718 (delete-backward-char 1)) 1808 (goto-char 1)))
1719 (goto-char 1)))
1720
1721 (if (not (re-search-forward gnus-uu-begin-string nil t))
1722 (if (not (re-search-forward gnus-uu-body-line nil t))
1723 (setq state 'wrong-type)))
1724
1725 (if (eq state 'wrong-type)
1726 ()
1727 (beginning-of-line)
1728 (setq start-char (point))
1729 1809
1730 (if (looking-at gnus-uu-begin-string) 1810 (if (not (re-search-forward gnus-uu-begin-string nil t))
1731 (progn 1811 (if (not (re-search-forward gnus-uu-body-line nil t))
1732 (setq name-end (match-end 1)) 1812 (setq state (list 'wrong-type))))
1733 (goto-char (setq name-beg (match-beginning 1))) 1813
1734 (while (re-search-forward "/" name-end t) 1814 (if (memq 'wrong-type state)
1735 (replace-match "-")) 1815 ()
1736 (setq gnus-uu-file-name (buffer-substring name-beg name-end)) 1816 (beginning-of-line)
1737 (and gnus-uu-uudecode-process 1817 (setq start-char (point))
1738 (setq pst (process-status 1818
1739 (or gnus-uu-uudecode-process "nevair"))) 1819 (if (looking-at gnus-uu-begin-string)
1740 (if (or (eq pst 'stop) (eq pst 'run)) 1820 (progn
1741 (progn 1821 (setq name-end (match-end 1))
1742 (delete-process gnus-uu-uudecode-process) 1822
1743 (gnus-uu-unmark-list-of-grabbed t)))) 1823 ; Replace any slashes and spaces in file names before decoding
1744 (setq gnus-uu-uudecode-process 1824 (goto-char (setq name-beg (match-beginning 1)))
1745 (start-process 1825 (while (re-search-forward "/" name-end t)
1746 "*uudecode*" 1826 (replace-match "-"))
1747 (get-buffer-create gnus-uu-output-buffer-name) 1827 (goto-char name-beg)
1748 "sh" "-c" 1828 (while (re-search-forward " " name-end t)
1749 (format "cd %s ; uudecode" gnus-uu-tmp-dir))) 1829 (replace-match "_"))
1750 (set-process-sentinel 1830
1751 gnus-uu-uudecode-process 'gnus-uu-uudecode-sentinel) 1831 (setq gnus-uu-file-name (buffer-substring name-beg name-end))
1752 (setq state 'begin) 1832 (and gnus-uu-uudecode-process
1753 (gnus-uu-add-file (concat gnus-uu-tmp-dir gnus-uu-file-name))) 1833 (setq pst (process-status
1754 (setq state 'middle)) 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)))
1755 1850
1756 (goto-char (point-max)) 1851 (goto-char (point-max))
1757
1758 (re-search-backward
1759 (concat gnus-uu-body-line "\\|" gnus-uu-end-string) nil t)
1760 (beginning-of-line)
1761 1852
1762 (if (looking-at gnus-uu-end-string) 1853 (re-search-backward
1763 (if (eq state 'begin) 1854 (concat gnus-uu-body-line "\\|" gnus-uu-end-string) nil t)
1764 (setq state 'begin-and-end) 1855 (beginning-of-line)
1765 (setq state 'end)))
1766 (forward-line 1)
1767 1856
1768; (message "Ja: %s" state)(sit-for 0)(sleep-for 2) 1857 (if (looking-at gnus-uu-end-string)
1769 1858 (setq state (cons 'end state)))
1770 (and gnus-uu-uudecode-process 1859 (forward-line 1)
1771 (setq pst (process-status (or gnus-uu-uudecode-process "nevair")))
1772 (if (or (eq pst 'run) (eq pst 'stop))
1773 (progn
1774 (if gnus-uu-correct-stripped-uucode
1775 (progn
1776 (gnus-uu-check-correct-stripped-uucode
1777 start-char (point))
1778 (goto-char (point-max))
1779 (re-search-backward
1780 (concat gnus-uu-body-line "\\|" gnus-uu-end-string)
1781 nil t)
1782 (forward-line 1)))
1783 (condition-case err
1784 (process-send-region gnus-uu-uudecode-process
1785 start-char (point))
1786 (error
1787 (progn
1788 (message "Her var en uuerror")
1789 (sleep-for 2)
1790 (setq state 'wrong-type)
1791 (delete-process gnus-uu-uudecode-process)))))
1792 (setq state 'wrong-type)))
1793 (if (not gnus-uu-uudecode-process)
1794 (setq state 'wrong-type)))
1795
1796 (setq buffer-read-only buf-state))
1797 state))
1798 1860
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))))
1799 1892
1800; This function is used by `gnus-uu-grab-articles' to treat 1893; This function is used by `gnus-uu-grab-articles' to treat
1801; a shared article. 1894; a shared article.
1802
1803(defun gnus-uu-unshar-article (process-buffer in-state) 1895(defun gnus-uu-unshar-article (process-buffer in-state)
1804 (let ((state 'ok) 1896 (let ((state (list 'ok))
1805 start-char) 1897 start-char)
1806 (save-excursion 1898 (save-excursion
1807 (set-buffer process-buffer) 1899 (set-buffer process-buffer)
1808 (goto-char 1) 1900 (goto-char 1)
1809 (if (not (re-search-forward gnus-uu-shar-begin-string nil t)) 1901 (if (not (re-search-forward gnus-uu-shar-begin-string nil t))
1810 (setq state 'wrong-type) 1902 (setq state (list 'wrong-type))
1811 (beginning-of-line) 1903 (beginning-of-line)
1812 (setq start-char (point)) 1904 (setq start-char (point))
1813 (call-process-region 1905 (call-process-region
@@ -1816,9 +1908,7 @@ it marks everything as read, even if it couldn't decode the articles."
1816 "-c" (concat "cd " gnus-uu-shar-directory " ; sh")))) 1908 "-c" (concat "cd " gnus-uu-shar-directory " ; sh"))))
1817 state)) 1909 state))
1818 1910
1819
1820; Returns the name of what the shar file is going to unpack. 1911; Returns the name of what the shar file is going to unpack.
1821
1822(defun gnus-uu-find-name-in-shar () 1912(defun gnus-uu-find-name-in-shar ()
1823 (let ((oldpoint (point)) 1913 (let ((oldpoint (point))
1824 res) 1914 res)
@@ -1827,10 +1917,8 @@ it marks everything as read, even if it couldn't decode the articles."
1827 (setq res (buffer-substring (match-beginning 1) (match-end 1)))) 1917 (setq res (buffer-substring (match-beginning 1) (match-end 1))))
1828 (goto-char oldpoint) 1918 (goto-char oldpoint)
1829 res)) 1919 res))
1830
1831 1920
1832; Returns the article number of the given subject. 1921; Returns the article number of the given subject.
1833
1834(defun gnus-uu-article-number (subject) 1922(defun gnus-uu-article-number (subject)
1835 (let (end) 1923 (let (end)
1836 (string-match "[0-9]+[^0-9]" subject 1) 1924 (string-match "[0-9]+[^0-9]" subject 1)
@@ -1838,26 +1926,9 @@ it marks everything as read, even if it couldn't decode the articles."
1838 (string-to-int 1926 (string-to-int
1839 (substring subject (string-match "[0-9]" subject 1) end)))) 1927 (substring subject (string-match "[0-9]" subject 1) end))))
1840 1928
1841
1842; UUdecodes everything in the buffer and returns the name of the
1843; resulting file.
1844
1845(defun gnus-uu-decode (directory)
1846 (let ((command (concat "cd " directory " ; uudecode"))
1847 file-name)
1848 (save-excursion
1849 (message "Uudecoding...")
1850 (set-buffer (get-buffer-create gnus-uu-result-buffer))
1851 (setq file-name (concat gnus-uu-tmp-dir gnus-uu-file-name))
1852 (gnus-uu-add-file file-name)
1853 (call-process-region 1 (point-max) "sh" nil t nil "-c" command)
1854 file-name)))
1855
1856
1857; `gnus-uu-choose-action' chooses what action to perform given the name 1929; `gnus-uu-choose-action' chooses what action to perform given the name
1858; and `gnus-uu-file-action-list'. Returns either nil if no action is 1930; and `gnus-uu-file-action-list'. Returns either nil if no action is
1859; found, or the name of the command to run if such a rule is found. 1931; found, or the name of the command to run if such a rule is found.
1860
1861(defun gnus-uu-choose-action (file-name file-action-list) 1932(defun gnus-uu-choose-action (file-name file-action-list)
1862 (let ((action-list (copy-sequence file-action-list)) 1933 (let ((action-list (copy-sequence file-action-list))
1863 rule action) 1934 rule action)
@@ -1868,9 +1939,30 @@ it marks everything as read, even if it couldn't decode the articles."
1868 (setq action (car (cdr rule))))) 1939 (setq action (car (cdr rule)))))
1869 action)) 1940 action))
1870 1941
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" "") "? "))))
1871 1950
1872; Moves the file from the tmp directory to where the user wants it. 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)))))
1873 1964
1965; Moves the file from the tmp directory to where the user wants it.
1874(defun gnus-uu-save-file (from-file-name &optional default-dir ignore-existing) 1966(defun gnus-uu-save-file (from-file-name &optional default-dir ignore-existing)
1875 (let (dir file-name command) 1967 (let (dir file-name command)
1876 (string-match "/[^/]*$" from-file-name) 1968 (string-match "/[^/]*$" from-file-name)
@@ -1879,16 +1971,12 @@ it marks everything as read, even if it couldn't decode the articles."
1879 (setq dir default-dir) 1971 (setq dir default-dir)
1880 (setq dir (gnus-uu-read-directory "Where do you want the file? "))) 1972 (setq dir (gnus-uu-read-directory "Where do you want the file? ")))
1881 (if (and (not ignore-existing) (file-exists-p (concat dir file-name))) 1973 (if (and (not ignore-existing) (file-exists-p (concat dir file-name)))
1882 (progn 1974 (setq file-name
1883 (message (concat "There already is a file called " file-name)) 1975 (read-file-name "File exist. Enter a new name: " dir
1884 (sit-for 2) 1976 (concat dir file-name) nil file-name))
1885 (setq file-name
1886 (read-file-name "Give a new name: " dir (concat dir file-name)
1887 nil file-name)))
1888 (setq file-name (concat dir file-name))) 1977 (setq file-name (concat dir file-name)))
1889 (rename-file from-file-name file-name t))) 1978 (rename-file from-file-name file-name t)))
1890 1979
1891
1892(defun gnus-uu-read-directory (prompt &optional default) 1980(defun gnus-uu-read-directory (prompt &optional default)
1893 (let (dir ok create) 1981 (let (dir ok create)
1894 (while (not ok) 1982 (while (not ok)
@@ -1912,110 +2000,113 @@ it marks everything as read, even if it couldn't decode the articles."
1912 (if (= create ?y) (make-directory dir)))) 2000 (if (= create ?y) (make-directory dir))))
1913 (setq gnus-uu-current-save-dir (concat dir "/")))) 2001 (setq gnus-uu-current-save-dir (concat dir "/"))))
1914 2002
1915
1916; Unpacks an archive and views all the files in it. Returns t if 2003; Unpacks an archive and views all the files in it. Returns t if
1917; viewing one or more files is successful. 2004; viewing one or more files is successful.
1918 2005(defun gnus-uu-treat-archive (file-path)
1919(defun gnus-uu-treat-archive (file-name) 2006 (let ((did-unpack t)
1920 (let ((arc-dir (make-temp-name 2007 action command files file file-name dir)
1921 (concat gnus-uu-tmp-dir "gnusuu")))
1922 action command files file did-view short-file-name)
1923 (setq action (gnus-uu-choose-action 2008 (setq action (gnus-uu-choose-action
1924 file-name (append gnus-uu-user-archive-rules 2009 file-path (append gnus-uu-user-archive-rules
1925 (if gnus-uu-ignore-default-archive-rules 2010 (if gnus-uu-ignore-default-archive-rules
1926 nil 2011 nil
1927 gnus-uu-default-archive-rules)))) 2012 gnus-uu-default-archive-rules))))
1928 (if (not action)
1929 (progn (message (format "No unpackers for the file %s" file-name))
1930 (sit-for 2))
1931 (string-match "/[^/]*$" file-name)
1932 (setq short-file-name (substring file-name (1+ (match-beginning 0))))
1933 (setq command (format "%s %s %s ; cd %s ; %s "
1934 (if (or (string= action "uncompress")
1935 (string= action "gunzip"))
1936 "cp"
1937 "mv")
1938 (gnus-uu-command "" file-name) arc-dir
1939 arc-dir
1940 (gnus-uu-command action short-file-name)))
1941
1942 (make-directory arc-dir)
1943 (gnus-uu-add-file arc-dir)
1944 2013
1945 (save-excursion 2014 (if (not action) (error "No unpackers for the file %s" file-path))
1946 (set-buffer (get-buffer-create gnus-uu-output-buffer-name))
1947 (erase-buffer))
1948
1949 (message (format "Unpacking with %s..." action))
1950 (sleep-for 1)
1951
1952 (if (= 0 (call-process "sh" nil
1953 (get-buffer-create gnus-uu-output-buffer-name)
1954 nil "-c" command))
1955 (message "")
1956 (message "Error during unpacking of archive")
1957 (sit-for 0) (sleep-for 2)
1958 (setq gnus-uu-error-during-unarching t))
1959
1960 (if (not (or (string= action "uncompress")
1961 (string= action "gunzip")))
1962 (call-process "sh" nil (get-buffer gnus-uu-output-buffer-name)
1963 nil "-c" (format "mv %s %s"
1964 (gnus-uu-command "" (concat arc-dir "/" short-file-name))
1965 gnus-uu-tmp-dir)))
1966 (gnus-uu-add-file (concat gnus-uu-tmp-dir short-file-name))
1967
1968 (setq did-view
1969 (or (gnus-uu-show-directory arc-dir gnus-uu-use-interactive-view)
1970 did-view))
1971 2015
1972 (if (and (not gnus-uu-use-interactive-view) 2016 (string-match "/[^/]*$" file-path)
1973 (file-directory-p arc-dir)) 2017 (setq file-name (substring file-path (1+ (match-beginning 0))))
1974 (delete-directory arc-dir))) 2018 (setq dir (substring file-path 0 (match-beginning 0)))
1975 2019
1976 did-view)) 2020 (if (gnus-uu-string-in-list action gnus-uu-destructive-archivers)
2021 (copy-file file-path (concat file-path "~") t))
1977 2022
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))
1978 2043
1979; Tries to view all the files in the given directory. Returns t if 2044; Tries to view all the files in the given directory. Returns t if
1980; viewing one or more files is successful. 2045; viewing one or more files is successful.
1981 2046(defun gnus-uu-view-directory (dir &optional dont-delete-files not-top)
1982(defun gnus-uu-show-directory (dir &optional dont-delete-files) 2047 (let ((first t)
1983 (let (files file did-view) 2048 files file did-view ignore-files)
1984 (setq files (directory-files dir t)) 2049 (setq files (directory-files dir t "[^/][^\\.][^\\.]?$"))
1985 (setq gnus-uu-generated-file-list 2050 (gnus-uu-add-file files)
1986 (append files gnus-uu-generated-file-list)) 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
1987 (while files 2060 (while files
1988 (setq file (car files)) 2061 (setq file (car files))
1989 (setq files (cdr files)) 2062 (setq files (cdr files))
1990 (if (and (not (string-match "/\\.$" file)) 2063 (if (not (string= (or (gnus-uu-get-action file) "") "gnus-uu-archive"))
1991 (not (string-match "/\\.\\.$" file)))
1992 (progn 2064 (progn
1993 (set-file-modes file 448) 2065 (set-file-modes file 448)
1994 (if (file-directory-p file) 2066 (if (file-directory-p file)
1995 (setq did-view (or (gnus-uu-show-directory file 2067 (setq did-view (or (gnus-uu-view-directory file
1996 dont-delete-files) 2068 dont-delete-files
2069 t)
1997 did-view)) 2070 did-view))
1998 (setq did-view (or (gnus-uu-view-file file t) did-view)) 2071 (setq did-view (or (gnus-uu-view-file file t) did-view)))))
1999 (if (and (not dont-delete-files) (file-exists-p file)) 2072 (if (and (not dont-delete-files) (file-exists-p file))
2000 (delete-file file)))))) 2073 (delete-file file)))
2074
2001 (if (not dont-delete-files) (delete-directory dir)) 2075 (if (not dont-delete-files) (delete-directory dir))
2002 did-view)) 2076 did-view))
2003 2077
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
2004 2094
2005;; Manual marking 2095;; Manual marking
2006 2096
2007(defun gnus-uu-enter-mark-in-list () 2097(defun gnus-uu-enter-mark-in-list ()
2008 (let (article beg) 2098 (let (article beg)
2009 (beginning-of-line) 2099 (save-excursion
2010 (setq beg (point)) 2100 (beginning-of-line)
2011 (end-of-line) 2101 (setq beg (point))
2012 (setq article (gnus-uu-article-number 2102 (end-of-line)
2013 (buffer-substring beg (point)))) 2103 (setq article (gnus-uu-article-number
2014 (message (format "Adding article %d to list" article)) 2104 (buffer-substring beg (point))))
2015 (setq gnus-uu-marked-article-list 2105 (message "Adding article %d to list" article)
2016 (cons article gnus-uu-marked-article-list)))) 2106 (setq gnus-uu-marked-article-list
2107 (cons article gnus-uu-marked-article-list)))))
2017 2108
2018(defun gnus-uu-mark-article () 2109(defun gnus-uu-mark-article (&optional dont-move)
2019 "Marks the current article to be decoded later." 2110 "Marks the current article to be decoded later."
2020 (interactive) 2111 (interactive)
2021 (gnus-uu-enter-mark-in-list) 2112 (gnus-uu-enter-mark-in-list)
@@ -2032,40 +2123,77 @@ it marks everything as read, even if it couldn't decode the articles."
2032 (setq beg (point)) 2123 (setq beg (point))
2033 (end-of-line) 2124 (end-of-line)
2034 (setq article (gnus-uu-article-number (buffer-substring beg (point)))) 2125 (setq article (gnus-uu-article-number (buffer-substring beg (point))))
2035 (message (format "Removing article %d" article)) 2126 (message "Removing article %d" article)
2036 (while in 2127 (while in
2037 (if (not (= (car in) article)) 2128 (if (not (= (car in) article))
2038 (setq out (cons (car in) out)) 2129 (setq out (cons (car in) out))
2039 (setq found t) 2130 (setq found t)
2040 (message (format "Removing article %d" article))) 2131 (message "Removing article %d" article))
2041 (setq in (cdr in))) 2132 (setq in (cdr in)))
2042 (if (not found) (message "Not a marked article.")) 2133 (if (not found) (message "Not a marked article."))
2043 (setq gnus-uu-marked-article-list (reverse out)) 2134 (setq gnus-uu-marked-article-list (reverse out))
2044 (gnus-summary-mark-as-unread nil t) 2135 (gnus-summary-mark-as-unread nil t)
2045 (gnus-summary-next-subject 1 nil))) 2136 (gnus-summary-next-subject 1 nil)))
2046
2047 2137
2048(defun gnus-uu-unmark-all-articles () 2138(defun gnus-uu-unmark-all-articles ()
2049 "Removes the mark from all articles marked for decoding." 2139 "Removes the mark from all articles marked for decoding."
2050 (interactive) 2140 (interactive)
2051 (let ((articles (copy-sequence gnus-uu-marked-article-list))) 2141 (while gnus-uu-marked-article-list
2052 (while articles 2142 (gnus-summary-goto-subject (car gnus-uu-marked-article-list))
2053 (gnus-summary-goto-subject (car articles)) 2143 (gnus-summary-mark-as-unread nil t)
2054 (gnus-summary-mark-as-unread nil t) 2144 (setq gnus-uu-marked-article-list (cdr gnus-uu-marked-article-list))))
2055 (setq articles (cdr articles)))
2056 (setq gnus-uu-marked-article-list ())))
2057 2145
2058(defun gnus-uu-mark-by-regexp () 2146(defun gnus-uu-mark-by-regexp ()
2059 "Asks for a regular expression and marks all articles that match." 2147 "Asks for a regular expression and marks all articles that match."
2060 (interactive) 2148 (interactive)
2061 (let (exp) 2149 (let (exp)
2062 (setq exp (read-from-minibuffer "Enter regular expression: ")) 2150 (setq exp (read-from-minibuffer "Mark (regexp): "))
2063 (setq gnus-uu-marked-article-list 2151 (setq gnus-uu-marked-article-list
2064 (reverse (gnus-uu-get-list-of-articles exp t))) 2152 (append gnus-uu-marked-article-list
2153 (reverse (gnus-uu-get-list-of-articles exp t))))
2065 (message ""))) 2154 (message "")))
2066 2155
2067 2156(defun gnus-uu-mark-thread ()
2068;; Various 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))
2069 2197
2070(defun gnus-uu-check-correct-stripped-uucode (start end) 2198(defun gnus-uu-check-correct-stripped-uucode (start end)
2071 (let (found beg length short) 2199 (let (found beg length short)
@@ -2100,26 +2228,26 @@ it marks everything as read, even if it couldn't decode the articles."
2100 (forward-line 1)))))) 2228 (forward-line 1))))))
2101 2229
2102(defun gnus-uu-initialize () 2230(defun gnus-uu-initialize ()
2231 (gnus-uu-check-for-generated-files)
2232 (setq gnus-uu-tmp-dir (expand-file-name gnus-uu-tmp-dir))
2233 (if (string-match "[^/]$" gnus-uu-tmp-dir)
2234 (setq gnus-uu-tmp-dir (concat gnus-uu-tmp-dir "/")))
2235 (if (not (file-directory-p gnus-uu-tmp-dir))
2236 (error "Temp directory %s doesn't exist" gnus-uu-tmp-dir)
2237 (if (not (file-writable-p gnus-uu-tmp-dir))
2238 (error "Temp directory %s can't be written to" gnus-uu-tmp-dir)))
2239 (setq gnus-uu-work-dir
2240 (concat gnus-uu-tmp-dir (make-temp-name "gnus")))
2241 (gnus-uu-add-file gnus-uu-work-dir)
2242 (if (not (file-directory-p gnus-uu-work-dir))
2243 (make-directory gnus-uu-work-dir))
2244 (setq gnus-uu-work-dir (concat gnus-uu-work-dir "/"))
2103 (setq gnus-uu-error-during-unarching nil) 2245 (setq gnus-uu-error-during-unarching nil)
2104 (if (not gnus-uu-use-interactive-view) 2246 (setq gnus-uu-interactive-file-list nil))
2105 ()
2106 (save-excursion
2107 (setq gnus-uu-interactive-file-list nil)
2108 (set-buffer (get-buffer-create gnus-uu-interactive-buffer-name))
2109 (erase-buffer)
2110 (gnus-uu-mode)
2111 (insert
2112 "# Press return to execute a command.
2113# Press `C-c C-c' to exit interactive view.
2114
2115"))))
2116
2117 2247
2118; Kills the temporary uu buffers, kills any processes, etc. 2248; Kills the temporary uu buffers, kills any processes, etc.
2119
2120(defun gnus-uu-clean-up () 2249(defun gnus-uu-clean-up ()
2121 (let (buf pst) 2250 (let (buf pst)
2122 (setq gnus-uu-do-sloppy-uudecode nil)
2123 (and gnus-uu-uudecode-process 2251 (and gnus-uu-uudecode-process
2124 (setq pst (process-status (or gnus-uu-uudecode-process "nevair"))) 2252 (setq pst (process-status (or gnus-uu-uudecode-process "nevair")))
2125 (if (or (eq pst 'stop) (eq pst 'run)) 2253 (if (or (eq pst 'stop) (eq pst 'run))
@@ -2130,44 +2258,57 @@ it marks everything as read, even if it couldn't decode the articles."
2130 (and (setq buf (get-buffer gnus-uu-result-buffer)) 2258 (and (setq buf (get-buffer gnus-uu-result-buffer))
2131 (kill-buffer buf)))) 2259 (kill-buffer buf))))
2132 2260
2133
2134; `gnus-uu-check-for-generated-files' deletes any generated files that 2261; `gnus-uu-check-for-generated-files' deletes any generated files that
2135; hasn't been deleted, if, for instance, the user terminated decoding 2262; hasn't been deleted, if, for instance, the user terminated decoding
2136; with `C-g'. 2263; with `C-g'.
2137
2138(defun gnus-uu-check-for-generated-files () 2264(defun gnus-uu-check-for-generated-files ()
2139 (let (file) 2265 (let (file dirs)
2140 (while gnus-uu-generated-file-list 2266 (while gnus-uu-generated-file-list
2141 (setq file (car gnus-uu-generated-file-list)) 2267 (setq file (car gnus-uu-generated-file-list))
2142 (setq gnus-uu-generated-file-list (cdr gnus-uu-generated-file-list)) 2268 (setq gnus-uu-generated-file-list (cdr gnus-uu-generated-file-list))
2143 (if (not (string-match "/\\.[\\.]?$" file)) 2269 (if (not (string-match "/\\.[\\.]?$" file))
2144 (progn 2270 (progn
2145 (if (file-directory-p file) 2271 (if (file-directory-p file)
2146 (delete-directory file) 2272 (setq dirs (cons file dirs))
2147 (if (file-exists-p file) 2273 (if (file-exists-p file)
2148 (delete-file file)))))))) 2274 (delete-file file))))))
2149 2275 (setq dirs (nreverse dirs))
2150 2276 (while dirs
2151; Add a file to be checked (and deleted if it still exists upon 2277 (setq file (car dirs))
2152; exiting the newsgroup) to a list 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).
2153(defun gnus-uu-add-file (file) 2284(defun gnus-uu-add-file (file)
2154 (setq gnus-uu-generated-file-list 2285 (if (stringp file)
2155 (cons file gnus-uu-generated-file-list))) 2286 (setq gnus-uu-generated-file-list
2156 2287 (cons file gnus-uu-generated-file-list))
2288 (setq gnus-uu-generated-file-list
2289 (append file gnus-uu-generated-file-list))))
2157 2290
2158; Go to the next unread subject. If there is no further unread 2291; Go to the next unread subject. If there is no further unread
2159; subjects, go to the last subject in the buffer. 2292; subjects, go to the last subject in the buffer.
2160(defun gnus-uu-summary-next-subject () 2293(defun gnus-uu-summary-next-subject ()
2161 (if (not (gnus-summary-search-forward t)) 2294 (let (opi)
2162 (progn 2295 (if (not (gnus-summary-search-forward t))
2163 (goto-char 1) 2296 (progn
2164 (sit-for 0) 2297 (goto-char 1)
2165 (goto-char (point-max)) 2298 (sit-for 0)
2166 (forward-line -1) 2299 (goto-char (point-max))
2167 (beginning-of-line) 2300 (forward-line -1)
2168 (search-forward ":" nil t))) 2301 (beginning-of-line)
2169 (sit-for 0) 2302 (search-forward ":" nil t)))
2170 (gnus-summary-recenter)) 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)))
2171 2312
2172; Inputs an action and a file and returns a full command, putting 2313; Inputs an action and a file and returns a full command, putting
2173; ticks round the file name and escaping any ticks in the file name. 2314; ticks round the file name and escaping any ticks in the file name.
@@ -2186,7 +2327,6 @@ it marks everything as read, even if it couldn't decode the articles."
2186 2327
2187 2328
2188;; Initializing 2329;; Initializing
2189
2190(add-hook 'gnus-exit-group-hook 2330(add-hook 'gnus-exit-group-hook
2191 '(lambda () 2331 '(lambda ()
2192 (gnus-uu-clean-up) 2332 (gnus-uu-clean-up)
@@ -2216,17 +2356,24 @@ it marks everything as read, even if it couldn't decode the articles."
2216 (forward-line 3) 2356 (forward-line 3)
2217 (run-hooks 'gnus-uu-mode-hook))) 2357 (run-hooks 'gnus-uu-mode-hook)))
2218 2358
2219
2220(defun gnus-uu-enter-interactive-file (action file) 2359(defun gnus-uu-enter-interactive-file (action file)
2221 (let (command) 2360 (let (command)
2222 (save-excursion 2361 (save-excursion
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")))
2223 (setq gnus-uu-interactive-file-list 2372 (setq gnus-uu-interactive-file-list
2224 (cons file gnus-uu-interactive-file-list)) 2373 (cons file gnus-uu-interactive-file-list))
2225 (set-buffer (get-buffer gnus-uu-interactive-buffer-name))
2226 (setq command (gnus-uu-command action file)) 2374 (setq command (gnus-uu-command action file))
2227 (insert (format "%s\n" command))))) 2375 (insert (format "%s\n" command)))))
2228 2376
2229
2230(defun gnus-uu-interactive-execute () 2377(defun gnus-uu-interactive-execute ()
2231 "Executes the command on the current line in interactive mode." 2378 "Executes the command on the current line in interactive mode."
2232 (interactive) 2379 (interactive)
@@ -2248,7 +2395,6 @@ it marks everything as read, even if it couldn't decode the articles."
2248 (forward-line 1) 2395 (forward-line 1)
2249 (beginning-of-line))) 2396 (beginning-of-line)))
2250 2397
2251
2252(defun gnus-uu-interactive-end () 2398(defun gnus-uu-interactive-end ()
2253 "This function exits interactive view mode and returns to summary mode." 2399 "This function exits interactive view mode and returns to summary mode."
2254 (interactive) 2400 (interactive)
@@ -2261,7 +2407,6 @@ it marks everything as read, even if it couldn't decode the articles."
2261 (if buf (kill-buffer buf)) 2407 (if buf (kill-buffer buf))
2262 (pop-to-buffer gnus-summary-buffer))) 2408 (pop-to-buffer gnus-summary-buffer)))
2263 2409
2264
2265(if gnus-uu-mode-map 2410(if gnus-uu-mode-map
2266 () 2411 ()
2267 (setq gnus-uu-mode-map (make-sparse-keymap)) 2412 (setq gnus-uu-mode-map (make-sparse-keymap))
@@ -2276,18 +2421,19 @@ it marks everything as read, even if it couldn't decode the articles."
2276 (define-key gnus-uu-mode-map "\C-c\C-w" 'gnus-uu-interactive-save-all-files) 2421 (define-key gnus-uu-mode-map "\C-c\C-w" 'gnus-uu-interactive-save-all-files)
2277 (define-key gnus-uu-mode-map "\C-c\C-o" 'gnus-uu-interactive-save-original-file)) 2422 (define-key gnus-uu-mode-map "\C-c\C-o" 'gnus-uu-interactive-save-original-file))
2278 2423
2279
2280(defun gnus-uu-interactive-save-original-file () 2424(defun gnus-uu-interactive-save-original-file ()
2281 "Saves the file from whence the file on the current line came from." 2425 "Saves the file from whence the file on the current line came from."
2282 (interactive) 2426 (interactive)
2283 (let (file) 2427 (let (file)
2284 (if (file-exists-p 2428 (if (file-exists-p
2285 (setq file (concat gnus-uu-tmp-dir 2429 (setq file (concat gnus-uu-work-dir
2286 (or gnus-uu-file-name gnus-uu-shar-file-name)))) 2430 (or gnus-uu-file-name gnus-uu-shar-file-name))))
2287 (gnus-uu-save-file file) 2431 (progn
2432 (gnus-uu-save-file file)
2433 (message "Saved file %s"
2434 (or gnus-uu-file-name gnus-uu-shar-file-name)))
2288 (message "Already saved.")))) 2435 (message "Already saved."))))
2289 2436
2290
2291(defun gnus-uu-interactive-save-current-file-silent () 2437(defun gnus-uu-interactive-save-current-file-silent ()
2292 "Saves the file referred to on the current line in the current directory." 2438 "Saves the file referred to on the current line in the current directory."
2293 (interactive) 2439 (interactive)
@@ -2315,7 +2461,6 @@ it marks everything as read, even if it couldn't decode the articles."
2315 (gnus-uu-save-file file (if dont-ask gnus-uu-current-save-dir nil) silent) 2461 (gnus-uu-save-file file (if dont-ask gnus-uu-current-save-dir nil) silent)
2316 (delete-region beg (point))))) 2462 (delete-region beg (point)))))
2317 2463
2318
2319(defun gnus-uu-interactive-save-all-files () 2464(defun gnus-uu-interactive-save-all-files ()
2320 "Saves all files referred to in the interactive buffer." 2465 "Saves all files referred to in the interactive buffer."
2321 (interactive) 2466 (interactive)
@@ -2357,6 +2502,426 @@ Commands:
2357 (define-key gnus-uu-mode-map "\C-c\C-a" 'gnus-uu-interactive-save-all-files) 2502 (define-key gnus-uu-mode-map "\C-c\C-a" 'gnus-uu-interactive-save-all-files)
2358 (define-key gnus-uu-mode-map "\C-c\C-o" 'gnus-uu-interactive-save-original-file) 2503 (define-key gnus-uu-mode-map "\C-c\C-o" 'gnus-uu-interactive-save-original-file)
2359 2504
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
2360(provide 'gnus-uu) 2924(provide 'gnus-uu)
2361 2925
2362;; gnus-uu.el ends here 2926;; gnus-uu.el ends here
2927