Function: gnus-dired-attach

gnus-dired-attach is an interactive and byte-compiled function defined in gnus-dired.el.gz.

Signature

(gnus-dired-attach FILES-TO-ATTACH)

Documentation

Attach Dired's marked files to a gnus message composition.

If called non-interactively, FILES-TO-ATTACH should be a list of filenames.

Key Bindings

Source Code

;; Defined in /usr/src/emacs/lisp/gnus/gnus-dired.el.gz
;; Method to attach files to a mail composition.
(defun gnus-dired-attach (files-to-attach)
  "Attach Dired's marked files to a gnus message composition.
If called non-interactively, FILES-TO-ATTACH should be a list of
filenames."
  (interactive
   (list
    (delq nil
	  (mapcar
	   ;; don't attach directories
	   (lambda (f) (if (file-directory-p f) nil f))
	   (nreverse (dired-map-over-marks (dired-get-filename) nil)))))
   dired-mode)
  (let ((destination nil)
	(files-str nil)
	(bufs nil))
    ;; warn if user tries to attach without any files marked
    (if (null files-to-attach)
	(error "No files to attach")
      (setq files-str (mapconcat #'file-name-nondirectory
                                 files-to-attach ", "))
      (setq bufs (gnus-dired-mail-buffers))

      ;; set up destination mail composition buffer
      (if (and bufs
	       (y-or-n-p "Attach files to existing mail composition buffer? "))
	  (setq destination
		(if (= (length bufs) 1)
		    (get-buffer (car bufs))
		  (gnus-completing-read "Attach to buffer"
                                         bufs t nil nil (car bufs))))
	;; setup a new mail composition buffer
	(let ((mail-user-agent gnus-dired-mail-mode)
	      ;; A workaround to prevent Gnus from displaying the Gnus
	      ;; logo when invoking this command without loading Gnus.
	      ;; Gnus demonstrates it when gnus.elc is being loaded if
	      ;; a command of which the name is prefixed with "gnus"
	      ;; causes that autoloading.  See the code in question,
	      ;; that is the one first found in gnus.el by performing
	      ;; `C-s this-command'.
	      (this-command (if (eq gnus-dired-mail-mode 'gnus-user-agent)
				'gnoose-dired-attach
			      this-command)))
	  (compose-mail))
	(setq destination (current-buffer)))

      ;; set buffer to destination buffer, and attach files
      (set-buffer destination)
      (when gnus-dired-attach-at-end
        (goto-char (point-max)))		;attach at end of buffer
      (while files-to-attach
	(mml-attach-file (car files-to-attach)
			 (or (mm-default-file-type (car files-to-attach))
			     "application/octet-stream")
			 nil)
	(setq files-to-attach (cdr files-to-attach)))
      (message "Attached file(s) %s" files-str))))