1 ;;; gnus-uu.el --- extract (uu)encoded files in Gnus
3 ;; Copyright (C) 1985-1987, 1993-1998, 2000-2017 Free Software
6 ;; Author: Lars Magne Ingebrigtsen <larsi@gnus.org>
10 ;; This file is part of GNU Emacs.
12 ;; GNU Emacs is free software: you can redistribute it and/or modify
13 ;; it under the terms of the GNU General Public License as published by
14 ;; the Free Software Foundation, either version 3 of the License, or
15 ;; (at your option) any later version.
17 ;; GNU Emacs is distributed in the hope that it will be useful,
18 ;; but WITHOUT ANY WARRANTY; without even the implied warranty of
19 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
20 ;; GNU General Public License for more details.
22 ;; You should have received a copy of the GNU General Public License
23 ;; along with GNU Emacs. If not, see <http://www.gnu.org/licenses/>.
29 (eval-when-compile (require 'cl
))
38 (defgroup gnus-extract nil
39 "Extracting encoded files."
43 (defgroup gnus-extract-view nil
44 "Viewing 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 behavior, 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 behavior 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 temporary-file-directory
221 "Variable saying where gnus-uu is to do its work.
222 Default is \"/tmp/\"."
226 (defcustom gnus-uu-do-not-unpack-archives nil
227 "Non-nil means that gnus-uu won't peek inside archives looking for files to display.
229 :group
'gnus-extract-archive
232 (defcustom gnus-uu-ignore-default-view-rules nil
233 "Non-nil means that gnus-uu will ignore the default viewing rules.
234 Only the user viewing rules will be consulted. Default is nil."
235 :group
'gnus-extract-view
238 (defcustom gnus-uu-grabbed-file-functions nil
239 "Functions run on each file after successful decoding.
240 They will be called with the name of the file as the argument.
241 Likely functions you can use in this list are `gnus-uu-grab-view'
242 and `gnus-uu-grab-move'."
244 :options
'(gnus-uu-grab-view gnus-uu-grab-move
)
247 (defcustom gnus-uu-ignore-default-archive-rules nil
248 "Non-nil means that gnus-uu will ignore the default archive unpacking commands.
249 Only the user unpacking commands will be consulted. Default is nil."
250 :group
'gnus-extract-archive
253 (defcustom gnus-uu-kill-carriage-return t
254 "Non-nil means that gnus-uu will strip all carriage returns from articles.
259 (defcustom gnus-uu-view-with-metamail nil
260 "Non-nil means that files will be viewed with metamail.
261 The gnus-uu viewing functions will be ignored and gnus-uu will try
262 to guess at a content-type based on file name suffixes. Default
267 (defcustom gnus-uu-unmark-articles-not-decoded nil
268 "Non-nil means that gnus-uu will mark articles that were unsuccessfully decoded as unread.
273 (defcustom gnus-uu-correct-stripped-uucode nil
274 "Non-nil means that gnus-uu will *try* to fix uuencoded files that have had trailing spaces deleted.
279 (defcustom gnus-uu-save-in-digest nil
280 "Non-nil means that gnus-uu, when asked to save without decoding, will save in digests.
281 If this variable is nil, gnus-uu will just save everything in a
282 file without any embellishments. The digesting almost conforms to RFC1153 -
283 no easy way to specify any meaningful volume and issue numbers were found,
284 so I simply dropped them."
288 (defcustom gnus-uu-pre-uudecode-hook nil
289 "Hook run before sending a message to uudecode."
293 (defcustom gnus-uu-digest-headers
294 '("^Date:" "^From:" "^To:" "^Cc:" "^Subject:" "^Message-ID:" "^Keywords:"
295 "^Summary:" "^References:" "^Content-Type:" "^Content-Transfer-Encoding:"
296 "^MIME-Version:" "^Content-Disposition:" "^Content-Description:"
298 "List of regexps to match headers included in digested messages.
299 The headers will be included in the sequence they are matched. If nil
300 include all headers."
302 :type
'(repeat regexp
))
304 (defcustom gnus-uu-save-separate-articles nil
305 "Non-nil means that gnus-uu will save articles in separate files."
309 (defcustom gnus-uu-be-dangerous
'ask
310 "Specifies what to do if unusual situations arise during decoding.
311 If nil, be as conservative as possible. If t, ignore things that
312 didn't work, and overwrite existing files. Otherwise, ask each time."
314 :type
'(choice (const :tag
"conservative" nil
)
315 (const :tag
"ask" ask
)
316 (const :tag
"liberal" t
)))
318 ;; Internal variables
320 (defvar gnus-uu-saved-article-name nil
)
322 (defvar gnus-uu-begin-string
"^begin[ \t]+0?[0-7][0-7][0-7][ \t]+\\(.*\\)$")
323 (defvar gnus-uu-end-string
"^end[ \t]*$")
325 (defvar gnus-uu-body-line
"^M")
327 (while (> (setq i
(1- i
)) 0)
328 (setq gnus-uu-body-line
(concat gnus-uu-body-line
"[^a-z]")))
329 (setq gnus-uu-body-line
(concat gnus-uu-body-line
".?$")))
331 ;"^M.............................................................?$"
333 (defvar gnus-uu-shar-begin-string
"^#! */bin/sh")
335 (defvar gnus-uu-shar-name-marker
336 "begin 0?[0-7][0-7][0-7][ \t]+\\(\\(\\w\\|[.\\:]\\)*\\b\\)")
338 (defvar gnus-uu-postscript-begin-string
"^%!PS-")
339 (defvar gnus-uu-postscript-end-string
"^%%EOF$")
341 (defvar gnus-uu-file-name nil
)
342 (defvar gnus-uu-uudecode-process nil
)
343 (defvar gnus-uu-binhex-article-name nil
)
344 (defvar gnus-uu-yenc-article-name nil
)
346 (defvar gnus-uu-work-dir nil
)
348 (defvar gnus-uu-output-buffer-name
" *Gnus UU Output*")
350 (defvar gnus-uu-default-dir gnus-article-save-directory
)
351 (defvar gnus-uu-digest-from-subject nil
)
352 (defvar gnus-uu-digest-buffer nil
)
356 (defun gnus-uu-decode-uu (&optional n
)
357 "Uudecodes the current article."
359 (gnus-uu-decode-with-method 'gnus-uu-uustrip-article n
))
361 (defun gnus-uu-decode-uu-and-save (n dir
)
362 "Decodes and saves the resulting file."
364 (list current-prefix-arg
365 (file-name-as-directory
366 (read-directory-name "Uudecode and save in dir: "
368 gnus-uu-default-dir t
))))
369 (gnus-uu-decode-with-method 'gnus-uu-uustrip-article n dir nil nil t
))
371 (defun gnus-uu-decode-unshar (&optional n
)
372 "Unshars the current article."
374 (gnus-uu-decode-with-method 'gnus-uu-unshar-article n nil nil
'scan t
))
376 (defun gnus-uu-decode-unshar-and-save (n dir
)
377 "Unshars and saves the current article."
379 (list current-prefix-arg
380 (file-name-as-directory
381 (read-directory-name "Unshar and save in dir: "
383 gnus-uu-default-dir t
))))
384 (gnus-uu-decode-with-method 'gnus-uu-unshar-article n dir nil
'scan t
))
386 (defun gnus-uu-decode-save (n file
)
387 "Saves the current article."
389 (list current-prefix-arg
390 (if gnus-uu-save-separate-articles
392 "Save articles in dir: " gnus-uu-default-dir gnus-uu-default-dir
)
394 "Save article in file: " gnus-uu-default-dir gnus-uu-default-dir
))))
395 (setq gnus-uu-saved-article-name file
)
396 (gnus-uu-decode-with-method 'gnus-uu-save-article n nil t
))
398 (defun gnus-uu-decode-binhex (n dir
)
399 "Unbinhexes the current article."
401 (list current-prefix-arg
402 (file-name-as-directory
403 (read-directory-name "Unbinhex and save in dir: "
405 gnus-uu-default-dir
))))
407 (setq gnus-uu-binhex-article-name
408 (make-temp-file (expand-file-name "binhex" gnus-uu-work-dir
)))
409 (gnus-uu-decode-with-method 'gnus-uu-binhex-article n dir
))
411 (defun gnus-uu-decode-yenc (n dir
)
412 "Decode the yEnc-encoded current article."
414 (list current-prefix-arg
415 (file-name-as-directory
416 (read-directory-name "yEnc decode and save in dir: "
418 gnus-uu-default-dir
))))
419 (setq gnus-uu-yenc-article-name nil
)
420 (gnus-uu-decode-with-method 'gnus-uu-yenc-article n dir nil t
))
422 (defun gnus-uu-decode-uu-view (&optional n
)
423 "Uudecodes and views the current article."
425 (let ((gnus-view-pseudos (or gnus-view-pseudos
'automatic
)))
426 (gnus-uu-decode-uu n
)))
428 (defun gnus-uu-decode-uu-and-save-view (n dir
)
429 "Decodes, views and saves the resulting file."
431 (list current-prefix-arg
432 (read-file-name "Uudecode, view and save in dir: "
434 gnus-uu-default-dir t
)))
435 (let ((gnus-view-pseudos (or gnus-view-pseudos
'automatic
)))
436 (gnus-uu-decode-uu-and-save n dir
)))
438 (defun gnus-uu-decode-unshar-view (&optional n
)
439 "Unshars and views the current article."
441 (let ((gnus-view-pseudos (or gnus-view-pseudos
'automatic
)))
442 (gnus-uu-decode-unshar n
)))
444 (defun gnus-uu-decode-unshar-and-save-view (n dir
)
445 "Unshars and saves the current article."
447 (list current-prefix-arg
448 (read-file-name "Unshar, view and save in dir: "
450 gnus-uu-default-dir t
)))
451 (let ((gnus-view-pseudos (or gnus-view-pseudos
'automatic
)))
452 (gnus-uu-decode-unshar-and-save n dir
)))
454 (defun gnus-uu-decode-save-view (n file
)
455 "Saves and views the current article."
457 (list current-prefix-arg
458 (if gnus-uu-save-separate-articles
459 (read-directory-name "Save articles in dir: "
460 gnus-uu-default-dir gnus-uu-default-dir
)
461 (read-file-name "Save articles in file: "
462 gnus-uu-default-dir gnus-uu-default-dir
))))
463 (let ((gnus-view-pseudos (or gnus-view-pseudos
'automatic
)))
464 (gnus-uu-decode-save n file
)))
466 (defun gnus-uu-decode-binhex-view (n file
)
467 "Unbinhexes and views the current article."
469 (list current-prefix-arg
470 (read-file-name "Unbinhex, view and save in dir: "
471 gnus-uu-default-dir gnus-uu-default-dir
)))
473 (setq gnus-uu-binhex-article-name
474 (make-temp-file (expand-file-name "binhex" gnus-uu-work-dir
)))
475 (let ((gnus-view-pseudos (or gnus-view-pseudos
'automatic
)))
476 (gnus-uu-decode-binhex n file
)))
479 ;; Digest and forward articles
481 (defun gnus-uu-digest-mail-forward (&optional n post
)
482 "Digests and forwards all articles in this series."
485 (let ((gnus-uu-save-in-digest t
)
486 (file (make-temp-file (nnheader-concat gnus-uu-work-dir
"forward")))
487 (message-forward-as-mime message-forward-as-mime
)
488 (mail-parse-charset gnus-newsgroup-charset
)
489 (mail-parse-ignored-charsets gnus-newsgroup-ignored-charsets
)
490 gnus-uu-digest-buffer subject from
)
491 (if (and n
(not (numberp n
)))
492 (setq message-forward-as-mime
(not message-forward-as-mime
)
494 (let ((gnus-article-reply (gnus-summary-work-articles n
)))
496 (= (length gnus-article-reply
) 1))
497 ;; The case where neither a number of articles nor a region is
499 (gnus-summary-top-thread)
500 (setq gnus-article-reply
(nreverse (gnus-uu-find-articles-matching))))
501 (gnus-setup-message 'forward
502 (setq gnus-uu-digest-from-subject nil
)
503 (setq gnus-uu-digest-buffer
504 (gnus-get-buffer-create " *gnus-uu-forward*"))
505 ;; Specify articles to be forwarded. Note that they should be
506 ;; reversed; see `gnus-uu-get-list-of-articles'.
507 (let ((gnus-newsgroup-processable (reverse gnus-article-reply
)))
508 (gnus-uu-decode-save n file
)
509 (setq gnus-article-reply gnus-newsgroup-processable
))
510 ;; Restore the value of `gnus-newsgroup-processable' to which
511 ;; it should be set when it is not `let'-bound.
512 (setq gnus-newsgroup-processable
(reverse gnus-article-reply
))
513 (switch-to-buffer gnus-uu-digest-buffer
)
514 (let ((fs gnus-uu-digest-from-subject
))
517 subject
(gnus-simplify-subject-fuzzy (cdar fs
))
519 (while (and fs
(or from subject
))
521 (unless (string= from
(caar fs
))
524 (unless (string= (gnus-simplify-subject-fuzzy (cdar fs
))
529 (setq subject
"Digested Articles"))
532 (if (gnus-news-group-p gnus-newsgroup-name
)
535 (goto-char (point-min))
536 (when (re-search-forward "^Subject: ")
537 (delete-region (point) (point-at-eol))
539 (goto-char (point-min))
540 (when (re-search-forward "^From:")
541 (delete-region (point) (point-at-eol))
543 (let ((message-forward-decoded-p t
))
544 (message-forward post t
))))
545 (setq gnus-uu-digest-from-subject nil
)))
547 (defun gnus-uu-digest-post-forward (&optional n
)
548 "Digest and forward to a newsgroup."
550 (gnus-uu-digest-mail-forward n t
))
554 (defun gnus-message-process-mark (unmarkp new-marked
)
555 (let ((old (- (length gnus-newsgroup-processable
) (length new-marked
))))
556 (gnus-message 6 "%d mark%s %s%s"
558 (if (= (length new-marked
) 1) "" "s")
559 (if unmarkp
"removed" "added")
565 (format ", %d remain marked"
566 (length gnus-newsgroup-processable
)))
568 (format ", %d already marked" old
))))))
570 (defun gnus-new-processable (unmarkp articles
)
572 (gnus-intersection gnus-newsgroup-processable articles
)
573 (gnus-set-difference articles gnus-newsgroup-processable
)))
575 (defun gnus-uu-mark-by-regexp (regexp &optional unmark
)
576 "Set the process mark on articles whose subjects match REGEXP.
577 When called interactively, prompt for REGEXP.
578 Optional UNMARK non-nil means unmark instead of mark."
579 (interactive "sMark (regexp): \nP")
581 (let* ((articles (gnus-uu-find-articles-matching regexp
))
582 (new-marked (gnus-new-processable unmark articles
)))
585 (gnus-summary-remove-process-mark (pop articles
))
586 (gnus-summary-set-process-mark (pop articles
))))
587 (gnus-message-process-mark unmark new-marked
)))
588 (gnus-summary-position-point))
590 (defun gnus-uu-unmark-by-regexp (regexp)
591 "Remove the process mark from articles whose subjects match REGEXP.
592 When called interactively, prompt for REGEXP."
593 (interactive "sUnmark (regexp): ")
594 (gnus-uu-mark-by-regexp regexp t
))
596 (defun gnus-uu-mark-series (&optional silent
)
597 "Mark the current series with the process mark."
599 (let* ((articles (gnus-uu-find-articles-matching))
600 (l (length articles
)))
602 (gnus-summary-set-process-mark (car articles
))
603 (setq articles
(cdr articles
)))
605 (gnus-message 6 "Marked %d articles" l
))
606 (gnus-summary-position-point)
609 (defun gnus-uu-mark-region (beg end
&optional unmark
)
610 "Set the process mark on all articles between point and mark."
614 (while (< (point) end
)
616 (gnus-summary-remove-process-mark (gnus-summary-article-number))
617 (gnus-summary-set-process-mark (gnus-summary-article-number)))
619 (gnus-summary-position-point))
621 (defun gnus-uu-unmark-region (beg end
)
622 "Remove the process mark from all articles between point and mark."
624 (gnus-uu-mark-region beg end t
))
626 (defun gnus-uu-mark-buffer ()
627 "Set the process mark on all articles in the buffer."
629 (gnus-uu-mark-region (point-min) (point-max)))
631 (defun gnus-uu-unmark-buffer ()
632 "Remove the process mark on all articles in the buffer."
634 (gnus-uu-mark-region (point-min) (point-max) t
))
636 (defun gnus-uu-mark-thread ()
637 "Marks all articles downwards in this thread."
639 (gnus-save-hidden-threads
640 (let ((level (gnus-summary-thread-level)))
641 (while (and (gnus-summary-set-process-mark (gnus-summary-article-number))
642 (zerop (forward-line 1))
644 (> (gnus-summary-thread-level) level
)))))
645 (gnus-summary-position-point))
647 (defun gnus-uu-unmark-thread ()
648 "Unmarks all articles downwards in this thread."
650 (let ((level (gnus-summary-thread-level)))
651 (while (and (gnus-summary-remove-process-mark
652 (gnus-summary-article-number))
653 (zerop (forward-line 1))
654 (> (gnus-summary-thread-level) level
))))
655 (gnus-summary-position-point))
657 (defun gnus-uu-invert-processable ()
658 "Invert the list of process-marked articles."
660 (let ((data gnus-newsgroup-data
)
664 (if (memq (setq number
(gnus-data-number (pop data
)))
665 gnus-newsgroup-processable
)
666 (gnus-summary-remove-process-mark number
)
667 (gnus-summary-set-process-mark number
)))))
668 (gnus-summary-position-point))
670 (defun gnus-uu-mark-over (&optional score
)
671 "Mark all articles with a score over SCORE (the prefix)."
673 (let ((score (or score gnus-summary-default-score
0))
674 (data gnus-newsgroup-data
))
677 (when (> (or (cdr (assq (gnus-data-number (car data
))
678 gnus-newsgroup-scored
))
679 gnus-summary-default-score
0)
681 (gnus-summary-set-process-mark (caar data
)))
682 (setq data
(cdr data
))))
683 (gnus-summary-position-point)))
685 (defun gnus-uu-mark-sparse ()
686 "Mark all series that have some articles marked."
688 (let ((marked (nreverse gnus-newsgroup-processable
))
689 subject articles total headers
)
691 (error "No articles marked with the process mark"))
692 (setq gnus-newsgroup-processable nil
)
695 (and (vectorp (setq headers
696 (gnus-summary-article-header (car marked
))))
697 (setq subject
(mail-header-subject headers
)
698 articles
(gnus-uu-find-articles-matching
699 (gnus-uu-reginize-string subject
))
700 total
(nconc total articles
)))
702 (gnus-summary-set-process-mark (car articles
))
703 (setcdr marked
(delq (car articles
) (cdr marked
)))
704 (setq articles
(cdr articles
)))
705 (setq marked
(cdr marked
)))
706 (setq gnus-newsgroup-processable
(nreverse total
)))
707 (gnus-summary-position-point)))
709 (defun gnus-uu-mark-all ()
710 "Mark all articles in \"series\" order."
712 (setq gnus-newsgroup-processable nil
)
714 (let ((data gnus-newsgroup-data
)
718 (when (and (not (memq (setq number
(gnus-data-number (car data
)))
719 gnus-newsgroup-processable
))
720 (vectorp (gnus-data-header (car data
))))
721 (gnus-summary-goto-subject number
)
722 (setq count
(+ count
(gnus-uu-mark-series t
))))
723 (setq data
(cdr data
)))
724 (gnus-message 6 "Marked %d articles" count
)))
725 (gnus-summary-position-point))
727 ;; All PostScript functions written by Erik Selberg <speed@cs.washington.edu>.
729 (defun gnus-uu-decode-postscript (&optional n
)
730 "Gets PostScript of the current article."
732 (gnus-uu-decode-with-method 'gnus-uu-decode-postscript-article n
))
734 (defun gnus-uu-decode-postscript-view (&optional n
)
735 "Gets and views the current article."
737 (let ((gnus-view-pseudos (or gnus-view-pseudos
'automatic
)))
738 (gnus-uu-decode-postscript n
)))
740 (defun gnus-uu-decode-postscript-and-save (n dir
)
741 "Extracts PostScript and saves the current article."
743 (list current-prefix-arg
744 (file-name-as-directory
745 (read-directory-name "Save in dir: "
747 gnus-uu-default-dir t
))))
748 (gnus-uu-decode-with-method 'gnus-uu-decode-postscript-article
751 (defun gnus-uu-decode-postscript-and-save-view (n dir
)
752 "Decodes, views and saves the resulting file."
754 (list current-prefix-arg
755 (read-file-name "Where do you want to save the file(s)? "
757 gnus-uu-default-dir t
)))
758 (let ((gnus-view-pseudos (or gnus-view-pseudos
'automatic
)))
759 (gnus-uu-decode-postscript-and-save n dir
)))
762 ;; Internal functions.
764 (defun gnus-uu-decode-with-method (method n
&optional save not-insert
766 (gnus-uu-initialize scan
)
768 (setq gnus-uu-default-dir save
))
769 ;; Create the directory we save to.
770 (when (and scan cdir save
771 (not (file-exists-p save
)))
772 (make-directory save t
))
773 (let ((articles (gnus-uu-get-list-of-articles n
))
775 (setq files
(gnus-uu-grab-articles articles method t
))
776 (let ((gnus-current-article (car articles
)))
778 (setq files
(gnus-uu-scan-directory gnus-uu-work-dir
))))
780 (gnus-uu-save-files files save
))
781 (when (eq gnus-uu-do-not-unpack-archives nil
)
782 (setq files
(gnus-uu-unpack-files files
)))
783 (setq files
(nreverse (gnus-uu-get-actions files
)))
784 (or not-insert
(not gnus-insert-pseudo-articles
)
785 (gnus-summary-insert-pseudos files save
))))
787 (defun gnus-uu-scan-directory (dir &optional rec
)
788 "Return a list of all files under DIR."
789 (let ((files (directory-files dir t
))
791 (while (setq file
(pop files
))
792 (unless (member (file-name-nondirectory file
) '("." ".."))
793 (push (list (cons 'name file
)
794 (cons 'article gnus-current-article
))
796 (when (file-directory-p file
)
797 (setq out
(nconc (gnus-uu-scan-directory file t
) out
)))))
802 (defun gnus-uu-save-files (files dir
)
804 (let ((len (length files
))
805 (reg (concat "^" (regexp-quote gnus-uu-work-dir
)))
806 to-file file fromdir
)
807 (while (setq file
(cdr (assq 'name
(pop files
))))
808 (when (file-exists-p file
)
809 (string-match reg file
)
810 (setq fromdir
(substring file
(match-end 0)))
811 (if (file-directory-p file
)
812 (gnus-make-directory (concat dir fromdir
))
813 (setq to-file
(concat dir fromdir
))
814 (when (or (not (file-exists-p to-file
))
815 (eq gnus-uu-be-dangerous t
)
816 (and gnus-uu-be-dangerous
817 (gnus-y-or-n-p (format "%s exists; overwrite? "
819 (copy-file file to-file t t
)))))
820 (gnus-message 5 "Saved %d file%s" len
(if (= len
1) "" "s"))))
822 ;; Functions for saving and possibly digesting articles without
825 ;; Function called by gnus-uu-grab-articles to treat each article.
826 (defun gnus-uu-save-article (buffer in-state
)
828 (gnus-uu-save-separate-articles
829 (with-current-buffer buffer
830 (let ((coding-system-for-write mm-text-coding-system
))
832 (concat gnus-uu-saved-article-name gnus-current-article
)))
833 (cond ((eq in-state
'first
) (list gnus-uu-saved-article-name
'begin
))
834 ((eq in-state
'first-and-last
) (list gnus-uu-saved-article-name
836 ((eq in-state
'last
) (list 'end
))
837 (t (list 'middle
)))))
838 ((not gnus-uu-save-in-digest
)
839 (with-current-buffer buffer
840 (write-region (point-min) (point-max) gnus-uu-saved-article-name t
)
841 (cond ((eq in-state
'first
) (list gnus-uu-saved-article-name
'begin
))
842 ((eq in-state
'first-and-last
) (list gnus-uu-saved-article-name
844 ((eq in-state
'last
) (list 'end
))
845 (t (list 'middle
)))))
847 (let ((header (gnus-summary-article-header)))
848 (push (cons (mail-header-from header
)
849 (mail-header-subject header
))
850 gnus-uu-digest-from-subject
))
851 (let ((name (file-name-nondirectory gnus-uu-saved-article-name
))
852 beg subj headers headline sorthead body end-string state
)
853 (if (or (eq in-state
'first
)
854 (eq in-state
'first-and-last
))
856 (setq state
(list 'begin
))
857 (with-current-buffer (gnus-get-buffer-create "*gnus-uu-body*")
859 (with-current-buffer (gnus-get-buffer-create "*gnus-uu-pre*")
862 "Date: %s\nFrom: %s\nSubject: %s Digest\n\n"
863 (message-make-date) name name
))
864 (when (and message-forward-as-mime gnus-uu-digest-buffer
)
866 "<#mml type=message/rfc822>\nSubject: Topics\n\n<#/mml>\n")
868 (insert "Topics:\n")))
869 (when (not (eq in-state
'end
))
870 (setq state
(list 'middle
))))
871 (with-current-buffer "*gnus-uu-body*"
872 (goto-char (setq beg
(point-max)))
873 (with-current-buffer buffer
875 (let ((inhibit-read-only t
))
876 (set-text-properties (point-min) (point-max) nil
))
877 (when (and message-forward-as-mime
878 message-forward-show-mml
879 gnus-uu-digest-buffer
)
880 (mm-enable-multibyte)
882 (goto-char (point-min))
883 (search-forward "\n\n")
884 (unless (and message-forward-as-mime gnus-uu-digest-buffer
)
885 ;; Quote all 30-dash lines.
887 (while (re-search-forward "^-" nil t
)
891 (setq body
(buffer-substring (1- (point)) (point-max)))
892 (narrow-to-region (point-min) (point))
893 (if (not (setq headers gnus-uu-digest-headers
))
894 (setq sorthead
(buffer-string))
896 (setq headline
(car headers
))
897 (setq headers
(cdr headers
))
898 (goto-char (point-min))
899 (while (re-search-forward headline nil t
)
904 (or (and (re-search-forward "^[^ \t]" nil t
)
906 (progn (forward-line 1) (point)))))))))))
907 (if (and message-forward-as-mime gnus-uu-digest-buffer
)
908 (if message-forward-show-mml
910 (insert "\n<#mml type=message/rfc822>\n")
911 (insert sorthead
) (goto-char (point-max))
912 (insert body
) (goto-char (point-max))
913 (insert "\n<#/mml>\n"))
914 (let ((buf (mml-generate-new-buffer " *mml*")))
915 (with-current-buffer buf
917 (goto-char (point-min))
918 (when (re-search-forward "^Subject: \\(.*\\)$" nil t
)
919 (setq subj
(buffer-substring (match-beginning 1)
921 (goto-char (point-max))
923 (insert "\n<#part type=message/rfc822"
924 " buffer=\"" (buffer-name buf
) "\">\n")))
925 (insert sorthead
) (goto-char (point-max))
926 (insert body
) (goto-char (point-max))
927 (insert (concat "\n" (make-string 30 ?-
) "\n\n")))
929 (when (re-search-forward "^Subject: \\(.*\\)$" nil t
)
930 (setq subj
(buffer-substring (match-beginning 1) (match-end 1))))
932 (with-current-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 (and message-forward-as-mime gnus-uu-digest-buffer
)
937 (with-current-buffer gnus-uu-digest-buffer
939 (insert-buffer-substring "*gnus-uu-pre*")
940 (goto-char (point-max))
941 (insert-buffer-substring "*gnus-uu-body*"))
942 (with-current-buffer "*gnus-uu-pre*"
943 (insert (format "\n\n%s\n\n" (make-string 70 ?-
)))
944 (if gnus-uu-digest-buffer
945 (with-current-buffer gnus-uu-digest-buffer
947 (insert-buffer-substring "*gnus-uu-pre*"))
948 (let ((coding-system-for-write mm-text-coding-system
))
949 (gnus-write-buffer gnus-uu-saved-article-name
))))
950 (with-current-buffer "*gnus-uu-body*"
951 (goto-char (point-max))
953 (concat (setq end-string
(format "End of %s Digest" name
))
955 (insert (concat (make-string (length end-string
) ?
*) "\n"))
956 (if gnus-uu-digest-buffer
957 (with-current-buffer gnus-uu-digest-buffer
958 (goto-char (point-max))
959 (insert-buffer-substring "*gnus-uu-body*"))
960 (let ((coding-system-for-write mm-text-coding-system
)
961 (file-name-coding-system nnmail-pathname-coding-system
))
963 (point-min) (point-max) gnus-uu-saved-article-name t
)))))
964 (gnus-kill-buffer "*gnus-uu-pre*")
965 (gnus-kill-buffer "*gnus-uu-body*")
967 (if (memq 'begin state
)
968 (cons gnus-uu-saved-article-name state
)
971 ;; Binhex treatment - not very advanced.
973 (defvar gnus-uu-binhex-body-line
974 "^[^:]...............................................................$")
975 (defvar gnus-uu-binhex-begin-line
976 "^:...............................................................$")
977 (defvar gnus-uu-binhex-end-line
980 (defun gnus-uu-binhex-article (buffer in-state
)
981 (let (state start-char
)
982 (with-current-buffer buffer
984 (goto-char (point-min))
985 (when (not (re-search-forward gnus-uu-binhex-begin-line nil t
))
986 (when (not (re-search-forward gnus-uu-binhex-body-line nil t
))
987 (setq state
(list 'wrong-type
))))
989 (if (memq 'wrong-type state
)
992 (setq start-char
(point))
993 (if (looking-at gnus-uu-binhex-begin-line
)
995 (setq state
(list 'begin
))
996 (write-region (point-min) (point-min)
997 gnus-uu-binhex-article-name
))
998 (setq state
(list 'middle
)))
999 (goto-char (point-max))
1000 (re-search-backward (concat gnus-uu-binhex-body-line
"\\|"
1001 gnus-uu-binhex-end-line
)
1003 (when (looking-at gnus-uu-binhex-end-line
)
1004 (setq state
(if (memq 'begin state
)
1009 (when (file-exists-p gnus-uu-binhex-article-name
)
1010 (mm-append-to-file start-char
(point) gnus-uu-binhex-article-name
))))
1011 (if (memq 'begin state
)
1012 (cons gnus-uu-binhex-article-name state
)
1017 (defun gnus-uu-yenc-article (buffer in-state
)
1018 (with-current-buffer gnus-original-article-buffer
1020 (let ((file-name (yenc-extract-filename))
1022 (when (not file-name
)
1023 (setq state
(list 'wrong-type
)))
1025 (if (memq 'wrong-type state
)
1027 (when (yenc-first-part-p)
1028 (setq gnus-uu-yenc-article-name
1029 (expand-file-name file-name gnus-uu-work-dir
))
1030 (push 'begin state
))
1031 (when (yenc-last-part-p)
1034 (push 'middle state
))
1035 (mm-with-unibyte-buffer
1036 (insert-buffer-substring gnus-original-article-buffer
)
1037 (yenc-decode-region (point-min) (point-max))
1038 (when (and (member 'begin state
)
1039 (file-exists-p gnus-uu-yenc-article-name
))
1040 (delete-file gnus-uu-yenc-article-name
))
1041 (mm-append-to-file (point-min) (point-max)
1042 gnus-uu-yenc-article-name
)))
1043 (if (memq 'begin state
)
1044 (cons file-name state
)
1049 (defun gnus-uu-decode-postscript-article (process-buffer in-state
)
1050 (let ((state (list 'ok
))
1051 start-char end-char file-name
)
1052 (with-current-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]+".
1114 (with-current-buffer (gnus-get-buffer-create gnus-uu-output-buffer-name
)
1115 (buffer-disable-undo)
1117 (insert (regexp-quote string
))
1119 (setq case-fold-search nil
)
1122 (if (re-search-backward "\\([^0-9]\\)[0-9]+/\\([0-9]+\\)" nil t
)
1123 (replace-match "\\1[0-9]+/\\2")
1126 (if (re-search-backward "\\([^0-9]\\)[0-9]+[ \t]*of[ \t]*\\([0-9]+\\)"
1128 (replace-match "\\1[0-9]+ of \\2")
1131 (if (re-search-backward "\\([^0-9]\\)[0-9]+\\([^0-9]+\\)[0-9]+"
1133 (replace-match "\\1[0-9]+\\2[0-9]+" t nil nil nil
))))
1135 (goto-char (point-min))
1136 (while (re-search-forward "[ \t]+" nil t
)
1137 (replace-match "[ \t]+" t t
))
1141 (defun gnus-uu-get-list-of-articles (n)
1142 ;; If N is non-nil, the article numbers of the N next articles
1143 ;; will be returned.
1144 ;; If any articles have been marked as processable, they will be
1146 ;; Failing that, articles that have subjects that are part of the
1147 ;; same "series" as the current will be returned.
1151 (setq n
(prefix-numeric-value n
))
1152 (let ((backward (< n
0))
1156 (push (gnus-summary-article-number)
1158 (gnus-summary-search-forward nil nil backward
))
1160 (nreverse articles
)))
1161 (gnus-newsgroup-processable
1162 (reverse gnus-newsgroup-processable
))
1164 (gnus-uu-find-articles-matching)))))
1166 (defun gnus-uu-string< (l1 l2
)
1167 (string< (car l1
) (car l2
)))
1169 (defun gnus-uu-find-articles-matching
1170 (&optional subject only-unread do-not-translate
)
1171 ;; Finds all articles that matches the regexp SUBJECT. If it is
1172 ;; nil, the current article name will be used. If ONLY-UNREAD is
1173 ;; non-nil, only unread articles are chosen. If DO-NOT-TRANSLATE is
1174 ;; non-nil, article names are not equalized before sorting.
1175 (let ((subject (or subject
1176 (gnus-uu-reginize-string (gnus-summary-article-subject))))
1180 ;; Collect all subjects matching subject.
1181 (let ((case-fold-search t
)
1182 (data gnus-newsgroup-data
)
1186 (and (not (gnus-data-pseudo-p d
))
1187 (or (not only-unread
)
1188 (= (setq mark
(gnus-data-mark d
))
1190 (= mark gnus-ticked-mark
)
1191 (= mark gnus-dormant-mark
))
1192 (setq subj
(mail-header-subject (gnus-data-header d
)))
1193 (string-match subject subj
)
1194 (push (cons subj
(gnus-data-number d
))
1195 list-of-subjects
))))
1197 ;; Expand numbers, sort, and return the list of article
1200 (sort (gnus-uu-expand-numbers
1202 (not do-not-translate
))
1203 'gnus-uu-string
<))))))
1205 (defun gnus-uu-expand-numbers (string-list &optional translate
)
1206 ;; Takes a list of strings and "expands" all numbers in all the
1207 ;; strings. That is, this function makes all numbers equal length by
1208 ;; prepending lots of zeroes before each number. This is to ease later
1209 ;; sorting to find out what sequence the articles are supposed to be
1210 ;; decoded in. Returns the list of expanded strings.
1211 (let ((out-list string-list
)
1213 (with-current-buffer (gnus-get-buffer-create gnus-uu-output-buffer-name
)
1214 (buffer-disable-undo)
1217 (insert (caar string-list
))
1218 ;; Translate multiple spaces to one space.
1219 (goto-char (point-min))
1220 (while (re-search-forward "[ \t]+" nil t
)
1221 (replace-match " "))
1222 ;; Translate all characters to "a".
1223 (goto-char (point-min))
1225 (while (re-search-forward "[A-Za-z]" nil t
)
1226 (replace-match "a" t t
)))
1228 (goto-char (point-min))
1229 (while (re-search-forward "[0-9]+" nil t
)
1233 (string-to-number (buffer-substring
1234 (match-beginning 0) (match-end 0)))))))
1235 (setq string
(buffer-substring (point-min) (point-max)))
1236 (setcar (car string-list
) string
)
1237 (setq string-list
(cdr string-list
))))
1241 ;; `gnus-uu-grab-articles' is the general multi-article treatment
1242 ;; function. It takes a list of articles to be grabbed and a function
1243 ;; to apply to each article.
1245 ;; The function to be called should take two parameters. The first
1246 ;; parameter is the article buffer. The function should leave the
1247 ;; result, if any, in this buffer. Most treatment functions will just
1248 ;; generate files...
1250 ;; The second parameter is the state of the list of articles, and can
1251 ;; have four values: `first', `middle', `last' and `first-and-last'.
1253 ;; The function should return a list. The list may contain the
1254 ;; following symbols:
1255 ;; `error' if an error occurred
1256 ;; `begin' if the beginning of an encoded file has been received
1257 ;; If the list returned contains a `begin', the first element of
1258 ;; the list *must* be a string with the file name of the decoded
1260 ;; `end' if the end of an encoded file has been received
1261 ;; `middle' if the article was a body part of an encoded file
1262 ;; `wrong-type' if the article was not a part of an encoded file
1263 ;; `ok', which can be used everything is ok
1265 (defvar gnus-uu-has-been-grabbed nil
)
1267 (defun gnus-uu-unmark-list-of-grabbed (&optional dont-unmark-last-article
)
1269 (if (not (and gnus-uu-has-been-grabbed
1270 gnus-uu-unmark-articles-not-decoded
))
1272 (when dont-unmark-last-article
1273 (setq art
(car gnus-uu-has-been-grabbed
))
1274 (setq gnus-uu-has-been-grabbed
(cdr gnus-uu-has-been-grabbed
)))
1275 (while gnus-uu-has-been-grabbed
1276 (gnus-summary-tick-article (car gnus-uu-has-been-grabbed
) t
)
1277 (setq gnus-uu-has-been-grabbed
(cdr gnus-uu-has-been-grabbed
)))
1278 (when dont-unmark-last-article
1279 (setq gnus-uu-has-been-grabbed
(list art
))))))
1281 ;; This function takes a list of articles and a function to apply to
1282 ;; each article grabbed.
1284 ;; This function returns a list of files decoded if the grabbing and
1285 ;; the process-function has been successful and nil otherwise.
1286 (defun gnus-uu-grab-articles (articles process-function
1287 &optional sloppy limit no-errors
)
1288 (require 'gnus-async
)
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.
1317 (with-current-buffer gnus-original-article-buffer
1318 (let ((buffer-read-only nil
))
1319 (with-current-buffer gnus-summary-buffer
1321 (funcall process-function
1322 gnus-original-article-buffer state
)))))
1324 (gnus-summary-remove-process-mark article
)
1326 ;; If this is the beginning of a decoded file, we push it
1328 (when (or (memq 'begin process-state
)
1329 (and (or (eq state
'first
)
1330 (eq state
'first-and-last
))
1331 (memq 'ok process-state
)))
1332 (when has-been-begin
1333 ;; If there is a `result-file' here, that means that the
1334 ;; file was unsuccessfully decoded, so we delete it.
1335 (when (and result-file
1336 (file-exists-p result-file
)
1337 (not gnus-uu-be-dangerous
)
1338 (or (eq gnus-uu-be-dangerous t
)
1340 (format "Delete unsuccessfully decoded file %s? "
1342 (delete-file result-file
)))
1343 (when (memq 'begin process-state
)
1344 (setq result-file
(car process-state
)))
1345 (setq has-been-begin t
))
1347 ;; Check whether we have decoded one complete file.
1348 (when (memq 'end process-state
)
1349 (setq article-series nil
)
1350 (setq has-been-begin nil
)
1351 (if (stringp result-file
)
1352 (setq files
(list result-file
))
1353 (setq files result-file
))
1354 (setq result-file
(car files
))
1356 (push (list (cons 'name
(pop files
))
1357 (cons 'article article
))
1359 ;; Allow user-defined functions to be run on this file.
1360 (when gnus-uu-grabbed-file-functions
1361 (let ((funcs gnus-uu-grabbed-file-functions
))
1362 (unless (listp funcs
)
1363 (setq funcs
(list funcs
)))
1365 (funcall (pop funcs
) result-file
))))
1366 (setq result-file nil
)
1367 ;; Check whether we have decoded enough articles.
1368 (and limit
(= (length result-files
) limit
)
1369 (setq articles nil
)))
1371 ;; If this is the last article to be decoded, and
1372 ;; we still haven't reached the end, then we delete
1373 ;; the partially decoded file.
1374 (and (or (eq state
'last
) (eq state
'first-and-last
))
1375 (not (memq 'end process-state
))
1377 (file-exists-p result-file
)
1378 (not gnus-uu-be-dangerous
)
1379 (or (eq gnus-uu-be-dangerous t
)
1381 (format "Delete incomplete file %s? " result-file
)))
1382 (delete-file result-file
))
1384 ;; If this was a file of the wrong sort, then
1385 (when (and (or (memq 'wrong-type process-state
)
1386 (memq 'error process-state
))
1387 gnus-uu-unmark-articles-not-decoded
)
1388 (gnus-summary-tick-article article t
))
1390 ;; Set the new series state.
1391 (if (and (not has-been-begin
)
1393 (or (memq 'end process-state
)
1394 (memq 'middle process-state
)))
1396 (setq process-state
(list 'error
))
1397 (gnus-message 2 "No begin part at the beginning")
1399 (setq state
'middle
))))
1401 ;; When there are no result-files, then something must be wrong.
1405 ((not has-been-begin
)
1406 (gnus-message 2 "Wrong type file"))
1407 ((memq 'error process-state
)
1408 (gnus-message 2 "An error occurred during decoding"))
1409 ((not (or (memq 'ok process-state
)
1410 (memq 'end process-state
)))
1411 (gnus-message 2 "End of articles reached before end of file")))
1412 ;; Make unsuccessfully decoded articles unread.
1413 (when gnus-uu-unmark-articles-not-decoded
1414 (while article-series
1415 (gnus-summary-tick-article (pop article-series
) t
))))
1417 ;; The original article buffer is hosed, shoot it down.
1418 (gnus-kill-buffer gnus-original-article-buffer
)
1419 (setq gnus-current-article nil
)
1422 (defun gnus-uu-grab-view (file)
1423 "View FILE using the gnus-uu methods."
1424 (let ((action (gnus-uu-get-action file
)))
1425 (gnus-execute-command
1426 (if (string-match "%" action
)
1427 (format action file
)
1428 (concat action
" " file
))
1429 (eq gnus-view-pseudos
'not-confirm
))))
1431 (defun gnus-uu-grab-move (file)
1432 "Move FILE to somewhere."
1433 (when gnus-uu-default-dir
1434 (let ((to-file (concat (file-name-as-directory gnus-uu-default-dir
)
1435 (file-name-nondirectory file
))))
1436 (rename-file file to-file
)
1437 (unless (file-exists-p file
)
1438 (make-symbolic-link to-file file
)))))
1440 (defun gnus-uu-part-number (article)
1441 (let* ((header (gnus-summary-article-header article
))
1442 (subject (and header
(mail-header-subject header
)))
1445 (while (string-match "[0-9]+/[0-9]+\\|[0-9]+[ \t]+of[ \t]+[0-9]+"
1447 (setq part
(match-string 0 subject
))
1448 (setq subject
(substring subject
(match-end 0)))))
1450 (while (string-match "[0-9]+[^0-9]+[0-9]+" subject
)
1451 (setq part
(match-string 0 subject
))
1452 (setq subject
(substring subject
(match-end 0)))))
1455 (defun gnus-uu-uudecode-sentinel (process event
)
1456 (delete-process (get-process process
)))
1458 (defun gnus-uu-uustrip-article (process-buffer in-state
)
1459 ;; Uudecodes a file asynchronously.
1460 (with-current-buffer process-buffer
1461 (let ((state (list 'wrong-type
))
1462 process-connection-type case-fold-search buffer-read-only
1464 (goto-char (point-min))
1466 ;; Deal with ^M at the end of the lines.
1467 (when gnus-uu-kill-carriage-return
1469 (while (search-forward "\r" nil t
)
1472 (while (or (re-search-forward gnus-uu-begin-string nil t
)
1473 (re-search-forward gnus-uu-body-line nil t
))
1474 (setq state
(list 'ok
))
1475 ;; Ok, we are at the first uucoded line.
1477 (setq start-char
(point))
1479 (if (not (looking-at gnus-uu-begin-string
))
1480 (setq state
(list 'middle
))
1481 ;; This is the beginning of a uuencoded article.
1482 ;; We replace certain characters that could make things messy.
1483 (setq gnus-uu-file-name
1485 mm-file-name-rewrite-functions
1486 (file-name-nondirectory (match-string 1))))
1487 (replace-match (concat "begin 644 " gnus-uu-file-name
) t t
)
1489 ;; Remove any non gnus-uu-body-line right after start.
1491 (while (and (not (eobp))
1492 (not (looking-at gnus-uu-body-line
)))
1495 ;; If a process is running, we kill it.
1496 (when (and gnus-uu-uudecode-process
1497 (memq (process-status gnus-uu-uudecode-process
)
1499 (delete-process gnus-uu-uudecode-process
)
1500 (gnus-uu-unmark-list-of-grabbed t
))
1502 ;; Start a new uudecoding process.
1503 (let ((cdir default-directory
))
1506 (cd gnus-uu-work-dir
)
1507 (setq gnus-uu-uudecode-process
1510 (gnus-get-buffer-create gnus-uu-output-buffer-name
)
1511 shell-file-name shell-command-switch
1512 (format "cd %s %s uudecode" gnus-uu-work-dir
1513 gnus-shell-command-separator
))))
1515 (set-process-sentinel
1516 gnus-uu-uudecode-process
'gnus-uu-uudecode-sentinel
)
1517 (setq state
(list 'begin
))
1518 (push (concat gnus-uu-work-dir gnus-uu-file-name
) files
))
1520 ;; We look for the end of the thing to be decoded.
1521 (if (re-search-forward gnus-uu-end-string nil t
)
1523 (goto-char (point-max))
1524 (re-search-backward gnus-uu-body-line nil t
))
1528 (when gnus-uu-uudecode-process
1529 (when (memq (process-status gnus-uu-uudecode-process
) '(run stop
))
1530 ;; Try to correct mishandled uucode.
1531 (when gnus-uu-correct-stripped-uucode
1532 (gnus-uu-check-correct-stripped-uucode start-char
(point)))
1533 (gnus-run-hooks 'gnus-uu-pre-uudecode-hook
)
1535 ;; Send the text to the process.
1537 (process-send-region
1538 gnus-uu-uudecode-process start-char
(point))
1541 (delete-process gnus-uu-uudecode-process
)
1542 (gnus-message 2 "gnus-uu: Couldn't uudecode")
1543 (setq state
(list 'wrong-type
)))))
1545 (if (memq 'end state
)
1547 ;; Send an EOF, just in case.
1549 (process-send-eof gnus-uu-uudecode-process
))
1550 (while (memq (process-status gnus-uu-uudecode-process
)
1552 (accept-process-output gnus-uu-uudecode-process
1)))
1553 (when (or (not gnus-uu-uudecode-process
)
1554 (not (memq (process-status gnus-uu-uudecode-process
)
1556 (setq state
(list 'wrong-type
)))))))
1558 (if (memq 'begin state
)
1559 (cons (if (= (length files
) 1) (car files
) files
) state
)
1562 (defvar gnus-uu-unshar-warning
1565 Shell archives are an archaic method of bundling files for distribution
1566 across computer networks. During the unpacking process, arbitrary commands
1567 are executed on your system, and all kinds of nasty things can happen.
1568 Please examine the archive very carefully before you instruct Emacs to
1569 unpack it. You can browse the archive buffer using \\[scroll-other-window].
1571 If you are unsure what to do, please answer \"no\"."
1572 "Text of warning message displayed by `gnus-uu-unshar-article'.
1573 Make sure that this text consists only of few text lines. Otherwise,
1574 Gnus might fail to display all of it.")
1577 ;; This function is used by `gnus-uu-grab-articles' to treat
1578 ;; a shared article.
1579 (defun gnus-uu-unshar-article (process-buffer in-state
)
1580 (let ((state (list 'ok
))
1582 (with-current-buffer process-buffer
1583 (goto-char (point-min))
1584 (if (not (re-search-forward gnus-uu-shar-begin-string nil t
))
1585 (setq state
(list 'wrong-type
))
1586 (save-window-excursion
1588 (switch-to-buffer (current-buffer))
1589 (delete-other-windows)
1590 (let ((buffer (get-buffer-create (generate-new-buffer-name
1594 (with-current-buffer buffer
1595 (insert (substitute-command-keys
1596 gnus-uu-unshar-warning
))
1597 (goto-char (point-min))
1598 (display-buffer buffer
)
1599 (yes-or-no-p "This is a shell archive, unshar it? "))
1600 (kill-buffer buffer
))
1601 (setq state
(list 'error
))))))
1602 (unless (memq 'error state
)
1604 (setq start-char
(point))
1605 (call-process-region
1606 start-char
(point-max) shell-file-name nil
1607 (gnus-get-buffer-create gnus-uu-output-buffer-name
) nil
1608 shell-command-switch
1609 (concat "cd " gnus-uu-work-dir
" "
1610 gnus-shell-command-separator
" sh")))))
1613 ;; `gnus-uu-choose-action' chooses what action to perform given the name
1614 ;; and `gnus-uu-file-action-list'. Returns either nil if no action is
1615 ;; found, or the name of the command to run if such a rule is found.
1616 (defun gnus-uu-choose-action (file-name file-action-list
&optional no-ignore
)
1617 (let ((action-list (copy-sequence file-action-list
))
1618 (case-fold-search t
)
1623 (and gnus-uu-ignore-files-by-name
1624 (string-match gnus-uu-ignore-files-by-name file-name
)))
1626 (and gnus-uu-ignore-files-by-type
1627 (string-match gnus-uu-ignore-files-by-type
1628 (or (gnus-uu-choose-action
1629 file-name gnus-uu-ext-to-mime-list t
)
1631 (while (not (or (eq action-list
()) action
))
1632 (setq rule
(car action-list
))
1633 (setq action-list
(cdr action-list
))
1634 (when (string-match (car rule
) file-name
)
1635 (setq action
(cadr rule
)))))
1638 (defun gnus-uu-treat-archive (file-path)
1639 ;; Unpacks an archive. Returns t if unpacking is successful.
1640 (let ((did-unpack t
)
1642 (setq action
(gnus-uu-choose-action
1643 file-path
(append gnus-uu-user-archive-rules
1644 (if gnus-uu-ignore-default-archive-rules
1646 gnus-uu-default-archive-rules
))))
1649 (error "No unpackers for the file %s" file-path
))
1651 (string-match "/[^/]*$" file-path
)
1652 (setq dir
(substring file-path
0 (match-beginning 0)))
1654 (when (member action gnus-uu-destructive-archivers
)
1655 (copy-file file-path
(concat file-path
"~") t
))
1657 (setq command
(format "cd %s ; %s" dir
(gnus-uu-command action file-path
)))
1659 (with-current-buffer (gnus-get-buffer-create gnus-uu-output-buffer-name
)
1662 (gnus-message 5 "Unpacking: %s..." (gnus-uu-command action file-path
))
1664 (if (eq 0 (call-process shell-file-name nil
1665 (gnus-get-buffer-create gnus-uu-output-buffer-name
)
1666 nil shell-command-switch command
))
1668 (gnus-message 2 "Error during unpacking of archive")
1669 (setq did-unpack nil
))
1671 (when (member action gnus-uu-destructive-archivers
)
1672 (rename-file (concat file-path
"~") file-path t
))
1676 (defun gnus-uu-dir-files (dir)
1677 (let ((dirs (directory-files dir t
"[^/][^\\.][^\\.]?$"))
1680 (if (file-directory-p (setq file
(car dirs
)))
1681 (setq files
(append files
(gnus-uu-dir-files file
)))
1683 (setq dirs
(cdr dirs
)))
1686 (defun gnus-uu-unpack-files (files &optional ignore
)
1687 ;; Go through FILES and look for files to unpack.
1688 (let* ((totfiles (gnus-uu-ls-r gnus-uu-work-dir
))
1692 (setq file
(cdr (assq 'name
(car files
))))
1693 (when (and (not (member file ignore
))
1694 (equal (gnus-uu-get-action (file-name-nondirectory file
))
1696 (push file did-unpack
)
1697 (unless (gnus-uu-treat-archive file
)
1698 (gnus-message 2 "Error during unpacking of %s" file
))
1699 (let* ((newfiles (gnus-uu-ls-r gnus-uu-work-dir
))
1702 (unless (member (car nfiles
) totfiles
)
1703 (push (list (cons 'name
(car nfiles
))
1704 (cons 'original file
))
1706 (setq nfiles
(cdr nfiles
)))
1707 (setq totfiles newfiles
)))
1708 (setq files
(cdr files
)))
1710 (gnus-uu-unpack-files ofiles
(append did-unpack ignore
))
1713 (defun gnus-uu-ls-r (dir)
1714 (let* ((files (gnus-uu-directory-files dir t
))
1717 (when (file-directory-p (car files
))
1718 (setq ofiles
(delete (car files
) ofiles
))
1719 (setq ofiles
(append ofiles
(gnus-uu-ls-r (car files
)))))
1720 (setq files
(cdr files
)))
1725 (defun gnus-uu-directory-files (dir &optional full
)
1726 (let (files out file
)
1727 (setq files
(directory-files dir full
))
1729 (setq file
(car files
))
1730 (setq files
(cdr files
))
1731 (unless (member (file-name-nondirectory file
) '("." ".."))
1733 (setq out
(nreverse out
))
1736 (defun gnus-uu-check-correct-stripped-uucode (start end
)
1738 (let (found beg length
)
1739 (unless gnus-uu-correct-stripped-uucode
1742 (if (re-search-forward " \\|`" end t
)
1747 (when (looking-at "\n")
1752 (unless (looking-at (concat gnus-uu-begin-string
"\\|"
1753 gnus-uu-end-string
))
1755 (setq length
(- (point-at-eol) (point-at-bol))))
1760 (unless (= length
(- (point) beg
))
1761 (insert (make-string (- length
(- (point) beg
)) ?
))))
1762 (forward-line 1)))))))
1764 (defvar gnus-uu-tmp-alist nil
)
1766 (defun gnus-uu-initialize (&optional scan
)
1769 (when (setq entry
(assoc gnus-newsgroup-name gnus-uu-tmp-alist
))
1770 (if (file-exists-p (cdr entry
))
1771 (setq gnus-uu-work-dir
(cdr entry
))
1772 (setq gnus-uu-tmp-alist
(delq entry gnus-uu-tmp-alist
))
1775 (setq gnus-uu-tmp-dir
(file-name-as-directory
1776 (expand-file-name gnus-uu-tmp-dir
)))
1777 (if (not (file-directory-p gnus-uu-tmp-dir
))
1778 (error "Temp directory %s doesn't exist" gnus-uu-tmp-dir
)
1779 (when (not (file-writable-p gnus-uu-tmp-dir
))
1780 (error "Temp directory %s can't be written to"
1783 (setq gnus-uu-work-dir
1784 (make-temp-file (concat gnus-uu-tmp-dir
"gnus") 'dir
))
1785 (gnus-set-file-modes gnus-uu-work-dir
448)
1786 (setq gnus-uu-work-dir
(file-name-as-directory gnus-uu-work-dir
))
1787 (push (cons gnus-newsgroup-name gnus-uu-work-dir
)
1788 gnus-uu-tmp-alist
))))
1791 ;; Kills the temporary uu buffers, kills any processes, etc.
1792 (defun gnus-uu-clean-up ()
1794 (and gnus-uu-uudecode-process
1795 (memq (process-status (or gnus-uu-uudecode-process
"nevair"))
1797 (delete-process gnus-uu-uudecode-process
))
1798 (when (setq buf
(get-buffer gnus-uu-output-buffer-name
))
1799 (kill-buffer buf
))))
1801 ;; Inputs an action and a filename and returns a full command, making sure
1802 ;; that the filename will be treated as a single argument when the shell
1803 ;; executes the command.
1804 (defun gnus-uu-command (action file
)
1805 (let ((quoted-file (shell-quote-argument file
)))
1806 (if (string-match "%s" action
)
1807 (format action quoted-file
)
1808 (concat action
" " quoted-file
))))
1810 (defun gnus-uu-delete-work-dir (&optional dir
)
1811 "Delete recursively all files and directories under `gnus-uu-work-dir'."
1813 (gnus-message 7 "Deleting directory %s..." dir
)
1814 (setq dir gnus-uu-work-dir
))
1816 (file-exists-p dir
))
1817 (let ((files (directory-files dir t nil t
))
1819 (while (setq file
(pop files
))
1820 (unless (member (file-name-nondirectory file
) '("." ".."))
1821 (if (file-directory-p file
)
1822 (gnus-uu-delete-work-dir file
)
1823 (gnus-message 9 "Deleting file %s..." file
)
1826 (error (gnus-message 3 "Deleting file %s failed... %s" file err
))))))
1828 (delete-directory dir
)
1829 (error (gnus-message 3 "Deleting directory %s failed... %s" file err
))))
1830 (gnus-message 7 "")))
1834 (add-hook 'gnus-summary-prepare-exit-hook
'gnus-uu-clean-up
)
1835 (add-hook 'gnus-summary-prepare-exit-hook
'gnus-uu-delete-work-dir
)
1840 ;;; uuencoded posting
1843 ;; Any function that is to be used as and encoding method will take two
1844 ;; parameters: PATH-NAME and FILE-NAME. (E.g. "/home/gaga/spiral.jpg"
1845 ;; and "spiral.jpg", respectively.) The function should return nil if
1846 ;; the encoding wasn't successful.
1847 (defcustom gnus-uu-post-encode-method
'gnus-uu-post-encode-uuencode
1848 "Function used for encoding binary files.
1849 There are three functions supplied with gnus-uu for encoding files:
1850 `gnus-uu-post-encode-uuencode', which does straight uuencoding;
1851 `gnus-uu-post-encode-mime', which encodes with base64 and adds MIME
1852 headers; and `gnus-uu-post-encode-mime-uuencode', which encodes with
1853 uuencode and adds MIME headers."
1854 :group
'gnus-extract-post
1855 :type
'(radio (function-item gnus-uu-post-encode-uuencode
)
1856 (function-item gnus-uu-post-encode-mime
)
1857 (function-item gnus-uu-post-encode-mime-uuencode
)
1858 (function :tag
"Other")))
1860 (defcustom gnus-uu-post-include-before-composing nil
1861 "Non-nil means that gnus-uu will ask for a file to encode before you compose the article.
1862 If this variable is t, you can either include an encoded file with
1863 \\[gnus-uu-post-insert-binary-in-article] or have one included for you when you post the article."
1864 :group
'gnus-extract-post
1867 (defcustom gnus-uu-post-length
990
1868 "Maximum length of an article.
1869 The encoded file will be split into how many articles it takes to
1870 post the entire file."
1871 :group
'gnus-extract-post
1874 (defcustom gnus-uu-post-threaded nil
1875 "Non-nil means that gnus-uu will post the encoded file in a thread.
1876 This may not be smart, as no other decoder I have seen are able to
1877 follow threads when collecting uuencoded articles. (Well, I have seen
1878 one package that does that - gnus-uu, but somehow, I don't think that
1879 counts...) The default is nil."
1880 :group
'gnus-extract-post
1883 (defcustom gnus-uu-post-separate-description t
1884 "Non-nil means that the description will be posted in a separate article.
1885 The first article will typically be numbered (0/x). If this variable
1886 is nil, the description the user enters will be included at the
1887 beginning of the first article, which will be numbered (1/x). Default
1889 :group
'gnus-extract-post
1892 (defvar gnus-uu-post-binary-separator
"--binary follows this line--")
1893 (defvar gnus-uu-post-message-id nil
)
1894 (defvar gnus-uu-post-inserted-file-name nil
)
1895 (defvar gnus-uu-winconf-post-news nil
)
1897 (defun gnus-uu-post-news ()
1898 "Compose an article and post an encoded file."
1900 (setq gnus-uu-post-inserted-file-name nil
)
1901 (setq gnus-uu-winconf-post-news
(current-window-configuration))
1903 (gnus-summary-post-news)
1905 (let ((map (make-sparse-keymap)))
1906 (set-keymap-parent map
(current-local-map))
1907 (use-local-map map
))
1908 ;;(local-set-key "\C-c\C-c" 'gnus-summary-edit-article-done)
1909 (local-set-key "\C-c\C-c" 'gnus-uu-post-news-inews
)
1910 (local-set-key "\C-c\C-s" 'gnus-uu-post-news-inews
)
1911 (local-set-key "\C-c\C-i" 'gnus-uu-post-insert-binary-in-article
)
1913 (when gnus-uu-post-include-before-composing
1914 (save-excursion (setq gnus-uu-post-inserted-file-name
1915 (gnus-uu-post-insert-binary)))))
1917 (defun gnus-uu-post-insert-binary-in-article ()
1918 "Inserts an encoded file in the buffer.
1919 The user will be asked for a file name."
1922 (setq gnus-uu-post-inserted-file-name
(gnus-uu-post-insert-binary))))
1924 ;; Encodes with uuencode and substitutes all spaces with backticks.
1925 (defun gnus-uu-post-encode-uuencode (path file-name
)
1926 (when (gnus-uu-post-encode-file "uuencode" path file-name
)
1927 (goto-char (point-min))
1929 (while (search-forward " " nil t
)
1930 (replace-match "`"))
1933 ;; Encodes with uuencode and adds MIME headers.
1934 (defun gnus-uu-post-encode-mime-uuencode (path file-name
)
1935 (when (gnus-uu-post-encode-uuencode path file-name
)
1936 (gnus-uu-post-make-mime file-name
"x-uue")
1939 ;; Encodes with base64 and adds MIME headers
1940 (defun gnus-uu-post-encode-mime (path file-name
)
1941 (when (eq 0 (call-process shell-file-name nil t nil shell-command-switch
1942 (format "%s %s -o %s" "mmencode" path file-name
)))
1943 (gnus-uu-post-make-mime file-name
"base64")
1946 ;; Adds MIME headers.
1947 (defun gnus-uu-post-make-mime (file-name encoding
)
1948 (goto-char (point-min))
1949 (insert (format "Content-Type: %s; name=\"%s\"\n"
1950 (gnus-uu-choose-action file-name gnus-uu-ext-to-mime-list
)
1952 (insert (format "Content-Transfer-Encoding: %s\n\n" encoding
))
1954 (set-buffer gnus-message-buffer
)
1955 (goto-char (point-min))
1956 (re-search-forward (concat "^" (regexp-quote mail-header-separator
) "$"))
1958 (narrow-to-region (point-min) (point))
1959 (unless (mail-fetch-field "mime-version")
1961 (insert "MIME-Version: 1.0\n"))
1964 ;; Encodes a file PATH with COMMAND, leaving the result in the
1966 (defun gnus-uu-post-encode-file (command path file-name
)
1967 (eq 0 (call-process shell-file-name nil t nil shell-command-switch
1968 (format "%s %s %s" command path file-name
))))
1970 (defun gnus-uu-post-news-inews ()
1971 "Posts the composed news article and encoded file.
1972 If no file has been included, the user will be asked for a file."
1977 (if gnus-uu-post-inserted-file-name
1978 (setq file-name gnus-uu-post-inserted-file-name
)
1979 (setq file-name
(gnus-uu-post-insert-binary)))
1981 (gnus-uu-post-encoded file-name gnus-uu-post-threaded
))
1982 (setq gnus-uu-post-inserted-file-name nil
)
1983 (when gnus-uu-winconf-post-news
1984 (set-window-configuration gnus-uu-winconf-post-news
)))
1986 ;; Asks for a file to encode, encodes it and inserts the result in
1987 ;; the current buffer. Returns the file name the user gave.
1988 (defun gnus-uu-post-insert-binary ()
1989 (let ((uuencode-buffer-name "*uuencode buffer*")
1990 file-path uubuf file-name
)
1992 (setq file-path
(read-file-name
1993 "What file do you want to encode? "))
1994 (when (not (file-exists-p file-path
))
1995 (error "%s: No such file" file-path
))
1997 (goto-char (point-max))
1998 (insert (format "\n%s\n" gnus-uu-post-binary-separator
))
2000 ;; #### Unix-specific?
2001 (when (string-match "^~/" file-path
)
2002 (setq file-path
(concat "$HOME" (substring file-path
1))))
2003 ;; #### Unix-specific?
2004 (if (string-match "/[^/]*$" file-path
)
2005 (setq file-name
(substring file-path
(1+ (match-beginning 0))))
2006 (setq file-name file-path
))
2009 (if (with-current-buffer
2010 (setq uubuf
(gnus-get-buffer-create uuencode-buffer-name
))
2012 (funcall gnus-uu-post-encode-method file-path file-name
))
2013 (insert-buffer-substring uubuf
)
2014 (error "Encoding unsuccessful"))
2015 (kill-buffer uubuf
))
2018 ;; Posts the article and all of the encoded file.
2019 (defun gnus-uu-post-encoded (file-name &optional threaded
)
2020 (let ((send-buffer-name "*uuencode send buffer*")
2021 (encoded-buffer-name "*encoded buffer*")
2022 (top-string "[ cut here %s (%s %d/%d) %s gnus-uu ]")
2023 (separator (concat mail-header-separator
"\n\n"))
2024 uubuf length parts header i end beg
2025 beg-line minlen post-buf whole-len beg-binary end-binary
)
2027 (setq post-buf
(current-buffer))
2029 (goto-char (point-min))
2030 (when (not (re-search-forward
2031 (if gnus-uu-post-separate-description
2032 (concat "^" (regexp-quote gnus-uu-post-binary-separator
)
2034 (concat "^" (regexp-quote mail-header-separator
) "$"))
2036 (error "Internal error: No binary/header separator"))
2039 (setq beg-binary
(point))
2040 (setq end-binary
(point-max))
2042 (with-current-buffer
2043 (setq uubuf
(gnus-get-buffer-create encoded-buffer-name
))
2045 (insert-buffer-substring post-buf beg-binary end-binary
)
2046 (goto-char (point-min))
2047 (setq length
(count-lines (point-min) (point-max)))
2048 (setq parts
(/ length gnus-uu-post-length
))
2049 (unless (< (% length gnus-uu-post-length
) 4)
2052 (when gnus-uu-post-separate-description
2054 (delete-region (point) (point-max))
2056 (goto-char (point-min))
2058 (concat "^" (regexp-quote mail-header-separator
) "$") nil t
)
2059 (setq header
(buffer-substring (point-min) (point-at-bol)))
2061 (goto-char (point-min))
2062 (when gnus-uu-post-separate-description
2063 (when (re-search-forward "^Subject: " nil t
)
2065 (insert (format " (0/%d)" parts
)))
2068 (setq gnus-uu-post-message-id
(message-fetch-field "message-id")))
2073 (while (not (> i parts
))
2074 (set-buffer (gnus-get-buffer-create send-buffer-name
))
2077 (when (and threaded gnus-uu-post-message-id
)
2078 (insert "References: " gnus-uu-post-message-id
"\n"))
2081 (- 62 (length (format top-string
"" file-name i parts
""))))
2082 (when (> 1 (setq minlen
(/ whole-len
2)))
2087 (make-string minlen ?-
)
2090 (if (= 0 (% whole-len
2)) (1- minlen
) minlen
) ?-
)))
2092 (goto-char (point-min))
2093 (when (re-search-forward "^Subject: " nil t
)
2095 (insert (format " (%d/%d)" i parts
)))
2097 (goto-char (point-max))
2098 (with-current-buffer uubuf
2101 (goto-char (point-max))
2102 (forward-line gnus-uu-post-length
))
2103 (when (and (= (1+ i
) parts
) (< (count-lines (point) (point-max)) 4))
2106 (insert-buffer-substring uubuf beg end
)
2107 (insert beg-line
"\n")
2110 (goto-char (point-min))
2112 (concat "^" (regexp-quote mail-header-separator
) "$") nil t
)
2115 (when (re-search-forward
2116 (concat "^" (regexp-quote gnus-uu-post-binary-separator
) "$")
2122 (let (message-sent-message-via)
2125 (setq gnus-uu-post-message-id
2126 (concat (message-fetch-field "references") " "
2127 (message-fetch-field "message-id"))))))
2129 (gnus-kill-buffer send-buffer-name
)
2130 (gnus-kill-buffer encoded-buffer-name
)
2132 (when (not gnus-uu-post-separate-description
)
2133 (set-buffer-modified-p nil
)
2138 ;;; gnus-uu.el ends here