+(defvar quoted-printable-external-decoder '("mmencode" "-q" "-u")
+ "*list of quoted-printable decoder program name and its arguments.")
+
+(defun quoted-printable-external-decode-region (start end)
+ (save-excursion
+ (as-binary-process
+ (apply (function call-process-region)
+ start end (car quoted-printable-external-decoder)
+ t t nil
+ (cdr quoted-printable-external-decoder)))))
+
+
+(defvar quoted-printable-internal-decoding-limit nil
+ "*limit size to use internal quoted-printable decoder.
+If size of input to decode is larger than this limit,
+external decoder is called.")
+
+(defun quoted-printable-decode-region (start end)
+ "Decode current region by quoted-printable.
+START and END are buffer positions.
+This function calls internal quoted-printable decoder if size of
+region is smaller than `quoted-printable-internal-decoding-limit',
+otherwise it calls external quoted-printable decoder specified by
+`quoted-printable-external-decoder'. In this case, you must install
+the program (maybe mmencode included in metamail or XEmacs package)."
+ (interactive "*r")
+ (if (and quoted-printable-internal-decoding-limit
+ (> (- end start) quoted-printable-internal-decoding-limit))
+ (quoted-printable-external-decode-region start end)
+ (quoted-printable-internal-decode-region start end)))
+
+(defun quoted-printable-decode-string (string)
+ "Decode STRING which is encoded in quoted-printable, and return the result."
+ (with-temp-buffer
+ (insert string)
+ (quoted-printable-decode-region (point-min)(point-max))
+ (buffer-string)))
+
+
+(mel-define-method-function
+ (mime-decode-string string (nil "quoted-printable"))
+ 'quoted-printable-decode-string)
+
+(mel-define-method-function
+ (mime-decode-region start end (nil "quoted-printable"))
+ 'quoted-printable-decode-region)
+
+
+(defvar quoted-printable-external-decoder-option-to-specify-file '("-o")
+ "*list of options of quoted-printable decoder program to specify file.
+If the quoted-printable decoder does not have such option, set this as nil.")
+
+(mel-define-method mime-write-decoded-region (start end filename
+ (nil "quoted-printable"))
+ "Decode and write current region encoded by quoted-printable into FILENAME.
+START and END are buffer positions."
+ (interactive "*r\nFWrite decoded region to file: ")
+ (as-binary-process
+ (apply (function call-process-region)
+ start end (car quoted-printable-external-decoder)
+ (null quoted-printable-external-decoder-option-to-specify-file)
+ (unless quoted-printable-external-decoder-option-to-specify-file
+ (list (current-buffer) nil))
+ nil
+ (delq nil
+ (append
+ (cdr quoted-printable-external-decoder)
+ quoted-printable-external-decoder-option-to-specify-file
+ (when quoted-printable-external-decoder-option-to-specify-file
+ (list filename))))))
+ (unless quoted-printable-external-decoder-option-to-specify-file
+ (write-region-as-binary (point-min) (point-max) filename)))
+
+\f