+(defun mm-find-part-by-type (handles type &optional notp)
+ (let (handle)
+ (while handles
+ (if (if notp
+ (not (equal (mm-handle-media-type (car handles)) type))
+ (equal (mm-handle-media-type (car handles)) type))
+ (setq handle (car handles)
+ handles nil))
+ (setq handles (cdr handles)))
+ handle))
+
+(defun mm-find-raw-part-by-type (ctl type &optional notp)
+ (goto-char (point-min))
+ (let* ((boundary (concat "\n--" (mail-content-type-get ctl 'boundary)))
+ (close-delimiter (concat (regexp-quote boundary) "--[ \t]*$"))
+ start
+ (end (save-excursion
+ (goto-char (point-max))
+ (if (re-search-backward close-delimiter nil t)
+ (match-beginning 0)
+ (point-max))))
+ result)
+ (setq boundary (concat (regexp-quote boundary) "[ \t]*$"))
+ (while (and (not result)
+ (re-search-forward boundary end t))
+ (goto-char (match-beginning 0))
+ (when start
+ (save-excursion
+ (save-restriction
+ (narrow-to-region start (point))
+ (when (let ((ctl (ignore-errors
+ (mail-header-parse-content-type
+ (mail-fetch-field "content-type")))))
+ (if notp
+ (not (equal (car ctl) type))
+ (equal (car ctl) type)))
+ (setq result (buffer-substring (point-min) (point-max)))))))
+ (forward-line 2)
+ (setq start (point)))
+ (when (and (not result) start)
+ (save-excursion
+ (save-restriction
+ (narrow-to-region start end)
+ (when (let ((ctl (ignore-errors
+ (mail-header-parse-content-type
+ (mail-fetch-field "content-type")))))
+ (if notp
+ (not (equal (car ctl) type))
+ (equal (car ctl) type)))
+ (setq result (buffer-substring (point-min) (point-max)))))))
+ result))
+
+(defun mm-possibly-verify-or-decrypt (parts ctl)
+ (let ((subtype (cadr (split-string (car ctl) "/")))
+ protocol func)
+ (cond
+ ((equal subtype "signed")
+ (setq protocol (mail-content-type-get ctl 'protocol))
+ (setq func (cdr (assoc protocol mm-verify-function-alist)))
+ (if (cond
+ ((eq mm-verify-option 'never) nil)
+ ((eq mm-verify-option 'always) t)
+ ((eq mm-verify-option 'known) func)
+ (t (y-or-n-p
+ (format "Verify signed part(protocol=%s)?" protocol))))
+ (condition-case err
+ (save-excursion
+ (if func
+ (funcall func parts ctl)
+ (error (format "Unknown sign protocol(%s)" protocol))))
+ (error
+ (unless (y-or-n-p (format "%s, continue?" err))
+ (error "Verify failure."))))))
+ ((equal subtype "encrypted")
+ (setq protocol (mail-content-type-get ctl 'protocol))
+ (setq func (cdr (assoc protocol mm-decrypt-function-alist)))
+ (if (cond
+ ((eq mm-decrypt-option 'never) nil)
+ ((eq mm-decrypt-option 'always) t)
+ ((eq mm-decrypt-option 'known) func)
+ (t (y-or-n-p
+ (format "Decrypt part (protocol=%s)?" protocol))))
+ (condition-case err
+ (save-excursion
+ (if func
+ (setq parts (funcall func parts ctl))
+ (error (format "Unknown encrypt protocol(%s)" protocol))))
+ (error
+ (unless (y-or-n-p (format "%s, continue?" err))
+ (error "Decrypt failure."))))))
+ (t nil))
+ parts))
+