1 ;;; qp.el --- Quoted-printable functions
2 ;; Copyright (C) 1998 Free Software Foundation, Inc.
4 ;; Author: Lars Magne Ingebrigtsen <larsi@gnus.org>
5 ;; This file is part of GNU Emacs.
7 ;; GNU Emacs is free software; you can redistribute it and/or modify
8 ;; it under the terms of the GNU General Public License as published by
9 ;; the Free Software Foundation; either version 2, or (at your option)
12 ;; GNU Emacs is distributed in the hope that it will be useful,
13 ;; but WITHOUT ANY WARRANTY; without even the implied warranty of
14 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 ;; GNU General Public License for more details.
17 ;; You should have received a copy of the GNU General Public License
18 ;; along with GNU Emacs; see the file COPYING. If not, write to the
19 ;; Free Software Foundation, Inc., 59 Temple Place - Suite 330,
20 ;; Boston, MA 02111-1307, USA.
26 (defvar quoted-printable-encoding-characters
27 (mapcar 'identity "0123456789ABCDEF"))
29 (defun quoted-printable-decode-region (from to)
30 "Decode quoted-printable in the region between FROM and TO."
34 (while (search-forward "=" to t)
35 (cond ((eq (following-char) ?\n)
39 (memq (following-char) quoted-printable-encoding-characters)
40 (memq (char-after (1+ (point)))
41 quoted-printable-encoding-characters))
43 (1- (point)) (point) ?=
45 (buffer-substring (point) (+ 2 (point)))
50 ((message "Malformed MIME quoted-printable message"))))))
52 (defun quoted-printable-decode-string (string)
53 "Decode the quoted-printable-encoded STRING and return the results."
56 (quoted-printable-decode-region (point-min) (point-max))
59 (defun quoted-printable-encode-region (from to &optional fold class)
60 "QP-encode the region between FROM and TO.
61 If FOLD, fold long lines. If CLASS, translate the characters
62 matched by that regexp."
66 (narrow-to-region from to)
67 (goto-char (point-min))
68 (while (re-search-forward
69 (or class "[\000-\007\013\015-\037\200-\377=]") nil t)
72 (format "=%x" (char-after (1- (point))))
75 (goto-char (point-min))
77 (while (> (current-column) 72)
80 (search-backward "=" (- (point) 2) t)
84 (defun quoted-printable-encode-string (string)
85 "QP-encode STRING and return the results."
88 (quoted-printable-encode-region (point-min) (point-max))