Function: rmail-mime-handle

rmail-mime-handle is a byte-compiled function defined in rmailmm.el.gz.

Signature

(rmail-mime-handle CONTENT-TYPE CONTENT-DISPOSITION CONTENT-TRANSFER-ENCODING)

Documentation

Handle the current buffer as a MIME part.

The current buffer should be narrowed to the respective body, and point should be at the beginning of the body.

CONTENT-TYPE, CONTENT-DISPOSITION, and CONTENT-TRANSFER-ENCODING are the values of the respective parsed headers. The latter should be lower-case. The parsed headers for CONTENT-TYPE and CONTENT-DISPOSITION have the form

  (VALUE . ALIST)

In other words:

  (VALUE (ATTRIBUTE . VALUE) (ATTRIBUTE . VALUE) ...)

VALUE is a string and ATTRIBUTE is a symbol.

Consider the following header, for example:

Content-Type: multipart/mixed;
boundary="----=_NextPart_000_0104_01C617E4.BDEC4C40"

The parsed header value:

("multipart/mixed"
  ("boundary" . "----=_NextPart_000_0104_01C617E4.BDEC4C40"))

Source Code

;; Defined in /usr/src/emacs/lisp/mail/rmailmm.el.gz
;;; Main code

(defun rmail-mime-handle (content-type
			  content-disposition
			  content-transfer-encoding)
  "Handle the current buffer as a MIME part.
The current buffer should be narrowed to the respective body, and
point should be at the beginning of the body.

CONTENT-TYPE, CONTENT-DISPOSITION, and CONTENT-TRANSFER-ENCODING
are the values of the respective parsed headers.  The latter should
be lower-case.  The parsed headers for CONTENT-TYPE and CONTENT-DISPOSITION
have the form

  (VALUE . ALIST)

In other words:

  (VALUE (ATTRIBUTE . VALUE) (ATTRIBUTE . VALUE) ...)

VALUE is a string and ATTRIBUTE is a symbol.

Consider the following header, for example:

Content-Type: multipart/mixed;
	boundary=\"----=_NextPart_000_0104_01C617E4.BDEC4C40\"

The parsed header value:

\(\"multipart/mixed\"
  (\"boundary\" . \"----=_NextPart_000_0104_01C617E4.BDEC4C40\"))"
  ;; Handle the content transfer encodings we know.  Unknown transfer
  ;; encodings will be passed on to the various handlers.
  (cond ((string= content-transfer-encoding "base64")
	 (when (ignore-errors
		 (base64-decode-region (point) (point-max)))
	   (setq content-transfer-encoding nil)))
	((string= content-transfer-encoding "quoted-printable")
	 (quoted-printable-decode-region (point) (point-max))
	 (setq content-transfer-encoding nil))
	((string= content-transfer-encoding "8bit")
	 ;; FIXME: Is this the correct way?
         ;; No, of course not, it just means there's no decoding to do.
	 ;; (set-buffer-multibyte nil)
         (setq content-transfer-encoding nil)
         ))
  ;; Inline stuff requires work.  Attachments are handled by the bulk
  ;; handler.
  (if (string= "inline" (car content-disposition))
      (let ((stop nil))
	(dolist (entry rmail-mime-media-type-handlers-alist)
	  (when (and (string-match (car entry) (car content-type)) (not stop))
	    (progn
	      (setq stop (funcall (cadr entry) content-type
				  content-disposition
				  content-transfer-encoding))))))
    ;; Everything else is an attachment.
    (rmail-mime-bulk-handler content-type
		       content-disposition
		       content-transfer-encoding))
  (save-restriction
    (widen)
    (let ((entity (get-text-property (1- (point)) 'rmail-mime-entity)))
      (when entity
	(let ((new (aref (rmail-mime-entity-display entity) 1)))
	  (setf (aref (rmail-mime-entity-display entity) 0)
                (rmail-mime--copy-display new)))))))