1 ;;; gnus-uu.el --- extract (uu)encoded files in Gnus
2 ;; Copyright (C) 1985, 1986, 1987, 1993, 1994, 1995, 1996, 1997, 1998, 2000,
3 ;; 2001 Free Software Foundation, Inc.
5 ;; Author: Lars Magne Ingebrigtsen <larsi@gnus.org>
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 the
23 ;; Free Software Foundation, Inc., 59 Temple Place - Suite 330,
24 ;; Boston, MA 02111-1307, USA.
30 (eval-when-compile (require 'cl))
38 (defgroup gnus-extract nil
39 "Extracting encoded files."
43 (defgroup gnus-extract-view nil
44 "Viewwing extracted files."
47 (defgroup gnus-extract-archive nil
48 "Extracting encoded archives."
51 (defgroup gnus-extract-post nil
52 "Extracting encoded archives."
53 :prefix "gnus-uu-post"
56 ;; Default viewing action rules
58 (defcustom gnus-uu-default-view-rules
59 '(("\\.te?xt$\\|\\.doc$\\|read.*me\\|\\.c?$\\|\\.h$\\|\\.bat$\\|\\.asm$\\|makefile" "cat %s | sed 's/\r$//'")
60 ("\\.pas$" "cat %s | sed 's/\r$//'")
61 ("\\.[1-9]$" "groff -mandoc -Tascii %s | sed s/\b.//g")
62 ("\\.\\(jpe?g\\|gif\\|tiff?\\|p[pgb]m\\|xwd\\|xbm\\|pcx\\)$" "display")
63 ("\\.tga$" "tgatoppm %s | ee -")
64 ("\\.\\(wav\\|aiff\\|hcom\\|u[blw]\\|s[bfw]\\|voc\\|smp\\)$"
65 "sox -v .5 %s -t .au -u - > /dev/audio")
66 ("\\.au$" "cat %s > /dev/audio")
67 ("\\.midi?$" "playmidi -f")
69 ("\\.ps$" "ghostview")
71 ("\\.html$" "xmosaic")
72 ("\\.mpe?g$" "mpeg_play")
73 ("\\.\\(flc\\|fli\\|rle\\|iff\\|pfx\\|avi\\|sme\\|rpza\\|dl\\|qt\\|rsrc\\|mov\\)$" "xanim")
74 ("\\.\\(tar\\|arj\\|zip\\|zoo\\|arc\\|gz\\|Z\\|lzh\\|ar\\|lha\\)$"
76 "*Default actions to be taken when the user asks to view a file.
77 To change the behaviour, you can either edit this variable or set
78 `gnus-uu-user-view-rules' to something useful.
82 To make gnus-uu use 'xli' to display JPEG and GIF files, put the
83 following in your .emacs file:
85 (setq gnus-uu-user-view-rules '((\"jpg$\\\\|gif$\" \"xli\")))
87 Both these variables are lists of lists with two string elements. The
88 first string is a regular expression. If the file name matches this
89 regular expression, the command in the second string is executed with
90 the file as an argument.
92 If the command string contains \"%s\", the file name will be inserted
93 at that point in the command string. If there's no \"%s\" in the
94 command string, the file name will be appended to the command string
97 There are several user variables to tailor the behaviour of gnus-uu to
98 your needs. First we have `gnus-uu-user-view-rules', which is the
99 variable gnus-uu first consults when trying to decide how to view a
100 file. If this variable contains no matches, gnus-uu examines the
101 default rule variable provided in this package. If gnus-uu finds no
102 match here, it uses `gnus-uu-user-view-rules-end' to try to make a
104 :group 'gnus-extract-view
105 :type '(repeat (group regexp (string :tag "Command"))))
107 (defcustom gnus-uu-user-view-rules nil
108 "What actions are to be taken to view a file.
109 See the documentation on the `gnus-uu-default-view-rules' variable for
111 :group 'gnus-extract-view
112 :type '(repeat (group regexp (string :tag "Command"))))
114 (defcustom gnus-uu-user-view-rules-end
116 "*What actions are to be taken if no rule matched the file name.
117 See the documentation on the `gnus-uu-default-view-rules' variable for
119 :group 'gnus-extract-view
120 :type '(repeat (group regexp (string :tag "Command"))))
122 ;; Default unpacking commands
124 (defcustom gnus-uu-default-archive-rules
125 '(("\\.tar$" "tar xf")
126 ("\\.zip$" "unzip -o")
128 ("\\.arj$" "unarj x")
130 ("\\.\\(lzh\\|lha\\)$" "lha x")
131 ("\\.Z$" "uncompress")
133 ("\\.arc$" "arc -x"))
134 "*See `gnus-uu-user-archive-rules'."
135 :group 'gnus-extract-archive
136 :type '(repeat (group regexp (string :tag "Command"))))
138 (defvar gnus-uu-destructive-archivers
139 (list "uncompress" "gunzip"))
141 (defcustom gnus-uu-user-archive-rules nil
142 "A list that can be set to override the default archive unpacking commands.
143 To use, for instance, 'untar' to unpack tar files and 'zip -x' to
144 unpack zip files, say the following:
145 (setq gnus-uu-user-archive-rules
146 '((\"\\\\.tar$\" \"untar\")
147 (\"\\\\.zip$\" \"zip -x\")))"
148 :group 'gnus-extract-archive
149 :type '(repeat (group regexp (string :tag "Command"))))
151 (defcustom gnus-uu-ignore-files-by-name nil
152 "*A regular expression saying what files should not be viewed based on name.
153 If, for instance, you want gnus-uu to ignore all .au and .wav files,
154 you could say something like
156 (setq gnus-uu-ignore-files-by-name \"\\\\.au$\\\\|\\\\.wav$\")
158 Note that this variable can be used in conjunction with the
159 `gnus-uu-ignore-files-by-type' variable."
161 :type '(choice (const :tag "off" nil)
162 (regexp :format "%v")))
164 (defcustom gnus-uu-ignore-files-by-type nil
165 "*A regular expression saying what files that shouldn't be viewed, based on MIME file type.
166 If, for instance, you want gnus-uu to ignore all audio files and all mpegs,
167 you could say something like
169 (setq gnus-uu-ignore-files-by-type \"audio/\\\\|video/mpeg\")
171 Note that this variable can be used in conjunction with the
172 `gnus-uu-ignore-files-by-name' variable."
174 :type '(choice (const :tag "off" nil)
175 (regexp :format "%v")))
177 ;; Pseudo-MIME support
179 (defconst gnus-uu-ext-to-mime-list
180 '(("\\.gif$" "image/gif")
181 ("\\.jpe?g$" "image/jpeg")
182 ("\\.tiff?$" "image/tiff")
183 ("\\.xwd$" "image/xwd")
184 ("\\.pbm$" "image/pbm")
185 ("\\.pgm$" "image/pgm")
186 ("\\.ppm$" "image/ppm")
187 ("\\.xbm$" "image/xbm")
188 ("\\.pcx$" "image/pcx")
189 ("\\.tga$" "image/tga")
190 ("\\.ps$" "image/postscript")
191 ("\\.fli$" "video/fli")
192 ("\\.wav$" "audio/wav")
193 ("\\.aiff$" "audio/aiff")
194 ("\\.hcom$" "audio/hcom")
195 ("\\.voc$" "audio/voc")
196 ("\\.smp$" "audio/smp")
197 ("\\.mod$" "audio/mod")
198 ("\\.dvi$" "image/dvi")
199 ("\\.mpe?g$" "video/mpeg")
200 ("\\.au$" "audio/basic")
201 ("\\.\\(te?xt\\|doc\\|c\\|h\\)$" "text/plain")
202 ("\\.\\(c\\|h\\)$" "text/source")
203 ("read.*me" "text/plain")
204 ("\\.html$" "text/html")
205 ("\\.bat$" "text/bat")
206 ("\\.[1-6]$" "text/man")
207 ("\\.flc$" "video/flc")
208 ("\\.rle$" "video/rle")
209 ("\\.pfx$" "video/pfx")
210 ("\\.avi$" "video/avi")
211 ("\\.sme$" "video/sme")
212 ("\\.rpza$" "video/prza")
213 ("\\.dl$" "video/dl")
214 ("\\.qt$" "video/qt")
215 ("\\.rsrc$" "video/rsrc")
216 ("\\..*$" "unknown/unknown")))
218 ;; Various variables users may set
220 (defcustom gnus-uu-tmp-dir
221 (cond ((fboundp 'temp-directory) (temp-directory))
222 ((boundp 'temporary-file-directory) temporary-file-directory)
224 "*Variable saying where gnus-uu is to do its work.
225 Default is \"/tmp/\"."
229 (defcustom gnus-uu-do-not-unpack-archives nil
230 "*Non-nil means that gnus-uu won't peek inside archives looking for files to display.
232 :group 'gnus-extract-archive
235 (defcustom gnus-uu-ignore-default-view-rules nil
236 "*Non-nil means that gnus-uu will ignore the default viewing rules.
237 Only the user viewing rules will be consulted. Default is nil."
238 :group 'gnus-extract-view
241 (defcustom gnus-uu-grabbed-file-functions nil
242 "Functions run on each file after successful decoding.
243 They will be called with the name of the file as the argument.
244 Likely functions you can use in this list are `gnus-uu-grab-view'
245 and `gnus-uu-grab-move'."
247 :options '(gnus-uu-grab-view gnus-uu-grab-move)
250 (defcustom gnus-uu-ignore-default-archive-rules nil
251 "*Non-nil means that gnus-uu will ignore the default archive unpacking commands.
252 Only the user unpacking commands will be consulted. Default is nil."
253 :group 'gnus-extract-archive
256 (defcustom gnus-uu-kill-carriage-return t
257 "*Non-nil means that gnus-uu will strip all carriage returns from articles.
262 (defcustom gnus-uu-view-with-metamail nil
263 "*Non-nil means that files will be viewed with metamail.
264 The gnus-uu viewing functions will be ignored and gnus-uu will try
265 to guess at a content-type based on file name suffixes. Default
270 (defcustom gnus-uu-unmark-articles-not-decoded nil
271 "*Non-nil means that gnus-uu will mark articles that were unsuccessfully decoded as unread.
276 (defcustom gnus-uu-correct-stripped-uucode nil
277 "*Non-nil means that gnus-uu will *try* to fix uuencoded files that have had trailing spaces deleted.
282 (defcustom gnus-uu-save-in-digest nil
283 "*Non-nil means that gnus-uu, when asked to save without decoding, will save in digests.
284 If this variable is nil, gnus-uu will just save everything in a
285 file without any embellishments. The digesting almost conforms to RFC1153 -
286 no easy way to specify any meaningful volume and issue numbers were found,
287 so I simply dropped them."
291 (defcustom gnus-uu-pre-uudecode-hook nil
292 "Hook run before sending a message to uudecode."
296 (defcustom gnus-uu-digest-headers
297 '("^Date:" "^From:" "^To:" "^Cc:" "^Subject:" "^Message-ID:" "^Keywords:"
298 "^Summary:" "^References:" "^Content-Type:" "^Content-Transfer-Encoding:"
299 "^MIME-Version:" "^Content-Disposition:" "^Content-Description:"
301 "*List of regexps to match headers included in digested messages.
302 The headers will be included in the sequence they are matched."
304 :type '(repeat regexp))
306 (defcustom gnus-uu-save-separate-articles nil
307 "*Non-nil means that gnus-uu will save articles in separate files."
311 (defcustom gnus-uu-be-dangerous 'ask
312 "*Specifies what to do if unusual situations arise during decoding.
313 If nil, be as conservative as possible. If t, ignore things that
314 didn't work, and overwrite existing files. Otherwise, ask each time."
316 :type '(choice (const :tag "conservative" nil)
317 (const :tag "ask" ask)
318 (const :tag "liberal" t)))
320 ;; Internal variables
322 (defvar gnus-uu-saved-article-name nil)
324 (defvar gnus-uu-begin-string "^begin[ \t]+[0-7][0-7][0-7][ \t]+\\(.*\\)$")
325 (defvar gnus-uu-end-string "^end[ \t]*$")
327 (defvar gnus-uu-body-line "^M")
329 (while (> (setq i (1- i)) 0)
330 (setq gnus-uu-body-line (concat gnus-uu-body-line "[^a-z]")))
331 (setq gnus-uu-body-line (concat gnus-uu-body-line ".?$")))
333 ;"^M.............................................................?$"
335 (defvar gnus-uu-shar-begin-string "^#! */bin/sh")
337 (defvar gnus-uu-shar-file-name nil)
338 (defvar gnus-uu-shar-name-marker
339 "begin [0-7][0-7][0-7][ \t]+\\(\\(\\w\\|\\.\\)*\\b\\)")
341 (defvar gnus-uu-postscript-begin-string "^%!PS-")
342 (defvar gnus-uu-postscript-end-string "^%%EOF$")
344 (defvar gnus-uu-file-name nil)
345 (defvar gnus-uu-uudecode-process nil)
346 (defvar gnus-uu-binhex-article-name nil)
348 (defvar gnus-uu-work-dir nil)
350 (defvar gnus-uu-output-buffer-name " *Gnus UU Output*")
352 (defvar gnus-uu-default-dir gnus-article-save-directory)
353 (defvar gnus-uu-digest-from-subject nil)
354 (defvar gnus-uu-digest-buffer nil)
358 (gnus-define-keys (gnus-uu-mark-map "P" gnus-summary-mark-map)
359 "p" gnus-summary-mark-as-processable
360 "u" gnus-summary-unmark-as-processable
361 "U" gnus-summary-unmark-all-processable
362 "v" gnus-uu-mark-over
363 "s" gnus-uu-mark-series
364 "r" gnus-uu-mark-region
365 "g" gnus-uu-unmark-region
366 "R" gnus-uu-mark-by-regexp
367 "G" gnus-uu-unmark-by-regexp
368 "t" gnus-uu-mark-thread
369 "T" gnus-uu-unmark-thread
371 "b" gnus-uu-mark-buffer
372 "S" gnus-uu-mark-sparse
373 "k" gnus-summary-kill-process-mark
374 "y" gnus-summary-yank-process-mark
375 "w" gnus-summary-save-process-mark
376 "i" gnus-uu-invert-processable)
378 (gnus-define-keys (gnus-uu-extract-map "X" gnus-summary-mode-map)
379 ;;"x" gnus-uu-extract-any
380 "m" gnus-summary-save-parts
381 "u" gnus-uu-decode-uu
382 "U" gnus-uu-decode-uu-and-save
383 "s" gnus-uu-decode-unshar
384 "S" gnus-uu-decode-unshar-and-save
385 "o" gnus-uu-decode-save
386 "O" gnus-uu-decode-save
387 "b" gnus-uu-decode-binhex
388 "B" gnus-uu-decode-binhex
389 "p" gnus-uu-decode-postscript
390 "P" gnus-uu-decode-postscript-and-save)
393 (gnus-uu-extract-view-map "v" gnus-uu-extract-map)
394 "u" gnus-uu-decode-uu-view
395 "U" gnus-uu-decode-uu-and-save-view
396 "s" gnus-uu-decode-unshar-view
397 "S" gnus-uu-decode-unshar-and-save-view
398 "o" gnus-uu-decode-save-view
399 "O" gnus-uu-decode-save-view
400 "b" gnus-uu-decode-binhex-view
401 "B" gnus-uu-decode-binhex-view
402 "p" gnus-uu-decode-postscript-view
403 "P" gnus-uu-decode-postscript-and-save-view)
408 (defun gnus-uu-decode-uu (&optional n)
409 "Uudecodes the current article."
411 (gnus-uu-decode-with-method 'gnus-uu-uustrip-article n))
413 (defun gnus-uu-decode-uu-and-save (n dir)
414 "Decodes and saves the resulting file."
416 (list current-prefix-arg
417 (file-name-as-directory
418 (read-file-name "Uudecode and save in dir: "
420 gnus-uu-default-dir t))))
421 (gnus-uu-decode-with-method 'gnus-uu-uustrip-article n dir nil nil t))
423 (defun gnus-uu-decode-unshar (&optional n)
424 "Unshars the current article."
426 (gnus-uu-decode-with-method 'gnus-uu-unshar-article n nil nil 'scan t))
428 (defun gnus-uu-decode-unshar-and-save (n dir)
429 "Unshars and saves the current article."
431 (list current-prefix-arg
432 (file-name-as-directory
433 (read-file-name "Unshar and save in dir: "
435 gnus-uu-default-dir t))))
436 (gnus-uu-decode-with-method 'gnus-uu-unshar-article n dir nil 'scan t))
438 (defun gnus-uu-decode-save (n file)
439 "Saves the current article."
441 (list current-prefix-arg
443 (if gnus-uu-save-separate-articles
444 "Save articles is dir: "
445 "Save articles in file: ")
447 gnus-uu-default-dir)))
448 (setq gnus-uu-saved-article-name file)
449 (gnus-uu-decode-with-method 'gnus-uu-save-article n nil t))
451 (defun gnus-uu-decode-binhex (n dir)
452 "Unbinhexes the current article."
454 (list current-prefix-arg
455 (file-name-as-directory
456 (read-file-name "Unbinhex and save in dir: "
458 gnus-uu-default-dir))))
459 (setq gnus-uu-binhex-article-name
460 (make-temp-name (concat gnus-uu-work-dir "binhex")))
461 (gnus-uu-decode-with-method 'gnus-uu-binhex-article n dir))
463 (defun gnus-uu-decode-uu-view (&optional n)
464 "Uudecodes and views the current article."
466 (let ((gnus-view-pseudos (or gnus-view-pseudos 'automatic)))
467 (gnus-uu-decode-uu n)))
469 (defun gnus-uu-decode-uu-and-save-view (n dir)
470 "Decodes, views and saves the resulting file."
472 (list current-prefix-arg
473 (read-file-name "Uudecode, view and save in dir: "
475 gnus-uu-default-dir t)))
476 (let ((gnus-view-pseudos (or gnus-view-pseudos 'automatic)))
477 (gnus-uu-decode-uu-and-save n dir)))
479 (defun gnus-uu-decode-unshar-view (&optional n)
480 "Unshars and views the current article."
482 (let ((gnus-view-pseudos (or gnus-view-pseudos 'automatic)))
483 (gnus-uu-decode-unshar n)))
485 (defun gnus-uu-decode-unshar-and-save-view (n dir)
486 "Unshars and saves the current article."
488 (list current-prefix-arg
489 (read-file-name "Unshar, view and save in dir: "
491 gnus-uu-default-dir t)))
492 (let ((gnus-view-pseudos (or gnus-view-pseudos 'automatic)))
493 (gnus-uu-decode-unshar-and-save n dir)))
495 (defun gnus-uu-decode-save-view (n file)
496 "Saves and views the current article."
498 (list current-prefix-arg
499 (read-file-name (if gnus-uu-save-separate-articles
500 "Save articles is dir: "
501 "Save articles in file: ")
502 gnus-uu-default-dir gnus-uu-default-dir)))
503 (let ((gnus-view-pseudos (or gnus-view-pseudos 'automatic)))
504 (gnus-uu-decode-save n file)))
506 (defun gnus-uu-decode-binhex-view (n file)
507 "Unbinhexes and views the current article."
509 (list current-prefix-arg
510 (read-file-name "Unbinhex, view and save in dir: "
511 gnus-uu-default-dir gnus-uu-default-dir)))
512 (setq gnus-uu-binhex-article-name
513 (make-temp-name (concat gnus-uu-work-dir "binhex")))
514 (let ((gnus-view-pseudos (or gnus-view-pseudos 'automatic)))
515 (gnus-uu-decode-binhex n file)))
518 ;; Digest and forward articles
520 (defun gnus-uu-digest-mail-forward (&optional n post)
521 "Digests and forwards all articles in this series."
523 (let ((gnus-uu-save-in-digest t)
524 (file (make-temp-name (nnheader-concat gnus-uu-tmp-dir "forward")))
525 (message-forward-as-mime message-forward-as-mime)
526 (mail-parse-charset gnus-newsgroup-charset)
527 (mail-parse-ignored-charsets gnus-newsgroup-ignored-charsets)
528 gnus-uu-digest-buffer subject from)
529 (if (and n (not (numberp n)))
530 (setq message-forward-as-mime (not message-forward-as-mime)
532 (let ((gnus-article-reply (gnus-summary-work-articles n)))
533 (gnus-setup-message 'forward
534 (setq gnus-uu-digest-from-subject nil)
535 (setq gnus-uu-digest-buffer
536 (gnus-get-buffer-create " *gnus-uu-forward*"))
537 (gnus-uu-decode-save n file)
538 (switch-to-buffer gnus-uu-digest-buffer)
539 (let ((fs gnus-uu-digest-from-subject))
542 subject (gnus-simplify-subject-fuzzy (cdar fs))
544 (while (and fs (or from subject))
546 (unless (string= from (caar fs))
549 (unless (string= (gnus-simplify-subject-fuzzy (cdar fs))
554 (setq subject "Digested Articles"))
557 (if (gnus-news-group-p gnus-newsgroup-name)
560 (goto-char (point-min))
561 (when (re-search-forward "^Subject: ")
562 (delete-region (point) (gnus-point-at-eol))
564 (goto-char (point-min))
565 (when (re-search-forward "^From:")
566 (delete-region (point) (gnus-point-at-eol))
568 (let ((message-forward-decoded-p t))
569 (message-forward post t))))
570 (setq gnus-uu-digest-from-subject nil)))
572 (defun gnus-uu-digest-post-forward (&optional n)
573 "Digest and forward to a newsgroup."
575 (gnus-uu-digest-mail-forward n t))
579 (defun gnus-message-process-mark (unmarkp new-marked)
580 (let ((old (- (length gnus-newsgroup-processable) (length new-marked))))
581 (message "%d mark%s %s%s"
583 (if (= (length new-marked) 1) "" "s")
584 (if unmarkp "removed" "added")
590 (format ", %d remain marked"
591 (length gnus-newsgroup-processable)))
593 (format ", %d already marked" old))))))
595 (defun gnus-new-processable (unmarkp articles)
597 (gnus-intersection gnus-newsgroup-processable articles)
598 (gnus-set-difference articles gnus-newsgroup-processable)))
600 (defun gnus-uu-mark-by-regexp (regexp &optional unmark)
601 "Set the process mark on articles whose subjects match REGEXP.
602 When called interactively, prompt for REGEXP.
603 Optional UNMARK non-nil means unmark instead of mark."
604 (interactive "sMark (regexp): \nP")
606 (let* ((articles (gnus-uu-find-articles-matching regexp))
607 (new-marked (gnus-new-processable unmark articles)))
610 (gnus-summary-remove-process-mark (pop articles))
611 (gnus-summary-set-process-mark (pop articles))))
612 (gnus-message-process-mark unmark new-marked)))
613 (gnus-summary-position-point))
615 (defun gnus-uu-unmark-by-regexp (regexp)
616 "Remove the process mark from articles whose subjects match REGEXP.
617 When called interactively, prompt for REGEXP."
618 (interactive "sUnmark (regexp): ")
619 (gnus-uu-mark-by-regexp regexp t))
621 (defun gnus-uu-mark-series ()
622 "Mark the current series with the process mark."
624 (let ((articles (gnus-uu-find-articles-matching)))
626 (gnus-summary-set-process-mark (car articles))
627 (setq articles (cdr articles)))
629 (gnus-summary-position-point))
631 (defun gnus-uu-mark-region (beg end &optional unmark)
632 "Set the process mark on all articles between point and mark."
636 (while (< (point) end)
638 (gnus-summary-remove-process-mark (gnus-summary-article-number))
639 (gnus-summary-set-process-mark (gnus-summary-article-number)))
641 (gnus-summary-position-point))
643 (defun gnus-uu-unmark-region (beg end)
644 "Remove the process mark from all articles between point and mark."
646 (gnus-uu-mark-region beg end t))
648 (defun gnus-uu-mark-buffer ()
649 "Set the process mark on all articles in the buffer."
651 (gnus-uu-mark-region (point-min) (point-max)))
653 (defun gnus-uu-unmark-buffer ()
654 "Remove the process mark on all articles in the buffer."
656 (gnus-uu-mark-region (point-min) (point-max) t))
658 (defun gnus-uu-mark-thread ()
659 "Marks all articles downwards in this thread."
661 (gnus-save-hidden-threads
662 (let ((level (gnus-summary-thread-level)))
663 (while (and (gnus-summary-set-process-mark
664 (gnus-summary-article-number))
665 (zerop (gnus-summary-next-subject 1 nil t))
666 (> (gnus-summary-thread-level) level)))))
667 (gnus-summary-position-point))
669 (defun gnus-uu-unmark-thread ()
670 "Unmarks all articles downwards in this thread."
672 (let ((level (gnus-summary-thread-level)))
673 (while (and (gnus-summary-remove-process-mark
674 (gnus-summary-article-number))
675 (zerop (gnus-summary-next-subject 1))
676 (> (gnus-summary-thread-level) level))))
677 (gnus-summary-position-point))
679 (defun gnus-uu-invert-processable ()
680 "Invert the list of process-marked articles."
682 (let ((data gnus-newsgroup-data)
686 (if (memq (setq number (gnus-data-number (pop data)))
687 gnus-newsgroup-processable)
688 (gnus-summary-remove-process-mark number)
689 (gnus-summary-set-process-mark number)))))
690 (gnus-summary-position-point))
692 (defun gnus-uu-mark-over (&optional score)
693 "Mark all articles with a score over SCORE (the prefix)."
695 (let ((score (or score gnus-summary-default-score 0))
696 (data gnus-newsgroup-data))
699 (when (> (or (cdr (assq (gnus-data-number (car data))
700 gnus-newsgroup-scored))
701 gnus-summary-default-score 0)
703 (gnus-summary-set-process-mark (caar data)))
704 (setq data (cdr data))))
705 (gnus-summary-position-point)))
707 (defun gnus-uu-mark-sparse ()
708 "Mark all series that have some articles marked."
710 (let ((marked (nreverse gnus-newsgroup-processable))
711 subject articles total headers)
713 (error "No articles marked with the process mark"))
714 (setq gnus-newsgroup-processable nil)
717 (and (vectorp (setq headers
718 (gnus-summary-article-header (car marked))))
719 (setq subject (mail-header-subject headers)
720 articles (gnus-uu-find-articles-matching
721 (gnus-uu-reginize-string subject))
722 total (nconc total articles)))
724 (gnus-summary-set-process-mark (car articles))
725 (setcdr marked (delq (car articles) (cdr marked)))
726 (setq articles (cdr articles)))
727 (setq marked (cdr marked)))
728 (setq gnus-newsgroup-processable (nreverse total)))
729 (gnus-summary-position-point)))
731 (defun gnus-uu-mark-all ()
732 "Mark all articles in \"series\" order."
734 (setq gnus-newsgroup-processable nil)
736 (let ((data gnus-newsgroup-data)
739 (when (and (not (memq (setq number (gnus-data-number (car data)))
740 gnus-newsgroup-processable))
741 (vectorp (gnus-data-header (car data))))
742 (gnus-summary-goto-subject number)
743 (gnus-uu-mark-series))
744 (setq data (cdr data)))))
745 (gnus-summary-position-point))
747 ;; All PostScript functions written by Erik Selberg <speed@cs.washington.edu>.
749 (defun gnus-uu-decode-postscript (&optional n)
750 "Gets postscript of the current article."
752 (gnus-uu-decode-with-method 'gnus-uu-decode-postscript-article n))
754 (defun gnus-uu-decode-postscript-view (&optional n)
755 "Gets and views the current article."
757 (let ((gnus-view-pseudos (or gnus-view-pseudos 'automatic)))
758 (gnus-uu-decode-postscript n)))
760 (defun gnus-uu-decode-postscript-and-save (n dir)
761 "Extracts postscript and saves the current article."
763 (list current-prefix-arg
764 (file-name-as-directory
765 (read-file-name "Save in dir: "
767 gnus-uu-default-dir t))))
768 (gnus-uu-decode-with-method 'gnus-uu-decode-postscript-article
771 (defun gnus-uu-decode-postscript-and-save-view (n dir)
772 "Decodes, views and saves the resulting file."
774 (list current-prefix-arg
775 (read-file-name "Where do you want to save the file(s)? "
777 gnus-uu-default-dir t)))
778 (let ((gnus-view-pseudos (or gnus-view-pseudos 'automatic)))
779 (gnus-uu-decode-postscript-and-save n dir)))
782 ;; Internal functions.
784 (defun gnus-uu-decode-with-method (method n &optional save not-insert
786 (gnus-uu-initialize scan)
788 (setq gnus-uu-default-dir save))
789 ;; Create the directory we save to.
790 (when (and scan cdir save
791 (not (file-exists-p save)))
792 (make-directory save t))
793 (let ((articles (gnus-uu-get-list-of-articles n))
795 (setq files (gnus-uu-grab-articles articles method t))
796 (let ((gnus-current-article (car articles)))
798 (setq files (gnus-uu-scan-directory gnus-uu-work-dir))))
800 (gnus-uu-save-files files save))
801 (when (eq gnus-uu-do-not-unpack-archives nil)
802 (setq files (gnus-uu-unpack-files files)))
803 (setq files (nreverse (gnus-uu-get-actions files)))
804 (or not-insert (not gnus-insert-pseudo-articles)
805 (gnus-summary-insert-pseudos files save))))
807 (defun gnus-uu-scan-directory (dir &optional rec)
808 "Return a list of all files under DIR."
809 (let ((files (directory-files dir t))
811 (while (setq file (pop files))
812 (unless (member (file-name-nondirectory file) '("." ".."))
813 (push (list (cons 'name file)
814 (cons 'article gnus-current-article))
816 (when (file-directory-p file)
817 (setq out (nconc (gnus-uu-scan-directory file t) out)))))
822 (defun gnus-uu-save-files (files dir)
824 (let ((len (length files))
825 (reg (concat "^" (regexp-quote gnus-uu-work-dir)))
826 to-file file fromdir)
827 (while (setq file (cdr (assq 'name (pop files))))
828 (when (file-exists-p file)
829 (string-match reg file)
830 (setq fromdir (substring file (match-end 0)))
831 (if (file-directory-p file)
832 (gnus-make-directory (concat dir fromdir))
833 (setq to-file (concat dir fromdir))
834 (when (or (not (file-exists-p to-file))
835 (eq gnus-uu-be-dangerous t)
836 (and gnus-uu-be-dangerous
837 (gnus-y-or-n-p (format "%s exists; overwrite? "
839 (copy-file file to-file t t)))))
840 (gnus-message 5 "Saved %d file%s" len (if (= len 1) "" "s"))))
842 ;; Functions for saving and possibly digesting articles without
845 ;; Function called by gnus-uu-grab-articles to treat each article.
846 (defun gnus-uu-save-article (buffer in-state)
848 (gnus-uu-save-separate-articles
851 (let ((coding-system-for-write mm-text-coding-system))
853 (concat gnus-uu-saved-article-name gnus-current-article)))
854 (cond ((eq in-state 'first) (list gnus-uu-saved-article-name 'begin))
855 ((eq in-state 'first-and-last) (list gnus-uu-saved-article-name
857 ((eq in-state 'last) (list 'end))
858 (t (list 'middle)))))
859 ((not gnus-uu-save-in-digest)
862 (write-region (point-min) (point-max) gnus-uu-saved-article-name t)
863 (cond ((eq in-state 'first) (list gnus-uu-saved-article-name 'begin))
864 ((eq in-state 'first-and-last) (list gnus-uu-saved-article-name
866 ((eq in-state 'last) (list 'end))
867 (t (list 'middle)))))
869 (let ((header (gnus-summary-article-header)))
870 (push (cons (mail-header-from header)
871 (mail-header-subject header))
872 gnus-uu-digest-from-subject))
873 (let ((name (file-name-nondirectory gnus-uu-saved-article-name))
874 beg subj headers headline sorthead body end-string state)
875 (if (or (eq in-state 'first)
876 (eq in-state 'first-and-last))
878 (setq state (list 'begin))
880 (set-buffer (gnus-get-buffer-create "*gnus-uu-body*"))
883 (set-buffer (gnus-get-buffer-create "*gnus-uu-pre*"))
886 "Date: %s\nFrom: %s\nSubject: %s Digest\n\n"
887 (current-time-string) name name))
888 (when (and message-forward-as-mime gnus-uu-digest-buffer)
889 (insert "<#mml type=message/rfc822>\nSubject: Topics\n\n"))
890 (insert "Topics:\n")))
891 (when (not (eq in-state 'end))
892 (setq state (list 'middle))))
894 (set-buffer "*gnus-uu-body*")
895 (goto-char (setq beg (point-max)))
899 (let (buffer-read-only)
900 (gnus-set-text-properties (point-min) (point-max) nil)
901 ;; These two are necessary for XEmacs 19.12 fascism.
902 (put-text-property (point-min) (point-max) 'invisible nil)
903 (put-text-property (point-min) (point-max) 'intangible nil))
904 (when (and message-forward-as-mime
905 message-forward-show-mml
906 gnus-uu-digest-buffer)
907 (mm-enable-multibyte)
909 (goto-char (point-min))
910 (re-search-forward "\n\n")
911 (unless (and message-forward-as-mime gnus-uu-digest-buffer)
912 ;; Quote all 30-dash lines.
914 (while (re-search-forward "^-" nil t)
918 (setq body (buffer-substring (1- (point)) (point-max)))
919 (narrow-to-region (point-min) (point))
920 (if (not (setq headers gnus-uu-digest-headers))
921 (setq sorthead (buffer-substring (point-min) (point-max)))
923 (setq headline (car headers))
924 (setq headers (cdr headers))
925 (goto-char (point-min))
926 (while (re-search-forward headline nil t)
931 (or (and (re-search-forward "^[^ \t]" nil t)
933 (progn (forward-line 1) (point)))))))))
935 (if (and message-forward-as-mime gnus-uu-digest-buffer)
936 (if message-forward-show-mml
938 (insert "\n<#mml type=message/rfc822>\n")
939 (insert sorthead) (goto-char (point-max))
940 (insert body) (goto-char (point-max))
941 (insert "\n<#/mml>\n"))
942 (let ((buf (mml-generate-new-buffer " *mml*")))
943 (with-current-buffer buf
945 (goto-char (point-min))
946 (when (re-search-forward "^Subject: \\(.*\\)$" nil t)
947 (setq subj (buffer-substring (match-beginning 1)
949 (goto-char (point-max))
951 (insert "\n<#part type=message/rfc822"
952 " buffer=\"" (buffer-name buf) "\">\n")))
953 (insert sorthead) (goto-char (point-max))
954 (insert body) (goto-char (point-max))
955 (insert (concat "\n" (make-string 30 ?-) "\n\n")))
957 (when (re-search-forward "^Subject: \\(.*\\)$" nil t)
958 (setq subj (buffer-substring (match-beginning 1) (match-end 1))))
961 (set-buffer "*gnus-uu-pre*")
962 (insert (format " %s\n" subj)))))
963 (when (or (eq in-state 'last)
964 (eq in-state 'first-and-last))
965 (if (and message-forward-as-mime gnus-uu-digest-buffer)
966 (with-current-buffer gnus-uu-digest-buffer
968 (insert-buffer "*gnus-uu-pre*")
969 (goto-char (point-max))
970 (insert-buffer "*gnus-uu-body*"))
972 (set-buffer "*gnus-uu-pre*")
973 (insert (format "\n\n%s\n\n" (make-string 70 ?-)))
974 (if gnus-uu-digest-buffer
975 (with-current-buffer gnus-uu-digest-buffer
977 (insert-buffer "*gnus-uu-pre*"))
978 (let ((coding-system-for-write mm-text-coding-system))
979 (gnus-write-buffer gnus-uu-saved-article-name))))
981 (set-buffer "*gnus-uu-body*")
982 (goto-char (point-max))
984 (concat (setq end-string (format "End of %s Digest" name))
986 (insert (concat (make-string (length end-string) ?*) "\n"))
987 (if gnus-uu-digest-buffer
988 (with-current-buffer gnus-uu-digest-buffer
989 (goto-char (point-max))
990 (insert-buffer "*gnus-uu-body*"))
991 (let ((coding-system-for-write mm-text-coding-system)
992 (file-name-coding-system nnmail-pathname-coding-system))
994 (point-min) (point-max) gnus-uu-saved-article-name t)))))
995 (gnus-kill-buffer "*gnus-uu-pre*")
996 (gnus-kill-buffer "*gnus-uu-body*")
998 (if (memq 'begin state)
999 (cons gnus-uu-saved-article-name state)
1002 ;; Binhex treatment - not very advanced.
1004 (defvar gnus-uu-binhex-body-line
1005 "^[^:]...............................................................$")
1006 (defvar gnus-uu-binhex-begin-line
1007 "^:...............................................................$")
1008 (defvar gnus-uu-binhex-end-line
1011 (defun gnus-uu-binhex-article (buffer in-state)
1012 (let (state start-char)
1016 (goto-char (point-min))
1017 (when (not (re-search-forward gnus-uu-binhex-begin-line nil t))
1018 (when (not (re-search-forward gnus-uu-binhex-body-line nil t))
1019 (setq state (list 'wrong-type))))
1021 (if (memq 'wrong-type state)
1024 (setq start-char (point))
1025 (if (looking-at gnus-uu-binhex-begin-line)
1027 (setq state (list 'begin))
1028 (write-region 1 1 gnus-uu-binhex-article-name))
1029 (setq state (list 'middle)))
1030 (goto-char (point-max))
1031 (re-search-backward (concat gnus-uu-binhex-body-line "\\|"
1032 gnus-uu-binhex-end-line)
1034 (when (looking-at gnus-uu-binhex-end-line)
1035 (setq state (if (memq 'begin state)
1040 (when (file-exists-p gnus-uu-binhex-article-name)
1041 (mm-append-to-file start-char (point) gnus-uu-binhex-article-name))))
1042 (if (memq 'begin state)
1043 (cons gnus-uu-binhex-article-name state)
1048 (defun gnus-uu-decode-postscript-article (process-buffer in-state)
1049 (let ((state (list 'ok))
1050 start-char end-char file-name)
1052 (set-buffer process-buffer)
1053 (goto-char (point-min))
1054 (if (not (re-search-forward gnus-uu-postscript-begin-string nil t))
1055 (setq state (list 'wrong-type))
1057 (setq start-char (point))
1058 (if (not (re-search-forward gnus-uu-postscript-end-string nil t))
1059 (setq state (list 'wrong-type))
1060 (setq end-char (point))
1061 (set-buffer (gnus-get-buffer-create gnus-uu-output-buffer-name))
1062 (insert-buffer-substring process-buffer start-char end-char)
1063 (setq file-name (concat gnus-uu-work-dir
1064 (cdr gnus-article-current) ".ps"))
1065 (write-region (point-min) (point-max) file-name)
1066 (setq state (list file-name 'begin 'end)))))
1072 (defun gnus-uu-get-actions (files)
1073 (let ((ofiles files)
1076 (setq name (cdr (assq 'name (car files))))
1078 (setq action (gnus-uu-get-action name))
1079 (setcar files (nconc (list (if (string= action "gnus-uu-archive")
1080 (cons 'action "file")
1081 (cons 'action action))
1082 (cons 'execute (gnus-uu-command
1085 (setq files (cdr files)))
1088 (defun gnus-uu-get-action (file-name)
1091 (gnus-uu-choose-action
1094 gnus-uu-user-view-rules
1095 (if gnus-uu-ignore-default-view-rules
1097 gnus-uu-default-view-rules)
1098 gnus-uu-user-view-rules-end)))
1099 (when (and (not (string= (or action "") "gnus-uu-archive"))
1100 gnus-uu-view-with-metamail)
1102 (gnus-uu-choose-action file-name gnus-uu-ext-to-mime-list))
1103 (setq action (format "metamail -d -b -c \"%s\"" action))))
1107 ;; Functions for treating subjects and collecting series.
1109 (defun gnus-uu-reginize-string (string)
1110 ;; Takes a string and puts a \ in front of every special character;
1111 ;; replaces the last thing that looks like "2/3" with "[0-9]+/3"
1112 ;; or, if it can't find something like that, tries "2 of 3", then
1113 ;; finally just replaces the next to last number with "[0-9]+".
1115 (set-buffer (gnus-get-buffer-create gnus-uu-output-buffer-name))
1116 (buffer-disable-undo)
1118 (insert (regexp-quote string))
1120 (setq case-fold-search nil)
1123 (if (re-search-backward "\\([^0-9]\\)[0-9]+/\\([0-9]+\\)" nil t)
1124 (replace-match "\\1[0-9]+/\\2")
1127 (if (re-search-backward "\\([^0-9]\\)[0-9]+[ \t]*of[ \t]*\\([0-9]+\\)"
1129 (replace-match "\\1[0-9]+ of \\2")
1132 (if (re-search-backward "\\([^0-9]\\)[0-9]+\\([^0-9]+\\)[0-9]+"
1134 (replace-match "\\1[0-9]+\\2[0-9]+" t nil nil nil))))
1137 (while (re-search-forward "[ \t]+" nil t)
1138 (replace-match "[ \t]+" t t))
1140 (buffer-substring 1 (point-max))))
1142 (defun gnus-uu-get-list-of-articles (n)
1143 ;; If N is non-nil, the article numbers of the N next articles
1144 ;; will be returned.
1145 ;; If any articles have been marked as processable, they will be
1147 ;; Failing that, articles that have subjects that are part of the
1148 ;; same "series" as the current will be returned.
1152 (setq n (prefix-numeric-value n))
1153 (let ((backward (< n 0))
1157 (push (gnus-summary-article-number)
1159 (gnus-summary-search-forward nil nil backward))
1161 (nreverse articles)))
1162 (gnus-newsgroup-processable
1163 (reverse gnus-newsgroup-processable))
1165 (gnus-uu-find-articles-matching)))))
1167 (defun gnus-uu-string< (l1 l2)
1168 (string< (car l1) (car l2)))
1170 (defun gnus-uu-find-articles-matching
1171 (&optional subject only-unread do-not-translate)
1172 ;; Finds all articles that matches the regexp SUBJECT. If it is
1173 ;; nil, the current article name will be used. If ONLY-UNREAD is
1174 ;; non-nil, only unread articles are chosen. If DO-NOT-TRANSLATE is
1175 ;; non-nil, article names are not equalized before sorting.
1176 (let ((subject (or subject
1177 (gnus-uu-reginize-string (gnus-summary-article-subject))))
1181 ;; Collect all subjects matching subject.
1182 (let ((case-fold-search t)
1183 (data gnus-newsgroup-data)
1187 (and (not (gnus-data-pseudo-p d))
1188 (or (not only-unread)
1189 (= (setq mark (gnus-data-mark d))
1191 (= mark gnus-ticked-mark)
1192 (= mark gnus-dormant-mark))
1193 (setq subj (mail-header-subject (gnus-data-header d)))
1194 (string-match subject subj)
1195 (push (cons subj (gnus-data-number d))
1196 list-of-subjects))))
1198 ;; Expand numbers, sort, and return the list of article
1200 (mapcar (lambda (sub) (cdr sub))
1201 (sort (gnus-uu-expand-numbers
1203 (not do-not-translate))
1204 'gnus-uu-string<))))))
1206 (defun gnus-uu-expand-numbers (string-list &optional translate)
1207 ;; Takes a list of strings and "expands" all numbers in all the
1208 ;; strings. That is, this function makes all numbers equal length by
1209 ;; prepending lots of zeroes before each number. This is to ease later
1210 ;; sorting to find out what sequence the articles are supposed to be
1211 ;; decoded in. Returns the list of expanded strings.
1212 (let ((out-list string-list)
1215 (set-buffer (gnus-get-buffer-create gnus-uu-output-buffer-name))
1216 (buffer-disable-undo)
1219 (insert (caar string-list))
1220 ;; Translate multiple spaces to one space.
1221 (goto-char (point-min))
1222 (while (re-search-forward "[ \t]+" nil t)
1223 (replace-match " "))
1224 ;; Translate all characters to "a".
1225 (goto-char (point-min))
1227 (while (re-search-forward "[A-Za-z]" nil t)
1228 (replace-match "a" t t)))
1230 (goto-char (point-min))
1231 (while (re-search-forward "[0-9]+" nil t)
1234 (string-to-int (buffer-substring
1235 (match-beginning 0) (match-end 0))))))
1236 (setq string (buffer-substring 1 (point-max)))
1237 (setcar (car string-list) string)
1238 (setq string-list (cdr string-list))))
1242 ;; `gnus-uu-grab-articles' is the general multi-article treatment
1243 ;; function. It takes a list of articles to be grabbed and a function
1244 ;; to apply to each article.
1246 ;; The function to be called should take two parameters. The first
1247 ;; parameter is the article buffer. The function should leave the
1248 ;; result, if any, in this buffer. Most treatment functions will just
1249 ;; generate files...
1251 ;; The second parameter is the state of the list of articles, and can
1252 ;; have four values: `first', `middle', `last' and `first-and-last'.
1254 ;; The function should return a list. The list may contain the
1255 ;; following symbols:
1256 ;; `error' if an error occurred
1257 ;; `begin' if the beginning of an encoded file has been received
1258 ;; If the list returned contains a `begin', the first element of
1259 ;; the list *must* be a string with the file name of the decoded
1261 ;; `end' if the end of an encoded file has been received
1262 ;; `middle' if the article was a body part of an encoded file
1263 ;; `wrong-type' if the article was not a part of an encoded file
1264 ;; `ok', which can be used everything is ok
1266 (defvar gnus-uu-has-been-grabbed nil)
1268 (defun gnus-uu-unmark-list-of-grabbed (&optional dont-unmark-last-article)
1270 (if (not (and gnus-uu-has-been-grabbed
1271 gnus-uu-unmark-articles-not-decoded))
1273 (when dont-unmark-last-article
1274 (setq art (car gnus-uu-has-been-grabbed))
1275 (setq gnus-uu-has-been-grabbed (cdr gnus-uu-has-been-grabbed)))
1276 (while gnus-uu-has-been-grabbed
1277 (gnus-summary-tick-article (car gnus-uu-has-been-grabbed) t)
1278 (setq gnus-uu-has-been-grabbed (cdr gnus-uu-has-been-grabbed)))
1279 (when dont-unmark-last-article
1280 (setq gnus-uu-has-been-grabbed (list art))))))
1282 ;; This function takes a list of articles and a function to apply to
1283 ;; each article grabbed.
1285 ;; This function returns a list of files decoded if the grabbing and
1286 ;; the process-function has been successful and nil otherwise.
1287 (defun gnus-uu-grab-articles (articles process-function
1288 &optional sloppy limit no-errors)
1289 (let ((state 'first)
1290 (gnus-asynchronous nil)
1291 (gnus-inhibit-treatment t)
1292 has-been-begin article result-file result-files process-state
1293 gnus-summary-display-article-function
1294 gnus-article-prepare-hook gnus-display-mime-function
1295 article-series files)
1297 (while (and articles
1298 (not (memq 'error process-state))
1300 (not (memq 'end process-state))))
1302 (setq article (pop articles))
1303 (when (vectorp (gnus-summary-article-header article))
1304 (push article article-series)
1307 (if (eq state 'first)
1308 (setq state 'first-and-last)
1309 (setq state 'last)))
1311 (let ((part (gnus-uu-part-number article)))
1312 (gnus-message 6 "Getting article %d%s..."
1313 article (if (string= part "") "" (concat ", " part))))
1314 (gnus-summary-display-article article)
1316 ;; Push the article to the processing function.
1318 (set-buffer gnus-original-article-buffer)
1319 (let ((buffer-read-only nil))
1321 (set-buffer gnus-summary-buffer)
1323 (funcall process-function
1324 gnus-original-article-buffer state)))))
1326 (gnus-summary-remove-process-mark article)
1328 ;; If this is the beginning of a decoded file, we push it
1330 (when (or (memq 'begin process-state)
1331 (and (or (eq state 'first)
1332 (eq state 'first-and-last))
1333 (memq 'ok process-state)))
1334 (when has-been-begin
1335 ;; If there is a `result-file' here, that means that the
1336 ;; file was unsuccessfully decoded, so we delete it.
1337 (when (and result-file
1338 (file-exists-p result-file)
1339 (not gnus-uu-be-dangerous)
1340 (or (eq gnus-uu-be-dangerous t)
1342 (format "Delete unsuccessfully decoded file %s"
1344 (delete-file result-file)))
1345 (when (memq 'begin process-state)
1346 (setq result-file (car process-state)))
1347 (setq has-been-begin t))
1349 ;; Check whether we have decoded one complete file.
1350 (when (memq 'end process-state)
1351 (setq article-series nil)
1352 (setq has-been-begin nil)
1353 (if (stringp result-file)
1354 (setq files (list result-file))
1355 (setq files result-file))
1356 (setq result-file (car files))
1358 (push (list (cons 'name (pop files))
1359 (cons 'article article))
1361 ;; Allow user-defined functions to be run on this file.
1362 (when gnus-uu-grabbed-file-functions
1363 (let ((funcs gnus-uu-grabbed-file-functions))
1364 (unless (listp funcs)
1365 (setq funcs (list funcs)))
1367 (funcall (pop funcs) result-file))))
1368 (setq result-file nil)
1369 ;; Check whether we have decoded enough articles.
1370 (and limit (= (length result-files) limit)
1371 (setq articles nil)))
1373 ;; If this is the last article to be decoded, and
1374 ;; we still haven't reached the end, then we delete
1375 ;; the partially decoded file.
1376 (and (or (eq state 'last) (eq state 'first-and-last))
1377 (not (memq 'end process-state))
1379 (file-exists-p result-file)
1380 (not gnus-uu-be-dangerous)
1381 (or (eq gnus-uu-be-dangerous t)
1383 (format "Delete incomplete file %s? " result-file)))
1384 (delete-file result-file))
1386 ;; If this was a file of the wrong sort, then
1387 (when (and (or (memq 'wrong-type process-state)
1388 (memq 'error process-state))
1389 gnus-uu-unmark-articles-not-decoded)
1390 (gnus-summary-tick-article article t))
1392 ;; Set the new series state.
1393 (if (and (not has-been-begin)
1395 (or (memq 'end process-state)
1396 (memq 'middle process-state)))
1398 (setq process-state (list 'error))
1399 (gnus-message 2 "No begin part at the beginning")
1401 (setq state 'middle)))
1403 ;; When there are no result-files, then something must be wrong.
1407 ((not has-been-begin)
1408 (gnus-message 2 "Wrong type file"))
1409 ((memq 'error process-state)
1410 (gnus-message 2 "An error occurred during decoding"))
1411 ((not (or (memq 'ok process-state)
1412 (memq 'end process-state)))
1413 (gnus-message 2 "End of articles reached before end of file")))
1414 ;; Make unsuccessfully decoded articles unread.
1415 (when gnus-uu-unmark-articles-not-decoded
1416 (while article-series
1417 (gnus-summary-tick-article (pop article-series) t)))))
1419 ;; The original article buffer is hosed, shoot it down.
1420 (gnus-kill-buffer gnus-original-article-buffer)
1424 (defun gnus-uu-grab-view (file)
1425 "View FILE using the gnus-uu methods."
1426 (let ((action (gnus-uu-get-action file)))
1427 (gnus-execute-command
1428 (if (string-match "%" action)
1429 (format action file)
1430 (concat action " " file))
1431 (eq gnus-view-pseudos 'not-confirm))))
1433 (defun gnus-uu-grab-move (file)
1434 "Move FILE to somewhere."
1435 (when gnus-uu-default-dir
1436 (let ((to-file (concat (file-name-as-directory gnus-uu-default-dir)
1437 (file-name-nondirectory file))))
1438 (rename-file file to-file)
1439 (unless (file-exists-p file)
1440 (make-symbolic-link to-file file)))))
1442 (defun gnus-uu-part-number (article)
1443 (let* ((header (gnus-summary-article-header article))
1444 (subject (and header (mail-header-subject header)))
1447 (while (string-match "[0-9]+/[0-9]+\\|[0-9]+[ \t]+of[ \t]+[0-9]+"
1449 (setq part (match-string 0 subject))
1450 (setq subject (substring subject (match-end 0)))))
1452 (while (string-match "\\([0-9]+\\)[^0-9]+\\([0-9]+\\)" subject)
1453 (setq part (match-string 0 subject))
1454 (setq subject (substring subject (match-end 0)))))
1457 (defun gnus-uu-uudecode-sentinel (process event)
1458 (delete-process (get-process process)))
1460 (defun gnus-uu-uustrip-article (process-buffer in-state)
1461 ;; Uudecodes a file asynchronously.
1463 (set-buffer process-buffer)
1464 (let ((state (list 'wrong-type))
1465 process-connection-type case-fold-search buffer-read-only
1467 (goto-char (point-min))
1469 ;; Deal with ^M at the end of the lines.
1470 (when gnus-uu-kill-carriage-return
1472 (while (search-forward "\r" nil t)
1473 (delete-backward-char 1))))
1475 (while (or (re-search-forward gnus-uu-begin-string nil t)
1476 (re-search-forward gnus-uu-body-line nil t))
1477 (setq state (list 'ok))
1478 ;; Ok, we are at the first uucoded line.
1480 (setq start-char (point))
1482 (if (not (looking-at gnus-uu-begin-string))
1483 (setq state (list 'middle))
1484 ;; This is the beginning of a uuencoded article.
1485 ;; We replace certain characters that could make things messy.
1486 (setq gnus-uu-file-name
1487 (let ((nnheader-file-name-translation-alist
1488 '((?/ . ?,) (? . ?_) (?* . ?_) (?$ . ?_))))
1489 (nnheader-translate-file-chars (match-string 1))))
1490 (replace-match (concat "begin 644 " gnus-uu-file-name) t t)
1492 ;; Remove any non gnus-uu-body-line right after start.
1494 (while (and (not (eobp))
1495 (not (looking-at gnus-uu-body-line)))
1498 ;; If a process is running, we kill it.
1499 (when (and gnus-uu-uudecode-process
1500 (memq (process-status gnus-uu-uudecode-process)
1502 (delete-process gnus-uu-uudecode-process)
1503 (gnus-uu-unmark-list-of-grabbed t))
1505 ;; Start a new uudecoding process.
1506 (let ((cdir default-directory))
1509 (cd gnus-uu-work-dir)
1510 (setq gnus-uu-uudecode-process
1513 (gnus-get-buffer-create gnus-uu-output-buffer-name)
1514 shell-file-name shell-command-switch
1515 (format "cd %s %s uudecode" gnus-uu-work-dir
1516 gnus-shell-command-separator))))
1518 (set-process-sentinel
1519 gnus-uu-uudecode-process 'gnus-uu-uudecode-sentinel)
1520 (setq state (list 'begin))
1521 (push (concat gnus-uu-work-dir gnus-uu-file-name) files))
1523 ;; We look for the end of the thing to be decoded.
1524 (if (re-search-forward gnus-uu-end-string nil t)
1526 (goto-char (point-max))
1527 (re-search-backward gnus-uu-body-line nil t))
1531 (when gnus-uu-uudecode-process
1532 (when (memq (process-status gnus-uu-uudecode-process) '(run stop))
1533 ;; Try to correct mishandled uucode.
1534 (when gnus-uu-correct-stripped-uucode
1535 (gnus-uu-check-correct-stripped-uucode start-char (point)))
1536 (gnus-run-hooks 'gnus-uu-pre-uudecode-hook)
1538 ;; Send the text to the process.
1540 (process-send-region
1541 gnus-uu-uudecode-process start-char (point))
1544 (delete-process gnus-uu-uudecode-process)
1545 (gnus-message 2 "gnus-uu: Couldn't uudecode")
1546 (setq state (list 'wrong-type)))))
1548 (if (memq 'end state)
1550 ;; Send an EOF, just in case.
1552 (process-send-eof gnus-uu-uudecode-process))
1553 (while (memq (process-status gnus-uu-uudecode-process)
1555 (accept-process-output gnus-uu-uudecode-process 1)))
1556 (when (or (not gnus-uu-uudecode-process)
1557 (not (memq (process-status gnus-uu-uudecode-process)
1559 (setq state (list 'wrong-type)))))))
1561 (if (memq 'begin state)
1562 (cons (if (= (length files) 1) (car files) files) state)
1565 (defvar gnus-uu-unshar-warning
1568 Shell archives are an archaic method of bundling files for distribution
1569 across computer networks. During the unpacking process, arbitrary commands
1570 are executed on your system, and all kinds of nasty things can happen.
1571 Please examine the archive very carefully before you instruct Emacs to
1572 unpack it. You can browse the archive buffer using \\[scroll-other-window].
1574 If you are unsure what to do, please answer \"no\"."
1575 "Text of warning message displayed by `gnus-uu-unshar-article'.
1576 Make sure that this text consists only of few text lines. Otherwise,
1577 Gnus might fail to display all of it.")
1580 ;; This function is used by `gnus-uu-grab-articles' to treat
1581 ;; a shared article.
1582 (defun gnus-uu-unshar-article (process-buffer in-state)
1583 (let ((state (list 'ok))
1586 (set-buffer process-buffer)
1587 (goto-char (point-min))
1588 (if (not (re-search-forward gnus-uu-shar-begin-string nil t))
1589 (setq state (list 'wrong-type))
1590 (save-window-excursion
1592 (switch-to-buffer (current-buffer))
1593 (delete-other-windows)
1594 (let ((buffer (get-buffer-create (generate-new-buffer-name
1598 (with-current-buffer buffer
1599 (insert (substitute-command-keys
1600 gnus-uu-unshar-warning))
1601 (goto-char (point-min))
1602 (display-buffer buffer)
1603 (yes-or-no-p "This is a shell archive, unshar it? "))
1604 (kill-buffer buffer))
1605 (setq state (list 'error))))))
1606 (unless (memq 'error state)
1608 (setq start-char (point))
1609 (call-process-region
1610 start-char (point-max) shell-file-name nil
1611 (gnus-get-buffer-create gnus-uu-output-buffer-name) nil
1612 shell-command-switch
1613 (concat "cd " gnus-uu-work-dir " "
1614 gnus-shell-command-separator " sh")))))
1617 ;; Returns the name of what the shar file is going to unpack.
1618 (defun gnus-uu-find-name-in-shar ()
1619 (let ((oldpoint (point))
1621 (goto-char (point-min))
1622 (when (re-search-forward gnus-uu-shar-name-marker nil t)
1623 (setq res (buffer-substring (match-beginning 1) (match-end 1))))
1624 (goto-char oldpoint)
1627 ;; `gnus-uu-choose-action' chooses what action to perform given the name
1628 ;; and `gnus-uu-file-action-list'. Returns either nil if no action is
1629 ;; found, or the name of the command to run if such a rule is found.
1630 (defun gnus-uu-choose-action (file-name file-action-list &optional no-ignore)
1631 (let ((action-list (copy-sequence file-action-list))
1632 (case-fold-search t)
1637 (and gnus-uu-ignore-files-by-name
1638 (string-match gnus-uu-ignore-files-by-name file-name)))
1640 (and gnus-uu-ignore-files-by-type
1641 (string-match gnus-uu-ignore-files-by-type
1642 (or (gnus-uu-choose-action
1643 file-name gnus-uu-ext-to-mime-list t)
1645 (while (not (or (eq action-list ()) action))
1646 (setq rule (car action-list))
1647 (setq action-list (cdr action-list))
1648 (when (string-match (car rule) file-name)
1649 (setq action (cadr rule)))))
1652 (defun gnus-uu-treat-archive (file-path)
1653 ;; Unpacks an archive. Returns t if unpacking is successful.
1654 (let ((did-unpack t)
1656 (setq action (gnus-uu-choose-action
1657 file-path (append gnus-uu-user-archive-rules
1658 (if gnus-uu-ignore-default-archive-rules
1660 gnus-uu-default-archive-rules))))
1663 (error "No unpackers for the file %s" file-path))
1665 (string-match "/[^/]*$" file-path)
1666 (setq dir (substring file-path 0 (match-beginning 0)))
1668 (when (member action gnus-uu-destructive-archivers)
1669 (copy-file file-path (concat file-path "~") t))
1671 (setq command (format "cd %s ; %s" dir (gnus-uu-command action file-path)))
1674 (set-buffer (gnus-get-buffer-create gnus-uu-output-buffer-name))
1677 (gnus-message 5 "Unpacking: %s..." (gnus-uu-command action file-path))
1679 (if (= 0 (call-process shell-file-name nil
1680 (gnus-get-buffer-create gnus-uu-output-buffer-name)
1681 nil shell-command-switch command))
1683 (gnus-message 2 "Error during unpacking of archive")
1684 (setq did-unpack nil))
1686 (when (member action gnus-uu-destructive-archivers)
1687 (rename-file (concat file-path "~") file-path t))
1691 (defun gnus-uu-dir-files (dir)
1692 (let ((dirs (directory-files dir t "[^/][^\\.][^\\.]?$"))
1695 (if (file-directory-p (setq file (car dirs)))
1696 (setq files (append files (gnus-uu-dir-files file)))
1698 (setq dirs (cdr dirs)))
1701 (defun gnus-uu-unpack-files (files &optional ignore)
1702 ;; Go through FILES and look for files to unpack.
1703 (let* ((totfiles (gnus-uu-ls-r gnus-uu-work-dir))
1707 (setq file (cdr (assq 'name (car files))))
1708 (when (and (not (member file ignore))
1709 (equal (gnus-uu-get-action (file-name-nondirectory file))
1711 (push file did-unpack)
1712 (unless (gnus-uu-treat-archive file)
1713 (gnus-message 2 "Error during unpacking of %s" file))
1714 (let* ((newfiles (gnus-uu-ls-r gnus-uu-work-dir))
1717 (unless (member (car nfiles) totfiles)
1718 (push (list (cons 'name (car nfiles))
1719 (cons 'original file))
1721 (setq nfiles (cdr nfiles)))
1722 (setq totfiles newfiles)))
1723 (setq files (cdr files)))
1725 (gnus-uu-unpack-files ofiles (append did-unpack ignore))
1728 (defun gnus-uu-ls-r (dir)
1729 (let* ((files (gnus-uu-directory-files dir t))
1732 (when (file-directory-p (car files))
1733 (setq ofiles (delete (car files) ofiles))
1734 (setq ofiles (append ofiles (gnus-uu-ls-r (car files)))))
1735 (setq files (cdr files)))
1740 (defun gnus-uu-directory-files (dir &optional full)
1741 (let (files out file)
1742 (setq files (directory-files dir full))
1744 (setq file (car files))
1745 (setq files (cdr files))
1746 (unless (member (file-name-nondirectory file) '("." ".."))
1748 (setq out (nreverse out))
1751 (defun gnus-uu-check-correct-stripped-uucode (start end)
1753 (let (found beg length)
1754 (if (not gnus-uu-correct-stripped-uucode)
1758 (if (re-search-forward " \\|`" end t)
1763 (when (looking-at "\n")
1768 (if (looking-at (concat gnus-uu-begin-string "\\|"
1769 gnus-uu-end-string))
1775 (setq length (- (point) beg)))
1780 (when (not (= length (- (point) beg)))
1781 (insert (make-string (- length (- (point) beg)) ? ))))
1782 (forward-line 1)))))))
1784 (defvar gnus-uu-tmp-alist nil)
1786 (defun gnus-uu-initialize (&optional scan)
1789 (when (setq entry (assoc gnus-newsgroup-name gnus-uu-tmp-alist))
1790 (if (file-exists-p (cdr entry))
1791 (setq gnus-uu-work-dir (cdr entry))
1792 (setq gnus-uu-tmp-alist (delq entry gnus-uu-tmp-alist))
1795 (setq gnus-uu-tmp-dir (file-name-as-directory
1796 (expand-file-name gnus-uu-tmp-dir)))
1797 (if (not (file-directory-p gnus-uu-tmp-dir))
1798 (error "Temp directory %s doesn't exist" gnus-uu-tmp-dir)
1799 (when (not (file-writable-p gnus-uu-tmp-dir))
1800 (error "Temp directory %s can't be written to"
1803 (setq gnus-uu-work-dir
1804 (make-temp-name (concat gnus-uu-tmp-dir "gnus")))
1805 (gnus-make-directory gnus-uu-work-dir)
1806 (set-file-modes gnus-uu-work-dir 448)
1807 (setq gnus-uu-work-dir (file-name-as-directory gnus-uu-work-dir))
1808 (push (cons gnus-newsgroup-name gnus-uu-work-dir)
1809 gnus-uu-tmp-alist))))
1812 ;; Kills the temporary uu buffers, kills any processes, etc.
1813 (defun gnus-uu-clean-up ()
1815 (and gnus-uu-uudecode-process
1816 (memq (process-status (or gnus-uu-uudecode-process "nevair"))
1818 (delete-process gnus-uu-uudecode-process))
1819 (when (setq buf (get-buffer gnus-uu-output-buffer-name))
1820 (kill-buffer buf))))
1822 ;; Inputs an action and a filename and returns a full command, making sure
1823 ;; that the filename will be treated as a single argument when the shell
1824 ;; executes the command.
1825 (defun gnus-uu-command (action file)
1826 (let ((quoted-file (mm-quote-arg file)))
1827 (if (string-match "%s" action)
1828 (format action quoted-file)
1829 (concat action " " quoted-file))))
1831 (defun gnus-uu-delete-work-dir (&optional dir)
1832 "Delete recursively all files and directories under `gnus-uu-work-dir'."
1834 (gnus-message 7 "Deleting directory %s..." dir)
1835 (setq dir gnus-uu-work-dir))
1837 (file-exists-p dir))
1838 (let ((files (directory-files dir t nil t))
1840 (while (setq file (pop files))
1841 (unless (member (file-name-nondirectory file) '("." ".."))
1842 (if (file-directory-p file)
1843 (gnus-uu-delete-work-dir file)
1844 (gnus-message 9 "Deleting file %s..." file)
1845 (delete-file file))))
1846 (delete-directory dir)))
1847 (gnus-message 7 ""))
1851 (add-hook 'gnus-exit-group-hook 'gnus-uu-clean-up)
1852 (add-hook 'gnus-exit-group-hook 'gnus-uu-delete-work-dir)
1857 ;;; uuencoded posting
1860 ;; Any function that is to be used as and encoding method will take two
1861 ;; parameters: PATH-NAME and FILE-NAME. (E.g. "/home/gaga/spiral.jpg"
1862 ;; and "spiral.jpg", respectively.) The function should return nil if
1863 ;; the encoding wasn't successful.
1864 (defcustom gnus-uu-post-encode-method 'gnus-uu-post-encode-uuencode
1865 "Function used for encoding binary files.
1866 There are three functions supplied with gnus-uu for encoding files:
1867 `gnus-uu-post-encode-uuencode', which does straight uuencoding;
1868 `gnus-uu-post-encode-mime', which encodes with base64 and adds MIME
1869 headers; and `gnus-uu-post-encode-mime-uuencode', which encodes with
1870 uuencode and adds MIME headers."
1871 :group 'gnus-extract-post
1872 :type '(radio (function-item gnus-uu-post-encode-uuencode)
1873 (function-item gnus-uu-post-encode-mime)
1874 (function-item gnus-uu-post-encode-mime-uuencode)
1875 (function :tag "Other")))
1877 (defcustom gnus-uu-post-include-before-composing nil
1878 "Non-nil means that gnus-uu will ask for a file to encode before you compose the article.
1879 If this variable is t, you can either include an encoded file with
1880 \\[gnus-uu-post-insert-binary-in-article] or have one included for you when you post the article."
1881 :group 'gnus-extract-post
1884 (defcustom gnus-uu-post-length 990
1885 "Maximum length of an article.
1886 The encoded file will be split into how many articles it takes to
1887 post the entire file."
1888 :group 'gnus-extract-post
1891 (defcustom gnus-uu-post-threaded nil
1892 "Non-nil means that gnus-uu will post the encoded file in a thread.
1893 This may not be smart, as no other decoder I have seen are able to
1894 follow threads when collecting uuencoded articles. (Well, I have seen
1895 one package that does that - gnus-uu, but somehow, I don't think that
1896 counts...) The default is nil."
1897 :group 'gnus-extract-post
1900 (defcustom gnus-uu-post-separate-description t
1901 "Non-nil means that the description will be posted in a separate article.
1902 The first article will typically be numbered (0/x). If this variable
1903 is nil, the description the user enters will be included at the
1904 beginning of the first article, which will be numbered (1/x). Default
1906 :group 'gnus-extract-post
1909 (defvar gnus-uu-post-binary-separator "--binary follows this line--")
1910 (defvar gnus-uu-post-message-id nil)
1911 (defvar gnus-uu-post-inserted-file-name nil)
1912 (defvar gnus-uu-winconf-post-news nil)
1914 (defun gnus-uu-post-news ()
1915 "Compose an article and post an encoded file."
1917 (setq gnus-uu-post-inserted-file-name nil)
1918 (setq gnus-uu-winconf-post-news (current-window-configuration))
1920 (gnus-summary-post-news)
1922 (let ((map (make-sparse-keymap)))
1923 (set-keymap-parent map (current-local-map))
1924 (use-local-map map))
1925 ;;(local-set-key "\C-c\C-c" 'gnus-summary-edit-article-done)
1926 (local-set-key "\C-c\C-c" 'gnus-uu-post-news-inews)
1927 (local-set-key "\C-c\C-s" 'gnus-uu-post-news-inews)
1928 (local-set-key "\C-c\C-i" 'gnus-uu-post-insert-binary-in-article)
1930 (when gnus-uu-post-include-before-composing
1931 (save-excursion (setq gnus-uu-post-inserted-file-name
1932 (gnus-uu-post-insert-binary)))))
1934 (defun gnus-uu-post-insert-binary-in-article ()
1935 "Inserts an encoded file in the buffer.
1936 The user will be asked for a file name."
1939 (setq gnus-uu-post-inserted-file-name (gnus-uu-post-insert-binary))))
1941 ;; Encodes with uuencode and substitutes all spaces with backticks.
1942 (defun gnus-uu-post-encode-uuencode (path file-name)
1943 (when (gnus-uu-post-encode-file "uuencode" path file-name)
1944 (goto-char (point-min))
1946 (while (re-search-forward " " nil t)
1947 (replace-match "`"))
1950 ;; Encodes with uuencode and adds MIME headers.
1951 (defun gnus-uu-post-encode-mime-uuencode (path file-name)
1952 (when (gnus-uu-post-encode-uuencode path file-name)
1953 (gnus-uu-post-make-mime file-name "x-uue")
1956 ;; Encodes with base64 and adds MIME headers
1957 (defun gnus-uu-post-encode-mime (path file-name)
1958 (when (zerop (call-process shell-file-name nil t nil shell-command-switch
1959 (format "%s %s -o %s" "mmencode" path file-name)))
1960 (gnus-uu-post-make-mime file-name "base64")
1963 ;; Adds MIME headers.
1964 (defun gnus-uu-post-make-mime (file-name encoding)
1965 (goto-char (point-min))
1966 (insert (format "Content-Type: %s; name=\"%s\"\n"
1967 (gnus-uu-choose-action file-name gnus-uu-ext-to-mime-list)
1969 (insert (format "Content-Transfer-Encoding: %s\n\n" encoding))
1971 (set-buffer gnus-message-buffer)
1972 (goto-char (point-min))
1973 (re-search-forward (concat "^" (regexp-quote mail-header-separator) "$"))
1975 (narrow-to-region 1 (point))
1976 (unless (mail-fetch-field "mime-version")
1978 (insert "MIME-Version: 1.0\n"))
1981 ;; Encodes a file PATH with COMMAND, leaving the result in the
1983 (defun gnus-uu-post-encode-file (command path file-name)
1984 (= 0 (call-process shell-file-name nil t nil shell-command-switch
1985 (format "%s %s %s" command path file-name))))
1987 (defun gnus-uu-post-news-inews ()
1988 "Posts the composed news article and encoded file.
1989 If no file has been included, the user will be asked for a file."
1994 (if gnus-uu-post-inserted-file-name
1995 (setq file-name gnus-uu-post-inserted-file-name)
1996 (setq file-name (gnus-uu-post-insert-binary)))
1998 (gnus-uu-post-encoded file-name gnus-uu-post-threaded))
1999 (setq gnus-uu-post-inserted-file-name nil)
2000 (when gnus-uu-winconf-post-news
2001 (set-window-configuration gnus-uu-winconf-post-news)))
2003 ;; Asks for a file to encode, encodes it and inserts the result in
2004 ;; the current buffer. Returns the file name the user gave.
2005 (defun gnus-uu-post-insert-binary ()
2006 (let ((uuencode-buffer-name "*uuencode buffer*")
2007 file-path uubuf file-name)
2009 (setq file-path (read-file-name
2010 "What file do you want to encode? "))
2011 (when (not (file-exists-p file-path))
2012 (error "%s: No such file" file-path))
2014 (goto-char (point-max))
2015 (insert (format "\n%s\n" gnus-uu-post-binary-separator))
2017 ;; #### Unix-specific?
2018 (when (string-match "^~/" file-path)
2019 (setq file-path (concat "$HOME" (substring file-path 1))))
2020 ;; #### Unix-specific?
2021 (if (string-match "/[^/]*$" file-path)
2022 (setq file-name (substring file-path (1+ (match-beginning 0))))
2023 (setq file-name file-path))
2027 (set-buffer (setq uubuf
2028 (gnus-get-buffer-create uuencode-buffer-name)))
2030 (funcall gnus-uu-post-encode-method file-path file-name))
2031 (insert-buffer-substring uubuf)
2032 (error "Encoding unsuccessful"))
2033 (kill-buffer uubuf))
2036 ;; Posts the article and all of the encoded file.
2037 (defun gnus-uu-post-encoded (file-name &optional threaded)
2038 (let ((send-buffer-name "*uuencode send buffer*")
2039 (encoded-buffer-name "*encoded buffer*")
2040 (top-string "[ cut here %s (%s %d/%d) %s gnus-uu ]")
2041 (separator (concat mail-header-separator "\n\n"))
2042 uubuf length parts header i end beg
2043 beg-line minlen post-buf whole-len beg-binary end-binary)
2045 (setq post-buf (current-buffer))
2047 (goto-char (point-min))
2048 (when (not (re-search-forward
2049 (if gnus-uu-post-separate-description
2050 (concat "^" (regexp-quote gnus-uu-post-binary-separator)
2052 (concat "^" (regexp-quote mail-header-separator) "$"))
2054 (error "Internal error: No binary/header separator"))
2057 (setq beg-binary (point))
2058 (setq end-binary (point-max))
2061 (set-buffer (setq uubuf (gnus-get-buffer-create encoded-buffer-name)))
2063 (insert-buffer-substring post-buf beg-binary end-binary)
2064 (goto-char (point-min))
2065 (setq length (count-lines 1 (point-max)))
2066 (setq parts (/ length gnus-uu-post-length))
2067 (unless (< (% length gnus-uu-post-length) 4)
2070 (when gnus-uu-post-separate-description
2072 (delete-region (point) (point-max))
2074 (goto-char (point-min))
2076 (concat "^" (regexp-quote mail-header-separator) "$") nil t)
2078 (setq header (buffer-substring 1 (point)))
2080 (goto-char (point-min))
2081 (when gnus-uu-post-separate-description
2082 (when (re-search-forward "^Subject: " nil t)
2084 (insert (format " (0/%d)" parts)))
2087 (setq gnus-uu-post-message-id (message-fetch-field "message-id")))
2092 (while (not (> i parts))
2093 (set-buffer (gnus-get-buffer-create send-buffer-name))
2096 (when (and threaded gnus-uu-post-message-id)
2097 (insert "References: " gnus-uu-post-message-id "\n"))
2100 (- 62 (length (format top-string "" file-name i parts ""))))
2101 (when (> 1 (setq minlen (/ whole-len 2)))
2106 (make-string minlen ?-)
2109 (if (= 0 (% whole-len 2)) (1- minlen) minlen) ?-)))
2111 (goto-char (point-min))
2112 (when (re-search-forward "^Subject: " nil t)
2114 (insert (format " (%d/%d)" i parts)))
2116 (goto-char (point-max))
2121 (goto-char (point-max))
2122 (forward-line gnus-uu-post-length))
2123 (when (and (= (1+ i) parts) (< (count-lines (point) (point-max)) 4))
2126 (insert-buffer-substring uubuf beg end)
2127 (insert beg-line "\n")
2130 (goto-char (point-min))
2132 (concat "^" (regexp-quote mail-header-separator) "$") nil t)
2135 (when (re-search-forward
2136 (concat "^" (regexp-quote gnus-uu-post-binary-separator) "$")
2142 (let (message-sent-message-via)
2145 (setq gnus-uu-post-message-id
2146 (concat (message-fetch-field "references") " "
2147 (message-fetch-field "message-id"))))))
2149 (gnus-kill-buffer send-buffer-name)
2150 (gnus-kill-buffer encoded-buffer-name)
2152 (when (not gnus-uu-post-separate-description)
2153 (set-buffer-modified-p nil)
2154 (when (fboundp 'bury-buffer)
2159 ;;; gnus-uu.el ends here