* gnus-uu.el (gnus-uu-decode-yenc): New command.
authorLars Magne Ingebrigtsen <larsi@gnus.org>
Mon, 3 Dec 2007 17:51:25 +0000 (17:51 +0000)
committerLars Magne Ingebrigtsen <larsi@gnus.org>
Mon, 3 Dec 2007 17:51:25 +0000 (17:51 +0000)
(gnus-uu-yenc-article): New function.

* yenc.el (yenc-first-part-p, yenc-last-part-p): New functions.

lisp/ChangeLog
lisp/gnus-uu.el
lisp/yenc.el

index 818f7f0..5684001 100644 (file)
@@ -1,3 +1,13 @@
+2007-12-03  Lars Magne Ingebrigtsen  <larsi@gnus.org>
+
+       * gnus-uu.el (gnus-uu-decode-yenc): New command.
+       (gnus-uu-yenc-article): New function.
+
+       * yenc.el (yenc-first-part-p, yenc-last-part-p): New functions. 
+
+       * mm-uu.el (mm-uu-yenc-extract): Get the data from the original
+       buffer. 
+
 2007-12-01  Reiner Steib  <Reiner.Steib@gmx.de>
 
        * message.el (message-cite-prefix-regexp): Remove `-' and `+' to avoid
index 2093756..33abf24 100644 (file)
@@ -35,6 +35,7 @@
 (require 'message)
 (require 'gnus-msg)
 (require 'mm-decode)
+(require 'yenc)
 
 (defgroup gnus-extract nil
   "Extracting encoded files."
@@ -346,6 +347,7 @@ didn't work, and overwrite existing files.  Otherwise, ask each time."
 (defvar gnus-uu-file-name nil)
 (defvar gnus-uu-uudecode-process nil)
 (defvar gnus-uu-binhex-article-name nil)
+(defvar gnus-uu-yenc-article-name nil)
 
 (defvar gnus-uu-work-dir nil)
 
@@ -412,6 +414,17 @@ didn't work, and overwrite existing files.  Otherwise, ask each time."
        (mm-make-temp-file (expand-file-name "binhex" gnus-uu-work-dir)))
   (gnus-uu-decode-with-method 'gnus-uu-binhex-article n dir))
 
+(defun gnus-uu-decode-yenc (n dir)
+  "Decode the yEnc-encoded current article."
+  (interactive
+   (list current-prefix-arg
+        (file-name-as-directory
+         (read-file-name "yEnc decode and save in dir: "
+                         gnus-uu-default-dir
+                         gnus-uu-default-dir))))
+  (setq gnus-uu-yenc-article-name nil)
+  (gnus-uu-decode-with-method 'gnus-uu-yenc-article n dir nil t))
+
 (defun gnus-uu-decode-uu-view (&optional n)
   "Uudecodes and views the current article."
   (interactive "P")
@@ -1016,6 +1029,39 @@ When called interactively, prompt for REGEXP."
        (cons gnus-uu-binhex-article-name state)
       state)))
 
+;; yEnc
+
+(defun gnus-uu-yenc-article (buffer in-state)
+  (save-excursion
+    (set-buffer gnus-original-article-buffer)
+    (widen)
+    (let ((file-name (yenc-extract-filename))
+         state start-char)
+      (when (not file-name)
+       (setq state (list 'wrong-type)))
+
+      (if (memq 'wrong-type state)
+         ()
+       (when (yenc-first-part-p)
+         (setq gnus-uu-yenc-article-name
+               (expand-file-name file-name gnus-uu-work-dir))
+         (push 'begin state))
+       (when (yenc-last-part-p)
+         (push 'end state))
+       (unless state
+         (push 'middle state))
+       (mm-with-unibyte-buffer
+         (insert-buffer gnus-original-article-buffer)
+         (yenc-decode-region (point-min) (point-max))
+         (when (and (member 'begin state)
+                    (file-exists-p gnus-uu-yenc-article-name))
+           (delete-file gnus-uu-yenc-article-name))
+         (mm-append-to-file (point-min) (point-max)
+                            gnus-uu-yenc-article-name)))
+      (if (memq 'begin state)
+         (cons file-name state)
+       state))))
+
 ;; PostScript
 
 (defun gnus-uu-decode-postscript-article (process-buffer in-state)
index 7550186..7843f6a 100644 (file)
        191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207
        208 209 210 211 212 213])
 
+(defun yenc-first-part-p ()
+  "Say whether the buffer contains the first part of a yEnc file."
+  (save-excursion
+    (goto-char (point-min))
+    (re-search-forward "^=ybegin part=1 " nil t)))
+
+(defun yenc-last-part-p ()
+  "Say whether the buffer contains the last part of a yEnc file."
+  (save-excursion
+    (goto-char (point-min))
+    (let (total-size end-size)
+      (when (re-search-forward "^=ybegin.*size=\\([0-9]+\\)" nil t)
+       (setq total-size (match-string 1)))
+      (when (re-search-forward "^=ypart.*end=\\([0-9]+\\)" nil t)
+       (setq end-size (match-string 1)))
+      (and total-size
+          end-size
+          (string= total-size end-size)))))
+
 ;;;###autoload
 (defun yenc-decode-region (start end)
   "Yenc decode region between START and END using an internal decoder."