1 ;;; gnus-uu.el --- extract (uu)encoded files in Gnus
2 ;; Copyright (C) 1985, 1986, 1987, 1993, 1994, 1995, 1996, 1997, 1998, 2000
3 ;; 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))
37 (defgroup gnus-extract nil
38 "Extracting encoded files."
42 (defgroup gnus-extract-view nil
43 "Viewwing extracted files."
46 (defgroup gnus-extract-archive nil
47 "Extracting encoded archives."
50 (defgroup gnus-extract-post nil
51 "Extracting encoded archives."
52 :prefix "gnus-uu-post"
55 ;; Default viewing action rules
57 (defcustom gnus-uu-default-view-rules
58 '(("\\.te?xt$\\|\\.doc$\\|read.*me\\|\\.c?$\\|\\.h$\\|\\.bat$\\|\\.asm$\\|makefile" "cat %s | sed 's/\r$//'")
59 ("\\.pas$" "cat %s | sed 's/\r$//'")
60 ("\\.[1-9]$" "groff -mandoc -Tascii %s | sed s/\b.//g")
61 ("\\.\\(jpe?g\\|gif\\|tiff?\\|p[pgb]m\\|xwd\\|xbm\\|pcx\\)$" "display")
62 ("\\.tga$" "tgatoppm %s | ee -")
63 ("\\.\\(wav\\|aiff\\|hcom\\|u[blw]\\|s[bfw]\\|voc\\|smp\\)$"
64 "sox -v .5 %s -t .au -u - > /dev/audio")
65 ("\\.au$" "cat %s > /dev/audio")
66 ("\\.midi?$" "playmidi -f")
68 ("\\.ps$" "ghostview")
70 ("\\.html$" "xmosaic")
71 ("\\.mpe?g$" "mpeg_play")
72 ("\\.\\(flc\\|fli\\|rle\\|iff\\|pfx\\|avi\\|sme\\|rpza\\|dl\\|qt\\|rsrc\\|mov\\)$" "xanim")
73 ("\\.\\(tar\\|arj\\|zip\\|zoo\\|arc\\|gz\\|Z\\|lzh\\|ar\\|lha\\)$"
75 "*Default actions to be taken when the user asks to view a file.
76 To change the behaviour, you can either edit this variable or set
77 `gnus-uu-user-view-rules' to something useful.
81 To make gnus-uu use 'xli' to display JPEG and GIF files, put the
82 following in your .emacs file:
84 (setq gnus-uu-user-view-rules '((\"jpg$\\\\|gif$\" \"xli\")))
86 Both these variables are lists of lists with two string elements. The
87 first string is a regular expression. If the file name matches this
88 regular expression, the command in the second string is executed with
89 the file as an argument.
91 If the command string contains \"%s\", the file name will be inserted
92 at that point in the command string. If there's no \"%s\" in the
93 command string, the file name will be appended to the command string
96 There are several user variables to tailor the behaviour of gnus-uu to
97 your needs. First we have `gnus-uu-user-view-rules', which is the
98 variable gnus-uu first consults when trying to decide how to view a
99 file. If this variable contains no matches, gnus-uu examines the
100 default rule variable provided in this package. If gnus-uu finds no
101 match here, it uses `gnus-uu-user-view-rules-end' to try to make a
103 :group 'gnus-extract-view
104 :type '(repeat (group regexp (string :tag "Command"))))
106 (defcustom gnus-uu-user-view-rules nil
107 "What actions are to be taken to view a file.
108 See the documentation on the `gnus-uu-default-view-rules' variable for
110 :group 'gnus-extract-view
111 :type '(repeat (group regexp (string :tag "Command"))))
113 (defcustom gnus-uu-user-view-rules-end
115 "*What actions are to be taken if no rule matched the file name.
116 See the documentation on the `gnus-uu-default-view-rules' variable for
118 :group 'gnus-extract-view
119 :type '(repeat (group regexp (string :tag "Command"))))
121 ;; Default unpacking commands
123 (defcustom gnus-uu-default-archive-rules
124 '(("\\.tar$" "tar xf")
125 ("\\.zip$" "unzip -o")
127 ("\\.arj$" "unarj x")
129 ("\\.\\(lzh\\|lha\\)$" "lha x")
130 ("\\.Z$" "uncompress")
132 ("\\.arc$" "arc -x"))
133 "*See `gnus-uu-user-archive-rules'."
134 :group 'gnus-extract-archive
135 :type '(repeat (group regexp (string :tag "Command"))))
137 (defvar gnus-uu-destructive-archivers
138 (list "uncompress" "gunzip"))
140 (defcustom gnus-uu-user-archive-rules nil
141 "A list that can be set to override the default archive unpacking commands.
142 To use, for instance, 'untar' to unpack tar files and 'zip -x' to
143 unpack zip files, say the following:
144 (setq gnus-uu-user-archive-rules
145 '((\"\\\\.tar$\" \"untar\")
146 (\"\\\\.zip$\" \"zip -x\")))"
147 :group 'gnus-extract-archive
148 :type '(repeat (group regexp (string :tag "Command"))))
150 (defcustom gnus-uu-ignore-files-by-name nil
151 "*A regular expression saying what files should not be viewed based on name.
152 If, for instance, you want gnus-uu to ignore all .au and .wav files,
153 you could say something like
155 (setq gnus-uu-ignore-files-by-name \"\\\\.au$\\\\|\\\\.wav$\")
157 Note that this variable can be used in conjunction with the
158 `gnus-uu-ignore-files-by-type' variable."
160 :type '(choice (const :tag "off" nil)
161 (regexp :format "%v")))
163 (defcustom gnus-uu-ignore-files-by-type nil
164 "*A regular expression saying what files that shouldn't be viewed, based on MIME file type.
165 If, for instance, you want gnus-uu to ignore all audio files and all mpegs,
166 you could say something like
168 (setq gnus-uu-ignore-files-by-type \"audio/\\\\|video/mpeg\")
170 Note that this variable can be used in conjunction with the
171 `gnus-uu-ignore-files-by-name' variable."
173 :type '(choice (const :tag "off" nil)
174 (regexp :format "%v")))
176 ;; Pseudo-MIME support
178 (defconst gnus-uu-ext-to-mime-list
179 '(("\\.gif$" "image/gif")
180 ("\\.jpe?g$" "image/jpeg")
181 ("\\.tiff?$" "image/tiff")
182 ("\\.xwd$" "image/xwd")
183 ("\\.pbm$" "image/pbm")
184 ("\\.pgm$" "image/pgm")
185 ("\\.ppm$" "image/ppm")
186 ("\\.xbm$" "image/xbm")
187 ("\\.pcx$" "image/pcx")
188 ("\\.tga$" "image/tga")
189 ("\\.ps$" "image/postscript")
190 ("\\.fli$" "video/fli")
191 ("\\.wav$" "audio/wav")
192 ("\\.aiff$" "audio/aiff")
193 ("\\.hcom$" "audio/hcom")
194 ("\\.voc$" "audio/voc")
195 ("\\.smp$" "audio/smp")
196 ("\\.mod$" "audio/mod")
197 ("\\.dvi$" "image/dvi")
198 ("\\.mpe?g$" "video/mpeg")
199 ("\\.au$" "audio/basic")
200 ("\\.\\(te?xt\\|doc\\|c\\|h\\)$" "text/plain")
201 ("\\.\\(c\\|h\\)$" "text/source")
202 ("read.*me" "text/plain")
203 ("\\.html$" "text/html")
204 ("\\.bat$" "text/bat")
205 ("\\.[1-6]$" "text/man")
206 ("\\.flc$" "video/flc")
207 ("\\.rle$" "video/rle")
208 ("\\.pfx$" "video/pfx")
209 ("\\.avi$" "video/avi")
210 ("\\.sme$" "video/sme")
211 ("\\.rpza$" "video/prza")
212 ("\\.dl$" "video/dl")
213 ("\\.qt$" "video/qt")
214 ("\\.rsrc$" "video/rsrc")
215 ("\\..*$" "unknown/unknown")))
217 ;; Various variables users may set
219 (defcustom gnus-uu-tmp-dir
220 (cond ((fboundp 'temp-directory) (temp-directory))
221 ((boundp 'temporary-file-directory) temporary-file-directory)
223 "*Variable saying where gnus-uu is to do its work.
224 Default is \"/tmp/\"."
228 (defcustom gnus-uu-do-not-unpack-archives nil
229 "*Non-nil means that gnus-uu won't peek inside archives looking for files to display.
231 :group 'gnus-extract-archive
234 (defcustom gnus-uu-ignore-default-view-rules nil
235 "*Non-nil means that gnus-uu will ignore the default viewing rules.
236 Only the user viewing rules will be consulted. Default is nil."
237 :group 'gnus-extract-view
240 (defcustom gnus-uu-grabbed-file-functions nil
241 "Functions run on each file after successful decoding.
242 They will be called with the name of the file as the argument.
243 Likely functions you can use in this list are `gnus-uu-grab-view'
244 and `gnus-uu-grab-move'."
246 :options '(gnus-uu-grab-view gnus-uu-grab-move)
249 (defcustom gnus-uu-ignore-default-archive-rules nil
250 "*Non-nil means that gnus-uu will ignore the default archive unpacking commands.
251 Only the user unpacking commands will be consulted. Default is nil."
252 :group 'gnus-extract-archive
255 (defcustom gnus-uu-kill-carriage-return t
256 "*Non-nil means that gnus-uu will strip all carriage returns from articles.
261 (defcustom gnus-uu-view-with-metamail nil
262 "*Non-nil means that files will be viewed with metamail.
263 The gnus-uu viewing functions will be ignored and gnus-uu will try
264 to guess at a content-type based on file name suffixes. Default
269 (defcustom gnus-uu-unmark-articles-not-decoded nil
270 "*Non-nil means that gnus-uu will mark articles that were unsuccessfully decoded as unread.
275 (defcustom gnus-uu-correct-stripped-uucode nil
276 "*Non-nil means that gnus-uu will *try* to fix uuencoded files that have had trailing spaces deleted.
281 (defcustom gnus-uu-save-in-digest nil
282 "*Non-nil means that gnus-uu, when asked to save without decoding, will save in digests.
283 If this variable is nil, gnus-uu will just save everything in a
284 file without any embellishments. The digesting almost conforms to RFC1153 -
285 no easy way to specify any meaningful volume and issue numbers were found,
286 so I simply dropped them."
290 (defcustom gnus-uu-pre-uudecode-hook nil
291 "Hook run before sending a message to uudecode."
295 (defcustom gnus-uu-digest-headers
296 '("^Date:" "^From:" "^To:" "^Cc:" "^Subject:" "^Message-ID:" "^Keywords:"
297 "^Summary:" "^References:" "^Content-Type:" "^Content-Transfer-Encoding:"
298 "^MIME-Version:" "^Content-Disposition:" "^Content-Description:"
299 "^Content-ID:" "^User-Agent:" "^X-Face:")
300 "*List of regexps to match headers included in digested messages.
301 The headers will be included in the sequence they are matched."
303 :type '(repeat regexp))
305 (defcustom gnus-uu-save-separate-articles nil
306 "*Non-nil means that gnus-uu will save articles in separate files."
310 (defcustom gnus-uu-be-dangerous 'ask
311 "*Specifies what to do if unusual situations arise during decoding.
312 If nil, be as conservative as possible. If t, ignore things that
313 didn't work, and overwrite existing files. Otherwise, ask each time."
315 :type '(choice (const :tag "conservative" nil)
316 (const :tag "ask" ask)
317 (const :tag "liberal" t)))
319 ;; Internal variables
321 (defvar gnus-uu-saved-article-name nil)
323 (defvar gnus-uu-begin-string "^begin[ \t]+[0-7][0-7][0-7][ \t]+\\(.*\\)$")
324 (defvar gnus-uu-end-string "^end[ \t]*$")
326 (defvar gnus-uu-body-line "^M")
328 (while (> (setq i (1- i)) 0)
329 (setq gnus-uu-body-line (concat gnus-uu-body-line "[^a-z]")))
330 (setq gnus-uu-body-line (concat gnus-uu-body-line ".?$")))
332 ;"^M.............................................................?$"
334 (defvar gnus-uu-shar-begin-string "^#! */bin/sh")
336 (defvar gnus-uu-shar-file-name nil)
337 (defvar gnus-uu-shar-name-marker
338 "begin [0-7][0-7][0-7][ \t]+\\(\\(\\w\\|\\.\\)*\\b\\)")
340 (defvar gnus-uu-postscript-begin-string "^%!PS-")
341 (defvar gnus-uu-postscript-end-string "^%%EOF$")
343 (defvar gnus-uu-file-name nil)
344 (defvar gnus-uu-uudecode-process nil)
345 (defvar gnus-uu-binhex-article-name nil)
347 (defvar gnus-uu-work-dir nil)
349 (defvar gnus-uu-output-buffer-name " *Gnus UU Output*")
351 (defvar gnus-uu-default-dir gnus-article-save-directory)
352 (defvar gnus-uu-digest-from-subject nil)
353 (defvar gnus-uu-digest-buffer nil)
357 (gnus-define-keys (gnus-uu-mark-map "P" gnus-summary-mark-map)
358 "p" gnus-summary-mark-as-processable
359 "u" gnus-summary-unmark-as-processable
360 "U" gnus-summary-unmark-all-processable
361 "v" gnus-uu-mark-over
362 "s" gnus-uu-mark-series
363 "r" gnus-uu-mark-region
364 "g" gnus-uu-unmark-region
365 "R" gnus-uu-mark-by-regexp
366 "G" gnus-uu-unmark-by-regexp
367 "t" gnus-uu-mark-thread
368 "T" gnus-uu-unmark-thread
370 "b" gnus-uu-mark-buffer
371 "S" gnus-uu-mark-sparse
372 "k" gnus-summary-kill-process-mark
373 "y" gnus-summary-yank-process-mark
374 "w" gnus-summary-save-process-mark
375 "i" gnus-uu-invert-processable)
377 (gnus-define-keys (gnus-uu-extract-map "X" gnus-summary-mode-map)
378 ;;"x" gnus-uu-extract-any
379 "m" gnus-summary-save-parts
380 "u" gnus-uu-decode-uu
381 "U" gnus-uu-decode-uu-and-save
382 "s" gnus-uu-decode-unshar
383 "S" gnus-uu-decode-unshar-and-save
384 "o" gnus-uu-decode-save
385 "O" gnus-uu-decode-save
386 "b" gnus-uu-decode-binhex
387 "B" gnus-uu-decode-binhex
388 "p" gnus-uu-decode-postscript
389 "P" gnus-uu-decode-postscript-and-save)
392 (gnus-uu-extract-view-map "v" gnus-uu-extract-map)
393 "u" gnus-uu-decode-uu-view
394 "U" gnus-uu-decode-uu-and-save-view
395 "s" gnus-uu-decode-unshar-view
396 "S" gnus-uu-decode-unshar-and-save-view
397 "o" gnus-uu-decode-save-view
398 "O" gnus-uu-decode-save-view
399 "b" gnus-uu-decode-binhex-view
400 "B" gnus-uu-decode-binhex-view
401 "p" gnus-uu-decode-postscript-view
402 "P" gnus-uu-decode-postscript-and-save-view)
407 (defun gnus-uu-decode-uu (&optional n)
408 "Uudecodes the current article."
410 (gnus-uu-decode-with-method 'gnus-uu-uustrip-article n))
412 (defun gnus-uu-decode-uu-and-save (n dir)
413 "Decodes and saves the resulting file."
415 (list current-prefix-arg
416 (file-name-as-directory
417 (read-file-name "Uudecode and save in dir: "
419 gnus-uu-default-dir t))))
420 (gnus-uu-decode-with-method 'gnus-uu-uustrip-article n dir nil nil t))
422 (defun gnus-uu-decode-unshar (&optional n)
423 "Unshars the current article."
425 (gnus-uu-decode-with-method 'gnus-uu-unshar-article n nil nil 'scan t))
427 (defun gnus-uu-decode-unshar-and-save (n dir)
428 "Unshars and saves the current article."
430 (list current-prefix-arg
431 (file-name-as-directory
432 (read-file-name "Unshar and save in dir: "
434 gnus-uu-default-dir t))))
435 (gnus-uu-decode-with-method 'gnus-uu-unshar-article n dir nil 'scan t))
437 (defun gnus-uu-decode-save (n file)
438 "Saves the current article."
440 (list current-prefix-arg
442 (if gnus-uu-save-separate-articles
443 "Save articles is dir: "
444 "Save articles in file: ")
446 gnus-uu-default-dir)))
447 (setq gnus-uu-saved-article-name file)
448 (gnus-uu-decode-with-method 'gnus-uu-save-article n nil t))
450 (defun gnus-uu-decode-binhex (n dir)
451 "Unbinhexes the current article."
453 (list current-prefix-arg
454 (file-name-as-directory
455 (read-file-name "Unbinhex and save in dir: "
457 gnus-uu-default-dir))))
458 (setq gnus-uu-binhex-article-name
459 (make-temp-name (concat gnus-uu-work-dir "binhex")))
460 (gnus-uu-decode-with-method 'gnus-uu-binhex-article n dir))
462 (defun gnus-uu-decode-uu-view (&optional n)
463 "Uudecodes and views the current article."
465 (let ((gnus-view-pseudos (or gnus-view-pseudos 'automatic)))
466 (gnus-uu-decode-uu n)))
468 (defun gnus-uu-decode-uu-and-save-view (n dir)
469 "Decodes, views and saves the resulting file."
471 (list current-prefix-arg
472 (read-file-name "Uudecode, view and save in dir: "
474 gnus-uu-default-dir t)))
475 (let ((gnus-view-pseudos (or gnus-view-pseudos 'automatic)))
476 (gnus-uu-decode-uu-and-save n dir)))
478 (defun gnus-uu-decode-unshar-view (&optional n)
479 "Unshars and views the current article."
481 (let ((gnus-view-pseudos (or gnus-view-pseudos 'automatic)))
482 (gnus-uu-decode-unshar n)))
484 (defun gnus-uu-decode-unshar-and-save-view (n dir)
485 "Unshars and saves the current article."
487 (list current-prefix-arg
488 (read-file-name "Unshar, view and save in dir: "
490 gnus-uu-default-dir t)))
491 (let ((gnus-view-pseudos (or gnus-view-pseudos 'automatic)))
492 (gnus-uu-decode-unshar-and-save n dir)))
494 (defun gnus-uu-decode-save-view (n file)
495 "Saves and views the current article."
497 (list current-prefix-arg
498 (read-file-name (if gnus-uu-save-separate-articles
499 "Save articles is dir: "
500 "Save articles in file: ")
501 gnus-uu-default-dir gnus-uu-default-dir)))
502 (let ((gnus-view-pseudos (or gnus-view-pseudos 'automatic)))
503 (gnus-uu-decode-save n file)))
505 (defun gnus-uu-decode-binhex-view (n file)
506 "Unbinhexes and views the current article."
508 (list current-prefix-arg
509 (read-file-name "Unbinhex, view and save in dir: "
510 gnus-uu-default-dir gnus-uu-default-dir)))
511 (setq gnus-uu-binhex-article-name
512 (make-temp-name (concat gnus-uu-work-dir "binhex")))
513 (let ((gnus-view-pseudos (or gnus-view-pseudos 'automatic)))
514 (gnus-uu-decode-binhex n file)))
517 ;; Digest and forward articles
519 (defun gnus-uu-digest-mail-forward (&optional n post)
520 "Digests and forwards all articles in this series."
522 (let ((gnus-uu-save-in-digest t)
523 (file (make-temp-name (nnheader-concat gnus-uu-tmp-dir "forward")))
524 gnus-uu-digest-buffer subject from)
525 (gnus-setup-message 'forward
526 (setq gnus-uu-digest-from-subject nil)
527 (setq gnus-uu-digest-buffer
528 (gnus-get-buffer-create " *gnus-uu-forward*"))
529 (gnus-uu-decode-save n file)
530 (set-buffer gnus-uu-digest-buffer)
531 (let ((fs gnus-uu-digest-from-subject))
534 subject (gnus-simplify-subject-fuzzy (cdar fs))
536 (while (and fs (or from subject))
538 (unless (string= from (caar fs))
541 (unless (string= (gnus-simplify-subject-fuzzy (cdar fs))
546 (setq subject "Digested Articles"))
549 (if (gnus-news-group-p gnus-newsgroup-name)
552 (mime-edit-enclose-digest-region (point-min) (point-max))
554 (message-news nil (concat "[" from "] " subject))
555 (message-mail nil (concat "[" from "] " subject)))
557 ;; Make sure we're at the start of the line.
560 ;; Insert the forwarded buffer.
561 (insert-buffer gnus-uu-digest-buffer)
562 (kill-buffer gnus-uu-digest-buffer)
563 (set-text-properties (point-min) (point-max) nil)
564 (message-position-point))
565 (setq gnus-uu-digest-from-subject nil)))
567 (defun gnus-uu-digest-post-forward (&optional n)
568 "Digest and forward to a newsgroup."
570 (gnus-uu-digest-mail-forward n t))
574 (defun gnus-message-process-mark (unmarkp new-marked)
575 (let ((old (- (length gnus-newsgroup-processable) (length new-marked))))
576 (message "%d mark%s %s%s"
578 (if (= (length new-marked) 1) "" "s")
579 (if unmarkp "removed" "added")
585 (format ", %d remain marked"
586 (length gnus-newsgroup-processable)))
588 (format ", %d already marked" old))))))
590 (defun gnus-new-processable (unmarkp articles)
592 (gnus-intersection gnus-newsgroup-processable articles)
593 (gnus-set-difference articles gnus-newsgroup-processable)))
595 (defun gnus-uu-mark-by-regexp (regexp &optional unmark)
596 "Set the process mark on articles whose subjects match REGEXP.
597 When called interactively, prompt for REGEXP.
598 Optional UNMARK non-nil means unmark instead of mark."
599 (interactive "sMark (regexp): \nP")
601 (let* ((articles (gnus-uu-find-articles-matching regexp))
602 (new-marked (gnus-new-processable unmark articles)))
605 (gnus-summary-remove-process-mark (pop articles))
606 (gnus-summary-set-process-mark (pop articles))))
607 (gnus-message-process-mark unmark new-marked)))
608 (gnus-summary-position-point))
610 (defun gnus-uu-unmark-by-regexp (regexp)
611 "Remove the process mark from articles whose subjects match REGEXP.
612 When called interactively, prompt for REGEXP."
613 (interactive "sUnmark (regexp): ")
614 (gnus-uu-mark-by-regexp regexp t))
616 (defun gnus-uu-mark-series ()
617 "Mark the current series with the process mark."
619 (let ((articles (gnus-uu-find-articles-matching)))
621 (gnus-summary-set-process-mark (car articles))
622 (setq articles (cdr articles)))
624 (gnus-summary-position-point))
626 (defun gnus-uu-mark-region (beg end &optional unmark)
627 "Set the process mark on all articles between point and mark."
631 (while (< (point) end)
633 (gnus-summary-remove-process-mark (gnus-summary-article-number))
634 (gnus-summary-set-process-mark (gnus-summary-article-number)))
636 (gnus-summary-position-point))
638 (defun gnus-uu-unmark-region (beg end)
639 "Remove the process mark from all articles between point and mark."
641 (gnus-uu-mark-region beg end t))
643 (defun gnus-uu-mark-buffer ()
644 "Set the process mark on all articles in the buffer."
646 (gnus-uu-mark-region (point-min) (point-max)))
648 (defun gnus-uu-unmark-buffer ()
649 "Remove the process mark on all articles in the buffer."
651 (gnus-uu-mark-region (point-min) (point-max) t))
653 (defun gnus-uu-mark-thread ()
654 "Marks all articles downwards in this thread."
656 (gnus-save-hidden-threads
657 (let ((level (gnus-summary-thread-level)))
658 (while (and (gnus-summary-set-process-mark
659 (gnus-summary-article-number))
660 (zerop (gnus-summary-next-subject 1 nil t))
661 (> (gnus-summary-thread-level) level)))))
662 (gnus-summary-position-point))
664 (defun gnus-uu-unmark-thread ()
665 "Unmarks all articles downwards in this thread."
667 (let ((level (gnus-summary-thread-level)))
668 (while (and (gnus-summary-remove-process-mark
669 (gnus-summary-article-number))
670 (zerop (gnus-summary-next-subject 1))
671 (> (gnus-summary-thread-level) level))))
672 (gnus-summary-position-point))
674 (defun gnus-uu-invert-processable ()
675 "Invert the list of process-marked articles."
677 (let ((data gnus-newsgroup-data)
681 (if (memq (setq number (gnus-data-number (pop data)))
682 gnus-newsgroup-processable)
683 (gnus-summary-remove-process-mark number)
684 (gnus-summary-set-process-mark number)))))
685 (gnus-summary-position-point))
687 (defun gnus-uu-mark-over (&optional score)
688 "Mark all articles with a score over SCORE (the prefix)."
690 (let ((score (or score gnus-summary-default-score 0))
691 (data gnus-newsgroup-data))
694 (when (> (or (cdr (assq (gnus-data-number (car data))
695 gnus-newsgroup-scored))
696 gnus-summary-default-score 0)
698 (gnus-summary-set-process-mark (caar data)))
699 (setq data (cdr data))))
700 (gnus-summary-position-point)))
702 (defun gnus-uu-mark-sparse ()
703 "Mark all series that have some articles marked."
705 (let ((marked (nreverse gnus-newsgroup-processable))
706 subject articles total headers)
708 (error "No articles marked with the process mark"))
709 (setq gnus-newsgroup-processable nil)
712 (and (vectorp (setq headers
713 (gnus-summary-article-header (car marked))))
714 (setq subject (mail-header-subject headers)
715 articles (gnus-uu-find-articles-matching
716 (gnus-uu-reginize-string subject))
717 total (nconc total articles)))
719 (gnus-summary-set-process-mark (car articles))
720 (setcdr marked (delq (car articles) (cdr marked)))
721 (setq articles (cdr articles)))
722 (setq marked (cdr marked)))
723 (setq gnus-newsgroup-processable (nreverse total)))
724 (gnus-summary-position-point)))
726 (defun gnus-uu-mark-all ()
727 "Mark all articles in \"series\" order."
729 (setq gnus-newsgroup-processable nil)
731 (let ((data gnus-newsgroup-data)
734 (when (and (not (memq (setq number (gnus-data-number (car data)))
735 gnus-newsgroup-processable))
736 (vectorp (gnus-data-header (car data))))
737 (gnus-summary-goto-subject number)
738 (gnus-uu-mark-series))
739 (setq data (cdr data)))))
740 (gnus-summary-position-point))
742 ;; All PostScript functions written by Erik Selberg <speed@cs.washington.edu>.
744 (defun gnus-uu-decode-postscript (&optional n)
745 "Gets postscript of the current article."
747 (gnus-uu-decode-with-method 'gnus-uu-decode-postscript-article n))
749 (defun gnus-uu-decode-postscript-view (&optional n)
750 "Gets and views the current article."
752 (let ((gnus-view-pseudos (or gnus-view-pseudos 'automatic)))
753 (gnus-uu-decode-postscript n)))
755 (defun gnus-uu-decode-postscript-and-save (n dir)
756 "Extracts postscript and saves the current article."
758 (list current-prefix-arg
759 (file-name-as-directory
760 (read-file-name "Save in dir: "
762 gnus-uu-default-dir t))))
763 (gnus-uu-decode-with-method 'gnus-uu-decode-postscript-article
766 (defun gnus-uu-decode-postscript-and-save-view (n dir)
767 "Decodes, views and saves the resulting file."
769 (list current-prefix-arg
770 (read-file-name "Where do you want to save the file(s)? "
772 gnus-uu-default-dir t)))
773 (let ((gnus-view-pseudos (or gnus-view-pseudos 'automatic)))
774 (gnus-uu-decode-postscript-and-save n dir)))
777 ;; Internal functions.
779 (defun gnus-uu-decode-with-method (method n &optional save not-insert
781 (gnus-uu-initialize scan)
783 (setq gnus-uu-default-dir save))
784 ;; Create the directory we save to.
785 (when (and scan cdir save
786 (not (file-exists-p save)))
787 (make-directory save t))
788 (let ((articles (gnus-uu-get-list-of-articles n))
790 (setq files (gnus-uu-grab-articles articles method t))
791 (let ((gnus-current-article (car articles)))
793 (setq files (gnus-uu-scan-directory gnus-uu-work-dir))))
795 (gnus-uu-save-files files save))
796 (when (eq gnus-uu-do-not-unpack-archives nil)
797 (setq files (gnus-uu-unpack-files files)))
798 (setq files (nreverse (gnus-uu-get-actions files)))
799 (or not-insert (not gnus-insert-pseudo-articles)
800 (gnus-summary-insert-pseudos files save))))
802 (defun gnus-uu-scan-directory (dir &optional rec)
803 "Return a list of all files under DIR."
804 (let ((files (directory-files dir t))
806 (while (setq file (pop files))
807 (unless (member (file-name-nondirectory file) '("." ".."))
808 (push (list (cons 'name file)
809 (cons 'article gnus-current-article))
811 (when (file-directory-p file)
812 (setq out (nconc (gnus-uu-scan-directory file t) out)))))
817 (defun gnus-uu-save-files (files dir)
819 (let ((len (length files))
820 (reg (concat "^" (regexp-quote gnus-uu-work-dir)))
821 to-file file fromdir)
822 (while (setq file (cdr (assq 'name (pop files))))
823 (when (file-exists-p file)
824 (string-match reg file)
825 (setq fromdir (substring file (match-end 0)))
826 (if (file-directory-p file)
827 (gnus-make-directory (concat dir fromdir))
828 (setq to-file (concat dir fromdir))
829 (when (or (not (file-exists-p to-file))
830 (eq gnus-uu-be-dangerous t)
831 (and gnus-uu-be-dangerous
832 (gnus-y-or-n-p (format "%s exists; overwrite? "
834 (copy-file file to-file t t)))))
835 (gnus-message 5 "Saved %d file%s" len (if (= len 1) "" "s"))))
837 ;; Functions for saving and possibly digesting articles without
840 ;; Function called by gnus-uu-grab-articles to treat each article.
841 (defun gnus-uu-save-article (buffer in-state)
843 (gnus-uu-save-separate-articles
846 (gnus-write-buffer-as-coding-system
847 nnheader-text-coding-system
848 (concat gnus-uu-saved-article-name gnus-current-article))
849 (cond ((eq in-state 'first) (list gnus-uu-saved-article-name 'begin))
850 ((eq in-state 'first-and-last) (list gnus-uu-saved-article-name
852 ((eq in-state 'last) (list 'end))
853 (t (list 'middle)))))
854 ((not gnus-uu-save-in-digest)
857 (write-region (point-min) (point-max) gnus-uu-saved-article-name t)
858 (cond ((eq in-state 'first) (list gnus-uu-saved-article-name 'begin))
859 ((eq in-state 'first-and-last) (list gnus-uu-saved-article-name
861 ((eq in-state 'last) (list 'end))
862 (t (list 'middle)))))
864 (let ((header (gnus-summary-article-header)))
865 (push (cons (mail-header-from header)
866 (mail-header-subject header))
867 gnus-uu-digest-from-subject))
868 (let ((name (file-name-nondirectory gnus-uu-saved-article-name))
869 beg subj headers headline sorthead body end-string state)
870 (if (or (eq in-state 'first)
871 (eq in-state 'first-and-last))
873 (setq state (list 'begin))
875 (set-buffer (gnus-get-buffer-create "*gnus-uu-body*"))
878 (set-buffer (gnus-get-buffer-create "*gnus-uu-pre*"))
881 "Date: %s\nFrom: %s\nSubject: %s Digest\n\n"
882 (current-time-string) name name))
883 (insert "Topics:\n")))
884 (when (not (eq in-state 'end))
885 (setq state (list 'middle))))
887 (set-buffer "*gnus-uu-body*")
888 (goto-char (setq beg (point-max)))
892 (let (buffer-read-only)
893 (gnus-set-text-properties (point-min) (point-max) nil)
894 ;; These two are necessary for XEmacs 19.12 fascism.
895 (put-text-property (point-min) (point-max) 'invisible nil)
896 (put-text-property (point-min) (point-max) 'intangible nil))
897 (goto-char (point-min))
898 (re-search-forward "\n\n")
899 (unless gnus-uu-digest-buffer
900 ;; Quote all 30-dash lines.
902 (while (re-search-forward "^-" nil t)
906 (setq body (buffer-substring (1- (point)) (point-max)))
907 (narrow-to-region (point-min) (point))
908 (if (not (setq headers gnus-uu-digest-headers))
909 (setq sorthead (buffer-substring (point-min) (point-max)))
911 (setq headline (car headers))
912 (setq headers (cdr headers))
913 (goto-char (point-min))
914 (while (re-search-forward headline nil t)
919 (or (and (re-search-forward "^[^ \t]" nil t)
921 (progn (forward-line 1) (point)))))))))
923 (insert message-forward-start-separator)
924 (insert sorthead) (goto-char (point-max))
925 (insert body) (goto-char (point-max))
927 (when (re-search-forward "^Subject:" nil t)
928 (setq subj (nnheader-decode-subject
929 (buffer-substring (match-end 0) (std11-field-end)))))
932 (set-buffer "*gnus-uu-pre*")
933 (insert (format " %s\n" subj)))))
934 (when (or (eq in-state 'last)
935 (eq in-state 'first-and-last))
936 (if gnus-uu-digest-buffer
937 (with-current-buffer gnus-uu-digest-buffer
939 (insert-buffer "*gnus-uu-pre*")
940 (goto-char (point-max))
941 (insert-buffer "*gnus-uu-body*"))
943 (set-buffer "*gnus-uu-pre*")
944 (insert (format "\n\n%s\n\n" (make-string 70 ?-)))
945 (if gnus-uu-digest-buffer
946 (with-current-buffer gnus-uu-digest-buffer
948 (insert-buffer "*gnus-uu-pre*"))
949 (gnus-write-buffer-as-coding-system
950 nnheader-text-coding-system gnus-uu-saved-article-name)))
952 (set-buffer "*gnus-uu-body*")
953 (goto-char (point-max))
955 (concat (setq end-string (format "End of %s Digest" name))
957 (insert (concat (make-string (length end-string) ?*) "\n"))
958 (if gnus-uu-digest-buffer
959 (with-current-buffer gnus-uu-digest-buffer
960 (goto-char (point-max))
961 (insert-buffer "*gnus-uu-body*"))
962 (let ((file-name-coding-system nnmail-pathname-coding-system)
963 (pathname-coding-system nnmail-pathname-coding-system))
964 (write-region-as-coding-system
965 nnheader-text-coding-system
966 (point-min) (point-max) gnus-uu-saved-article-name t)))))
967 (gnus-kill-buffer "*gnus-uu-pre*")
968 (gnus-kill-buffer "*gnus-uu-body*")
970 (if (memq 'begin state)
971 (cons gnus-uu-saved-article-name state)
974 ;; Binhex treatment - not very advanced.
976 (defvar gnus-uu-binhex-body-line
977 "^[^:]...............................................................$")
978 (defvar gnus-uu-binhex-begin-line
979 "^:...............................................................$")
980 (defvar gnus-uu-binhex-end-line
983 (defun gnus-uu-binhex-article (buffer in-state)
984 (let (state start-char)
988 (goto-char (point-min))
989 (when (not (re-search-forward gnus-uu-binhex-begin-line nil t))
990 (when (not (re-search-forward gnus-uu-binhex-body-line nil t))
991 (setq state (list 'wrong-type))))
993 (if (memq 'wrong-type state)
996 (setq start-char (point))
997 (if (looking-at gnus-uu-binhex-begin-line)
999 (setq state (list 'begin))
1000 (write-region 1 1 gnus-uu-binhex-article-name))
1001 (setq state (list 'middle)))
1002 (goto-char (point-max))
1003 (re-search-backward (concat gnus-uu-binhex-body-line "\\|"
1004 gnus-uu-binhex-end-line)
1006 (when (looking-at gnus-uu-binhex-end-line)
1007 (setq state (if (memq 'begin state)
1012 (when (file-exists-p gnus-uu-binhex-article-name)
1013 (write-region-as-binary start-char (point)
1014 gnus-uu-binhex-article-name 'append))))
1015 (if (memq 'begin state)
1016 (cons gnus-uu-binhex-article-name state)
1021 (defun gnus-uu-decode-postscript-article (process-buffer in-state)
1022 (let ((state (list 'ok))
1023 start-char end-char file-name)
1025 (set-buffer process-buffer)
1026 (goto-char (point-min))
1027 (if (not (re-search-forward gnus-uu-postscript-begin-string nil t))
1028 (setq state (list 'wrong-type))
1030 (setq start-char (point))
1031 (if (not (re-search-forward gnus-uu-postscript-end-string nil t))
1032 (setq state (list 'wrong-type))
1033 (setq end-char (point))
1034 (set-buffer (gnus-get-buffer-create gnus-uu-output-buffer-name))
1035 (insert-buffer-substring process-buffer start-char end-char)
1036 (setq file-name (concat gnus-uu-work-dir
1037 (cdr gnus-article-current) ".ps"))
1038 (write-region (point-min) (point-max) file-name)
1039 (setq state (list file-name 'begin 'end)))))
1045 (defun gnus-uu-get-actions (files)
1046 (let ((ofiles files)
1049 (setq name (cdr (assq 'name (car files))))
1051 (setq action (gnus-uu-get-action name))
1052 (setcar files (nconc (list (if (string= action "gnus-uu-archive")
1053 (cons 'action "file")
1054 (cons 'action action))
1055 (cons 'execute (gnus-uu-command
1058 (setq files (cdr files)))
1061 (defun gnus-uu-get-action (file-name)
1064 (gnus-uu-choose-action
1067 gnus-uu-user-view-rules
1068 (if gnus-uu-ignore-default-view-rules
1070 gnus-uu-default-view-rules)
1071 gnus-uu-user-view-rules-end)))
1072 (when (and (not (string= (or action "") "gnus-uu-archive"))
1073 gnus-uu-view-with-metamail)
1075 (gnus-uu-choose-action file-name gnus-uu-ext-to-mime-list))
1076 (setq action (format "metamail -d -b -c \"%s\"" action))))
1080 ;; Functions for treating subjects and collecting series.
1082 (defun gnus-uu-reginize-string (string)
1083 ;; Takes a string and puts a \ in front of every special character;
1084 ;; replaces the last thing that looks like "2/3" with "[0-9]+/3"
1085 ;; or, if it can't find something like that, tries "2 of 3", then
1086 ;; finally just replaces the next to last number with "[0-9]+".
1088 (set-buffer (gnus-get-buffer-create gnus-uu-output-buffer-name))
1089 (buffer-disable-undo)
1091 (insert (regexp-quote string))
1093 (setq case-fold-search nil)
1096 (if (re-search-backward "\\([^0-9]\\)[0-9]+/\\([0-9]+\\)" nil t)
1097 (replace-match "\\1[0-9]+/\\2")
1100 (if (re-search-backward "\\([^0-9]\\)[0-9]+[ \t]*of[ \t]*\\([0-9]+\\)"
1102 (replace-match "\\1[0-9]+ of \\2")
1105 (if (re-search-backward "\\([^0-9]\\)[0-9]+\\([^0-9]+\\)[0-9]+"
1107 (replace-match "\\1[0-9]+\\2[0-9]+" t nil nil nil))))
1110 (while (re-search-forward "[ \t]+" nil t)
1111 (replace-match "[ \t]+" t t))
1113 (buffer-substring 1 (point-max))))
1115 (defun gnus-uu-get-list-of-articles (n)
1116 ;; If N is non-nil, the article numbers of the N next articles
1117 ;; will be returned.
1118 ;; If any articles have been marked as processable, they will be
1120 ;; Failing that, articles that have subjects that are part of the
1121 ;; same "series" as the current will be returned.
1125 (setq n (prefix-numeric-value n))
1126 (let ((backward (< n 0))
1130 (push (gnus-summary-article-number)
1132 (gnus-summary-search-forward nil nil backward))
1134 (nreverse articles)))
1135 (gnus-newsgroup-processable
1136 (reverse gnus-newsgroup-processable))
1138 (gnus-uu-find-articles-matching)))))
1140 (defun gnus-uu-string< (l1 l2)
1141 (string< (car l1) (car l2)))
1143 (defun gnus-uu-find-articles-matching
1144 (&optional subject only-unread do-not-translate)
1145 ;; Finds all articles that matches the regexp SUBJECT. If it is
1146 ;; nil, the current article name will be used. If ONLY-UNREAD is
1147 ;; non-nil, only unread articles are chosen. If DO-NOT-TRANSLATE is
1148 ;; non-nil, article names are not equalized before sorting.
1149 (let ((subject (or subject
1150 (gnus-uu-reginize-string (gnus-summary-article-subject))))
1154 ;; Collect all subjects matching subject.
1155 (let ((case-fold-search t)
1156 (data gnus-newsgroup-data)
1160 (and (not (gnus-data-pseudo-p d))
1161 (or (not only-unread)
1162 (= (setq mark (gnus-data-mark d))
1164 (= mark gnus-ticked-mark)
1165 (= mark gnus-dormant-mark))
1166 (setq subj (mail-header-subject (gnus-data-header d)))
1167 (string-match subject subj)
1168 (push (cons subj (gnus-data-number d))
1169 list-of-subjects))))
1171 ;; Expand numbers, sort, and return the list of article
1173 (mapcar (lambda (sub) (cdr sub))
1174 (sort (gnus-uu-expand-numbers
1176 (not do-not-translate))
1177 'gnus-uu-string<))))))
1179 (defun gnus-uu-expand-numbers (string-list &optional translate)
1180 ;; Takes a list of strings and "expands" all numbers in all the
1181 ;; strings. That is, this function makes all numbers equal length by
1182 ;; prepending lots of zeroes before each number. This is to ease later
1183 ;; sorting to find out what sequence the articles are supposed to be
1184 ;; decoded in. Returns the list of expanded strings.
1185 (let ((out-list string-list)
1188 (set-buffer (gnus-get-buffer-create gnus-uu-output-buffer-name))
1189 (buffer-disable-undo)
1192 (insert (caar string-list))
1193 ;; Translate multiple spaces to one space.
1194 (goto-char (point-min))
1195 (while (re-search-forward "[ \t]+" nil t)
1196 (replace-match " "))
1197 ;; Translate all characters to "a".
1198 (goto-char (point-min))
1200 (while (re-search-forward "[A-Za-z]" nil t)
1201 (replace-match "a" t t)))
1203 (goto-char (point-min))
1204 (while (re-search-forward "[0-9]+" nil t)
1207 (string-to-int (buffer-substring
1208 (match-beginning 0) (match-end 0))))))
1209 (setq string (buffer-substring 1 (point-max)))
1210 (setcar (car string-list) string)
1211 (setq string-list (cdr string-list))))
1215 ;; `gnus-uu-grab-articles' is the general multi-article treatment
1216 ;; function. It takes a list of articles to be grabbed and a function
1217 ;; to apply to each article.
1219 ;; The function to be called should take two parameters. The first
1220 ;; parameter is the article buffer. The function should leave the
1221 ;; result, if any, in this buffer. Most treatment functions will just
1222 ;; generate files...
1224 ;; The second parameter is the state of the list of articles, and can
1225 ;; have four values: `first', `middle', `last' and `first-and-last'.
1227 ;; The function should return a list. The list may contain the
1228 ;; following symbols:
1229 ;; `error' if an error occurred
1230 ;; `begin' if the beginning of an encoded file has been received
1231 ;; If the list returned contains a `begin', the first element of
1232 ;; the list *must* be a string with the file name of the decoded
1234 ;; `end' if the end of an encoded file has been received
1235 ;; `middle' if the article was a body part of an encoded file
1236 ;; `wrong-type' if the article was not a part of an encoded file
1237 ;; `ok', which can be used everything is ok
1239 (defvar gnus-uu-has-been-grabbed nil)
1241 (defun gnus-uu-unmark-list-of-grabbed (&optional dont-unmark-last-article)
1243 (if (not (and gnus-uu-has-been-grabbed
1244 gnus-uu-unmark-articles-not-decoded))
1246 (when dont-unmark-last-article
1247 (setq art (car gnus-uu-has-been-grabbed))
1248 (setq gnus-uu-has-been-grabbed (cdr gnus-uu-has-been-grabbed)))
1249 (while gnus-uu-has-been-grabbed
1250 (gnus-summary-tick-article (car gnus-uu-has-been-grabbed) t)
1251 (setq gnus-uu-has-been-grabbed (cdr gnus-uu-has-been-grabbed)))
1252 (when dont-unmark-last-article
1253 (setq gnus-uu-has-been-grabbed (list art))))))
1255 ;; This function takes a list of articles and a function to apply to
1256 ;; each article grabbed.
1258 ;; This function returns a list of files decoded if the grabbing and
1259 ;; the process-function has been successful and nil otherwise.
1260 (defun gnus-uu-grab-articles (articles process-function
1261 &optional sloppy limit no-errors)
1262 (let ((state 'first)
1263 (gnus-asynchronous nil)
1264 (gnus-inhibit-treatment t)
1265 has-been-begin article result-file result-files process-state
1266 gnus-summary-display-article-function
1267 gnus-article-display-hook gnus-article-prepare-hook gnus-display-mime-function
1268 article-series files)
1270 (while (and articles
1271 (not (memq 'error process-state))
1273 (not (memq 'end process-state))))
1275 (setq article (pop articles))
1276 (when (vectorp (gnus-summary-article-header article))
1277 (push article article-series)
1280 (if (eq state 'first)
1281 (setq state 'first-and-last)
1282 (setq state 'last)))
1284 (let ((part (gnus-uu-part-number article)))
1285 (gnus-message 6 "Getting article %d%s..."
1286 article (if (string= part "") "" (concat ", " part))))
1287 (gnus-summary-display-article article)
1289 ;; Push the article to the processing function.
1291 (set-buffer gnus-original-article-buffer)
1292 (let ((buffer-read-only nil))
1294 (set-buffer gnus-summary-buffer)
1296 (funcall process-function
1297 gnus-original-article-buffer state)))))
1299 (gnus-summary-remove-process-mark article)
1301 ;; If this is the beginning of a decoded file, we push it
1303 (when (or (memq 'begin process-state)
1304 (and (or (eq state 'first)
1305 (eq state 'first-and-last))
1306 (memq 'ok process-state)))
1307 (when has-been-begin
1308 ;; If there is a `result-file' here, that means that the
1309 ;; file was unsuccessfully decoded, so we delete it.
1310 (when (and result-file
1311 (file-exists-p result-file)
1312 (not gnus-uu-be-dangerous)
1313 (or (eq gnus-uu-be-dangerous t)
1315 (format "Delete unsuccessfully decoded file %s"
1317 (delete-file result-file)))
1318 (when (memq 'begin process-state)
1319 (setq result-file (car process-state)))
1320 (setq has-been-begin t))
1322 ;; Check whether we have decoded one complete file.
1323 (when (memq 'end process-state)
1324 (setq article-series nil)
1325 (setq has-been-begin nil)
1326 (if (stringp result-file)
1327 (setq files (list result-file))
1328 (setq files result-file))
1329 (setq result-file (car files))
1331 (push (list (cons 'name (pop files))
1332 (cons 'article article))
1334 ;; Allow user-defined functions to be run on this file.
1335 (when gnus-uu-grabbed-file-functions
1336 (let ((funcs gnus-uu-grabbed-file-functions))
1337 (unless (listp funcs)
1338 (setq funcs (list funcs)))
1340 (funcall (pop funcs) result-file))))
1341 (setq result-file nil)
1342 ;; Check whether we have decoded enough articles.
1343 (and limit (= (length result-files) limit)
1344 (setq articles nil)))
1346 ;; If this is the last article to be decoded, and
1347 ;; we still haven't reached the end, then we delete
1348 ;; the partially decoded file.
1349 (and (or (eq state 'last) (eq state 'first-and-last))
1350 (not (memq 'end process-state))
1352 (file-exists-p result-file)
1353 (not gnus-uu-be-dangerous)
1354 (or (eq gnus-uu-be-dangerous t)
1356 (format "Delete incomplete file %s? " result-file)))
1357 (delete-file result-file))
1359 ;; If this was a file of the wrong sort, then
1360 (when (and (or (memq 'wrong-type process-state)
1361 (memq 'error process-state))
1362 gnus-uu-unmark-articles-not-decoded)
1363 (gnus-summary-tick-article article t))
1365 ;; Set the new series state.
1366 (if (and (not has-been-begin)
1368 (or (memq 'end process-state)
1369 (memq 'middle process-state)))
1371 (setq process-state (list 'error))
1372 (gnus-message 2 "No begin part at the beginning")
1374 (setq state 'middle)))
1376 ;; When there are no result-files, then something must be wrong.
1380 ((not has-been-begin)
1381 (gnus-message 2 "Wrong type file"))
1382 ((memq 'error process-state)
1383 (gnus-message 2 "An error occurred during decoding"))
1384 ((not (or (memq 'ok process-state)
1385 (memq 'end process-state)))
1386 (gnus-message 2 "End of articles reached before end of file")))
1387 ;; Make unsuccessfully decoded articles unread.
1388 (when gnus-uu-unmark-articles-not-decoded
1389 (while article-series
1390 (gnus-summary-tick-article (pop article-series) t)))))
1394 (defun gnus-uu-grab-view (file)
1395 "View FILE using the gnus-uu methods."
1396 (let ((action (gnus-uu-get-action file)))
1397 (gnus-execute-command
1398 (if (string-match "%" action)
1399 (format action file)
1400 (concat action " " file))
1401 (eq gnus-view-pseudos 'not-confirm))))
1403 (defun gnus-uu-grab-move (file)
1404 "Move FILE to somewhere."
1405 (when gnus-uu-default-dir
1406 (let ((to-file (concat (file-name-as-directory gnus-uu-default-dir)
1407 (file-name-nondirectory file))))
1408 (cond ((fboundp 'make-symbolic-link)
1409 (rename-file file to-file)
1410 (unless (file-exists-p file)
1411 (make-symbolic-link to-file file)))
1413 (copy-file file to-file))))))
1415 (defun gnus-uu-part-number (article)
1416 (let* ((header (gnus-summary-article-header article))
1417 (subject (and header (mail-header-subject header)))
1420 (while (string-match "[0-9]+/[0-9]+\\|[0-9]+[ \t]+of[ \t]+[0-9]+"
1422 (setq part (match-string 0 subject))
1423 (setq subject (substring subject (match-end 0)))))
1425 (while (string-match "\\([0-9]+\\)[^0-9]+\\([0-9]+\\)" subject)
1426 (setq part (match-string 0 subject))
1427 (setq subject (substring subject (match-end 0)))))
1430 (defun gnus-uu-uudecode-sentinel (process event)
1431 (delete-process (get-process process)))
1433 (defun gnus-uu-uustrip-article (process-buffer in-state)
1434 ;; Uudecodes a file asynchronously.
1436 (set-buffer process-buffer)
1437 (let ((state (list 'wrong-type))
1438 process-connection-type case-fold-search buffer-read-only
1440 (goto-char (point-min))
1442 ;; Deal with ^M at the end of the lines.
1443 (when gnus-uu-kill-carriage-return
1445 (while (search-forward "\r" nil t)
1446 (delete-backward-char 1))))
1448 (while (or (re-search-forward gnus-uu-begin-string nil t)
1449 (re-search-forward gnus-uu-body-line nil t))
1450 (setq state (list 'ok))
1451 ;; Ok, we are at the first uucoded line.
1453 (setq start-char (point))
1455 (if (not (looking-at gnus-uu-begin-string))
1456 (setq state (list 'middle))
1457 ;; This is the beginning of a uuencoded article.
1458 ;; We replace certain characters that could make things messy.
1459 (setq gnus-uu-file-name
1460 (let ((nnheader-file-name-translation-alist
1461 '((?/ . ?,) (? . ?_) (?* . ?_) (?$ . ?_))))
1462 (nnheader-translate-file-chars (match-string 1))))
1463 (replace-match (concat "begin 644 " gnus-uu-file-name) t t)
1465 ;; Remove any non gnus-uu-body-line right after start.
1467 (while (and (not (eobp))
1468 (not (looking-at gnus-uu-body-line)))
1471 ;; If a process is running, we kill it.
1472 (when (and gnus-uu-uudecode-process
1473 (memq (process-status gnus-uu-uudecode-process)
1475 (delete-process gnus-uu-uudecode-process)
1476 (gnus-uu-unmark-list-of-grabbed t))
1478 ;; Start a new uudecoding process.
1479 (let ((cdir default-directory))
1482 (cd gnus-uu-work-dir)
1483 (setq gnus-uu-uudecode-process
1486 (gnus-get-buffer-create gnus-uu-output-buffer-name)
1487 shell-file-name shell-command-switch
1488 (format "cd %s %s uudecode" gnus-uu-work-dir
1489 gnus-shell-command-separator))))
1491 (set-process-sentinel
1492 gnus-uu-uudecode-process 'gnus-uu-uudecode-sentinel)
1493 (setq state (list 'begin))
1494 (push (concat gnus-uu-work-dir gnus-uu-file-name) files))
1496 ;; We look for the end of the thing to be decoded.
1497 (if (re-search-forward gnus-uu-end-string nil t)
1499 (goto-char (point-max))
1500 (re-search-backward gnus-uu-body-line nil t))
1504 (when gnus-uu-uudecode-process
1505 (when (memq (process-status gnus-uu-uudecode-process) '(run stop))
1506 ;; Try to correct mishandled uucode.
1507 (when gnus-uu-correct-stripped-uucode
1508 (gnus-uu-check-correct-stripped-uucode start-char (point)))
1509 (gnus-run-hooks 'gnus-uu-pre-uudecode-hook)
1511 ;; Send the text to the process.
1513 (process-send-region
1514 gnus-uu-uudecode-process start-char (point))
1517 (delete-process gnus-uu-uudecode-process)
1518 (gnus-message 2 "gnus-uu: Couldn't uudecode")
1519 (setq state (list 'wrong-type)))))
1521 (if (memq 'end state)
1523 ;; Send an EOF, just in case.
1525 (process-send-eof gnus-uu-uudecode-process))
1526 (while (memq (process-status gnus-uu-uudecode-process)
1528 (accept-process-output gnus-uu-uudecode-process 1)))
1529 (when (or (not gnus-uu-uudecode-process)
1530 (not (memq (process-status gnus-uu-uudecode-process)
1532 (setq state (list 'wrong-type)))))))
1534 (if (memq 'begin state)
1535 (cons (if (= (length files) 1) (car files) files) state)
1538 (defvar gnus-uu-unshar-warning
1541 Shell archives are an archaic method of bundling files for distribution
1542 across computer networks. During the unpacking process, arbitrary commands
1543 are executed on your system, and all kinds of nasty things can happen.
1544 Please examine the archive very carefully before you instruct Emacs to
1545 unpack it. You can browse the archive buffer using \\[scroll-other-window].
1547 If you are unsure what to do, please answer \"no\"."
1548 "Text of warning message displayed by `gnus-uu-unshar-article'.
1549 Make sure that this text consists only of few text lines. Otherwise,
1550 Gnus might fail to display all of it.")
1553 ;; This function is used by `gnus-uu-grab-articles' to treat
1554 ;; a shared article.
1555 (defun gnus-uu-unshar-article (process-buffer in-state)
1556 (let ((state (list 'ok))
1559 (set-buffer process-buffer)
1560 (goto-char (point-min))
1561 (if (not (re-search-forward gnus-uu-shar-begin-string nil t))
1562 (setq state (list 'wrong-type))
1563 (save-window-excursion
1565 (switch-to-buffer (current-buffer))
1566 (delete-other-windows)
1567 (let ((buffer (get-buffer-create (generate-new-buffer-name
1571 (with-current-buffer buffer
1572 (insert (substitute-command-keys
1573 gnus-uu-unshar-warning))
1574 (goto-char (point-min))
1575 (display-buffer buffer)
1576 (yes-or-no-p "This is a shell archive, unshar it? "))
1577 (kill-buffer buffer))
1578 (setq state (list 'error))))))
1579 (unless (memq 'error state)
1581 (setq start-char (point))
1582 (call-process-region
1583 start-char (point-max) shell-file-name nil
1584 (gnus-get-buffer-create gnus-uu-output-buffer-name) nil
1585 shell-command-switch
1586 (concat "cd " gnus-uu-work-dir " "
1587 gnus-shell-command-separator " sh")))))
1590 ;; Returns the name of what the shar file is going to unpack.
1591 (defun gnus-uu-find-name-in-shar ()
1592 (let ((oldpoint (point))
1594 (goto-char (point-min))
1595 (when (re-search-forward gnus-uu-shar-name-marker nil t)
1596 (setq res (buffer-substring (match-beginning 1) (match-end 1))))
1597 (goto-char oldpoint)
1600 ;; `gnus-uu-choose-action' chooses what action to perform given the name
1601 ;; and `gnus-uu-file-action-list'. Returns either nil if no action is
1602 ;; found, or the name of the command to run if such a rule is found.
1603 (defun gnus-uu-choose-action (file-name file-action-list &optional no-ignore)
1604 (let ((action-list (copy-sequence file-action-list))
1605 (case-fold-search t)
1610 (and gnus-uu-ignore-files-by-name
1611 (string-match gnus-uu-ignore-files-by-name file-name)))
1613 (and gnus-uu-ignore-files-by-type
1614 (string-match gnus-uu-ignore-files-by-type
1615 (or (gnus-uu-choose-action
1616 file-name gnus-uu-ext-to-mime-list t)
1618 (while (not (or (eq action-list ()) action))
1619 (setq rule (car action-list))
1620 (setq action-list (cdr action-list))
1621 (when (string-match (car rule) file-name)
1622 (setq action (cadr rule)))))
1625 (defun gnus-uu-treat-archive (file-path)
1626 ;; Unpacks an archive. Returns t if unpacking is successful.
1627 (let ((did-unpack t)
1629 (setq action (gnus-uu-choose-action
1630 file-path (append gnus-uu-user-archive-rules
1631 (if gnus-uu-ignore-default-archive-rules
1633 gnus-uu-default-archive-rules))))
1636 (error "No unpackers for the file %s" file-path))
1638 (string-match "/[^/]*$" file-path)
1639 (setq dir (substring file-path 0 (match-beginning 0)))
1641 (when (member action gnus-uu-destructive-archivers)
1642 (copy-file file-path (concat file-path "~") t))
1644 (setq command (format "cd %s ; %s" dir (gnus-uu-command action file-path)))
1647 (set-buffer (gnus-get-buffer-create gnus-uu-output-buffer-name))
1650 (gnus-message 5 "Unpacking: %s..." (gnus-uu-command action file-path))
1652 (if (= 0 (call-process shell-file-name nil
1653 (gnus-get-buffer-create gnus-uu-output-buffer-name)
1654 nil shell-command-switch command))
1656 (gnus-message 2 "Error during unpacking of archive")
1657 (setq did-unpack nil))
1659 (when (member action gnus-uu-destructive-archivers)
1660 (rename-file (concat file-path "~") file-path t))
1664 (defun gnus-uu-dir-files (dir)
1665 (let ((dirs (directory-files dir t "[^/][^\\.][^\\.]?$"))
1668 (if (file-directory-p (setq file (car dirs)))
1669 (setq files (append files (gnus-uu-dir-files file)))
1671 (setq dirs (cdr dirs)))
1674 (defun gnus-uu-unpack-files (files &optional ignore)
1675 ;; Go through FILES and look for files to unpack.
1676 (let* ((totfiles (gnus-uu-ls-r gnus-uu-work-dir))
1680 (setq file (cdr (assq 'name (car files))))
1681 (when (and (not (member file ignore))
1682 (equal (gnus-uu-get-action (file-name-nondirectory file))
1684 (push file did-unpack)
1685 (unless (gnus-uu-treat-archive file)
1686 (gnus-message 2 "Error during unpacking of %s" file))
1687 (let* ((newfiles (gnus-uu-ls-r gnus-uu-work-dir))
1690 (unless (member (car nfiles) totfiles)
1691 (push (list (cons 'name (car nfiles))
1692 (cons 'original file))
1694 (setq nfiles (cdr nfiles)))
1695 (setq totfiles newfiles)))
1696 (setq files (cdr files)))
1698 (gnus-uu-unpack-files ofiles (append did-unpack ignore))
1701 (defun gnus-uu-ls-r (dir)
1702 (let* ((files (gnus-uu-directory-files dir t))
1705 (when (file-directory-p (car files))
1706 (setq ofiles (delete (car files) ofiles))
1707 (setq ofiles (append ofiles (gnus-uu-ls-r (car files)))))
1708 (setq files (cdr files)))
1713 (defun gnus-uu-directory-files (dir &optional full)
1714 (let (files out file)
1715 (setq files (directory-files dir full))
1717 (setq file (car files))
1718 (setq files (cdr files))
1719 (unless (member (file-name-nondirectory file) '("." ".."))
1721 (setq out (nreverse out))
1724 (defun gnus-uu-check-correct-stripped-uucode (start end)
1726 (let (found beg length)
1727 (if (not gnus-uu-correct-stripped-uucode)
1731 (if (re-search-forward " \\|`" end t)
1736 (when (looking-at "\n")
1741 (if (looking-at (concat gnus-uu-begin-string "\\|"
1742 gnus-uu-end-string))
1748 (setq length (- (point) beg)))
1753 (when (not (= length (- (point) beg)))
1754 (insert (make-string (- length (- (point) beg)) ? ))))
1755 (forward-line 1)))))))
1757 (defvar gnus-uu-tmp-alist nil)
1759 (defun gnus-uu-initialize (&optional scan)
1762 (when (setq entry (assoc gnus-newsgroup-name gnus-uu-tmp-alist))
1763 (if (file-exists-p (cdr entry))
1764 (setq gnus-uu-work-dir (cdr entry))
1765 (setq gnus-uu-tmp-alist (delq entry gnus-uu-tmp-alist))
1768 (setq gnus-uu-tmp-dir (file-name-as-directory
1769 (expand-file-name gnus-uu-tmp-dir)))
1770 (if (not (file-directory-p gnus-uu-tmp-dir))
1771 (error "Temp directory %s doesn't exist" gnus-uu-tmp-dir)
1772 (when (not (file-writable-p gnus-uu-tmp-dir))
1773 (error "Temp directory %s can't be written to"
1776 (setq gnus-uu-work-dir
1777 (make-temp-name (concat gnus-uu-tmp-dir "gnus")))
1778 (gnus-make-directory gnus-uu-work-dir)
1779 (set-file-modes gnus-uu-work-dir 448)
1780 (setq gnus-uu-work-dir (file-name-as-directory gnus-uu-work-dir))
1781 (push (cons gnus-newsgroup-name gnus-uu-work-dir)
1782 gnus-uu-tmp-alist))))
1785 ;; Kills the temporary uu buffers, kills any processes, etc.
1786 (defun gnus-uu-clean-up ()
1788 (and gnus-uu-uudecode-process
1789 (memq (process-status (or gnus-uu-uudecode-process "nevair"))
1791 (delete-process gnus-uu-uudecode-process))
1792 (when (setq buf (get-buffer gnus-uu-output-buffer-name))
1793 (kill-buffer buf))))
1795 (defun gnus-quote-arg-for-sh-or-csh (arg)
1796 (let ((pos 0) new-pos accum)
1797 ;; *** bug: we don't handle newline characters properly
1798 (while (setq new-pos (string-match "[!`\"$\\& \t{}]" arg pos))
1799 (push (substring arg pos new-pos) accum)
1801 (push (list (aref arg new-pos)) accum)
1802 (setq pos (1+ new-pos)))
1805 (apply 'concat (nconc (nreverse accum) (list (substring arg pos)))))))
1807 ;; Inputs an action and a filename and returns a full command, making sure
1808 ;; that the filename will be treated as a single argument when the shell
1809 ;; executes the command.
1810 (defun gnus-uu-command (action file)
1811 (let ((quoted-file (gnus-quote-arg-for-sh-or-csh file)))
1812 (if (string-match "%s" action)
1813 (format action quoted-file)
1814 (concat action " " quoted-file))))
1816 (defun gnus-uu-delete-work-dir (&optional dir)
1817 "Delete recursively all files and directories under `gnus-uu-work-dir'."
1819 (gnus-message 7 "Deleting directory %s..." dir)
1820 (setq dir gnus-uu-work-dir))
1822 (file-exists-p dir))
1823 (let ((files (directory-files dir t nil t))
1825 (while (setq file (pop files))
1826 (unless (member (file-name-nondirectory file) '("." ".."))
1827 (if (file-directory-p file)
1828 (gnus-uu-delete-work-dir file)
1829 (gnus-message 9 "Deleting file %s..." file)
1830 (delete-file file))))
1831 (delete-directory dir)))
1832 (gnus-message 7 ""))
1836 (add-hook 'gnus-exit-group-hook 'gnus-uu-clean-up)
1837 (add-hook 'gnus-exit-group-hook 'gnus-uu-delete-work-dir)
1842 ;;; uuencoded posting
1845 ;; Any function that is to be used as and encoding method will take two
1846 ;; parameters: PATH-NAME and FILE-NAME. (E.g. "/home/gaga/spiral.jpg"
1847 ;; and "spiral.jpg", respectively.) The function should return nil if
1848 ;; the encoding wasn't successful.
1849 (defcustom gnus-uu-post-encode-method 'gnus-uu-post-encode-uuencode
1850 "Function used for encoding binary files.
1851 There are three functions supplied with gnus-uu for encoding files:
1852 `gnus-uu-post-encode-uuencode', which does straight uuencoding;
1853 `gnus-uu-post-encode-mime', which encodes with base64 and adds MIME
1854 headers; and `gnus-uu-post-encode-mime-uuencode', which encodes with
1855 uuencode and adds MIME headers."
1856 :group 'gnus-extract-post
1857 :type '(radio (function-item gnus-uu-post-encode-uuencode)
1858 (function-item gnus-uu-post-encode-mime)
1859 (function-item gnus-uu-post-encode-mime-uuencode)
1860 (function :tag "Other")))
1862 (defcustom gnus-uu-post-include-before-composing nil
1863 "Non-nil means that gnus-uu will ask for a file to encode before you compose the article.
1864 If this variable is t, you can either include an encoded file with
1865 \\[gnus-uu-post-insert-binary-in-article] or have one included for you when you post the article."
1866 :group 'gnus-extract-post
1869 (defcustom gnus-uu-post-length 990
1870 "Maximum length of an article.
1871 The encoded file will be split into how many articles it takes to
1872 post the entire file."
1873 :group 'gnus-extract-post
1876 (defcustom gnus-uu-post-threaded nil
1877 "Non-nil means that gnus-uu will post the encoded file in a thread.
1878 This may not be smart, as no other decoder I have seen are able to
1879 follow threads when collecting uuencoded articles. (Well, I have seen
1880 one package that does that - gnus-uu, but somehow, I don't think that
1881 counts...) The default is nil."
1882 :group 'gnus-extract-post
1885 (defcustom gnus-uu-post-separate-description t
1886 "Non-nil means that the description will be posted in a separate article.
1887 The first article will typically be numbered (0/x). If this variable
1888 is nil, the description the user enters will be included at the
1889 beginning of the first article, which will be numbered (1/x). Default
1891 :group 'gnus-extract-post
1894 (defvar gnus-uu-post-binary-separator "--binary follows this line--")
1895 (defvar gnus-uu-post-message-id nil)
1896 (defvar gnus-uu-post-inserted-file-name nil)
1897 (defvar gnus-uu-winconf-post-news nil)
1899 (defun gnus-uu-post-news ()
1900 "Compose an article and post an encoded file."
1902 (setq gnus-uu-post-inserted-file-name nil)
1903 (setq gnus-uu-winconf-post-news (current-window-configuration))
1905 (gnus-summary-post-news)
1907 (let ((map (make-sparse-keymap)))
1908 (set-keymap-parent map (current-local-map))
1909 (use-local-map map))
1910 ;;(local-set-key "\C-c\C-c" 'gnus-summary-edit-article-done)
1911 (local-set-key "\C-c\C-c" 'gnus-uu-post-news-inews)
1912 (local-set-key "\C-c\C-s" 'gnus-uu-post-news-inews)
1913 (local-set-key "\C-c\C-i" 'gnus-uu-post-insert-binary-in-article)
1915 (when gnus-uu-post-include-before-composing
1916 (save-excursion (setq gnus-uu-post-inserted-file-name
1917 (gnus-uu-post-insert-binary)))))
1919 (defun gnus-uu-post-insert-binary-in-article ()
1920 "Inserts an encoded file in the buffer.
1921 The user will be asked for a file name."
1924 (setq gnus-uu-post-inserted-file-name (gnus-uu-post-insert-binary))))
1926 ;; Encodes with uuencode and substitutes all spaces with backticks.
1927 (defun gnus-uu-post-encode-uuencode (path file-name)
1928 (when (gnus-uu-post-encode-file "uuencode" path file-name)
1929 (goto-char (point-min))
1931 (while (re-search-forward " " nil t)
1932 (replace-match "`"))
1935 ;; Encodes with uuencode and adds MIME headers.
1936 (defun gnus-uu-post-encode-mime-uuencode (path file-name)
1937 (when (gnus-uu-post-encode-uuencode path file-name)
1938 (gnus-uu-post-make-mime file-name "x-uue")
1941 ;; Encodes with base64 and adds MIME headers
1942 (defun gnus-uu-post-encode-mime (path file-name)
1943 (when (zerop (call-process shell-file-name nil t nil shell-command-switch
1944 (format "%s %s -o %s" "mmencode" path file-name)))
1945 (gnus-uu-post-make-mime file-name "base64")
1948 ;; Adds MIME headers.
1949 (defun gnus-uu-post-make-mime (file-name encoding)
1950 (goto-char (point-min))
1951 (insert (format "Content-Type: %s; name=\"%s\"\n"
1952 (gnus-uu-choose-action file-name gnus-uu-ext-to-mime-list)
1954 (insert (format "Content-Transfer-Encoding: %s\n\n" encoding))
1956 (set-buffer gnus-message-buffer)
1957 (goto-char (point-min))
1958 (re-search-forward (concat "^" (regexp-quote mail-header-separator) "$"))
1960 (narrow-to-region 1 (point))
1961 (unless (mail-fetch-field "mime-version")
1963 (insert "MIME-Version: 1.0\n"))
1966 ;; Encodes a file PATH with COMMAND, leaving the result in the
1968 (defun gnus-uu-post-encode-file (command path file-name)
1969 (= 0 (call-process shell-file-name nil t nil shell-command-switch
1970 (format "%s %s %s" command path file-name))))
1972 (defun gnus-uu-post-news-inews ()
1973 "Posts the composed news article and encoded file.
1974 If no file has been included, the user will be asked for a file."
1979 (if gnus-uu-post-inserted-file-name
1980 (setq file-name gnus-uu-post-inserted-file-name)
1981 (setq file-name (gnus-uu-post-insert-binary)))
1983 (gnus-uu-post-encoded file-name gnus-uu-post-threaded))
1984 (setq gnus-uu-post-inserted-file-name nil)
1985 (when gnus-uu-winconf-post-news
1986 (set-window-configuration gnus-uu-winconf-post-news)))
1988 ;; Asks for a file to encode, encodes it and inserts the result in
1989 ;; the current buffer. Returns the file name the user gave.
1990 (defun gnus-uu-post-insert-binary ()
1991 (let ((uuencode-buffer-name "*uuencode buffer*")
1992 file-path uubuf file-name)
1994 (setq file-path (read-file-name
1995 "What file do you want to encode? "))
1996 (when (not (file-exists-p file-path))
1997 (error "%s: No such file" file-path))
1999 (goto-char (point-max))
2000 (insert (format "\n%s\n" gnus-uu-post-binary-separator))
2002 ;; #### Unix-specific?
2003 (when (string-match "^~/" file-path)
2004 (setq file-path (concat "$HOME" (substring file-path 1))))
2005 ;; #### Unix-specific?
2006 (if (string-match "/[^/]*$" file-path)
2007 (setq file-name (substring file-path (1+ (match-beginning 0))))
2008 (setq file-name file-path))
2012 (set-buffer (setq uubuf
2013 (gnus-get-buffer-create uuencode-buffer-name)))
2015 (funcall gnus-uu-post-encode-method file-path file-name))
2016 (insert-buffer-substring uubuf)
2017 (error "Encoding unsuccessful"))
2018 (kill-buffer uubuf))
2021 ;; Posts the article and all of the encoded file.
2022 (defun gnus-uu-post-encoded (file-name &optional threaded)
2023 (let ((send-buffer-name "*uuencode send buffer*")
2024 (encoded-buffer-name "*encoded buffer*")
2025 (top-string "[ cut here %s (%s %d/%d) %s gnus-uu ]")
2026 (separator (concat mail-header-separator "\n\n"))
2027 uubuf length parts header i end beg
2028 beg-line minlen post-buf whole-len beg-binary end-binary)
2030 (setq post-buf (current-buffer))
2032 (goto-char (point-min))
2033 (when (not (re-search-forward
2034 (if gnus-uu-post-separate-description
2035 (concat "^" (regexp-quote gnus-uu-post-binary-separator)
2037 (concat "^" (regexp-quote mail-header-separator) "$"))
2039 (error "Internal error: No binary/header separator"))
2042 (setq beg-binary (point))
2043 (setq end-binary (point-max))
2046 (set-buffer (setq uubuf (gnus-get-buffer-create encoded-buffer-name)))
2048 (insert-buffer-substring post-buf beg-binary end-binary)
2049 (goto-char (point-min))
2050 (setq length (count-lines 1 (point-max)))
2051 (setq parts (/ length gnus-uu-post-length))
2052 (unless (< (% length gnus-uu-post-length) 4)
2055 (when gnus-uu-post-separate-description
2057 (delete-region (point) (point-max))
2059 (goto-char (point-min))
2061 (concat "^" (regexp-quote mail-header-separator) "$") nil t)
2063 (setq header (buffer-substring 1 (point)))
2065 (goto-char (point-min))
2066 (when gnus-uu-post-separate-description
2067 (when (re-search-forward "^Subject: " nil t)
2069 (insert (format " (0/%d)" parts)))
2072 (setq gnus-uu-post-message-id (message-fetch-field "message-id")))
2077 (while (not (> i parts))
2078 (set-buffer (gnus-get-buffer-create send-buffer-name))
2081 (when (and threaded gnus-uu-post-message-id)
2082 (insert "References: " gnus-uu-post-message-id "\n"))
2085 (- 62 (length (format top-string "" file-name i parts ""))))
2086 (when (> 1 (setq minlen (/ whole-len 2)))
2091 (make-string minlen ?-)
2094 (if (= 0 (% whole-len 2)) (1- minlen) minlen) ?-)))
2096 (goto-char (point-min))
2097 (when (re-search-forward "^Subject: " nil t)
2099 (insert (format " (%d/%d)" i parts)))
2101 (goto-char (point-max))
2106 (goto-char (point-max))
2107 (forward-line gnus-uu-post-length))
2108 (when (and (= (1+ i) parts) (< (count-lines (point) (point-max)) 4))
2111 (insert-buffer-substring uubuf beg end)
2112 (insert beg-line "\n")
2115 (goto-char (point-min))
2117 (concat "^" (regexp-quote mail-header-separator) "$") nil t)
2120 (when (re-search-forward
2121 (concat "^" (regexp-quote gnus-uu-post-binary-separator) "$")
2127 (let (message-sent-message-via)
2130 (setq gnus-uu-post-message-id
2131 (concat (message-fetch-field "references") " "
2132 (message-fetch-field "message-id"))))))
2134 (gnus-kill-buffer send-buffer-name)
2135 (gnus-kill-buffer encoded-buffer-name)
2137 (when (not gnus-uu-post-separate-description)
2138 (set-buffer-modified-p nil)
2139 (when (fboundp 'bury-buffer)
2144 ;; gnus-uu.el ends here