Initial Commit
[packages] / xemacs-packages / vm / lisp / vm-vcard.el
1 ;;; vm-vcard.el --- vcard parsing and formatting routines for VM
2
3 ;; Copyright (C) 1997, 2000 Noah S. Friedman
4
5 ;; Author: Noah Friedman <friedman@splode.com>
6 ;; Maintainer: friedman@splode.com
7 ;; Keywords: extensions
8 ;; Created: 1997-10-03
9
10
11 ;; This program is free software; you can redistribute it and/or modify
12 ;; it under the terms of the GNU General Public License as published by
13 ;; the Free Software Foundation; either version 2, or (at your option)
14 ;; any later version.
15 ;;
16 ;; This program is distributed in the hope that it will be useful,
17 ;; but WITHOUT ANY WARRANTY; without even the implied warranty of
18 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
19 ;; GNU General Public License for more details.
20 ;;
21 ;; You should have received a copy of the GNU General Public License
22 ;; along with this program; if not, you can either send email to this
23 ;; program's maintainer or write to: The Free Software Foundation,
24 ;; Inc.; 59 Temple Place, Suite 330; Boston, MA 02111-1307, USA.
25
26 ;;; Commentary:
27 ;;; Code:
28
29 (require 'vcard)
30
31 (and (string-lessp vcard-api-version "2.0")
32      (error "vm-vcard.el requires vcard API version 2.0 or later."))
33
34 ;;;###autoload
35 (defvar vm-vcard-format-function nil
36   "*Function to use for formatting vcards; if nil, use default.")
37
38 ;;;###autoload
39 (defvar vm-vcard-filter nil
40   "*Filter function to use for formatting vcards; if nil, use default.")
41
42 ;;;###autoload
43 (defun vm-mime-display-internal-text/x-vcard (layout)
44   (let ((inhibit-read-only t)
45         (buffer-read-only nil))
46     (insert (vm-vcard-format-layout layout)))
47   t)
48
49 (defun vm-vcard-format-layout (layout)
50   (let* ((beg (vm-mm-layout-body-start layout))
51          (end (vm-mm-layout-body-end layout))
52          (buf (if (markerp beg) (marker-buffer beg) (current-buffer)))
53          (raw (vm-vcard-decode (save-excursion
54                                  (set-buffer buf)
55                                  (save-restriction
56                                    (widen)
57                                    (buffer-substring beg end)))
58                                layout))
59          (vcard-pretty-print-function (or vm-vcard-format-function
60                                           vcard-pretty-print-function)))
61     (vcard-pretty-print (vcard-parse-string raw vm-vcard-filter))))
62
63 (defun vm-vcard-decode (string layout)
64   (let ((buf (generate-new-buffer " *vcard decoding*")))
65     (save-excursion
66       (set-buffer buf)
67       (insert string)
68       (vm-mime-transfer-decode-region layout (point-min) (point-max))
69       (setq string (buffer-substring (point-min) (point-max))))
70     (kill-buffer buf))
71   string)
72
73 (defun vm-vcard-format-simple (vcard)
74   (concat "\n\n--\n" (vcard-format-sample-string vcard) "\n\n"))
75
76 (provide 'vm-vcard)
77
78 ;;; vm-vcard.el ends here.