Sync with semi-1_14.
[elisp/semi.git] / mime-vcard.el
1 ;;; mime-vcard.el --- mime-view content filter for vCard.
2
3 ;; Copyright (C) 2000 Free Software Foundation, Inc.
4
5 ;; Author: Daiki Ueno <ueno@unixuser.org>
6 ;; Keywords: vCard, MIME, multimedia, mail, news
7
8 ;; This file is part of SEMI (Sample of Elastic MIME Interfaces).
9
10 ;; This program is free software; you can redistribute it and/or
11 ;; modify it under the terms of the GNU General Public License as
12 ;; published by the Free Software Foundation; either version 2, or (at
13 ;; your option) any later version.
14
15 ;; This program is distributed in the hope that it will be useful, but
16 ;; WITHOUT ANY WARRANTY; without even the implied warranty of
17 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
18 ;; General Public License for more details.
19
20 ;; You should have received a copy of the GNU General Public License
21 ;; along with GNU Emacs; see the file COPYING.  If not, write to the
22 ;; Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
23 ;; Boston, MA 02110-1301, USA.
24
25
26 ;;; Commentary:
27 ;; 
28
29 ;;; Code:
30
31 (require 'vcard)
32
33 (defvar mime-vcard-standard-filters
34   (cons #'mime-vcard-filter-quoted-printable
35         vcard-standard-filters))
36
37 (defun mime-vcard-filter-quoted-printable (key data)
38   (save-match-data
39     (when (string-match ";\\(encoding=\\)?quoted-printable$" key)
40       (while (string-match "\\(=[0-9A-F][0-9A-F]\\)+" data)
41         (setq data
42               (replace-match
43                (concat
44                 (string-as-multibyte
45                  (decode-coding-string
46                   (mime-decode-string
47                    (match-string 0 data) "quoted-printable")
48                   'raw-text-dos)))
49                t t data))))
50     data))
51
52 (defun mime-display-text/x-vcard (entity situation)
53   (save-restriction
54     (narrow-to-region (point-max)(point-max))
55     (let ((vcard-standard-filters mime-vcard-standard-filters))
56       (insert
57        (string-as-multibyte
58         (vcard-format-string
59          (vcard-parse-string
60           (mime-entity-content entity)
61           #'vcard-standard-filter)))))
62     (if (not (eq (char-after (1- (point))) ?\n))
63         (insert "\n"))
64     (mime-add-url-buttons)
65     (run-hooks 'mime-display-text/x-vcard-hook)))
66
67 (provide 'mime-vcard)
68
69 ;;; mime-vcard.el ends here