+ (while (re-search-forward "\r$" nil t)
+ (replace-match "")))))
+
+
+(defvar quoted-printable-internal-encoding-limit
+ (if (and (featurep 'xemacs)(featurep 'mule))
+ 0
+ (require 'path-util)
+ (if (exec-installed-p "mmencode")
+ 1000
+ ;; XXX: Fix this message, or simply remove it.
+ ;; (message "Don't found external encoder for Quoted-Printable!")
+ nil))
+ "*limit size to use internal quoted-printable encoder.
+If size of input to encode is larger than this limit,
+external encoder is called.")
+
+(defun quoted-printable-encode-region (start end)
+ "Encode current region by quoted-printable.
+START and END are buffer positions.
+This function calls internal quoted-printable encoder if size of
+region is smaller than `quoted-printable-internal-encoding-limit',
+otherwise it calls external quoted-printable encoder specified by
+`quoted-printable-external-encoder'. In this case, you must install
+the program (maybe mmencode included in metamail or XEmacs package)."
+ (interactive "*r")
+ (if (and quoted-printable-internal-encoding-limit
+ (> (- end start) quoted-printable-internal-encoding-limit))
+ (quoted-printable-external-encode-region start end)
+ (quoted-printable-internal-encode-region start end)))
+
+(defun quoted-printable-encode-string (string)
+ "Encode STRING to quoted-printable, and return the result."
+ (with-temp-buffer
+ (insert string)
+ (quoted-printable-encode-region (point-min)(point-max))
+ (buffer-string)))
+
+
+(mel-define-method-function
+ (mime-encode-string string (nil "quoted-printable"))
+ 'quoted-printable-encode-string)
+
+(mel-define-method-function
+ (mime-encode-region start end (nil "quoted-printable"))
+ 'quoted-printable-encode-region)
+
+(mel-define-method mime-insert-encoded-file (filename (nil "quoted-printable"))
+ "Encode contents of file FILENAME to quoted-printable, and insert the result.
+It calls external quoted-printable encoder specified by
+`quoted-printable-external-encoder'. So you must install the program
+\(maybe mmencode included in metamail or XEmacs package)."
+ (interactive "*fInsert encoded file: ")
+ (apply (function call-process)
+ (car quoted-printable-external-encoder)
+ filename t nil
+ (cdr quoted-printable-external-encoder)))
+
+
+;;; @ Quoted-Printable decoder
+;;;
+
+(defsubst quoted-printable-hex-char-to-num (chr)
+ (cond ((<= ?a chr) (+ (- chr ?a) 10))
+ ((<= ?A chr) (+ (- chr ?A) 10))
+ ((<= ?0 chr) (- chr ?0))
+ ))
+
+(defun quoted-printable-internal-decode-region (start end)