X-Git-Url: https://cgit.sxemacs.org/?a=blobdiff_plain;f=lisp%2Fmm-decode.el;h=9d0a44b819a7e6ff32f3d8e040b74782247273c3;hb=0f7d64ee3a11093ff6b9621478681d34403168cb;hp=26dd8323caf99208e9b365eed43fe552cd1faa96;hpb=1626a196f4c06639aaf46dc4a6a0901b7b6e9b5c;p=gnus diff --git a/lisp/mm-decode.el b/lisp/mm-decode.el index 26dd8323c..9d0a44b81 100644 --- a/lisp/mm-decode.el +++ b/lisp/mm-decode.el @@ -1,8 +1,9 @@ -;;; mm-decode.el --- Function for decoding MIME things +;;; mm-decode.el --- Functions for decoding MIME things ;; Copyright (C) 1998 Free Software Foundation, Inc. ;; Author: Lars Magne Ingebrigtsen -;; This file is not yet part of GNU Emacs. +;; MORIOKA Tomohiko +;; This file is part of GNU Emacs. ;; GNU Emacs is free software; you can redistribute it and/or modify ;; it under the terms of the GNU General Public License as published by @@ -23,106 +24,6 @@ ;;; Code: -(require 'base64) -(require 'qp) -(require 'nnheader) - -(defvar mm-charset-regexp (concat "[^" "][\000-\040()<>@,\;:\\\"/?.=" "]+")) - -(defvar mm-encoded-word-regexp - (concat "=\\?\\(" mm-charset-regexp "\\)\\?\\(B\\|Q\\)\\?" - "\\([!->@-~]+\\)\\?=")) - -(defun mm-decode-words-region (start end) - "Decode MIME-encoded words in region between START and END." - (interactive "r") - (save-excursion - (save-restriction - (narrow-to-region start end) - (goto-char (point-min)) - ;; Remove whitespace between encoded words. - (while (re-search-forward - (concat "\\(" mm-encoded-word-regexp "\\)" - "\\(\n?[ \t]\\)+" - "\\(" mm-encoded-word-regexp "\\)") - nil t) - (delete-region (goto-char (match-end 1)) (match-beginning 6))) - ;; Decode the encoded words. - (goto-char (point-min)) - (while (re-search-forward mm-encoded-word-regexp nil t) - (insert (mm-decode-word - (prog1 - (match-string 0) - (delete-region (match-beginning 0) (match-end 0))))))))) - -(defun mm-decode-words-string (string) - "Decode the quoted-printable-encoded STRING and return the results." - (with-temp-buffer - (insert string) - (inline - (mm-decode-words-region (point-min) (point-max))) - (buffer-string))) - -(defun mm-decode-word (word) - "Decode WORD and return it if it is an encoded word. -Return WORD if not." - (if (not (string-match mm-encoded-word-regexp word)) - word - (or - (condition-case nil - (mm-decode-text - (match-string 1 word) - (upcase (match-string 2 word)) - (match-string 3 word)) - (error word)) - word))) - -(defun mm-decode-text (charset encoding string) - "Decode STRING as an encoded text. -Valid ENCODINGs are \"B\" and \"Q\". -If your Emacs implementation can't decode CHARSET, it returns nil." - (let ((cs (mm-charset-to-coding-system charset))) - (when cs - (decode-coding-string - (cond - ((equal "B" encoding) - (base64-decode string)) - ((equal "Q" encoding) - (quoted-printable-decode-string - (nnheader-replace-chars-in-string string ?_ ? ))) - (t (error "Invalid encoding: %s" encoding))) - cs)))) - -(defvar mm-charset-coding-system-alist - (let ((rest - '((us-ascii . iso-8859-1) - (gb2312 . cn-gb-2312) - (iso-2022-jp-2 . iso-2022-7bit-ss2) - (x-ctext . ctext))) - dest) - (while rest - (let ((pair (car rest))) - (unless (coding-system-p (car pair)) - (setq dest (cons pair dest)))) - (setq rest (cdr rest))) - dest) - "Charset/coding system alist.") - -(defun mm-charset-to-coding-system (charset &optional lbt) - "Return coding-system corresponding to CHARSET. -CHARSET is a symbol naming a MIME charset. -If optional argument LBT (`unix', `dos' or `mac') is specified, it is -used as the line break code type of the coding system." - (when (stringp charset) - (setq charset (intern (downcase charset)))) - (setq charset - (or (cdr (assq charset mm-charset-coding-system-alist)) - charset)) - (when lbt - (setq charset (intern (format "%s-%s" charset lbt)))) - (when (memq charset (coding-system-list)) - charset)) - (provide 'mm-decode) -;; qp.el ends here +;; mm-decode.el ends here