Function: gnus-uu-uustrip-article

gnus-uu-uustrip-article is a byte-compiled function defined in gnus-uu.el.gz.

Signature

(gnus-uu-uustrip-article PROCESS-BUFFER IN-STATE)

Source Code

;; Defined in /usr/src/emacs/lisp/gnus/gnus-uu.el.gz
(defun gnus-uu-uustrip-article (process-buffer _in-state)
  ;; Uudecodes a file asynchronously.
  (with-current-buffer process-buffer
    (let ((state (list 'wrong-type))
	  process-connection-type case-fold-search buffer-read-only
	  files start-char)
      (goto-char (point-min))

      ;; Deal with ^M at the end of the lines.
      (when gnus-uu-kill-carriage-return
	(save-excursion
	  (while (search-forward "\r" nil t)
	    (delete-char -1))))

      (while (or (re-search-forward gnus-uu-begin-string nil t)
		 (re-search-forward gnus-uu-body-line nil t))
	(setq state (list 'ok))
	;; Ok, we are at the first uucoded line.
	(beginning-of-line)
	(setq start-char (point))

	(if (not (looking-at gnus-uu-begin-string))
	    (setq state (list 'middle))
	  ;; This is the beginning of a uuencoded article.
	  ;; We replace certain characters that could make things messy.
	  (setq gnus-uu-file-name
		(gnus-map-function
		 mm-file-name-rewrite-functions
		 (file-name-nondirectory (match-string 1))))
	  (replace-match (concat "begin 644 " gnus-uu-file-name) t t)

	  ;; Remove any non gnus-uu-body-line right after start.
	  (forward-line 1)
	  (while (and (not (eobp))
		      (not (looking-at gnus-uu-body-line)))
	    (gnus-delete-line))

	  ;; If a process is running, we kill it.
	  (when (and gnus-uu-uudecode-process
		     (memq (process-status gnus-uu-uudecode-process)
			   '(run stop)))
	    (delete-process gnus-uu-uudecode-process)
	    (gnus-uu-unmark-list-of-grabbed t))

	  ;; Start a new uudecoding process.
	  (let ((cdir default-directory))
	    (unwind-protect
		(progn
		  (cd gnus-uu-work-dir)
		  (setq gnus-uu-uudecode-process
			(start-process
			 "*uudecode*"
			 (gnus-get-buffer-create gnus-uu-output-buffer-name)
			 shell-file-name shell-command-switch
			 (format "cd %s %s uudecode" gnus-uu-work-dir
				 gnus-shell-command-separator))))
	      (cd cdir)))
	  (set-process-sentinel
	   gnus-uu-uudecode-process 'gnus-uu-uudecode-sentinel)
	  (setq state (list 'begin))
	  (push (concat gnus-uu-work-dir gnus-uu-file-name) files))

	;; We look for the end of the thing to be decoded.
	(if (re-search-forward gnus-uu-end-string nil t)
	    (push 'end state)
	  (goto-char (point-max))
	  (re-search-backward gnus-uu-body-line nil t))

	(forward-line 1)

	(when gnus-uu-uudecode-process
	  (when (memq (process-status gnus-uu-uudecode-process) '(run stop))
	    ;; Try to correct mishandled uucode.
	    (when gnus-uu-correct-stripped-uucode
	      (gnus-uu-check-correct-stripped-uucode start-char (point)))
	    (gnus-run-hooks 'gnus-uu-pre-uudecode-hook)

	    ;; Send the text to the process.
	    (condition-case nil
		(process-send-region
		 gnus-uu-uudecode-process start-char (point))
	      (error
	       (progn
		 (delete-process gnus-uu-uudecode-process)
		 (gnus-message 2 "gnus-uu: Couldn't uudecode")
		 (setq state (list 'wrong-type)))))

	    (if (memq 'end state)
		(progn
		  ;; Send an EOF, just in case.
		  (ignore-errors
		    (process-send-eof gnus-uu-uudecode-process))
		  (while (memq (process-status gnus-uu-uudecode-process)
			       '(open run))
		    (accept-process-output gnus-uu-uudecode-process 1)))
	      (when (or (not gnus-uu-uudecode-process)
			(not (memq (process-status gnus-uu-uudecode-process)
				   '(run stop))))
		(setq state (list 'wrong-type)))))))

      (if (memq 'begin state)
	  (cons (if (= (length files) 1) (car files) files) state)
	state))))