1 ;;; gnus-uu.el --- extract (uu)encoded files in Gnus
2 ;; Copyright (C) 1985,86,87,93,94,95 Free Software Foundation, Inc.
4 ;; Author: Lars Ingebrigtsen <larsi@ifi.uio.no>
9 ;; This file is part of GNU Emacs.
11 ;; GNU Emacs is free software; you can redistribute it and/or modify
12 ;; it under the terms of the GNU General Public License as published by
13 ;; the Free Software Foundation; either version 2, or (at your option)
16 ;; GNU Emacs is distributed in the hope that it will be useful,
17 ;; but WITHOUT ANY WARRANTY; without even the implied warranty of
18 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19 ;; GNU General Public License for more details.
21 ;; You should have received a copy of the GNU General Public License
22 ;; along with GNU Emacs; see the file COPYING. If not, write to
23 ;; the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA.
31 ;; Default viewing action rules
33 (defvar gnus-uu-default-view-rules
34 '(("\\.te?xt$\\|\\.doc$\\|read.*me\\|\\.c?$\\|\\.h$\\|\\.bat$\\|\\.asm$\\|makefile" "cat %s | sed s/\r//g")
35 ("\\.pas$" "cat %s | sed s/\r//g")
36 ("\\.[1-9]$" "groff -mandoc -Tascii %s | sed s/\b.//g")
37 ("\\.\\(jpe?g\\|gif\\|tiff?\\|p[pgb]m\\|xwd\\|xbm\\|pcx\\)$" "xv")
38 ("\\.tga$" "tgatoppm %s | xv -")
39 ("\\.\\(wav\\|aiff\\|hcom\\|u[blw]\\|s[bfw]\\|voc\\|smp\\)$"
40 "sox -v .5 %s -t .au -u - > /dev/audio")
41 ("\\.au$" "cat %s > /dev/audio")
43 ("\\.ps$" "ghostview")
45 ("\\.html$" "xmosaic")
46 ("\\.mpe?g$" "mpeg_play")
47 ("\\.\\(flc\\|fli\\|rle\\|iff\\|pfx\\|avi\\|sme\\|rpza\\|dl\\|qt\\|rsrc\\|mov\\)$" "xanim")
48 ("\\.\\(tar\\|arj\\|zip\\|zoo\\|arc\\|gz\\|Z\\|lzh\\|ar\\|lha\\)$"
51 "Default actions to be taken when the user asks to view a file.
52 To change the behaviour, you can either edit this variable or set
53 `gnus-uu-user-view-rules' to something useful.
57 To make gnus-uu use 'xli' to display JPEG and GIF files, put the
58 following in your .emacs file
60 (setq gnus-uu-user-view-rules '((\"jpg$\\\\|gif$\" \"xli\")))
62 Both these variables are lists of lists with two string elements. The
63 first string is a regular expression. If the file name matches this
64 regular expression, the command in the second string is executed with
65 the file as an argument.
67 If the command string contains \"%s\", the file name will be inserted
68 at that point in the command string. If there's no \"%s\" in the
69 command string, the file name will be appended to the command string
72 There are several user variables to tailor the behaviour of gnus-uu to
73 your needs. First we have `gnus-uu-user-view-rules', which is the
74 variable gnus-uu first consults when trying to decide how to view a
75 file. If this variable contains no matches, gnus-uu examines the
76 default rule vaiable provided in this package. If gnus-uu finds no
77 match here, it uses `gnus-uu-user-view-rules-end' to try to make a
80 (defvar gnus-uu-user-view-rules nil
81 "Variable detailing what actions are to be taken to view a file.
82 See the documentation on the `gnus-uu-default-view-rules' variable for
85 (defvar gnus-uu-user-view-rules-end
87 "Variable saying what actions are to be taken if no rule matched the file name.
88 See the documentation on the `gnus-uu-default-view-rules' variable for
91 ;; Default unpacking commands
93 (defvar gnus-uu-default-archive-rules
94 '(("\\.tar$" "tar xf")
95 ("\\.zip$" "unzip -o")
99 ("\\.\\(lzh\\|lha\\)$" "lha x")
100 ("\\.Z$" "uncompress")
102 ("\\.arc$" "arc -x")))
104 (defvar gnus-uu-destructive-archivers
105 (list "uncompress" "gunzip"))
107 (defvar gnus-uu-user-archive-rules nil
108 "A list that can be set to override the default archive unpacking commands.
109 To use, for instance, 'untar' to unpack tar files and 'zip -x' to
110 unpack zip files, say the following:
111 (setq gnus-uu-user-archive-rules
112 '((\"\\\\.tar$\" \"untar\")
113 (\"\\\\.zip$\" \"zip -x\")))")
115 (defvar gnus-uu-ignore-files-by-name nil
116 "A regular expression saying what files should not be viewed based on name.
117 If, for instance, you want gnus-uu to ignore all .au and .wav files,
118 you could say something like
120 (setq gnus-uu-ignore-files-by-name \"\\\\.au$\\\\|\\\\.wav$\")
122 Note that this variable can be used in conjunction with the
123 `gnus-uu-ignore-files-by-type' variable.")
125 (defvar gnus-uu-ignore-files-by-type nil
126 "A regular expression saying what files that shouldn't be viewed, based on MIME file type.
127 If, for instance, you want gnus-uu to ignore all audio files and all mpegs,
128 you could say something like
130 (setq gnus-uu-ignore-files-by-type \"audio/\\\\|video/mpeg\")
132 Note that this variable can be used in conjunction with the
133 `gnus-uu-ignore-files-by-name' variable.")
135 ;; Pseudo-MIME support
137 (defconst gnus-uu-ext-to-mime-list
138 '(("\\.gif$" "image/gif")
139 ("\\.jpe?g$" "image/jpeg")
140 ("\\.tiff?$" "image/tiff")
141 ("\\.xwd$" "image/xwd")
142 ("\\.pbm$" "image/pbm")
143 ("\\.pgm$" "image/pgm")
144 ("\\.ppm$" "image/ppm")
145 ("\\.xbm$" "image/xbm")
146 ("\\.pcx$" "image/pcx")
147 ("\\.tga$" "image/tga")
148 ("\\.ps$" "image/postscript")
149 ("\\.fli$" "video/fli")
150 ("\\.wav$" "audio/wav")
151 ("\\.aiff$" "audio/aiff")
152 ("\\.hcom$" "audio/hcom")
153 ("\\.voc$" "audio/voc")
154 ("\\.smp$" "audio/smp")
155 ("\\.mod$" "audio/mod")
156 ("\\.dvi$" "image/dvi")
157 ("\\.mpe?g$" "video/mpeg")
158 ("\\.au$" "audio/basic")
159 ("\\.\\(te?xt\\|doc\\|c\\|h\\)$" "text/plain")
160 ("\\.\\(c\\|h\\)$" "text/source")
161 ("read.*me" "text/plain")
162 ("\\.html$" "text/html")
163 ("\\.bat$" "text/bat")
164 ("\\.[1-6]$" "text/man")
165 ("\\.flc$" "video/flc")
166 ("\\.rle$" "video/rle")
167 ("\\.pfx$" "video/pfx")
168 ("\\.avi$" "video/avi")
169 ("\\.sme$" "video/sme")
170 ("\\.rpza$" "video/prza")
171 ("\\.dl$" "video/dl")
172 ("\\.qt$" "video/qt")
173 ("\\.rsrc$" "video/rsrc")
174 ("\\..*$" "unknown/unknown")))
176 ;; Various variables users may set
178 (defvar gnus-uu-tmp-dir "/tmp/"
179 "Variable saying where gnus-uu is to do its work.
180 Default is \"/tmp/\".")
182 (defvar gnus-uu-do-not-unpack-archives nil
183 "Non-nil means that gnus-uu won't peek inside archives looking for files to dispay.
186 (defvar gnus-uu-view-and-save nil
187 "Non-nil means that the user will always be asked to save a file after viewing it.
188 If the variable is nil, the suer will only be asked to save if the
189 viewing is unsuccessful. Default is nil.")
191 (defvar gnus-uu-ignore-default-view-rules nil
192 "Non-nil means that gnus-uu will ignore the default viewing rules.
193 Only the user viewing rules will be consulted. Default is nil.")
195 (defvar gnus-uu-ignore-default-archive-rules nil
196 "Non-nil means that gnus-uu will ignore the default archive unpacking commands.
197 Only the user unpacking commands will be consulted. Default is nil.")
199 (defvar gnus-uu-kill-carriage-return t
200 "Non-nil means that gnus-uu will strip all carriage returns from articles.
203 (defvar gnus-uu-view-with-metamail nil
204 "Non-nil means that files will be viewed with metamail.
205 The gnus-uu viewing functions will be ignored and gnus-uu will try
206 to guess at a content-type based on file name suffixes. Default
209 (defvar gnus-uu-unmark-articles-not-decoded nil
210 "Non-nil means that gnus-uu will mark articles that were unsuccessfully decoded as unread.
213 (defvar gnus-uu-correct-stripped-uucode nil
214 "Non-nil means that gnus-uu will *try* to fix uuencoded files that have had traling spaces deleted.
217 (defvar gnus-uu-save-in-digest nil
218 "Non-nil means that gnus-uu, when asked to save without decoding, will save in digests.
219 If this variable is nil, gnus-uu will just save everything in a
220 file without any embellishments. The digesting almost conforms to RFC1153 -
221 no easy way to specify any meaningful volume and issue numbers were found,
222 so I simply dropped them.")
224 (defvar gnus-uu-save-separate-articles nil
225 "Non-nil means that gnus-uu will save articles in separate files.")
227 ;; Internal variables
229 (defvar gnus-uu-saved-article-name nil)
231 (defconst gnus-uu-begin-string "^begin[ \t]+[0-7][0-7][0-7][ \t]+\\(.*\\)$")
232 (defconst gnus-uu-end-string "^end[ \t]*$")
234 (defconst gnus-uu-body-line "^M")
236 (while (> (setq i (1- i)) 0)
237 (setq gnus-uu-body-line (concat gnus-uu-body-line "[^a-z]")))
238 (setq gnus-uu-body-line (concat gnus-uu-body-line ".?$")))
240 ;"^M.............................................................?$"
242 (defconst gnus-uu-shar-begin-string "^#! */bin/sh")
244 (defvar gnus-uu-shar-file-name nil)
245 (defconst gnus-uu-shar-name-marker "begin [0-7][0-7][0-7][ \t]+\\(\\(\\w\\|\\.\\)*\\b\\)")
247 (defvar gnus-uu-file-name nil)
248 (defvar gnus-uu-list-of-files-decoded nil)
249 (defconst gnus-uu-uudecode-process nil)
251 (defvar gnus-uu-generated-file-list nil)
252 (defvar gnus-uu-work-dir nil)
254 (defconst gnus-uu-output-buffer-name "*Gnus UU Output*")
256 (defconst gnus-uu-highest-article-number 1)
260 (defun gnus-uu-decode-uu (n)
261 "Uudecodes the current article."
263 (gnus-uu-decode-with-method 'gnus-uu-uustrip-article n))
265 (defun gnus-uu-decode-uu-and-save (n dir)
266 "Decodes and saves the resulting file."
267 (interactive "P\nDWhere do you want to save the file(s)? ")
268 (gnus-uu-decode-with-method 'gnus-uu-uustrip-article n dir))
270 (defun gnus-uu-decode-unshar (n)
271 "Unshars the current article."
273 (gnus-uu-decode-with-method 'gnus-uu-unshar-article n))
275 (defun gnus-uu-decode-unshar-and-save (n dir)
276 "Unshars and saves the current article."
277 (interactive "P\nDWhere do you want to save the file(s)? ")
278 (gnus-uu-decode-with-method 'gnus-uu-unshar-article n dir))
280 (defun gnus-uu-decode-save (n file)
281 "Saves the current article."
282 (interactive "P\nDWhere do you want to save the file(s)? ")
283 (setq gnus-uu-saved-article-name file)
284 (gnus-uu-decode-with-method 'gnus-uu-save-article n nil)
285 (setq gnus-uu-generated-file-list
286 (delete file gnus-uu-generated-file-list)))
288 (defun gnus-uu-decode-binhex (n dir)
289 "Unbinhexes the current article."
290 (interactive "P\nDWhere do you want to save the file(s)? ")
291 (gnus-uu-decode-with-method 'gnus-uu-binhex-article n dir))
293 ;; Digest and forward articles
295 (defun gnus-uu-digest-and-forward (n)
296 "Digests and forwards all articles in this series."
299 (let ((gnus-uu-save-in-digest t)
300 (file (concat gnus-uu-work-dir (make-temp-name "forward"))))
301 (gnus-uu-decode-save n file)
302 (switch-to-buffer (get-buffer-create "*gnus-uu-forward*"))
304 (delete-other-windows)
306 (goto-char (point-min))
307 (funcall gnus-mail-forward-method)))
311 (defun gnus-uu-mark-by-regexp (regexp)
312 "Ask for a regular expression and set the process mark on all articles that match."
313 (interactive (list (read-from-minibuffer "Mark (regexp): ")))
314 (let ((articles (gnus-uu-find-articles-matching regexp)))
316 (gnus-summary-set-process-mark (car articles))
317 (setq articles (cdr articles)))
319 (gnus-summary-position-cursor))
321 (defun gnus-uu-mark-region (beg end)
322 "Marks all articles between point and mark."
326 (while (< (point) end)
327 (gnus-summary-set-process-mark (gnus-summary-article-number))
329 (gnus-summary-position-cursor))
331 (defun gnus-uu-mark-thread ()
332 "Marks all articles downwards in this thread."
335 (let ((level (gnus-summary-thread-level)))
336 (while (and (gnus-summary-set-process-mark (gnus-summary-article-number))
337 (zerop (gnus-summary-next-subject 1))
338 (> (gnus-summary-thread-level) level)))))
339 (gnus-summary-position-cursor))
341 (defun gnus-uu-mark-sparse ()
342 "Mark all series that have some articles marked."
344 (let ((marked (nreverse gnus-newsgroup-processable))
345 subject articles total)
346 (or marked (error "No articles marked with the process mark"))
347 (setq gnus-newsgroup-processable nil)
350 (setq subject (header-subject
352 (int-to-string (car marked))
353 gnus-newsgroup-headers-hashtb-by-number)))
354 (setq articles (gnus-uu-find-articles-matching
355 (gnus-uu-reginize-string subject)))
356 (setq total (nconc total articles))
358 (gnus-summary-set-process-mark (car articles))
359 (setcdr marked (delq (car articles) (cdr marked)))
360 (setq articles (cdr articles)))
361 (setq marked (cdr marked)))
362 (setq gnus-newsgroup-processable (nreverse total)))
363 (gnus-summary-position-cursor)))
367 (defun gnus-uu-decode-with-method (method n &optional save)
369 (let ((articles (gnus-uu-get-list-of-articles n))
371 (setq files (gnus-uu-grab-articles articles method t))
372 (and save (gnus-uu-save-files files save))
373 (setq files (gnus-uu-unpack-files files))
374 (gnus-uu-add-file (mapcar (lambda (file) (cdr (assq 'name file))) files))
375 (setq files (gnus-uu-get-actions files))
376 (gnus-summary-insert-pseudos files)))
378 (defun gnus-uu-save-files (files dir)
379 (let ((len (length files))
382 (setq file (cdr (assq 'name (car files))))
383 (copy-file file (if (file-directory-p dir)
384 (concat dir (file-name-nondirectory file))
386 (setq files (cdr files)))
387 (message "Saved %d file%s" len (if (> len 1) "s" ""))))
389 ;; Functions for saving and possibly digesting articles without
392 ;; Function called by gnus-uu-grab-articles to treat each article.
393 (defun gnus-uu-save-article (buffer in-state)
395 (gnus-uu-save-separate-articles
398 (write-region 1 (point-max) (concat gnus-uu-saved-article-name
399 gnus-current-article))
400 (cond ((eq in-state 'first) (list gnus-uu-saved-article-name 'begin))
401 ((eq in-state 'first-and-last) (list gnus-uu-saved-article-name
403 ((eq in-state 'last) (list 'end))
404 (t (list 'middle)))))
405 ((not gnus-uu-save-in-digest)
408 (write-region 1 (point-max) gnus-uu-saved-article-name t)
409 (cond ((eq in-state 'first) (list gnus-uu-saved-article-name 'begin))
410 ((eq in-state 'first-and-last) (list gnus-uu-saved-article-name
412 ((eq in-state 'last) (list 'end))
413 (t (list 'middle)))))
415 (let (beg subj name headers headline sorthead body end-string state)
416 (string-match "/\\([^/]*\\)$" gnus-uu-saved-article-name)
417 (setq name (substring gnus-uu-saved-article-name (match-beginning 1)
419 (if (or (eq in-state 'first)
420 (eq in-state 'first-and-last))
422 (setq state (list 'begin))
423 (save-excursion (set-buffer (get-buffer-create "*gnus-uu-body*"))
426 (set-buffer (get-buffer-create "*gnus-uu-pre*"))
429 "Date: %s\nFrom: %s\nSubject: %s Digest\n\nTopics:\n"
430 (current-time-string) name name))))
431 (if (not (eq in-state 'end))
432 (setq state (list 'middle))))
434 (set-buffer (get-buffer "*gnus-uu-body*"))
435 (goto-char (setq beg (point-max)))
440 (re-search-forward "\n\n")
441 (setq body (buffer-substring (1- (point)) (point-max)))
442 (narrow-to-region 1 (point))
443 (setq headers (list "Date:" "From:" "To:" "Cc:" "Subject:"
444 "Message-ID:" "Keywords:" "Summary:"))
446 (setq headline (car headers))
447 (setq headers (cdr headers))
449 (if (re-search-forward (concat "^" headline ".*$") nil t)
451 (concat sorthead (buffer-substring
453 (match-end 0)) "\n"))))
455 (insert sorthead)(goto-char (point-max))
456 (insert body)(goto-char (point-max))
457 (insert (concat "\n" (make-string 30 ?-) "\n\n"))
459 (if (re-search-forward "^Subject: \\(.*\\)$" nil t)
461 (setq subj (buffer-substring (match-beginning 1) (match-end 1)))
463 (set-buffer (get-buffer "*gnus-uu-pre*"))
464 (insert (format " %s\n" subj))))))
465 (if (or (eq in-state 'last)
466 (eq in-state 'first-and-last))
469 (set-buffer (get-buffer "*gnus-uu-pre*"))
470 (insert (format "\n\n%s\n\n" (make-string 70 ?-)))
471 (write-region 1 (point-max) gnus-uu-saved-article-name))
473 (set-buffer (get-buffer "*gnus-uu-body*"))
474 (goto-char (point-max))
476 (concat (setq end-string (format "End of %s Digest" name))
478 (insert (concat (make-string (length end-string) ?*) "\n"))
479 (write-region 1 (point-max) gnus-uu-saved-article-name t))
480 (kill-buffer (get-buffer "*gnus-uu-pre*"))
481 (kill-buffer (get-buffer "*gnus-uu-body*"))
482 (setq state (cons 'end state))))
483 (if (memq 'begin state)
484 (cons gnus-uu-saved-article-name state)
487 ;; Binhex treatment - not very advanced.
489 (defconst gnus-uu-binhex-body-line
490 "^[^:]...............................................................$")
491 (defconst gnus-uu-binhex-begin-line
492 "^:...............................................................$")
493 (defconst gnus-uu-binhex-end-line
495 (defvar gnus-uu-binhex-article-name nil)
497 (defun gnus-uu-binhex-article (buffer in-state)
498 (let (state start-char)
503 (if (not (re-search-forward gnus-uu-binhex-begin-line nil t))
504 (if (not (re-search-forward gnus-uu-binhex-body-line nil t))
505 (setq state (list 'wrong-type))))
507 (if (memq 'wrong-type state)
510 (setq start-char (point))
511 (if (looking-at gnus-uu-binhex-begin-line)
513 (setq state (list 'begin))
514 (write-region 1 1 gnus-uu-binhex-article-name))
515 (setq state (list 'middle)))
516 (goto-char (point-max))
517 (re-search-backward (concat gnus-uu-binhex-body-line "\\|"
518 gnus-uu-binhex-end-line) nil t)
519 (if (looking-at gnus-uu-binhex-end-line)
520 (setq state (if (memq 'begin state)
525 (if (file-exists-p gnus-uu-binhex-article-name)
526 (append-to-file start-char (point) gnus-uu-binhex-article-name))))
527 (if (memq 'begin state)
528 (cons gnus-uu-binhex-article-name state)
534 (defun gnus-uu-get-actions (files)
538 (setq name (cdr (assq 'name (car files))))
540 (setq action (gnus-uu-get-action name))
541 (setcar files (cons (cons 'execute (if (string-match "%" action)
543 (concat action " " name)))
545 (setq files (cdr files)))
548 (defun gnus-uu-get-action (file-name)
551 (gnus-uu-choose-action
554 gnus-uu-user-view-rules
555 (if gnus-uu-ignore-default-view-rules
557 gnus-uu-default-view-rules)
558 gnus-uu-user-view-rules-end)))
559 (if (and (not (string= (or action "") "gnus-uu-archive"))
560 gnus-uu-view-with-metamail)
562 (gnus-uu-choose-action file-name gnus-uu-ext-to-mime-list))
563 (setq action (format "metamail -d -b -c \"%s\"" action))))
567 ;; Functions for treating subjects and collecting series.
569 (defun gnus-uu-reginize-string (string)
570 ;; Takes a string and puts a \ in front of every special character;
571 ;; ignores any leading "version numbers" thingies that they use in
572 ;; the comp.binaries groups, and either replaces anything that looks
573 ;; like "2/3" with "[0-9]+/[0-9]+" or, if it can't find something
574 ;; like that, replaces the last two numbers with "[0-9]+". This, in
575 ;; my experience, should get most postings of a series.
577 (vernum "v[0-9]+[a-z][0-9]+:")
580 (set-buffer (get-buffer-create gnus-uu-output-buffer-name))
581 (buffer-disable-undo (current-buffer))
583 (insert (regexp-quote string))
586 (setq case-fold-search nil)
588 (if (looking-at vernum)
590 (replace-match vernum t t)
591 (setq beg (length vernum))))
594 (if (re-search-forward "[ \t]*[0-9]+/[0-9]+" nil t)
595 (replace-match " [0-9]+/[0-9]+")
598 (if (re-search-forward "[0-9]+[ \t]*of[ \t]*[0-9]+" nil t)
599 (replace-match "[0-9]+ of [0-9]+")
602 (while (and (re-search-backward "[0-9]" nil t) (> count 0))
605 (< 1 (goto-char (1- (point))))))
606 (re-search-forward "[0-9]+" nil t)
607 (replace-match "[0-9]+")
609 (setq count (1- count)))))
612 (while (re-search-forward "[ \t]+" nil t)
613 (replace-match "[ \t]*" t t))
615 (buffer-substring 1 (point-max)))))
617 (defun gnus-uu-get-list-of-articles (n)
618 ;; If N is non-nil, the article numbers of the N next articles
620 ;; If any articles have been marked as processable, they will be
622 ;; Failing that, articles that have subjects that are part of the
623 ;; same "series" as the current will be returned.
624 (let (articles process)
627 (let ((backward (< n 0))
631 (setq articles (cons (gnus-summary-article-number)
633 (gnus-summary-search-forward nil nil backward))
635 (nreverse articles)))
636 (gnus-newsgroup-processable
637 (reverse gnus-newsgroup-processable))
639 (gnus-uu-find-articles-matching)))))
641 (defun gnus-uu-string< (l1 l2)
642 (string< (car l1) (car l2)))
644 (defun gnus-uu-find-articles-matching
645 (&optional subject only-unread do-not-translate)
646 ;; Finds all articles that matches the regexp SUBJECT. If it is
647 ;; nil, the current article name will be used. If ONLY-UNREAD is
648 ;; non-nil, only unread articles are chosen. If DO-NOT-TRANSLATE is
649 ;; non-nil, article names are not equalized before sorting.
650 (let ((subject (or subject
651 (gnus-uu-reginize-string (gnus-summary-subject-string))))
652 beg end list-of-subjects)
656 ;; Collect all subjects matching subject.
657 (let ((case-fold-search t)
659 (goto-char (point-min))
661 (and (setq subj (gnus-summary-subject-string))
662 (string-match subject subj)
663 (or (not only-unread)
664 (= (setq mark (gnus-summary-article-mark))
666 (= mark gnus-ticked-mark)
667 (= mark gnus-dormant-mark))
668 (setq list-of-subjects
669 (cons (cons subj (gnus-summary-article-number))
673 ;; Expand numbers, sort, and return the list of article
675 (mapcar (lambda (sub) (cdr sub))
676 (sort (gnus-uu-expand-numbers
678 (not do-not-translate))
679 'gnus-uu-string<))))))
681 (defun gnus-uu-expand-numbers (string-list &optional translate)
682 ;; Takes a list of strings and "expands" all numbers in all the
683 ;; strings. That is, this function makes all numbers equal length by
684 ;; prepending lots of zeroes before each number. This is to ease later
685 ;; sorting to find out what sequence the articles are supposed to be
686 ;; decoded in. Returns the list of expanded strings.
687 (let ((out-list string-list)
690 (set-buffer (get-buffer-create gnus-uu-output-buffer-name))
691 (buffer-disable-undo (current-buffer))
694 (insert (car (car string-list)))
695 ;; Translate multiple spaces to one space.
697 (while (re-search-forward "[ \t]+" nil t)
699 ;; Translate all characters to "a".
702 (while (re-search-forward "[A-Za-z]" nil t)
703 (replace-match "a" t t)))
706 (while (re-search-forward "[0-9]+" nil t)
709 (string-to-int (buffer-substring
710 (match-beginning 0) (match-end 0))))))
711 (setq string (buffer-substring 1 (point-max)))
712 (setcar (car string-list) string)
713 (setq string-list (cdr string-list))))
717 ;; `gnus-uu-grab-articles' is the general multi-article treatment
718 ;; function. It takes a list of articles to be grabbed and a function
719 ;; to apply to each article.
721 ;; The function to be called should take two parameters. The first
722 ;; parameter is the article buffer. The function should leave the
723 ;; result, if any, in this buffer. Most treatment functions will just
726 ;; The second parameter is the state of the list of articles, and can
727 ;; have four values: `first', `middle', `last' and `first-and-last'.
729 ;; The function should return a list. The list may contain the
730 ;; following symbols:
731 ;; `error' if an error occurred
732 ;; `begin' if the beginning of an encoded file has been received
733 ;; If the list returned contains a `begin', the first element of
734 ;; the list *must* be a string with the file name of the decoded
736 ;; `end' if the the end of an encoded file has been received
737 ;; `middle' if the article was a body part of an encoded file
738 ;; `wrong-type' if the article was not a part of an encoded file
739 ;; `ok', which can be used everything is ok
741 (defvar gnus-uu-has-been-grabbed nil)
743 (defun gnus-uu-unmark-list-of-grabbed (&optional dont-unmark-last-article)
745 (if (not (and gnus-uu-has-been-grabbed
746 gnus-uu-unmark-articles-not-decoded))
748 (if dont-unmark-last-article
750 (setq art (car gnus-uu-has-been-grabbed))
751 (setq gnus-uu-has-been-grabbed (cdr gnus-uu-has-been-grabbed))))
752 (while gnus-uu-has-been-grabbed
753 (gnus-summary-tick-article (car gnus-uu-has-been-grabbed) t)
754 (setq gnus-uu-has-been-grabbed (cdr gnus-uu-has-been-grabbed)))
755 (if dont-unmark-last-article
756 (setq gnus-uu-has-been-grabbed (list art))))))
758 ;; This function takes a list of articles and a function to apply to
759 ;; each article grabbed.
761 ;; This function returns a list of files decoded if the grabbing and
762 ;; the process-function has been successful and nil otherwise.
763 (defun gnus-uu-grab-articles
764 (articles process-function &optional sloppy limit no-errors)
767 has-been-begin has-been-end
768 article result-file result-files process-state article-buffer)
770 (if (not (gnus-server-opened gnus-current-select-method))
772 (gnus-start-news-server)
773 (gnus-request-group gnus-newsgroup-name)))
775 (setq gnus-uu-has-been-grabbed nil)
778 (not (memq 'error process-state))
780 (not (memq 'end process-state))))
782 (setq article (car articles))
783 (setq articles (cdr articles))
784 (setq gnus-uu-has-been-grabbed (cons article gnus-uu-has-been-grabbed))
786 (if (> article gnus-uu-highest-article-number)
787 (setq gnus-uu-highest-article-number article))
790 (if (eq state 'first)
791 (setq state 'first-and-last)
794 (message "Getting article %d" article)
796 (if (not (= (or gnus-current-article 0) article))
798 (gnus-request-article article gnus-newsgroup-name
800 (setq gnus-last-article gnus-current-article)
801 (setq gnus-current-article article)
802 (if (stringp nntp-server-buffer)
803 (setq article-buffer nntp-server-buffer)
804 (setq article-buffer (buffer-name nntp-server-buffer))))
805 (setq article-buffer gnus-article-buffer))
807 (buffer-disable-undo article-buffer)
808 (gnus-summary-mark-as-read article)
809 (and (memq article gnus-newsgroup-processable)
810 (gnus-summary-remove-process-mark article))
812 (setq process-state (funcall process-function article-buffer state))
814 (if (or (memq 'begin process-state)
815 (and (or (eq state 'first) (eq state 'first-and-last))
816 (memq 'ok process-state)))
819 (if (and result-file (file-exists-p result-file))
820 (delete-file result-file)))
821 (if (memq 'begin process-state)
822 (setq result-file (car process-state)))
823 (setq has-been-begin t)
824 (setq has-been-end nil)))
826 (if (memq 'end process-state)
828 (setq gnus-uu-has-been-grabbed nil)
829 (setq result-files (cons result-file result-files))
830 (setq has-been-end t)
831 (setq has-been-begin nil)
832 (and limit (= (length result-files) limit)
833 (setq articles nil))))
835 (if (and (or (eq state 'last) (eq state 'first-and-last))
836 (not (memq 'end process-state)))
837 (if (and result-file (file-exists-p result-file))
838 (delete-file result-file)))
840 ; (setq result-file nil)
842 (if (not (memq 'wrong-type process-state))
843 (setq wrong-type nil)
844 (if gnus-uu-unmark-articles-not-decoded
845 (gnus-summary-tick-article article t)))
847 (if sloppy (setq wrong-type nil))
849 (if (and (not has-been-begin)
851 (or (memq 'end process-state)
852 (memq 'middle process-state)))
854 (setq process-state (list 'error))
855 (message "No begin part at the beginning")
857 (setq state 'middle)))
859 ;; Make sure the last article is put in the article buffer & fix
862 (if (not (string= article-buffer gnus-article-buffer))
864 (set-buffer (get-buffer-create gnus-article-buffer))
865 (let ((buffer-read-only nil))
868 (insert-buffer-substring article-buffer)
870 (run-hooks 'gnus-mark-article-hook)
874 (if (not has-been-begin)
875 (if (not no-errors) (message "Wrong type file"))
876 (if (memq 'error process-state)
877 (setq result-files nil)
878 (if (not (or (memq 'ok process-state)
879 (memq 'end process-state)))
882 (message "End of articles reached before end of file"))
883 (setq result-files nil))
884 (gnus-uu-unmark-list-of-grabbed)))))
885 (setq gnus-uu-list-of-files-decoded result-files)
887 (mapcar (lambda (file) (list (cons 'name file))) result-files))))
889 (defun gnus-uu-uudecode-sentinel (process event)
890 (delete-process (get-process process)))
892 (defun gnus-uu-uustrip-article (process-buffer in-state)
893 ;; Uudecodes a file asynchronously.
894 (let ((state (list 'ok))
895 (process-connection-type nil)
896 start-char pst name-beg name-end)
898 (set-buffer process-buffer)
899 (let ((case-fold-search nil)
900 (buffer-read-only nil))
904 (if gnus-uu-kill-carriage-return
906 (while (search-forward "\r" nil t)
907 (delete-backward-char 1))
910 (if (not (re-search-forward gnus-uu-begin-string nil t))
911 (if (not (re-search-forward gnus-uu-body-line nil t))
912 (setq state (list 'wrong-type))))
914 (if (memq 'wrong-type state)
917 (setq start-char (point))
919 (if (looking-at gnus-uu-begin-string)
921 (setq name-end (match-end 1))
923 ; Replace any slashes and spaces in file names before decoding
924 (goto-char (setq name-beg (match-beginning 1)))
925 (while (re-search-forward "/" name-end t)
928 (while (re-search-forward " " name-end t)
931 (if (re-search-forward "_*$" name-end t)
934 (setq gnus-uu-file-name (buffer-substring name-beg name-end))
935 (and gnus-uu-uudecode-process
936 (setq pst (process-status
937 (or gnus-uu-uudecode-process "nevair")))
938 (if (or (eq pst 'stop) (eq pst 'run))
940 (delete-process gnus-uu-uudecode-process)
941 (gnus-uu-unmark-list-of-grabbed t))))
942 (if (get-process "*uudecode*")
943 (delete-process "*uudecode*"))
944 (setq gnus-uu-uudecode-process
947 (get-buffer-create gnus-uu-output-buffer-name)
949 (format "cd %s ; uudecode" gnus-uu-work-dir)))
950 (set-process-sentinel
951 gnus-uu-uudecode-process 'gnus-uu-uudecode-sentinel)
952 (setq state (list 'begin))
953 (gnus-uu-add-file (concat gnus-uu-work-dir gnus-uu-file-name)))
954 (setq state (list 'middle)))
956 (goto-char (point-max))
959 (concat gnus-uu-body-line "\\|" gnus-uu-end-string) nil t)
962 (if (looking-at gnus-uu-end-string)
963 (setq state (cons 'end state)))
966 (and gnus-uu-uudecode-process
967 (setq pst (process-status
968 (or gnus-uu-uudecode-process "nevair")))
969 (if (or (eq pst 'run) (eq pst 'stop))
971 (if gnus-uu-correct-stripped-uucode
973 (gnus-uu-check-correct-stripped-uucode
975 (goto-char (point-max))
977 (concat gnus-uu-body-line "\\|"
983 (process-send-region gnus-uu-uudecode-process
987 (delete-process gnus-uu-uudecode-process)
988 (message "gnus-uu: Couldn't uudecode")
990 (setq state (list 'wrong-type)))))
992 (if (memq 'end state)
993 (accept-process-output gnus-uu-uudecode-process)))
994 (setq state (list 'wrong-type))))
995 (if (not gnus-uu-uudecode-process)
996 (setq state (list 'wrong-type)))))
998 (if (memq 'begin state)
999 (cons (concat gnus-uu-work-dir gnus-uu-file-name) state)
1002 ;; This function is used by `gnus-uu-grab-articles' to treat
1003 ;; a shared article.
1004 (defun gnus-uu-unshar-article (process-buffer in-state)
1005 (let ((state (list 'ok))
1008 (set-buffer process-buffer)
1010 (if (not (re-search-forward gnus-uu-shar-begin-string nil t))
1011 (setq state (list 'wrong-type))
1013 (setq start-char (point))
1014 (call-process-region
1015 start-char (point-max) "sh" nil
1016 (get-buffer-create gnus-uu-output-buffer-name) nil
1017 "-c" (concat "cd " gnus-uu-work-dir " ; sh"))))
1020 ;; Returns the name of what the shar file is going to unpack.
1021 (defun gnus-uu-find-name-in-shar ()
1022 (let ((oldpoint (point))
1025 (if (re-search-forward gnus-uu-shar-name-marker nil t)
1026 (setq res (buffer-substring (match-beginning 1) (match-end 1))))
1027 (goto-char oldpoint)
1030 ;; `gnus-uu-choose-action' chooses what action to perform given the name
1031 ;; and `gnus-uu-file-action-list'. Returns either nil if no action is
1032 ;; found, or the name of the command to run if such a rule is found.
1033 (defun gnus-uu-choose-action (file-name file-action-list &optional no-ignore)
1034 (let ((action-list (copy-sequence file-action-list))
1039 (and gnus-uu-ignore-files-by-name
1040 (string-match gnus-uu-ignore-files-by-name file-name)))
1042 (and gnus-uu-ignore-files-by-type
1043 (string-match gnus-uu-ignore-files-by-type
1044 (or (gnus-uu-choose-action
1045 file-name gnus-uu-ext-to-mime-list t)
1047 (while (not (or (eq action-list ()) action))
1048 (setq rule (car action-list))
1049 (setq action-list (cdr action-list))
1050 (if (string-match (car rule) file-name)
1051 (setq action (car (cdr rule))))))
1054 (defun gnus-uu-treat-archive (file-path)
1055 ;; Unpacks an archive. Returns t if unpacking is successful.
1056 (let ((did-unpack t)
1057 action command files file file-name dir)
1058 (setq action (gnus-uu-choose-action
1059 file-path (append gnus-uu-user-archive-rules
1060 (if gnus-uu-ignore-default-archive-rules
1062 gnus-uu-default-archive-rules))))
1064 (if (not action) (error "No unpackers for the file %s" file-path))
1066 (string-match "/[^/]*$" file-path)
1067 (setq file-name (substring file-path (1+ (match-beginning 0))))
1068 (setq dir (substring file-path 0 (match-beginning 0)))
1070 (if (member action gnus-uu-destructive-archivers)
1071 (copy-file file-path (concat file-path "~") t))
1073 (setq command (format "cd %s ; %s" dir (gnus-uu-command action file-path)))
1076 (set-buffer (get-buffer-create gnus-uu-output-buffer-name))
1079 (message "Unpacking: %s..." (gnus-uu-command action file-path))
1081 (if (= 0 (call-process "sh" nil
1082 (get-buffer-create gnus-uu-output-buffer-name)
1085 (message "Error during unpacking of archive")
1086 (setq did-unpack nil))
1088 (if (member action gnus-uu-destructive-archivers)
1089 (rename-file (concat file-path "~") file-path t))
1093 (defun gnus-uu-dir-files (dir)
1094 (let ((dirs (directory-files dir t "[^/][^\\.][^\\.]?$"))
1097 (if (file-directory-p (setq file (car dirs)))
1098 (setq files (append files (gnus-uu-dir-files file)))
1099 (setq files (cons file files)))
1100 (setq dirs (cdr dirs)))
1103 (defun gnus-uu-unpack-files (files &optional ignore)
1104 ;; Go through FILES and look for files to unpack.
1105 (let* ((totfiles (gnus-uu-ls-r gnus-uu-work-dir))
1109 (setq file (cdr (assq 'name (car files))))
1110 (if (and (not (member file ignore))
1111 (equal (gnus-uu-get-action (file-name-nondirectory file))
1114 (setq did-unpack (cons file did-unpack))
1115 (or (gnus-uu-treat-archive file)
1116 (message "Error during unpacking of %s" file))
1117 (let* ((newfiles (gnus-uu-ls-r gnus-uu-work-dir))
1120 (or (member (car nfiles) totfiles)
1121 (setq ofiles (cons (list (cons 'name (car nfiles))
1122 (cons 'original file))
1124 (setq nfiles (cdr nfiles)))
1125 (setq totfiles newfiles))))
1126 (setq files (cdr files)))
1128 (gnus-uu-unpack-files ofiles (append did-unpack ignore))
1131 (defun gnus-uu-ls-r (dir)
1132 (let* ((files (gnus-uu-directory-files dir t))
1135 (if (file-directory-p (car files))
1137 (setq ofiles (delete (car files) ofiles))
1138 (setq ofiles (append ofiles (gnus-uu-ls-r (car files))))))
1139 (setq files (cdr files)))
1144 (defun gnus-uu-directory-files (dir &optional full)
1145 (let (files out file)
1146 (setq files (directory-files dir full))
1148 (setq file (car files))
1149 (setq files (cdr files))
1150 (or (string-match "/\\.\\.?$" file)
1151 (setq out (cons file out))))
1152 (setq out (nreverse out))
1155 (defun gnus-uu-check-correct-stripped-uucode (start end)
1156 (let (found beg length short)
1157 (if (not gnus-uu-correct-stripped-uucode)
1161 (if (re-search-forward " \\|`" end t)
1166 (if (looking-at "\n") (replace-match ""))
1170 (if (looking-at (concat gnus-uu-begin-string "\\|"
1171 gnus-uu-end-string))
1178 (setq length (- (point) beg))))
1183 (if (not (= length (- (point) beg)))
1184 (insert (make-string (- length (- (point) beg)) ? ))))
1185 (forward-line 1))))))
1187 (defun gnus-uu-initialize ()
1188 (setq gnus-uu-highest-article-number 1)
1189 (gnus-uu-check-for-generated-files)
1190 (setq gnus-uu-tmp-dir (expand-file-name gnus-uu-tmp-dir))
1191 (if (string-match "[^/]$" gnus-uu-tmp-dir)
1192 (setq gnus-uu-tmp-dir (concat gnus-uu-tmp-dir "/")))
1193 (if (not (file-directory-p gnus-uu-tmp-dir))
1194 (error "Temp directory %s doesn't exist" gnus-uu-tmp-dir)
1195 (if (not (file-writable-p gnus-uu-tmp-dir))
1196 (error "Temp directory %s can't be written to" gnus-uu-tmp-dir)))
1197 (setq gnus-uu-work-dir
1198 (concat gnus-uu-tmp-dir (make-temp-name "gnus")))
1199 (gnus-uu-add-file gnus-uu-work-dir)
1200 (if (not (file-directory-p gnus-uu-work-dir))
1201 (make-directory gnus-uu-work-dir))
1202 (setq gnus-uu-work-dir (concat gnus-uu-work-dir "/")))
1204 ;; Kills the temporary uu buffers, kills any processes, etc.
1205 (defun gnus-uu-clean-up ()
1207 (and gnus-uu-uudecode-process
1208 (setq pst (process-status (or gnus-uu-uudecode-process "nevair")))
1209 (if (or (eq pst 'stop) (eq pst 'run))
1210 (delete-process gnus-uu-uudecode-process)))
1211 (and (setq buf (get-buffer gnus-uu-output-buffer-name))
1212 (kill-buffer buf))))
1214 ;; `gnus-uu-check-for-generated-files' deletes any generated files that
1215 ;; hasn't been deleted, if, for instance, the user terminated decoding
1217 (defun gnus-uu-check-for-generated-files ()
1219 (while gnus-uu-generated-file-list
1220 (setq file (car gnus-uu-generated-file-list))
1221 (setq gnus-uu-generated-file-list (cdr gnus-uu-generated-file-list))
1222 (if (not (string-match "/\\.[\\.]?$" file))
1224 (if (file-directory-p file)
1225 (setq dirs (cons file dirs))
1226 (if (file-exists-p file)
1227 (delete-file file))))))
1228 (setq dirs (nreverse dirs))
1230 (setq file (car dirs))
1231 (setq dirs (cdr dirs))
1232 (if (file-directory-p file)
1233 (if (string-match "/$" file)
1234 (delete-directory (substring file 0 (match-beginning 0)))
1235 (delete-directory file))))))
1237 ;; Add a file (or a list of files) to be checked (and deleted if it/they
1238 ;; still exists upon exiting the newsgroup).
1239 (defun gnus-uu-add-file (file)
1241 (setq gnus-uu-generated-file-list
1242 (cons file gnus-uu-generated-file-list))
1243 (setq gnus-uu-generated-file-list
1244 (append file gnus-uu-generated-file-list))))
1246 ;; Inputs an action and a file and returns a full command, putting
1247 ;; ticks round the file name and escaping any ticks in the file name.
1248 (defun gnus-uu-command (action file)
1250 (while (string-match "`\\|\"\\|\\$\\|\\\\" file)
1253 (concat ofile (substring file 0 (match-beginning 0)) "\\"
1254 (substring file (match-beginning 0) (match-end 0))))
1255 (setq file (substring file (1+ (match-beginning 0))))))
1256 (setq ofile (concat "\"" ofile file "\""))
1257 (if (string-match "%s" action)
1258 (format action ofile)
1259 (concat action " " ofile))))
1264 (add-hook 'gnus-exit-group-hook 'gnus-uu-clean-up)
1265 (add-hook 'gnus-exit-group-hook 'gnus-uu-check-for-generated-files)
1268 ;; Major mode for posting encoded articles.
1273 ;; Any function that is to be used as and encoding method will take two
1274 ;; parameters: PATH-NAME and FILE-NAME. (E.g. "/home/gaga/spiral.jpg"
1275 ;; and "spiral.jpg", respectively.) The function should return nil if
1276 ;; the encoding wasn't successful.
1277 (defvar gnus-uu-post-encode-method 'gnus-uu-post-encode-uuencode
1278 "Function used for encoding binary files.
1279 There are three functions supplied with gnus-uu for encoding files:
1280 `gnus-uu-post-encode-uuencode', which does straight uuencoding;
1281 `gnus-uu-post-encode-mime', which encodes with base64 and adds MIME
1282 headers; and `gnus-uu-post-encode-mime-uuencode', which encodes with
1283 uuencode and adds MIME headers.")
1285 (defvar gnus-uu-post-include-before-composing nil
1286 "Non-nil means that gnus-uu will ask for a file to encode before you compose the article.
1287 If this variable is t, you can either include an encoded file with
1288 \\<gnus-uu-post-reply-mode-map>\\[gnus-uu-post-insert-binary-in-article] or have one included for you when you post the article.")
1290 (defvar gnus-uu-post-length 990
1291 "Maximum length of an article.
1292 The encoded file will be split into how many articles it takes to
1293 post the entire file.")
1295 (defvar gnus-uu-post-threaded nil
1296 "Non-nil means that gnus-uu will post the encoded file in a thread.
1297 This may not be smart, as no other decoder I have seen are able to
1298 follow threads when collecting uuencoded articles. (Well, I have seen
1299 one package that does that - gnus-uu, but somehow, I don't think that
1300 counts...) Default is nil.")
1302 (defvar gnus-uu-post-separate-description t
1303 "Non-nil means that the description will be posted in a separate article.
1304 The first article will typically be numbered (0/x). If this variable
1305 is nil, the description the user enters will be included at the
1306 beginning of the first article, which will be numbered (1/x). Default
1309 (defconst gnus-uu-post-binary-separator "--binary follows this line--")
1310 (defvar gnus-uu-post-message-id nil)
1311 (defvar gnus-uu-post-inserted-file-name nil)
1312 (defvar gnus-uu-winconf-post-news nil)
1314 ;; The following map and mode was taken from rnewspost.el and edited
1316 (defvar gnus-uu-post-reply-mode-map nil)
1317 (if gnus-uu-post-reply-mode-map
1319 (setq gnus-uu-post-reply-mode-map (make-keymap))
1320 (define-key gnus-uu-post-reply-mode-map "\C-c?" 'describe-mode)
1321 (define-key gnus-uu-post-reply-mode-map "\C-c\C-f\C-d"
1322 'news-reply-distribution)
1323 (define-key gnus-uu-post-reply-mode-map "\C-c\C-f\C-k"
1324 'news-reply-keywords)
1325 (define-key gnus-uu-post-reply-mode-map "\C-c\C-f\C-n"
1326 'news-reply-newsgroups)
1328 (define-key gnus-uu-post-reply-mode-map "\C-c\C-f\C-f"
1329 'news-reply-followup-to)
1330 (define-key gnus-uu-post-reply-mode-map "\C-c\C-f\C-s" 'mail-subject)
1331 (define-key gnus-uu-post-reply-mode-map "\C-c\C-f\C-a"
1332 'gnus-uu-post-reply-summary)
1333 (define-key gnus-uu-post-reply-mode-map "\C-c\C-r"
1334 'news-caesar-buffer-body)
1335 (define-key gnus-uu-post-reply-mode-map "\C-c\C-w" 'news-reply-signature)
1336 (define-key gnus-uu-post-reply-mode-map "\C-c\C-y"
1337 'news-reply-yank-original)
1338 (define-key gnus-uu-post-reply-mode-map "\C-c\C-q"
1339 'mail-fill-yanked-message)
1340 (define-key gnus-uu-post-reply-mode-map "\C-c\C-c"
1341 'gnus-uu-post-news-inews)
1342 (define-key gnus-uu-post-reply-mode-map "\C-c\C-s"
1343 'gnus-uu-post-news-inews)
1344 (define-key gnus-uu-post-reply-mode-map "\C-c\C-i"
1345 'gnus-uu-post-insert-binary-in-article)
1348 ;; This mode was taken from rnewspost.el and modified slightly.
1349 (defun gnus-uu-post-reply-mode ()
1350 "Major mode for editing binary news to be posted on USENET.
1351 First-time posters are asked to please read the articles in newsgroup:
1352 news.announce.newusers .
1354 Like news-reply-mode, which is like Text Mode, but with these
1355 additional commands:
1357 \\<gnus-uu-post-reply-mode-map>\\[gnus-uu-post-news-inews] post the message.
1358 C-c C-f move to a header field (and create it if there isn't):
1359 C-c C-f C-n move to Newsgroups: C-c C-f C-s move to Subj:
1360 C-c C-f C-f move to Followup-To: C-c C-f C-k move to Keywords:
1361 C-c C-f C-d move to Distribution: C-c C-f C-a move to Summary:
1362 C-c C-y news-reply-yank-original (insert current message, in NEWS).
1363 C-c C-q mail-fill-yanked-message (fill what was yanked).
1364 C-c C-r caesar rotate all letters by 13 places in the article's body (rot13).
1365 \\[gnus-uu-post-insert-binary-in-article] encode and include a file in this article.
1367 This mode is almost identical to news-reply-mode, but has some
1368 additional commands for treating encoded binary articles. In
1369 particular, \\[gnus-uu-post-news-inews] will ask for a file to include, if
1370 one hasn't been included already. It will post, first, the message
1371 composed, and then it will post as many additional articles it takes
1372 to post the entire encoded files.
1376 `gnus-uu-post-encode-method'
1377 There are three functions supplied with gnus-uu for encoding files:
1378 `gnus-uu-post-encode-uuencode', which does straight uuencoding;
1379 `gnus-uu-post-encode-mime', which encodes with base64 and adds MIME
1380 headers; and `gnus-uu-post-encode-mime-uuencode', which encodes with
1381 uuencode and adds MIME headers.
1383 `gnus-uu-post-include-before-composing'
1384 Non-nil means that gnus-uu will ask for a file to encode before you
1385 compose the article. If this variable is t, you can either include
1386 an encoded file with `C-c C-i' or have one included for you when you
1389 `gnus-uu-post-length'
1390 Maximum length of an article. The encoded file will be split into how
1391 many articles it takes to post the entire file.
1393 `gnus-uu-post-separate-description'
1394 Non-nil means that the description will be posted in a separate
1395 article. The first article will typically be numbered (0/x). If
1396 this variable is nil, the description the user enters will be
1397 included at the beginning of the first article, which will be
1398 numbered (1/x). Default is t.
1400 `gnus-uu-post-threaded'
1401 Non-nil means that gnus-uu will post the encoded file in a thread.
1402 This may not be smart, as no other decoder I have seen are able to
1403 follow threads when collecting uuencoded articles. (Well, I have seen
1404 one package that does that - gnus-uu, but somehow, I don't think that
1405 counts...) Default is nil.
1409 (or (fboundp 'mail-setup) (load "sendmail"))
1410 (kill-all-local-variables)
1411 (make-local-variable 'mail-reply-buffer)
1412 (setq mail-reply-buffer nil)
1413 (set-syntax-table text-mode-syntax-table)
1414 (use-local-map gnus-uu-post-reply-mode-map)
1415 (setq local-abbrev-table text-mode-abbrev-table)
1416 (setq major-mode 'gnus-uu-post-reply-mode)
1417 (setq mode-name "Gnus UU News")
1418 (make-local-variable 'paragraph-separate)
1419 (make-local-variable 'paragraph-start)
1420 (setq paragraph-start (concat "^" mail-header-separator "$\\|"
1422 (setq paragraph-separate (concat "^" mail-header-separator "$\\|"
1423 paragraph-separate))
1424 (run-hooks 'text-mode-hook 'gnus-uu-post-reply-mode-hook))
1426 (defun gnus-uu-post-news ()
1427 "Compose an article and post an encoded file."
1429 (setq gnus-uu-post-inserted-file-name nil)
1430 (setq gnus-uu-winconf-post-news (current-window-configuration))
1431 (let (news-reply-mode)
1432 (fset 'news-reply-mode 'gnus-uu-post-reply-mode)
1433 (gnus-summary-post-news)
1434 (if gnus-uu-post-include-before-composing
1435 (save-excursion (setq gnus-uu-post-inserted-file-name
1436 (gnus-uu-post-insert-binary))))))
1438 (defun gnus-uu-post-insert-binary-in-article ()
1439 "Inserts an encoded file in the buffer.
1440 The user will be asked for a file name."
1442 (if (not (eq (current-buffer) (get-buffer gnus-post-news-buffer)))
1443 (error "Not in post-news buffer"))
1445 (setq gnus-uu-post-inserted-file-name (gnus-uu-post-insert-binary))))
1447 ;; Encodes with uuencode and substitutes all spaces with backticks.
1448 (defun gnus-uu-post-encode-uuencode (path file-name)
1449 (if (gnus-uu-post-encode-file "uuencode" path file-name)
1453 (while (re-search-forward " " nil t)
1454 (replace-match "`"))
1457 ;; Encodes with uuencode and adds MIME headers.
1458 (defun gnus-uu-post-encode-mime-uuencode (path file-name)
1459 (if (gnus-uu-post-encode-uuencode path file-name)
1461 (gnus-uu-post-make-mime file-name "x-uue")
1464 ;; Encodes with base64 and adds MIME headers
1465 (defun gnus-uu-post-encode-mime (path file-name)
1466 (if (gnus-uu-post-encode-file "mmencode" path file-name)
1468 (gnus-uu-post-make-mime file-name "base64")
1471 ;; Adds MIME headers.
1472 (defun gnus-uu-post-make-mime (file-name encoding)
1474 (insert (format "Content-Type: %s; name=\"%s\"\n"
1475 (gnus-uu-choose-action file-name gnus-uu-ext-to-mime-list)
1477 (insert (format "Content-Transfer-Encoding: %s\n\n" encoding))
1479 (set-buffer gnus-post-news-buffer)
1481 (re-search-forward mail-header-separator)
1484 (narrow-to-region 1 (point))
1485 (or (mail-fetch-field "mime-version")
1488 (insert "MIME-Version: 1.0\n")))
1491 ;; Encodes a file PATH with COMMAND, leaving the result in the
1493 (defun gnus-uu-post-encode-file (command path file-name)
1494 (= 0 (call-process "sh" nil t nil "-c"
1495 (format "%s %s %s" command path file-name))))
1497 (defun gnus-uu-post-news-inews ()
1498 "Posts the composed news article and encoded file.
1499 If no file has been included, the user will be asked for a file."
1501 (if (not (eq (current-buffer) (get-buffer gnus-post-news-buffer)))
1502 (error "Not in post news buffer"))
1506 (if gnus-uu-post-inserted-file-name
1507 (setq file-name gnus-uu-post-inserted-file-name)
1508 (setq file-name (gnus-uu-post-insert-binary)))
1510 (if gnus-uu-post-threaded
1511 (let ((gnus-required-headers
1512 (if (memq 'Message-ID gnus-required-headers)
1513 gnus-required-headers
1514 (cons 'Message-ID gnus-required-headers)))
1515 gnus-inews-article-hook elem)
1517 (setq gnus-inews-article-hook (if (listp gnus-inews-article-hook)
1518 gnus-inews-article-hook
1519 (list gnus-inews-article-hook)))
1520 (setq gnus-inews-article-hook
1525 (if (re-search-forward "^Message-ID: \\(.*\\)$" nil t)
1526 (setq gnus-uu-post-message-id
1528 (match-beginning 1) (match-end 1)))
1529 (setq gnus-uu-post-message-id nil))))
1530 gnus-inews-article-hook))
1531 (gnus-uu-post-encoded file-name t))
1532 (gnus-uu-post-encoded file-name nil)))
1533 (setq gnus-uu-post-inserted-file-name nil)
1534 (and gnus-uu-winconf-post-news
1535 (set-window-configuration gnus-uu-winconf-post-news)))
1537 ;; Asks for a file to encode, encodes it and inserts the result in
1538 ;; the current buffer. Returns the file name the user gave.
1539 (defun gnus-uu-post-insert-binary ()
1540 (let ((uuencode-buffer-name "*uuencode buffer*")
1541 file-path post-buf uubuf file-name)
1543 (setq file-path (read-file-name
1544 "What file do you want to encode? "))
1545 (if (not (file-exists-p file-path))
1546 (error "%s: No such file" file-path))
1548 (goto-char (point-max))
1549 (insert (format "\n%s\n" gnus-uu-post-binary-separator))
1551 (if (string-match "^~/" file-path)
1552 (setq file-path (concat "$HOME" (substring file-path 1))))
1553 (if (string-match "/[^/]*$" file-path)
1554 (setq file-name (substring file-path (1+ (match-beginning 0))))
1555 (setq file-name file-path))
1559 (set-buffer (setq uubuf
1560 (get-buffer-create uuencode-buffer-name)))
1562 (funcall gnus-uu-post-encode-method file-path file-name))
1563 (insert-buffer uubuf)
1564 (error "Encoding unsuccessful"))
1565 (kill-buffer uubuf))
1568 ;; Posts the article and all of the encoded file.
1569 (defun gnus-uu-post-encoded (file-name &optional threaded)
1570 (let ((send-buffer-name "*uuencode send buffer*")
1571 (encoded-buffer-name "*encoded buffer*")
1572 (top-string "[ cut here %s (%s %d/%d) %s gnus-uu ]")
1573 (separator (concat mail-header-separator "\n\n"))
1574 file uubuf length parts header i end beg
1575 beg-line minlen buf post-buf whole-len beg-binary end-binary)
1577 (setq post-buf (current-buffer))
1580 (if (not (re-search-forward
1581 (if gnus-uu-post-separate-description
1582 gnus-uu-post-binary-separator
1583 mail-header-separator) nil t))
1584 (error "Internal error: No binary/header separator"))
1587 (setq beg-binary (point))
1588 (setq end-binary (point-max))
1591 (set-buffer (setq uubuf (get-buffer-create encoded-buffer-name)))
1593 (insert-buffer-substring post-buf beg-binary end-binary)
1595 (setq length (count-lines 1 (point-max)))
1596 (setq parts (/ length gnus-uu-post-length))
1597 (if (not (< (% length gnus-uu-post-length) 4))
1598 (setq parts (1+ parts))))
1600 (if gnus-uu-post-separate-description
1602 (kill-region (point) (point-max))
1605 (search-forward mail-header-separator nil t)
1607 (setq header (buffer-substring 1 (point)))
1610 (if (not gnus-uu-post-separate-description)
1612 (if (and (not threaded) (re-search-forward "^Subject: " nil t))
1615 (insert (format " (0/%d)" parts))))
1621 (while (not (> i parts))
1622 (set-buffer (get-buffer-create send-buffer-name))
1625 (if (and threaded gnus-uu-post-message-id)
1626 (insert (format "References: %s\n" gnus-uu-post-message-id)))
1629 (- 62 (length (format top-string "" file-name i parts ""))))
1630 (if (> 1 (setq minlen (/ whole-len 2)))
1635 (make-string minlen ?-)
1638 (if (= 0 (% whole-len 2)) (1- minlen) minlen) ?-)))
1641 (if (not (re-search-forward "^Subject: " nil t))
1646 (insert (format " (%d/%d)" i parts)))
1647 (if (or (and (= i 2) gnus-uu-post-separate-description)
1648 (and (= i 1) (not gnus-uu-post-separate-description)))
1649 (replace-match "Subject: Re: "))))
1651 (goto-char (point-max))
1656 (goto-char (point-max))
1657 (forward-line gnus-uu-post-length))
1658 (if (and (= (1+ i) parts) (< (count-lines (point) (point-max)) 4))
1661 (insert-buffer-substring uubuf beg end)
1667 (re-search-forward mail-header-separator nil t)
1670 (if (re-search-forward gnus-uu-post-binary-separator nil t)
1678 (and (setq buf (get-buffer send-buffer-name))
1680 (and (setq buf (get-buffer encoded-buffer-name))
1683 (if (not gnus-uu-post-separate-description)
1685 (set-buffer-modified-p nil)
1686 (and (fboundp 'bury-buffer) (bury-buffer))))))
1690 ;; gnus-uu.el ends here