X-Git-Url: http://git.chise.org/gitweb/?a=blobdiff_plain;f=mel-q.el;h=04d27e6b3abba4a5ddace8560498ddb1296146ed;hb=96940805912c6e81f08decf8ef4ff742bbc2e00c;hp=dfa1d06a696eb58beb59d40ae28349d0223af11b;hpb=9a7c7a72ccf132312e55ab54006d0e8645a62d3a;p=elisp%2Fflim.git diff --git a/mel-q.el b/mel-q.el index dfa1d06..04d27e6 100644 --- a/mel-q.el +++ b/mel-q.el @@ -119,7 +119,7 @@ If size of input to encode is larger than this limit, external encoder is called.") -(defun quoted-printable-encode-region (start end) +(defun quoted-printable-int-ext-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 @@ -135,16 +135,23 @@ the program (maybe mmencode included in metamail or XEmacs package)." )) -(defun quoted-printable-encode-string (string) +(defun quoted-printable-internal-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)) + (quoted-printable-internal-encode-region (point-min)(point-max)) (buffer-string) )) +(defun quoted-printable-external-encode-string (string) + "Encode STRING to quoted-printable, and return the result." + (with-temp-buffer + (insert string) + (quoted-printable-external-encode-region (point-min)(point-max)) + (buffer-string) + )) -(defun quoted-printable-insert-encoded-file (filename) +(defun quoted-printable-external-insert-encoded-file (filename) "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 @@ -164,46 +171,31 @@ It calls external quoted-printable encoder specified by ((<= ?0 chr) (- chr ?0)) )) -(defun quoted-printable-decode-string (string) - "Decode STRING which is encoded in quoted-printable, and return the result." - (let (q h l) - (mapconcat (function - (lambda (chr) - (cond ((eq chr ?=) - (setq q t) - "") - (q (setq h (quoted-printable-hex-char-to-num chr)) - (setq q nil) - "") - (h (setq l (quoted-printable-hex-char-to-num chr)) - (prog1 - (char-to-string (logior (ash h 4) l)) - (setq h nil) - ) - ) - (t (char-to-string chr)) - ))) - string ""))) - (defun quoted-printable-internal-decode-region (start end) (save-excursion (save-restriction (narrow-to-region start end) (goto-char (point-min)) - (while (re-search-forward "=\n" nil t) - (replace-match "") - ) - (goto-char (point-min)) - (let (b e str) - (while (re-search-forward quoted-printable-octet-regexp nil t) - (setq b (match-beginning 0)) - (setq e (match-end 0)) - (setq str (buffer-substring b e)) - (delete-region b e) - (insert (string-as-multibyte (quoted-printable-decode-string str))) - )) - ))) - + (while (search-forward "=" nil t) + (let ((beg (match-beginning 0))) + (cond ((looking-at "\n") + (delete-region beg (match-end 0)) + ) + ((looking-at + `,(concat "[" quoted-printable-hex-chars + "][" quoted-printable-hex-chars "]")) + (let* ((end (match-end 0)) + (hex (buffer-substring (match-beginning 0) end))) + (delete-region beg end) + (insert + (logior + (ash (quoted-printable-hex-char-to-num (aref hex 0)) 4) + (quoted-printable-hex-char-to-num (aref hex 1)))) + )) + (t + ;; invalid + )) + ))))) (defvar quoted-printable-external-decoder '("mmencode" "-q" "-u") "*list of quoted-printable decoder program name and its arguments.") @@ -222,7 +214,7 @@ It calls external quoted-printable encoder specified by If size of input to decode is larger than this limit, external decoder is called.") -(defun quoted-printable-decode-region (start end) +(defun quoted-printable-int-ext-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 @@ -237,11 +229,24 @@ the program (maybe mmencode included in metamail or XEmacs package)." (quoted-printable-internal-decode-region start end) )) +(defun quoted-printable-internal-decode-string (string) + "Decode STRING which is encoded in quoted-printable, and return the result." + (with-temp-buffer + (insert string) + (quoted-printable-internal-decode-region (point-min)(point-max)) + (buffer-string))) + +(defun quoted-printable-external-decode-string (string) + "Decode STRING which is encoded in quoted-printable, and return the result." + (with-temp-buffer + (insert string) + (quoted-printable-external-decode-region (point-min)(point-max)) + (buffer-string))) (defvar quoted-printable-external-decoder-option-to-specify-file '("-o") "*list of options of quoted-printable decoder program to specify file.") -(defun quoted-printable-write-decoded-region (start end filename) +(defun quoted-printable-external-write-decoded-region (start end filename) "Decode and write current region encoded by quoted-printable into FILENAME. START and END are buffer positions." (interactive @@ -267,7 +272,7 @@ START and END are buffer positions." ?: ?\; ?< ?> ?@ ?\[ ?\] ?^ ?` ?{ ?| ?} ?~) )) -(defun q-encoding-encode-string (string &optional mode) +(defun q-encoding-internal-encode-string (string &optional mode) "Encode STRING to Q-encoding of encoded-word, and return the result. MODE allows `text', `comment', `phrase' or nil. Default value is `phrase'." @@ -289,7 +294,7 @@ MODE allows `text', `comment', `phrase' or nil. Default value is string "") )) -(defun q-encoding-decode-string (string) +(defun q-encoding-internal-decode-string (string) "Decode STRING which is encoded in Q-encoding and return the result." (let (q h l) (mapconcat (function @@ -326,7 +331,7 @@ MODE allows `text', `comment', `phrase' or nil. Default value is (string-match "[A-Za-z0-9!*+/=_---]" (char-to-string chr)) )))) -(defun q-encoding-encoded-length (string &optional mode) +(defun q-encoding-internal-encoded-length (string &optional mode) (let ((l 0)(i 0)(len (length string)) chr) (while (< i len) (setq chr (elt string i))