File: vm-vcard.el

package info (click to toggle)
xemacs21-packages 2009.02.17.dfsg.1-1
  • links: PTS
  • area: main
  • in suites: squeeze
  • size: 116,928 kB
  • ctags: 88,975
  • sloc: lisp: 1,232,060; ansic: 16,570; java: 13,514; xml: 6,477; sh: 4,611; makefile: 4,036; asm: 3,007; perl: 839; cpp: 500; ruby: 257; csh: 96; haskell: 93; awk: 49; python: 47
file content (78 lines) | stat: -rw-r--r-- 2,771 bytes parent folder | download | duplicates (7)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
;;; vm-vcard.el --- vcard parsing and formatting routines for VM

;; Copyright (C) 1997, 2000 Noah S. Friedman

;; Author: Noah Friedman <friedman@splode.com>
;; Maintainer: friedman@splode.com
;; Keywords: extensions
;; Created: 1997-10-03


;; This program is free software; you can redistribute it and/or modify
;; it under the terms of the GNU General Public License as published by
;; the Free Software Foundation; either version 2, or (at your option)
;; any later version.
;;
;; This program is distributed in the hope that it will be useful,
;; but WITHOUT ANY WARRANTY; without even the implied warranty of
;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
;; GNU General Public License for more details.
;;
;; You should have received a copy of the GNU General Public License
;; along with this program; if not, you can either send email to this
;; program's maintainer or write to: The Free Software Foundation,
;; Inc.; 59 Temple Place, Suite 330; Boston, MA 02111-1307, USA.

;;; Commentary:
;;; Code:

(require 'vcard)

(and (string-lessp vcard-api-version "2.0")
     (error "vm-vcard.el requires vcard API version 2.0 or later."))

;;;###autoload
(defvar vm-vcard-format-function nil
  "*Function to use for formatting vcards; if nil, use default.")

;;;###autoload
(defvar vm-vcard-filter nil
  "*Filter function to use for formatting vcards; if nil, use default.")

;;;###autoload
(defun vm-mime-display-internal-text/x-vcard (layout)
  (let ((inhibit-read-only t)
        (buffer-read-only nil))
    (insert (vm-vcard-format-layout layout)))
  t)

(defun vm-vcard-format-layout (layout)
  (let* ((beg (vm-mm-layout-body-start layout))
         (end (vm-mm-layout-body-end layout))
         (buf (if (markerp beg) (marker-buffer beg) (current-buffer)))
         (raw (vm-vcard-decode (save-excursion
                                 (set-buffer buf)
                                 (save-restriction
                                   (widen)
                                   (buffer-substring beg end)))
                               layout))
         (vcard-pretty-print-function (or vm-vcard-format-function
                                          vcard-pretty-print-function)))
    (vcard-pretty-print (vcard-parse-string raw vm-vcard-filter))))

(defun vm-vcard-decode (string layout)
  (let ((buf (generate-new-buffer " *vcard decoding*")))
    (save-excursion
      (set-buffer buf)
      (insert string)
      (vm-mime-transfer-decode-region layout (point-min) (point-max))
      (setq string (buffer-substring (point-min) (point-max))))
    (kill-buffer buf))
  string)

(defun vm-vcard-format-simple (vcard)
  (concat "\n\n--\n" (vcard-format-sample-string vcard) "\n\n"))

(provide 'vm-vcard)

;;; vm-vcard.el ends here.