Skip to content

Commit

Permalink
Enforce our own customization of vcard.el.
Browse files Browse the repository at this point in the history
  • Loading branch information
trebb committed Apr 3, 2010
1 parent 800166a commit edb840b
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 27 deletions.
32 changes: 17 additions & 15 deletions bbdb-vcard.el
Expand Up @@ -476,7 +476,7 @@ When VCARDS is nil, return nil. Otherwise, return t."
(let ((vcard (match-string 0)))
(if (string= "3.0" (bbdb-vcard-version-of vcard))
(funcall vcard-processor vcard)
(funcall vcard-processor ; probably a v2.1 vcard
(funcall vcard-processor ; probably a v2.1 vCard
(bbdb-vcard-unfold-lines
(bbdb-vcard-convert-to-3.0 vcard))))))))

Expand Down Expand Up @@ -788,19 +788,21 @@ Extend existing BBDB records where possible."
"Convert VCARD from v2.1 to v3.0.
Return a version 3.0 vCard as a string. Don't bother about the vCard
v3.0 mandatory elements N and FN."
(with-temp-buffer
(bbdb-vcard-insert-vcard-element "BEGIN" "VCARD")
(bbdb-vcard-insert-vcard-element "VERSION" "3.0")
(dolist (element (remove*
"VERSION" (vcard-parse-string vcard)
:key (lambda (x) (upcase (caar x))) :test 'string=))
(bbdb-vcard-insert-vcard-element
(concat (caar element)
(mapconcat 'bbdb-vcard-parameter-pair (cdar element) ""))
(bbdb-join (bbdb-vcard-escape-strings (cdr element)) ";")))
(bbdb-vcard-insert-vcard-element "END" "VCARD")
(bbdb-vcard-insert-vcard-element nil)
(buffer-string)))
;; Prevent customization of vcard.el's from being changed behind our back:
(let ((vcard-standard-filters '(vcard-filter-html)))
(with-temp-buffer
(bbdb-vcard-insert-vcard-element "BEGIN" "VCARD")
(bbdb-vcard-insert-vcard-element "VERSION" "3.0")
(dolist (element (remove*
"VERSION" (vcard-parse-string vcard)
:key (lambda (x) (upcase (caar x))) :test 'string=))
(bbdb-vcard-insert-vcard-element
(concat (caar element)
(mapconcat 'bbdb-vcard-parameter-pair (cdar element) ""))
(bbdb-join (bbdb-vcard-escape-strings (cdr element)) ";")))
(bbdb-vcard-insert-vcard-element "END" "VCARD")
(bbdb-vcard-insert-vcard-element nil)
(buffer-string))))

(defun bbdb-vcard-parameter-pair (input)
"Return \"parameter=value\" made from INPUT.
Expand Down Expand Up @@ -918,7 +920,7 @@ ESCAPED-STRINGS may be a string or a sequence of strings."
(defun bbdb-vcard-escape-strings (unescaped-strings )
"Escape `;', `,', `\\', and newlines in UNESCAPED-STRINGS.
UNESCAPED-STRINGS may be a string or a sequence of strings."
(flet ((escape (x) (replace-regexp-in-string ; from 2.1 conversion
(flet ((escape (x) (replace-regexp-in-string ; from 2.1 conversion:
"\r" "" (replace-regexp-in-string
"\n" "\\\\n" (replace-regexp-in-string
"\\(\\)[,;\\]" "\\\\" (or x "")
Expand Down
24 changes: 12 additions & 12 deletions test-bbdb-vcard.el
Expand Up @@ -1479,8 +1479,8 @@ END:VCARD
["Fred" "Friday"
nil
nil
(["Office" "+1 213 555 1234"]
["Office" "+1 213 555 5678"])
(["Office" "+1-213-555-1234"]
["Office" "+1-213-555-5678"])
nil
nil
((creation-date . "2010-03-04") (timestamp . "2010-03-04"))]
Expand All @@ -1502,8 +1502,8 @@ end:VCARD
["Tom" "Thursday"
nil
nil
(["Office" "+1 213 555 1234"]
["Office" "+1 213 555 5678"])
(["Office" "+1-213-555-1234"]
["Office" "+1-213-555-5678"])
nil
nil
((creation-date . "2010-03-04") (timestamp . "2010-03-04"))]
Expand All @@ -1526,9 +1526,9 @@ END:VCARD
["Mr. John M." "Smith Esq."
nil
nil
(["Office" "+1 (919) 555 1234"]
["Mobile" "+1 (919) 554 6758"]
["Office" "+1 (919) 555 9876"])
(["Office" "+1 (919) 555-1234"]
["Mobile" "+1 (919) 554-6758"]
["Office" "+1 (919) 555-9876"])
(["Office" ("Suite 101" "1 Central St." "AnyTown") "NC" "27654" "" ""])
nil
((creation-date . "2010-03-04") (timestamp . "2010-03-04"))]
Expand Down Expand Up @@ -1567,10 +1567,10 @@ END:VCARD
nil
"Doe Company, The
"
(["Office" "+1 987 123 4567"]
["Home" "+1 987 765 4321"]
["Mobile" "+1 987 135 8642"]
["Office" "+1 987 246 1357"])
(["Office" "(987) 123-4567"]
["Home" "(987) 765-4321"]
["Mobile" "(987) 135-8642"]
["Office" "(987) 246-1357"])
(["Office" ("1234 North Street") "Anytown" "TX 751234" "" "United States of America"])
("jdoe@nowhere.com")
((label\;type=work . "1234 North Street
Expand Down Expand Up @@ -1632,7 +1632,7 @@ END:VCARD
["Innerfirst2A" "Innerlast2A"
nil
nil
(["Office" "+1 919 555 1234"])
(["Office" "+1-919-555-1234"])
nil
("InnerA@hostA.com")
((creation-date . "2010-03-04") (timestamp . "2010-03-04"))]
Expand Down

0 comments on commit edb840b

Please sign in to comment.