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 Magne 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\\)$"
50 "*Default actions to be taken when the user asks to view a file.
51 To change the behaviour, you can either edit this variable or set
52 `gnus-uu-user-view-rules' to something useful.
56 To make gnus-uu use 'xli' to display JPEG and GIF files, put the
57 following in your .emacs file
59 (setq gnus-uu-user-view-rules '((\"jpg$\\\\|gif$\" \"xli\")))
61 Both these variables are lists of lists with two string elements. The
62 first string is a regular expression. If the file name matches this
63 regular expression, the command in the second string is executed with
64 the file as an argument.
66 If the command string contains \"%s\", the file name will be inserted
67 at that point in the command string. If there's no \"%s\" in the
68 command string, the file name will be appended to the command string
71 There are several user variables to tailor the behaviour of gnus-uu to
72 your needs. First we have `gnus-uu-user-view-rules', which is the
73 variable gnus-uu first consults when trying to decide how to view a
74 file. If this variable contains no matches, gnus-uu examines the
75 default rule vaiable provided in this package. If gnus-uu finds no
76 match here, it uses `gnus-uu-user-view-rules-end' to try to make a
79 (defvar gnus-uu-user-view-rules nil
80 "*Variable detailing what actions are to be taken to view a file.
81 See the documentation on the `gnus-uu-default-view-rules' variable for
84 (defvar gnus-uu-user-view-rules-end
86 "*Variable saying what actions are to be taken if no rule matched the file name.
87 See the documentation on the `gnus-uu-default-view-rules' variable for
90 ;; Default unpacking commands
92 (defvar gnus-uu-default-archive-rules
93 '(("\\.tar$" "tar xf")
94 ("\\.zip$" "unzip -o")
98 ("\\.\\(lzh\\|lha\\)$" "lha x")
99 ("\\.Z$" "uncompress")
101 ("\\.arc$" "arc -x")))
103 (defvar gnus-uu-destructive-archivers
104 (list "uncompress" "gunzip"))
106 (defvar gnus-uu-user-archive-rules nil
107 "*A list that can be set to override the default archive unpacking commands.
108 To use, for instance, 'untar' to unpack tar files and 'zip -x' to
109 unpack zip files, say the following:
110 (setq gnus-uu-user-archive-rules
111 '((\"\\\\.tar$\" \"untar\")
112 (\"\\\\.zip$\" \"zip -x\")))")
114 (defvar gnus-uu-ignore-files-by-name nil
115 "*A regular expression saying what files should not be viewed based on name.
116 If, for instance, you want gnus-uu to ignore all .au and .wav files,
117 you could say something like
119 (setq gnus-uu-ignore-files-by-name \"\\\\.au$\\\\|\\\\.wav$\")
121 Note that this variable can be used in conjunction with the
122 `gnus-uu-ignore-files-by-type' variable.")
124 (defvar gnus-uu-ignore-files-by-type nil
125 "*A regular expression saying what files that shouldn't be viewed, based on MIME file type.
126 If, for instance, you want gnus-uu to ignore all audio files and all mpegs,
127 you could say something like
129 (setq gnus-uu-ignore-files-by-type \"audio/\\\\|video/mpeg\")
131 Note that this variable can be used in conjunction with the
132 `gnus-uu-ignore-files-by-name' variable.")
134 ;; Pseudo-MIME support
136 (defconst gnus-uu-ext-to-mime-list
137 '(("\\.gif$" "image/gif")
138 ("\\.jpe?g$" "image/jpeg")
139 ("\\.tiff?$" "image/tiff")
140 ("\\.xwd$" "image/xwd")
141 ("\\.pbm$" "image/pbm")
142 ("\\.pgm$" "image/pgm")
143 ("\\.ppm$" "image/ppm")
144 ("\\.xbm$" "image/xbm")
145 ("\\.pcx$" "image/pcx")
146 ("\\.tga$" "image/tga")
147 ("\\.ps$" "image/postscript")
148 ("\\.fli$" "video/fli")
149 ("\\.wav$" "audio/wav")
150 ("\\.aiff$" "audio/aiff")
151 ("\\.hcom$" "audio/hcom")
152 ("\\.voc$" "audio/voc")
153 ("\\.smp$" "audio/smp")
154 ("\\.mod$" "audio/mod")
155 ("\\.dvi$" "image/dvi")
156 ("\\.mpe?g$" "video/mpeg")
157 ("\\.au$" "audio/basic")
158 ("\\.\\(te?xt\\|doc\\|c\\|h\\)$" "text/plain")
159 ("\\.\\(c\\|h\\)$" "text/source")
160 ("read.*me" "text/plain")
161 ("\\.html$" "text/html")
162 ("\\.bat$" "text/bat")
163 ("\\.[1-6]$" "text/man")
164 ("\\.flc$" "video/flc")
165 ("\\.rle$" "video/rle")
166 ("\\.pfx$" "video/pfx")
167 ("\\.avi$" "video/avi")
168 ("\\.sme$" "video/sme")
169 ("\\.rpza$" "video/prza")
170 ("\\.dl$" "video/dl")
171 ("\\.qt$" "video/qt")
172 ("\\.rsrc$" "video/rsrc")
173 ("\\..*$" "unknown/unknown")))
175 ;; Various variables users may set
177 (defvar gnus-uu-tmp-dir "/tmp/"
178 "*Variable saying where gnus-uu is to do its work.
179 Default is \"/tmp/\".")
181 (defvar gnus-uu-do-not-unpack-archives nil
182 "*Non-nil means that gnus-uu won't peek inside archives looking for files to dispay.
185 (defvar gnus-uu-view-and-save nil
186 "*Non-nil means that the user will always be asked to save a file after viewing it.
187 If the variable is nil, the suer will only be asked to save if the
188 viewing is unsuccessful. Default is nil.")
190 (defvar gnus-uu-ignore-default-view-rules nil
191 "*Non-nil means that gnus-uu will ignore the default viewing rules.
192 Only the user viewing rules will be consulted. Default is nil.")
194 (defvar gnus-uu-ignore-default-archive-rules nil
195 "*Non-nil means that gnus-uu will ignore the default archive unpacking commands.
196 Only the user unpacking commands will be consulted. Default is nil.")
198 (defvar gnus-uu-kill-carriage-return t
199 "*Non-nil means that gnus-uu will strip all carriage returns from articles.
202 (defvar gnus-uu-view-with-metamail nil
203 "*Non-nil means that files will be viewed with metamail.
204 The gnus-uu viewing functions will be ignored and gnus-uu will try
205 to guess at a content-type based on file name suffixes. Default
208 (defvar gnus-uu-unmark-articles-not-decoded nil
209 "*Non-nil means that gnus-uu will mark articles that were unsuccessfully decoded as unread.
212 (defvar gnus-uu-correct-stripped-uucode nil
213 "*Non-nil means that gnus-uu will *try* to fix uuencoded files that have had traling spaces deleted.
216 (defvar gnus-uu-save-in-digest nil
217 "*Non-nil means that gnus-uu, when asked to save without decoding, will save in digests.
218 If this variable is nil, gnus-uu will just save everything in a
219 file without any embellishments. The digesting almost conforms to RFC1153 -
220 no easy way to specify any meaningful volume and issue numbers were found,
221 so I simply dropped them.")
223 (defvar gnus-uu-save-separate-articles nil
224 "*Non-nil means that gnus-uu will save articles in separate files.")
226 ;; Internal variables
228 (defvar gnus-uu-saved-article-name nil)
230 (defconst gnus-uu-begin-string "^begin[ \t]+[0-7][0-7][0-7][ \t]+\\(.*\\)$")
231 (defconst gnus-uu-end-string "^end[ \t]*$")
233 (defconst gnus-uu-body-line "^M")
235 (while (> (setq i (1- i)) 0)
236 (setq gnus-uu-body-line (concat gnus-uu-body-line "[^a-z]")))
237 (setq gnus-uu-body-line (concat gnus-uu-body-line ".?$")))
239 ;"^M.............................................................?$"
241 (defconst gnus-uu-shar-begin-string "^#! */bin/sh")
243 (defvar gnus-uu-shar-file-name nil)
244 (defconst gnus-uu-shar-name-marker "begin [0-7][0-7][0-7][ \t]+\\(\\(\\w\\|\\.\\)*\\b\\)")
246 (defvar gnus-uu-file-name nil)
247 (defconst gnus-uu-uudecode-process nil)
249 (defvar gnus-uu-generated-file-list nil)
250 (defvar gnus-uu-work-dir nil)
252 (defconst gnus-uu-output-buffer-name "*Gnus UU Output*")
254 (defconst gnus-uu-highest-article-number 1)
255 (defvar gnus-uu-default-dir default-directory)
259 (defun gnus-uu-decode-uu (n)
260 "Uudecodes the current article."
262 (gnus-uu-decode-with-method 'gnus-uu-uustrip-article n))
264 (defun gnus-uu-decode-uu-and-save (n dir)
265 "Decodes and saves the resulting file."
267 (list current-prefix-arg
268 (read-file-name "Where do you want to save the file(s)? "
270 gnus-uu-default-dir t)))
271 (gnus-uu-decode-with-method 'gnus-uu-uustrip-article n dir))
273 (defun gnus-uu-decode-unshar (n)
274 "Unshars the current article."
276 (gnus-uu-decode-with-method 'gnus-uu-unshar-article n))
278 (defun gnus-uu-decode-unshar-and-save (n dir)
279 "Unshars and saves the current article."
281 (list current-prefix-arg
282 (read-file-name "Where do you want to save the file(s)? "
284 gnus-uu-default-dir t)))
285 (gnus-uu-decode-with-method 'gnus-uu-unshar-article n dir))
287 (defun gnus-uu-decode-save (n file)
288 "Saves the current article."
290 (list current-prefix-arg
291 (read-file-name "Where do you want to save the file? "
293 gnus-uu-default-dir)))
294 (setq gnus-uu-saved-article-name file)
295 (gnus-uu-decode-with-method 'gnus-uu-save-article n nil)
296 (setq gnus-uu-generated-file-list
297 (delete file gnus-uu-generated-file-list)))
299 (defun gnus-uu-decode-binhex (n dir)
300 "Unbinhexes the current article."
302 (list current-prefix-arg
303 (read-file-name "Where do you want to save the file(s)? "
305 gnus-uu-default-dir t)))
306 (gnus-uu-decode-with-method 'gnus-uu-binhex-article n dir))
308 (defun gnus-uu-decode-uu-view (n)
309 "Uudecodes and views the current article."
311 (let ((gnus-view-pseudos (or gnus-view-pseudos 'automatic)))
312 (gnus-uu-decode-uu n)))
314 (defun gnus-uu-decode-uu-and-save-view (n dir)
315 "Decodes, views and saves the resulting file."
317 (list current-prefix-arg
318 (read-file-name "Where do you want to save the file(s)? "
320 gnus-uu-default-dir t)))
321 (let ((gnus-view-pseudos (or gnus-view-pseudos 'automatic)))
322 (gnus-uu-decode-uu-and-save n dir)))
324 (defun gnus-uu-decode-unshar-view (n)
325 "Unshars and views the current article."
327 (let ((gnus-view-pseudos (or gnus-view-pseudos 'automatic)))
328 (gnus-uu-decode-unshar n)))
330 (defun gnus-uu-decode-unshar-and-save-view (n dir)
331 "Unshars and saves the current article."
333 (list current-prefix-arg
334 (read-file-name "Where do you want to save the file(s)? "
336 gnus-uu-default-dir t)))
337 (let ((gnus-view-pseudos (or gnus-view-pseudos 'automatic)))
338 (gnus-uu-decode-unshar-and-save n dir)))
340 (defun gnus-uu-decode-save-view (n file)
341 "Saves and views the current article."
343 (list current-prefix-arg
344 (read-file-name "Where do you want to save the file? "
345 gnus-uu-default-dir gnus-uu-default-dir)))
346 (let ((gnus-view-pseudos (or gnus-view-pseudos 'automatic)))
347 (gnus-uu-decode-save n file)))
349 (defun gnus-uu-decode-binhex-view (n file)
350 "Unbinhexes and views the current article."
352 (list current-prefix-arg
353 (read-file-name "Where do you want to save the file(s)? "
354 gnus-uu-default-dir gnus-uu-default-dir)))
355 (let ((gnus-view-pseudos (or gnus-view-pseudos 'automatic)))
356 (gnus-uu-decode-binhex n file)))
359 ;; Digest and forward articles
361 (defun gnus-uu-digest-and-forward (n)
362 "Digests and forwards all articles in this series."
365 (let ((gnus-uu-save-in-digest t)
366 (file (concat gnus-uu-work-dir (make-temp-name "forward"))))
367 (gnus-uu-decode-save n file)
368 (switch-to-buffer (get-buffer-create "*gnus-uu-forward*"))
370 (delete-other-windows)
372 (goto-char (point-min))
373 (funcall gnus-mail-forward-method)))
377 (defun gnus-uu-mark-by-regexp (regexp)
378 "Ask for a regular expression and set the process mark on all articles that match."
379 (interactive (list (read-from-minibuffer "Mark (regexp): ")))
380 (let ((articles (gnus-uu-find-articles-matching regexp)))
382 (gnus-summary-set-process-mark (car articles))
383 (setq articles (cdr articles)))
385 (gnus-summary-position-cursor))
387 (defun gnus-uu-mark-series ()
388 "Mark the current series with the process mark."
390 (let ((articles (gnus-uu-find-articles-matching)))
392 (gnus-summary-set-process-mark (car articles))
393 (setq articles (cdr articles)))
395 (gnus-summary-position-cursor))
397 (defun gnus-uu-mark-region (beg end)
398 "Marks all articles between point and mark."
402 (while (< (point) end)
403 (gnus-summary-set-process-mark (gnus-summary-article-number))
405 (gnus-summary-position-cursor))
407 (defun gnus-uu-mark-thread ()
408 "Marks all articles downwards in this thread."
411 (let ((level (gnus-summary-thread-level)))
412 (while (and (gnus-summary-set-process-mark (gnus-summary-article-number))
413 (zerop (gnus-summary-next-subject 1))
414 (> (gnus-summary-thread-level) level)))))
415 (gnus-summary-position-cursor))
417 (defun gnus-uu-mark-sparse ()
418 "Mark all series that have some articles marked."
420 (let ((marked (nreverse gnus-newsgroup-processable))
421 subject articles total)
422 (or marked (error "No articles marked with the process mark"))
423 (setq gnus-newsgroup-processable nil)
426 (setq subject (header-subject (gnus-get-header-by-number (car marked)))
427 articles (gnus-uu-find-articles-matching
428 (gnus-uu-reginize-string subject))
429 total (nconc total articles))
431 (gnus-summary-set-process-mark (car articles))
432 (setcdr marked (delq (car articles) (cdr marked)))
433 (setq articles (cdr articles)))
434 (setq marked (cdr marked)))
435 (setq gnus-newsgroup-processable (nreverse total)))
436 (gnus-summary-position-cursor)))
438 (defun gnus-uu-mark-all ()
439 "Mark all articles in \"series\" order."
441 (setq gnus-newsgroup-processable nil)
443 (goto-char (point-min))
445 (while (and (not (eobp))
446 (setq number (gnus-summary-article-number)))
447 (if (not (memq number gnus-newsgroup-processable))
448 (save-excursion (gnus-uu-mark-series)))
450 (gnus-summary-position-cursor))
452 ;; Internal functions.
454 (defun gnus-uu-decode-with-method (method n &optional save)
456 (if save (setq gnus-uu-default-dir save))
457 (let ((articles (gnus-uu-get-list-of-articles n))
459 (setq files (gnus-uu-grab-articles articles method t))
460 (and save (gnus-uu-save-files files save))
461 (setq files (gnus-uu-unpack-files files))
462 (gnus-uu-add-file (mapcar (lambda (file) (cdr (assq 'name file))) files))
463 (setq files (nreverse (gnus-uu-get-actions files)))
464 (gnus-summary-insert-pseudos files)))
466 (defun gnus-uu-save-files (files dir)
467 (let ((len (length files))
470 (setq file (cdr (assq 'name (car files))))
471 (and (file-exists-p file)
472 (copy-file file (if (file-directory-p dir)
473 (concat dir (file-name-nondirectory file)) dir)
475 (setq files (cdr files)))
476 (message "Saved %d file%s" len (if (> len 1) "s" ""))))
478 ;; Functions for saving and possibly digesting articles without
481 ;; Function called by gnus-uu-grab-articles to treat each article.
482 (defun gnus-uu-save-article (buffer in-state)
484 (gnus-uu-save-separate-articles
487 (write-region 1 (point-max) (concat gnus-uu-saved-article-name
488 gnus-current-article))
489 (cond ((eq in-state 'first) (list gnus-uu-saved-article-name 'begin))
490 ((eq in-state 'first-and-last) (list gnus-uu-saved-article-name
492 ((eq in-state 'last) (list 'end))
493 (t (list 'middle)))))
494 ((not gnus-uu-save-in-digest)
497 (write-region 1 (point-max) gnus-uu-saved-article-name t)
498 (cond ((eq in-state 'first) (list gnus-uu-saved-article-name 'begin))
499 ((eq in-state 'first-and-last) (list gnus-uu-saved-article-name
501 ((eq in-state 'last) (list 'end))
502 (t (list 'middle)))))
504 (let (beg subj name headers headline sorthead body end-string state)
505 (string-match "/\\([^/]*\\)$" gnus-uu-saved-article-name)
506 (setq name (substring gnus-uu-saved-article-name (match-beginning 1)
508 (if (or (eq in-state 'first)
509 (eq in-state 'first-and-last))
511 (setq state (list 'begin))
512 (save-excursion (set-buffer (get-buffer-create "*gnus-uu-body*"))
515 (set-buffer (get-buffer-create "*gnus-uu-pre*"))
518 "Date: %s\nFrom: %s\nSubject: %s Digest\n\nTopics:\n"
519 (current-time-string) name name))))
520 (if (not (eq in-state 'end))
521 (setq state (list 'middle))))
523 (set-buffer (get-buffer "*gnus-uu-body*"))
524 (goto-char (setq beg (point-max)))
529 (re-search-forward "\n\n")
530 (setq body (buffer-substring (1- (point)) (point-max)))
531 (narrow-to-region 1 (point))
532 (setq headers (list "Date:" "From:" "To:" "Cc:" "Subject:"
533 "Message-ID:" "Keywords:" "Summary:"))
535 (setq headline (car headers))
536 (setq headers (cdr headers))
538 (if (re-search-forward (concat "^" headline ".*$") nil t)
540 (concat sorthead (buffer-substring
542 (match-end 0)) "\n"))))
544 (insert sorthead)(goto-char (point-max))
545 (insert body)(goto-char (point-max))
546 (insert (concat "\n" (make-string 30 ?-) "\n\n"))
548 (if (re-search-forward "^Subject: \\(.*\\)$" nil t)
550 (setq subj (buffer-substring (match-beginning 1) (match-end 1)))
552 (set-buffer (get-buffer "*gnus-uu-pre*"))
553 (insert (format " %s\n" subj))))))
554 (if (or (eq in-state 'last)
555 (eq in-state 'first-and-last))
558 (set-buffer (get-buffer "*gnus-uu-pre*"))
559 (insert (format "\n\n%s\n\n" (make-string 70 ?-)))
560 (write-region 1 (point-max) gnus-uu-saved-article-name))
562 (set-buffer (get-buffer "*gnus-uu-body*"))
563 (goto-char (point-max))
565 (concat (setq end-string (format "End of %s Digest" name))
567 (insert (concat (make-string (length end-string) ?*) "\n"))
568 (write-region 1 (point-max) gnus-uu-saved-article-name t))
569 (kill-buffer (get-buffer "*gnus-uu-pre*"))
570 (kill-buffer (get-buffer "*gnus-uu-body*"))
571 (setq state (cons 'end state))))
572 (if (memq 'begin state)
573 (cons gnus-uu-saved-article-name state)
576 ;; Binhex treatment - not very advanced.
578 (defconst gnus-uu-binhex-body-line
579 "^[^:]...............................................................$")
580 (defconst gnus-uu-binhex-begin-line
581 "^:...............................................................$")
582 (defconst gnus-uu-binhex-end-line
584 (defvar gnus-uu-binhex-article-name nil)
586 (defun gnus-uu-binhex-article (buffer in-state)
587 (let (state start-char)
592 (if (not (re-search-forward gnus-uu-binhex-begin-line nil t))
593 (if (not (re-search-forward gnus-uu-binhex-body-line nil t))
594 (setq state (list 'wrong-type))))
596 (if (memq 'wrong-type state)
599 (setq start-char (point))
600 (if (looking-at gnus-uu-binhex-begin-line)
602 (setq state (list 'begin))
603 (write-region 1 1 gnus-uu-binhex-article-name))
604 (setq state (list 'middle)))
605 (goto-char (point-max))
606 (re-search-backward (concat gnus-uu-binhex-body-line "\\|"
607 gnus-uu-binhex-end-line) nil t)
608 (if (looking-at gnus-uu-binhex-end-line)
609 (setq state (if (memq 'begin state)
614 (if (file-exists-p gnus-uu-binhex-article-name)
615 (append-to-file start-char (point) gnus-uu-binhex-article-name))))
616 (if (memq 'begin state)
617 (cons gnus-uu-binhex-article-name state)
623 (defun gnus-uu-get-actions (files)
627 (setq name (cdr (assq 'name (car files))))
629 (setq action (gnus-uu-get-action name))
630 (setcar files (cons (cons 'execute (if (string-match "%" action)
632 (concat action " " name)))
634 (setq files (cdr files)))
637 (defun gnus-uu-get-action (file-name)
640 (gnus-uu-choose-action
643 gnus-uu-user-view-rules
644 (if gnus-uu-ignore-default-view-rules
646 gnus-uu-default-view-rules)
647 gnus-uu-user-view-rules-end)))
648 (if (and (not (string= (or action "") "gnus-uu-archive"))
649 gnus-uu-view-with-metamail)
651 (gnus-uu-choose-action file-name gnus-uu-ext-to-mime-list))
652 (setq action (format "metamail -d -b -c \"%s\"" action))))
656 ;; Functions for treating subjects and collecting series.
658 (defun gnus-uu-reginize-string (string)
659 ;; Takes a string and puts a \ in front of every special character;
660 ;; ignores any leading "version numbers" thingies that they use in
661 ;; the comp.binaries groups, and either replaces anything that looks
662 ;; like "2/3" with "[0-9]+/[0-9]+" or, if it can't find something
663 ;; like that, replaces the last two numbers with "[0-9]+". This, in
664 ;; my experience, should get most postings of a series.
666 (vernum "v[0-9]+[a-z][0-9]+:")
669 (set-buffer (get-buffer-create gnus-uu-output-buffer-name))
670 (buffer-disable-undo (current-buffer))
672 (insert (regexp-quote string))
675 (setq case-fold-search nil)
677 (if (looking-at vernum)
679 (replace-match vernum t t)
680 (setq beg (length vernum))))
683 (if (re-search-forward "[ \t]*[0-9]+/[0-9]+" nil t)
684 (replace-match " [0-9]+/[0-9]+")
687 (if (re-search-forward "[0-9]+[ \t]*of[ \t]*[0-9]+" nil t)
688 (replace-match "[0-9]+ of [0-9]+")
691 (while (and (re-search-backward "[0-9]" nil t) (> count 0))
694 (< 1 (goto-char (1- (point))))))
695 (re-search-forward "[0-9]+" nil t)
696 (replace-match "[0-9]+")
698 (setq count (1- count)))))
701 (while (re-search-forward "[ \t]+" nil t)
702 (replace-match "[ \t]*" t t))
704 (buffer-substring 1 (point-max)))))
706 (defun gnus-uu-get-list-of-articles (n)
707 ;; If N is non-nil, the article numbers of the N next articles
709 ;; If any articles have been marked as processable, they will be
711 ;; Failing that, articles that have subjects that are part of the
712 ;; same "series" as the current will be returned.
713 (let (articles process)
716 (let ((backward (< n 0))
720 (setq articles (cons (gnus-summary-article-number)
722 (gnus-summary-search-forward nil nil backward))
724 (nreverse articles)))
725 (gnus-newsgroup-processable
726 (reverse gnus-newsgroup-processable))
728 (gnus-uu-find-articles-matching)))))
730 (defun gnus-uu-string< (l1 l2)
731 (string< (car l1) (car l2)))
733 (defun gnus-uu-find-articles-matching
734 (&optional subject only-unread do-not-translate)
735 ;; Finds all articles that matches the regexp SUBJECT. If it is
736 ;; nil, the current article name will be used. If ONLY-UNREAD is
737 ;; non-nil, only unread articles are chosen. If DO-NOT-TRANSLATE is
738 ;; non-nil, article names are not equalized before sorting.
739 (let ((subject (or subject
740 (gnus-uu-reginize-string (gnus-summary-subject-string))))
741 beg end list-of-subjects)
745 ;; Collect all subjects matching subject.
746 (let ((case-fold-search t)
748 (goto-char (point-min))
750 (and (setq subj (gnus-summary-subject-string))
751 (string-match subject subj)
752 (or (not only-unread)
753 (= (setq mark (gnus-summary-article-mark))
755 (= mark gnus-ticked-mark)
756 (= mark gnus-dormant-mark))
757 (setq list-of-subjects
758 (cons (cons subj (gnus-summary-article-number))
762 ;; Expand numbers, sort, and return the list of article
764 (mapcar (lambda (sub) (cdr sub))
765 (sort (gnus-uu-expand-numbers
767 (not do-not-translate))
768 'gnus-uu-string<))))))
770 (defun gnus-uu-expand-numbers (string-list &optional translate)
771 ;; Takes a list of strings and "expands" all numbers in all the
772 ;; strings. That is, this function makes all numbers equal length by
773 ;; prepending lots of zeroes before each number. This is to ease later
774 ;; sorting to find out what sequence the articles are supposed to be
775 ;; decoded in. Returns the list of expanded strings.
776 (let ((out-list string-list)
779 (set-buffer (get-buffer-create gnus-uu-output-buffer-name))
780 (buffer-disable-undo (current-buffer))
783 (insert (car (car string-list)))
784 ;; Translate multiple spaces to one space.
786 (while (re-search-forward "[ \t]+" nil t)
788 ;; Translate all characters to "a".
791 (while (re-search-forward "[A-Za-z]" nil t)
792 (replace-match "a" t t)))
795 (while (re-search-forward "[0-9]+" nil t)
798 (string-to-int (buffer-substring
799 (match-beginning 0) (match-end 0))))))
800 (setq string (buffer-substring 1 (point-max)))
801 (setcar (car string-list) string)
802 (setq string-list (cdr string-list))))
806 ;; `gnus-uu-grab-articles' is the general multi-article treatment
807 ;; function. It takes a list of articles to be grabbed and a function
808 ;; to apply to each article.
810 ;; The function to be called should take two parameters. The first
811 ;; parameter is the article buffer. The function should leave the
812 ;; result, if any, in this buffer. Most treatment functions will just
815 ;; The second parameter is the state of the list of articles, and can
816 ;; have four values: `first', `middle', `last' and `first-and-last'.
818 ;; The function should return a list. The list may contain the
819 ;; following symbols:
820 ;; `error' if an error occurred
821 ;; `begin' if the beginning of an encoded file has been received
822 ;; If the list returned contains a `begin', the first element of
823 ;; the list *must* be a string with the file name of the decoded
825 ;; `end' if the the end of an encoded file has been received
826 ;; `middle' if the article was a body part of an encoded file
827 ;; `wrong-type' if the article was not a part of an encoded file
828 ;; `ok', which can be used everything is ok
830 (defvar gnus-uu-has-been-grabbed nil)
832 (defun gnus-uu-unmark-list-of-grabbed (&optional dont-unmark-last-article)
834 (if (not (and gnus-uu-has-been-grabbed
835 gnus-uu-unmark-articles-not-decoded))
837 (if dont-unmark-last-article
839 (setq art (car gnus-uu-has-been-grabbed))
840 (setq gnus-uu-has-been-grabbed (cdr gnus-uu-has-been-grabbed))))
841 (while gnus-uu-has-been-grabbed
842 (gnus-summary-tick-article (car gnus-uu-has-been-grabbed) t)
843 (setq gnus-uu-has-been-grabbed (cdr gnus-uu-has-been-grabbed)))
844 (if dont-unmark-last-article
845 (setq gnus-uu-has-been-grabbed (list art))))))
847 ;; This function takes a list of articles and a function to apply to
848 ;; each article grabbed.
850 ;; This function returns a list of files decoded if the grabbing and
851 ;; the process-function has been successful and nil otherwise.
852 (defun gnus-uu-grab-articles
853 (articles process-function &optional sloppy limit no-errors)
856 has-been-begin has-been-end
857 article result-file result-files process-state article-buffer
860 (if (not (gnus-server-opened gnus-current-select-method))
862 (gnus-start-news-server)
863 (gnus-request-group gnus-newsgroup-name)))
865 (setq gnus-uu-has-been-grabbed nil)
868 (not (memq 'error process-state))
870 (not (memq 'end process-state))))
872 (setq article (car articles))
873 (setq articles (cdr articles))
874 (setq gnus-uu-has-been-grabbed (cons article gnus-uu-has-been-grabbed))
876 (if (> article gnus-uu-highest-article-number)
877 (setq gnus-uu-highest-article-number article))
880 (if (eq state 'first)
881 (setq state 'first-and-last)
884 (message "Getting article %d" article)
886 (if (not (= (or gnus-current-article 0) article))
888 (gnus-request-article article gnus-newsgroup-name
890 (setq gnus-last-article gnus-current-article)
891 (setq gnus-current-article article)
892 (if (stringp nntp-server-buffer)
893 (setq article-buffer nntp-server-buffer)
894 (setq article-buffer (buffer-name nntp-server-buffer))))
895 (setq article-buffer gnus-article-buffer))
897 (buffer-disable-undo article-buffer)
898 ;; Mark article as read.
899 (run-hooks 'gnus-mark-article-hook)
900 (and (memq article gnus-newsgroup-processable)
901 (gnus-summary-remove-process-mark article))
903 (setq process-state (funcall process-function article-buffer state))
905 (if (or (memq 'begin process-state)
906 (and (or (eq state 'first) (eq state 'first-and-last))
907 (memq 'ok process-state)))
910 (if (and result-file (file-exists-p result-file))
911 (delete-file result-file)))
912 (if (memq 'begin process-state)
913 (setq result-file (car process-state)))
914 (setq begin-article article)
915 (setq has-been-begin t)
916 (setq has-been-end nil)))
918 (if (memq 'end process-state)
920 (setq gnus-uu-has-been-grabbed nil)
921 (setq result-files (cons (list (cons 'name result-file)
922 (cons 'article article))
924 (setq has-been-end t)
925 (setq has-been-begin nil)
926 (and limit (= (length result-files) limit)
927 (setq articles nil))))
929 (if (and (or (eq state 'last) (eq state 'first-and-last))
930 (not (memq 'end process-state)))
931 (if (and result-file (file-exists-p result-file))
932 (delete-file result-file)))
934 (if (not (memq 'wrong-type process-state))
935 (setq wrong-type nil)
936 (if gnus-uu-unmark-articles-not-decoded
937 (gnus-summary-tick-article article t)))
939 (if sloppy (setq wrong-type nil))
941 (if (and (not has-been-begin)
943 (or (memq 'end process-state)
944 (memq 'middle process-state)))
946 (setq process-state (list 'error))
947 (message "No begin part at the beginning")
949 (setq state 'middle)))
951 ;; Make sure the last article is put in the article buffer & fix
954 (if (not (string= article-buffer gnus-article-buffer))
956 (set-buffer (get-buffer-create gnus-article-buffer))
957 (let ((buffer-read-only nil))
960 (insert-buffer-substring article-buffer)
965 (if (not has-been-begin)
966 (if (not no-errors) (message "Wrong type file"))
967 (if (memq 'error process-state)
968 (setq result-files nil)
969 (if (not (or (memq 'ok process-state)
970 (memq 'end process-state)))
973 (message "End of articles reached before end of file"))
974 (setq result-files nil))
975 (gnus-uu-unmark-list-of-grabbed)))))
978 (defun gnus-uu-uudecode-sentinel (process event)
979 (delete-process (get-process process)))
981 (defun gnus-uu-uustrip-article (process-buffer in-state)
982 ;; Uudecodes a file asynchronously.
983 (let ((state (list 'ok))
984 (process-connection-type nil)
985 start-char pst name-beg name-end)
987 (set-buffer process-buffer)
988 (let ((case-fold-search nil)
989 (buffer-read-only nil))
993 (if gnus-uu-kill-carriage-return
995 (while (search-forward "\r" nil t)
996 (delete-backward-char 1))
999 (if (not (re-search-forward gnus-uu-begin-string nil t))
1000 (if (not (re-search-forward gnus-uu-body-line nil t))
1001 (setq state (list 'wrong-type))))
1003 (if (memq 'wrong-type state)
1006 (setq start-char (point))
1008 (if (looking-at gnus-uu-begin-string)
1010 (setq name-end (match-end 1))
1012 ; Replace any slashes and spaces in file names before decoding
1013 (goto-char (setq name-beg (match-beginning 1)))
1014 (while (re-search-forward "/" name-end t)
1015 (replace-match ","))
1016 (goto-char name-beg)
1017 (while (re-search-forward " " name-end t)
1018 (replace-match "_"))
1019 (goto-char name-beg)
1020 (if (re-search-forward "_*$" name-end t)
1023 (setq gnus-uu-file-name (buffer-substring name-beg name-end))
1024 (and gnus-uu-uudecode-process
1025 (setq pst (process-status
1026 (or gnus-uu-uudecode-process "nevair")))
1027 (if (or (eq pst 'stop) (eq pst 'run))
1029 (delete-process gnus-uu-uudecode-process)
1030 (gnus-uu-unmark-list-of-grabbed t))))
1031 (if (get-process "*uudecode*")
1032 (delete-process "*uudecode*"))
1033 (setq gnus-uu-uudecode-process
1036 (get-buffer-create gnus-uu-output-buffer-name)
1038 (format "cd %s ; uudecode" gnus-uu-work-dir)))
1039 (set-process-sentinel
1040 gnus-uu-uudecode-process 'gnus-uu-uudecode-sentinel)
1041 (setq state (list 'begin))
1042 (gnus-uu-add-file (concat gnus-uu-work-dir gnus-uu-file-name)))
1043 (setq state (list 'middle)))
1045 (goto-char (point-max))
1048 (concat gnus-uu-body-line "\\|" gnus-uu-end-string) nil t)
1051 (if (looking-at gnus-uu-end-string)
1052 (setq state (cons 'end state)))
1055 (and gnus-uu-uudecode-process
1056 (setq pst (process-status
1057 (or gnus-uu-uudecode-process "nevair")))
1058 (if (or (eq pst 'run) (eq pst 'stop))
1060 (if gnus-uu-correct-stripped-uucode
1062 (gnus-uu-check-correct-stripped-uucode
1064 (goto-char (point-max))
1066 (concat gnus-uu-body-line "\\|"
1072 (process-send-region gnus-uu-uudecode-process
1076 (delete-process gnus-uu-uudecode-process)
1077 (message "gnus-uu: Couldn't uudecode")
1079 (setq state (list 'wrong-type)))))
1081 (if (memq 'end state)
1082 (accept-process-output gnus-uu-uudecode-process)))
1083 (setq state (list 'wrong-type))))
1084 (if (not gnus-uu-uudecode-process)
1085 (setq state (list 'wrong-type)))))
1087 (if (memq 'begin state)
1088 (cons (concat gnus-uu-work-dir gnus-uu-file-name) state)
1091 ;; This function is used by `gnus-uu-grab-articles' to treat
1092 ;; a shared article.
1093 (defun gnus-uu-unshar-article (process-buffer in-state)
1094 (let ((state (list 'ok))
1097 (set-buffer process-buffer)
1099 (if (not (re-search-forward gnus-uu-shar-begin-string nil t))
1100 (setq state (list 'wrong-type))
1102 (setq start-char (point))
1103 (call-process-region
1104 start-char (point-max) "sh" nil
1105 (get-buffer-create gnus-uu-output-buffer-name) nil
1106 "-c" (concat "cd " gnus-uu-work-dir " ; sh"))))
1109 ;; Returns the name of what the shar file is going to unpack.
1110 (defun gnus-uu-find-name-in-shar ()
1111 (let ((oldpoint (point))
1114 (if (re-search-forward gnus-uu-shar-name-marker nil t)
1115 (setq res (buffer-substring (match-beginning 1) (match-end 1))))
1116 (goto-char oldpoint)
1119 ;; `gnus-uu-choose-action' chooses what action to perform given the name
1120 ;; and `gnus-uu-file-action-list'. Returns either nil if no action is
1121 ;; found, or the name of the command to run if such a rule is found.
1122 (defun gnus-uu-choose-action (file-name file-action-list &optional no-ignore)
1123 (let ((action-list (copy-sequence file-action-list))
1128 (and gnus-uu-ignore-files-by-name
1129 (string-match gnus-uu-ignore-files-by-name file-name)))
1131 (and gnus-uu-ignore-files-by-type
1132 (string-match gnus-uu-ignore-files-by-type
1133 (or (gnus-uu-choose-action
1134 file-name gnus-uu-ext-to-mime-list t)
1136 (while (not (or (eq action-list ()) action))
1137 (setq rule (car action-list))
1138 (setq action-list (cdr action-list))
1139 (if (string-match (car rule) file-name)
1140 (setq action (car (cdr rule))))))
1143 (defun gnus-uu-treat-archive (file-path)
1144 ;; Unpacks an archive. Returns t if unpacking is successful.
1145 (let ((did-unpack t)
1146 action command files file file-name dir)
1147 (setq action (gnus-uu-choose-action
1148 file-path (append gnus-uu-user-archive-rules
1149 (if gnus-uu-ignore-default-archive-rules
1151 gnus-uu-default-archive-rules))))
1153 (if (not action) (error "No unpackers for the file %s" file-path))
1155 (string-match "/[^/]*$" file-path)
1156 (setq file-name (substring file-path (1+ (match-beginning 0))))
1157 (setq dir (substring file-path 0 (match-beginning 0)))
1159 (if (member action gnus-uu-destructive-archivers)
1160 (copy-file file-path (concat file-path "~") t))
1162 (setq command (format "cd %s ; %s" dir (gnus-uu-command action file-path)))
1165 (set-buffer (get-buffer-create gnus-uu-output-buffer-name))
1168 (message "Unpacking: %s..." (gnus-uu-command action file-path))
1170 (if (= 0 (call-process "sh" nil
1171 (get-buffer-create gnus-uu-output-buffer-name)
1174 (message "Error during unpacking of archive")
1175 (setq did-unpack nil))
1177 (if (member action gnus-uu-destructive-archivers)
1178 (rename-file (concat file-path "~") file-path t))
1182 (defun gnus-uu-dir-files (dir)
1183 (let ((dirs (directory-files dir t "[^/][^\\.][^\\.]?$"))
1186 (if (file-directory-p (setq file (car dirs)))
1187 (setq files (append files (gnus-uu-dir-files file)))
1188 (setq files (cons file files)))
1189 (setq dirs (cdr dirs)))
1192 (defun gnus-uu-unpack-files (files &optional ignore)
1193 ;; Go through FILES and look for files to unpack.
1194 (let* ((totfiles (gnus-uu-ls-r gnus-uu-work-dir))
1198 (setq file (cdr (assq 'name (car files))))
1199 (if (and (not (member file ignore))
1200 (equal (gnus-uu-get-action (file-name-nondirectory file))
1203 (setq did-unpack (cons file did-unpack))
1204 (or (gnus-uu-treat-archive file)
1205 (message "Error during unpacking of %s" file))
1206 (let* ((newfiles (gnus-uu-ls-r gnus-uu-work-dir))
1209 (or (member (car nfiles) totfiles)
1210 (setq ofiles (cons (list (cons 'name (car nfiles))
1211 (cons 'original file))
1213 (setq nfiles (cdr nfiles)))
1214 (setq totfiles newfiles))))
1215 (setq files (cdr files)))
1217 (gnus-uu-unpack-files ofiles (append did-unpack ignore))
1220 (defun gnus-uu-ls-r (dir)
1221 (let* ((files (gnus-uu-directory-files dir t))
1224 (if (file-directory-p (car files))
1226 (setq ofiles (delete (car files) ofiles))
1227 (setq ofiles (append ofiles (gnus-uu-ls-r (car files))))))
1228 (setq files (cdr files)))
1233 (defun gnus-uu-directory-files (dir &optional full)
1234 (let (files out file)
1235 (setq files (directory-files dir full))
1237 (setq file (car files))
1238 (setq files (cdr files))
1239 (or (string-match "/\\.\\.?$" file)
1240 (setq out (cons file out))))
1241 (setq out (nreverse out))
1244 (defun gnus-uu-check-correct-stripped-uucode (start end)
1245 (let (found beg length short)
1246 (if (not gnus-uu-correct-stripped-uucode)
1250 (if (re-search-forward " \\|`" end t)
1255 (if (looking-at "\n") (replace-match ""))
1259 (if (looking-at (concat gnus-uu-begin-string "\\|"
1260 gnus-uu-end-string))
1267 (setq length (- (point) beg))))
1272 (if (not (= length (- (point) beg)))
1273 (insert (make-string (- length (- (point) beg)) ? ))))
1274 (forward-line 1))))))
1276 (defun gnus-uu-initialize ()
1277 (setq gnus-uu-highest-article-number 1)
1278 (gnus-uu-check-for-generated-files)
1279 (setq gnus-uu-tmp-dir (expand-file-name gnus-uu-tmp-dir))
1280 (if (string-match "[^/]$" gnus-uu-tmp-dir)
1281 (setq gnus-uu-tmp-dir (concat gnus-uu-tmp-dir "/")))
1282 (if (not (file-directory-p gnus-uu-tmp-dir))
1283 (error "Temp directory %s doesn't exist" gnus-uu-tmp-dir)
1284 (if (not (file-writable-p gnus-uu-tmp-dir))
1285 (error "Temp directory %s can't be written to" gnus-uu-tmp-dir)))
1286 (setq gnus-uu-work-dir
1287 (concat gnus-uu-tmp-dir (make-temp-name "gnus")))
1288 (gnus-uu-add-file gnus-uu-work-dir)
1289 (if (not (file-directory-p gnus-uu-work-dir))
1290 (make-directory gnus-uu-work-dir))
1291 (setq gnus-uu-work-dir (concat gnus-uu-work-dir "/")))
1293 ;; Kills the temporary uu buffers, kills any processes, etc.
1294 (defun gnus-uu-clean-up ()
1296 (and gnus-uu-uudecode-process
1297 (setq pst (process-status (or gnus-uu-uudecode-process "nevair")))
1298 (if (or (eq pst 'stop) (eq pst 'run))
1299 (delete-process gnus-uu-uudecode-process)))
1300 (and (setq buf (get-buffer gnus-uu-output-buffer-name))
1301 (kill-buffer buf))))
1303 ;; `gnus-uu-check-for-generated-files' deletes any generated files that
1304 ;; hasn't been deleted, if, for instance, the user terminated decoding
1306 (defun gnus-uu-check-for-generated-files ()
1308 (while gnus-uu-generated-file-list
1309 (setq file (car gnus-uu-generated-file-list))
1310 (setq gnus-uu-generated-file-list (cdr gnus-uu-generated-file-list))
1311 (if (not (string-match "/\\.[\\.]?$" file))
1313 (if (file-directory-p file)
1314 (setq dirs (cons file dirs))
1315 (if (file-exists-p file)
1316 (delete-file file))))))
1317 (setq dirs (nreverse dirs))
1319 (setq file (car dirs))
1320 (setq dirs (cdr dirs))
1321 (if (file-directory-p file)
1322 (if (string-match "/$" file)
1323 (delete-directory (substring file 0 (match-beginning 0)))
1324 (delete-directory file))))))
1326 ;; Add a file (or a list of files) to be checked (and deleted if it/they
1327 ;; still exists upon exiting the newsgroup).
1328 (defun gnus-uu-add-file (file)
1330 (setq gnus-uu-generated-file-list
1331 (cons file gnus-uu-generated-file-list))
1332 (setq gnus-uu-generated-file-list
1333 (append file gnus-uu-generated-file-list))))
1335 ;; Inputs an action and a file and returns a full command, putting
1336 ;; ticks round the file name and escaping any ticks in the file name.
1337 (defun gnus-uu-command (action file)
1339 (while (string-match "`\\|\"\\|\\$\\|\\\\" file)
1342 (concat ofile (substring file 0 (match-beginning 0)) "\\"
1343 (substring file (match-beginning 0) (match-end 0))))
1344 (setq file (substring file (1+ (match-beginning 0))))))
1345 (setq ofile (concat "\"" ofile file "\""))
1346 (if (string-match "%s" action)
1347 (format action ofile)
1348 (concat action " " ofile))))
1353 (add-hook 'gnus-exit-group-hook 'gnus-uu-clean-up)
1354 (add-hook 'gnus-exit-group-hook 'gnus-uu-check-for-generated-files)
1357 ;; Major mode for posting encoded articles.
1362 ;; Any function that is to be used as and encoding method will take two
1363 ;; parameters: PATH-NAME and FILE-NAME. (E.g. "/home/gaga/spiral.jpg"
1364 ;; and "spiral.jpg", respectively.) The function should return nil if
1365 ;; the encoding wasn't successful.
1366 (defvar gnus-uu-post-encode-method 'gnus-uu-post-encode-uuencode
1367 "Function used for encoding binary files.
1368 There are three functions supplied with gnus-uu for encoding files:
1369 `gnus-uu-post-encode-uuencode', which does straight uuencoding;
1370 `gnus-uu-post-encode-mime', which encodes with base64 and adds MIME
1371 headers; and `gnus-uu-post-encode-mime-uuencode', which encodes with
1372 uuencode and adds MIME headers.")
1374 (defvar gnus-uu-post-include-before-composing nil
1375 "Non-nil means that gnus-uu will ask for a file to encode before you compose the article.
1376 If this variable is t, you can either include an encoded file with
1377 \\<gnus-uu-post-reply-mode-map>\\[gnus-uu-post-insert-binary-in-article] or have one included for you when you post the article.")
1379 (defvar gnus-uu-post-length 990
1380 "Maximum length of an article.
1381 The encoded file will be split into how many articles it takes to
1382 post the entire file.")
1384 (defvar gnus-uu-post-threaded nil
1385 "Non-nil means that gnus-uu will post the encoded file in a thread.
1386 This may not be smart, as no other decoder I have seen are able to
1387 follow threads when collecting uuencoded articles. (Well, I have seen
1388 one package that does that - gnus-uu, but somehow, I don't think that
1389 counts...) Default is nil.")
1391 (defvar gnus-uu-post-separate-description t
1392 "Non-nil means that the description will be posted in a separate article.
1393 The first article will typically be numbered (0/x). If this variable
1394 is nil, the description the user enters will be included at the
1395 beginning of the first article, which will be numbered (1/x). Default
1398 (defconst gnus-uu-post-binary-separator "--binary follows this line--")
1399 (defvar gnus-uu-post-message-id nil)
1400 (defvar gnus-uu-post-inserted-file-name nil)
1401 (defvar gnus-uu-winconf-post-news nil)
1403 ;; The following map and mode was taken from rnewspost.el and edited
1405 (defvar gnus-uu-post-reply-mode-map nil)
1406 (if gnus-uu-post-reply-mode-map
1408 (setq gnus-uu-post-reply-mode-map (make-keymap))
1409 (define-key gnus-uu-post-reply-mode-map "\C-c?" 'describe-mode)
1410 (define-key gnus-uu-post-reply-mode-map "\C-c\C-f\C-d"
1411 'news-reply-distribution)
1412 (define-key gnus-uu-post-reply-mode-map "\C-c\C-f\C-k"
1413 'news-reply-keywords)
1414 (define-key gnus-uu-post-reply-mode-map "\C-c\C-f\C-n"
1415 'news-reply-newsgroups)
1417 (define-key gnus-uu-post-reply-mode-map "\C-c\C-f\C-f"
1418 'news-reply-followup-to)
1419 (define-key gnus-uu-post-reply-mode-map "\C-c\C-f\C-s" 'mail-subject)
1420 (define-key gnus-uu-post-reply-mode-map "\C-c\C-f\C-a"
1421 'gnus-uu-post-reply-summary)
1422 (define-key gnus-uu-post-reply-mode-map "\C-c\C-r"
1423 'news-caesar-buffer-body)
1424 (define-key gnus-uu-post-reply-mode-map "\C-c\C-w" 'news-reply-signature)
1425 (define-key gnus-uu-post-reply-mode-map "\C-c\C-y"
1426 'news-reply-yank-original)
1427 (define-key gnus-uu-post-reply-mode-map "\C-c\C-q"
1428 'mail-fill-yanked-message)
1429 (define-key gnus-uu-post-reply-mode-map "\C-c\C-c"
1430 'gnus-uu-post-news-inews)
1431 (define-key gnus-uu-post-reply-mode-map "\C-c\C-s"
1432 'gnus-uu-post-news-inews)
1433 (define-key gnus-uu-post-reply-mode-map "\C-c\C-i"
1434 'gnus-uu-post-insert-binary-in-article)
1437 ;; This mode was taken from rnewspost.el and modified slightly.
1438 (defun gnus-uu-post-reply-mode ()
1439 "Major mode for editing binary news to be posted on USENET.
1440 First-time posters are asked to please read the articles in newsgroup:
1441 news.announce.newusers .
1443 Like news-reply-mode, which is like Text Mode, but with these
1444 additional commands:
1446 \\<gnus-uu-post-reply-mode-map>\\[gnus-uu-post-news-inews] post the message.
1447 C-c C-f move to a header field (and create it if there isn't):
1448 C-c C-f C-n move to Newsgroups: C-c C-f C-s move to Subj:
1449 C-c C-f C-f move to Followup-To: C-c C-f C-k move to Keywords:
1450 C-c C-f C-d move to Distribution: C-c C-f C-a move to Summary:
1451 C-c C-y news-reply-yank-original (insert current message, in NEWS).
1452 C-c C-q mail-fill-yanked-message (fill what was yanked).
1453 C-c C-r caesar rotate all letters by 13 places in the article's body (rot13).
1454 \\[gnus-uu-post-insert-binary-in-article] encode and include a file in this article.
1456 This mode is almost identical to news-reply-mode, but has some
1457 additional commands for treating encoded binary articles. In
1458 particular, \\[gnus-uu-post-news-inews] will ask for a file to include, if
1459 one hasn't been included already. It will post, first, the message
1460 composed, and then it will post as many additional articles it takes
1461 to post the entire encoded files.
1465 `gnus-uu-post-encode-method'
1466 There are three functions supplied with gnus-uu for encoding files:
1467 `gnus-uu-post-encode-uuencode', which does straight uuencoding;
1468 `gnus-uu-post-encode-mime', which encodes with base64 and adds MIME
1469 headers; and `gnus-uu-post-encode-mime-uuencode', which encodes with
1470 uuencode and adds MIME headers.
1472 `gnus-uu-post-include-before-composing'
1473 Non-nil means that gnus-uu will ask for a file to encode before you
1474 compose the article. If this variable is t, you can either include
1475 an encoded file with `C-c C-i' or have one included for you when you
1478 `gnus-uu-post-length'
1479 Maximum length of an article. The encoded file will be split into how
1480 many articles it takes to post the entire file.
1482 `gnus-uu-post-separate-description'
1483 Non-nil means that the description will be posted in a separate
1484 article. The first article will typically be numbered (0/x). If
1485 this variable is nil, the description the user enters will be
1486 included at the beginning of the first article, which will be
1487 numbered (1/x). Default is t.
1489 `gnus-uu-post-threaded'
1490 Non-nil means that gnus-uu will post the encoded file in a thread.
1491 This may not be smart, as no other decoder I have seen are able to
1492 follow threads when collecting uuencoded articles. (Well, I have seen
1493 one package that does that - gnus-uu, but somehow, I don't think that
1494 counts...) Default is nil.
1498 (or (fboundp 'mail-setup) (load "sendmail"))
1499 (kill-all-local-variables)
1500 (make-local-variable 'mail-reply-buffer)
1501 (setq mail-reply-buffer nil)
1502 (set-syntax-table text-mode-syntax-table)
1503 (use-local-map gnus-uu-post-reply-mode-map)
1504 (setq local-abbrev-table text-mode-abbrev-table)
1505 (setq major-mode 'gnus-uu-post-reply-mode)
1506 (setq mode-name "Gnus UU News")
1507 (make-local-variable 'paragraph-separate)
1508 (make-local-variable 'paragraph-start)
1509 (setq paragraph-start (concat "^" (regexp-quote mail-header-separator)
1510 "$\\|" paragraph-start))
1511 (setq paragraph-separate (concat "^" (regexp-quote mail-header-separator)
1512 "$\\|" paragraph-separate))
1513 (run-hooks 'text-mode-hook 'gnus-uu-post-reply-mode-hook))
1515 (defun gnus-uu-post-news ()
1516 "Compose an article and post an encoded file."
1518 (setq gnus-uu-post-inserted-file-name nil)
1519 (setq gnus-uu-winconf-post-news (current-window-configuration))
1520 (let (news-reply-mode)
1521 (fset 'news-reply-mode 'gnus-uu-post-reply-mode)
1522 (gnus-summary-post-news)
1523 (if gnus-uu-post-include-before-composing
1524 (save-excursion (setq gnus-uu-post-inserted-file-name
1525 (gnus-uu-post-insert-binary))))))
1527 (defun gnus-uu-post-insert-binary-in-article ()
1528 "Inserts an encoded file in the buffer.
1529 The user will be asked for a file name."
1531 (if (not (eq (current-buffer) (get-buffer gnus-post-news-buffer)))
1532 (error "Not in post-news buffer"))
1534 (setq gnus-uu-post-inserted-file-name (gnus-uu-post-insert-binary))))
1536 ;; Encodes with uuencode and substitutes all spaces with backticks.
1537 (defun gnus-uu-post-encode-uuencode (path file-name)
1538 (if (gnus-uu-post-encode-file "uuencode" path file-name)
1542 (while (re-search-forward " " nil t)
1543 (replace-match "`"))
1546 ;; Encodes with uuencode and adds MIME headers.
1547 (defun gnus-uu-post-encode-mime-uuencode (path file-name)
1548 (if (gnus-uu-post-encode-uuencode path file-name)
1550 (gnus-uu-post-make-mime file-name "x-uue")
1553 ;; Encodes with base64 and adds MIME headers
1554 (defun gnus-uu-post-encode-mime (path file-name)
1555 (if (gnus-uu-post-encode-file "mmencode" path file-name)
1557 (gnus-uu-post-make-mime file-name "base64")
1560 ;; Adds MIME headers.
1561 (defun gnus-uu-post-make-mime (file-name encoding)
1563 (insert (format "Content-Type: %s; name=\"%s\"\n"
1564 (gnus-uu-choose-action file-name gnus-uu-ext-to-mime-list)
1566 (insert (format "Content-Transfer-Encoding: %s\n\n" encoding))
1568 (set-buffer gnus-post-news-buffer)
1570 (re-search-forward (regexp-quote mail-header-separator))
1573 (narrow-to-region 1 (point))
1574 (or (mail-fetch-field "mime-version")
1577 (insert "MIME-Version: 1.0\n")))
1580 ;; Encodes a file PATH with COMMAND, leaving the result in the
1582 (defun gnus-uu-post-encode-file (command path file-name)
1583 (= 0 (call-process "sh" nil t nil "-c"
1584 (format "%s %s %s" command path file-name))))
1586 (defun gnus-uu-post-news-inews ()
1587 "Posts the composed news article and encoded file.
1588 If no file has been included, the user will be asked for a file."
1590 (if (not (eq (current-buffer) (get-buffer gnus-post-news-buffer)))
1591 (error "Not in post news buffer"))
1595 (if gnus-uu-post-inserted-file-name
1596 (setq file-name gnus-uu-post-inserted-file-name)
1597 (setq file-name (gnus-uu-post-insert-binary)))
1599 (if gnus-uu-post-threaded
1600 (let ((gnus-required-headers
1601 (if (memq 'Message-ID gnus-required-headers)
1602 gnus-required-headers
1603 (cons 'Message-ID gnus-required-headers)))
1604 gnus-inews-article-hook elem)
1606 (setq gnus-inews-article-hook (if (listp gnus-inews-article-hook)
1607 gnus-inews-article-hook
1608 (list gnus-inews-article-hook)))
1609 (setq gnus-inews-article-hook
1614 (if (re-search-forward "^Message-ID: \\(.*\\)$" nil t)
1615 (setq gnus-uu-post-message-id
1617 (match-beginning 1) (match-end 1)))
1618 (setq gnus-uu-post-message-id nil))))
1619 gnus-inews-article-hook))
1620 (gnus-uu-post-encoded file-name t))
1621 (gnus-uu-post-encoded file-name nil)))
1622 (setq gnus-uu-post-inserted-file-name nil)
1623 (and gnus-uu-winconf-post-news
1624 (set-window-configuration gnus-uu-winconf-post-news)))
1626 ;; Asks for a file to encode, encodes it and inserts the result in
1627 ;; the current buffer. Returns the file name the user gave.
1628 (defun gnus-uu-post-insert-binary ()
1629 (let ((uuencode-buffer-name "*uuencode buffer*")
1630 file-path post-buf uubuf file-name)
1632 (setq file-path (read-file-name
1633 "What file do you want to encode? "))
1634 (if (not (file-exists-p file-path))
1635 (error "%s: No such file" file-path))
1637 (goto-char (point-max))
1638 (insert (format "\n%s\n" gnus-uu-post-binary-separator))
1640 (if (string-match "^~/" file-path)
1641 (setq file-path (concat "$HOME" (substring file-path 1))))
1642 (if (string-match "/[^/]*$" file-path)
1643 (setq file-name (substring file-path (1+ (match-beginning 0))))
1644 (setq file-name file-path))
1648 (set-buffer (setq uubuf
1649 (get-buffer-create uuencode-buffer-name)))
1651 (funcall gnus-uu-post-encode-method file-path file-name))
1652 (insert-buffer uubuf)
1653 (error "Encoding unsuccessful"))
1654 (kill-buffer uubuf))
1657 ;; Posts the article and all of the encoded file.
1658 (defun gnus-uu-post-encoded (file-name &optional threaded)
1659 (let ((send-buffer-name "*uuencode send buffer*")
1660 (encoded-buffer-name "*encoded buffer*")
1661 (top-string "[ cut here %s (%s %d/%d) %s gnus-uu ]")
1662 (separator (concat mail-header-separator "\n\n"))
1663 file uubuf length parts header i end beg
1664 beg-line minlen buf post-buf whole-len beg-binary end-binary)
1666 (setq post-buf (current-buffer))
1669 (if (not (re-search-forward
1670 (if gnus-uu-post-separate-description
1671 gnus-uu-post-binary-separator
1672 (concat "^" (regexp-quote mail-header-separator) "$")) nil t))
1673 (error "Internal error: No binary/header separator"))
1676 (setq beg-binary (point))
1677 (setq end-binary (point-max))
1680 (set-buffer (setq uubuf (get-buffer-create encoded-buffer-name)))
1682 (insert-buffer-substring post-buf beg-binary end-binary)
1684 (setq length (count-lines 1 (point-max)))
1685 (setq parts (/ length gnus-uu-post-length))
1686 (if (not (< (% length gnus-uu-post-length) 4))
1687 (setq parts (1+ parts))))
1689 (if gnus-uu-post-separate-description
1691 (kill-region (point) (point-max))
1695 (concat "^" (regexp-quote mail-header-separator) "$") nil t)
1697 (setq header (buffer-substring 1 (point)))
1700 (if (not gnus-uu-post-separate-description)
1702 (if (and (not threaded) (re-search-forward "^Subject: " nil t))
1705 (insert (format " (0/%d)" parts))))
1711 (while (not (> i parts))
1712 (set-buffer (get-buffer-create send-buffer-name))
1715 (if (and threaded gnus-uu-post-message-id)
1716 (insert (format "References: %s\n" gnus-uu-post-message-id)))
1719 (- 62 (length (format top-string "" file-name i parts ""))))
1720 (if (> 1 (setq minlen (/ whole-len 2)))
1725 (make-string minlen ?-)
1728 (if (= 0 (% whole-len 2)) (1- minlen) minlen) ?-)))
1731 (if (not (re-search-forward "^Subject: " nil t))
1736 (insert (format " (%d/%d)" i parts)))
1737 (if (or (and (= i 2) gnus-uu-post-separate-description)
1738 (and (= i 1) (not gnus-uu-post-separate-description)))
1739 (replace-match "Subject: Re: "))))
1741 (goto-char (point-max))
1746 (goto-char (point-max))
1747 (forward-line gnus-uu-post-length))
1748 (if (and (= (1+ i) parts) (< (count-lines (point) (point-max)) 4))
1751 (insert-buffer-substring uubuf beg end)
1758 (concat "^" (regexp-quote mail-header-separator) "$") nil t)
1761 (if (re-search-forward gnus-uu-post-binary-separator nil t)
1769 (and (setq buf (get-buffer send-buffer-name))
1771 (and (setq buf (get-buffer encoded-buffer-name))
1774 (if (not gnus-uu-post-separate-description)
1776 (set-buffer-modified-p nil)
1777 (and (fboundp 'bury-buffer) (bury-buffer))))))
1781 ;; gnus-uu.el ends here