Permalink
Browse files

Import of vCard types BDAY and REV changed.

Both may now include time and time zone.
  • Loading branch information...
1 parent 5d960f9 commit 06b2e1e60b5b2aa7d5b8240348b9ee35c0c48281 @trebb trebb committed Apr 21, 2010
Showing with 56 additions and 23 deletions.
  1. +24 −14 bbdb-vcard.el
  2. +32 −9 test-bbdb-vcard.el
View
@@ -113,7 +113,9 @@
;; `bbdb-vcard-import-translation-table'.
;;
;; If there is a REV element, it is stored in BBDB's creation-date in
-;; newly created BBDB records, or discarded for existing ones.
+;; newly created BBDB records, or discarded for existing ones. Time
+;; and time zone information from REV are stored there as well if
+;; there are any, but are ignored by BBDB (v2.36).
;;
;; VCard type prefixes (A.ADR:..., B.ADR:... etc.) are stripped off
;; and discarded from the following types: N, FN, NICKNAME, ORG (first
@@ -561,7 +563,8 @@ Extend existing BBDB records where possible."
(bbdb-vcard-split-structured-text
(car (bbdb-vcard-values-of-type "X-BBDB-ANNIVERSARY" "value"))
"\\\\n" t))
- (vcard-rev (car (bbdb-vcard-values-of-type "REV" "value")))
+ (vcard-rev (bbdb-vcard-unvcardize-date-time
+ (car (bbdb-vcard-values-of-type "REV" "value"))))
(vcard-categories (bbdb-vcard-values-of-type "CATEGORIES" "value"))
;; The BBDB record to change:
(record-freshness-info "BBDB record changed:") ; default user info
@@ -599,10 +602,7 @@ Extend existing BBDB records where possible."
(make-vector bbdb-cache-length nil))
(if vcard-rev ; For fresh records,
(bbdb-record-putprop ; set creation-date from vcard-rev
- fresh-record 'creation-date
- (replace-regexp-in-string
- "\\([0-9]\\{4\\}-[01][0-9]-[0-3][0-9]\\).*" "\\1"
- vcard-rev))
+ fresh-record 'creation-date vcard-rev)
(bbdb-invoke-hook 'bbdb-create-hook fresh-record))
(setq record-freshness-info "BBDB record added:") ; user info
fresh-record)))
@@ -648,7 +648,9 @@ Extend existing BBDB records where possible."
";\n")))
(when (or vcard-bday vcard-x-bbdb-anniversaries)
;; Put vCard BDAY and vCard X-BBDB-ANNIVERSARY's under key
- ;; 'anniversary (append if necessary) where org-mode can find it.
+ ;; 'anniversary (append if necessary) where org-mode can find
+ ;; it. Org-mode doesn't currently (v6.35) bother with time
+ ;; and time zone, though.
(when vcard-bday (push vcard-bday vcard-x-bbdb-anniversaries))
(unless (assq 'anniversary bbdb-raw-notes)
(push (cons 'anniversary "") bbdb-raw-notes))
@@ -709,7 +711,7 @@ Extend existing BBDB records where possible."
(raw-anniversaries (bbdb-vcard-split-structured-text
(bbdb-get-field record 'anniversary) "\n" t))
(birthday-regexp
- "\\([0-9]\\{4\\}-[01][0-9]-[0-3][0-9]\\)\\([[:blank:]]+birthday\\)?\\'")
+ "\\([0-9]\\{4\\}-[01][0-9]-[0-3][0-9][t:0-9]*[-+z:0-9]*\\)\\([[:blank:]]+birthday\\)?\\'")
(birthday
(car (bbdb-vcard-split-structured-text
(find-if (lambda (x) (string-match birthday-regexp x))
@@ -1003,20 +1005,26 @@ COUNTRY)."
(defun bbdb-vcard-unvcardize-date-time (date-time)
"If necessary, make DATE-TIME usable for storage in BBDB.
-Convert yyyymmdd or yyyymmddThhmmss into yyyy-mm-dd or
-yyyy-mm-ddThh:mm:ss respectively. Discard fractions of a second and
-time zone information. Return anything else unchanged."
+Convert yyyymmdd, yyyymmddThhmmss, or yyymmddThhmmssZhhmm into
+yyyy-mm-dd, yyyy-mm-ddThh:mm:ss, or yyy-mm-ddThh:mm:ssZhh:mm
+respectively. Discard fractions of a second. Return anything else
+unchanged."
(if (and (stringp date-time)
(string-match
- "\\([0-9]\\{4\\}\\)-?\\([0-2][0-9]\\)-?\\([0-3][0-9]\\)\\(?:t\\([0-5][0-9]\\):?\\([0-5][0-9]\\):?\\([0-5][0-9]\\)\\)?"
+ "\\([0-9]\\{4\\}\\)-?\\([0-2][0-9]\\)-?\\([0-3][0-9]\\)\\(?:t\\([0-5][0-9]\\):?\\([0-5][0-9]\\):?\\([0-5][0-9]\\)\\(?:[,.0-9]*\\(\\([+-][0-5][0-9]\\):?\\([0-5][0-9]\\)?\\|z\\)\\)?\\)?"
date-time))
(concat
(match-string 1 date-time) "-"
(match-string 2 date-time) "-" (match-string 3 date-time)
- (when (match-string 6 date-time) ; seconds part of time
+ (when (match-string 6 date-time) ; seconds part of time
(concat
"T" (match-string 4 date-time) ":"
- (match-string 5 date-time) ":" (match-string 6 date-time))))
+ (match-string 5 date-time) ":" (match-string 6 date-time)
+ (when (match-string 7 date-time) ; time zone
+ (if (match-string 9 date-time) ; time zone minute
+ (concat (match-string 8 date-time) ; time zone hour
+ ":" (match-string 9 date-time)) ; time zone minute
+ "Z")))))
date-time))
(defun bbdb-vcard-vcardize-address-element (address-element)
@@ -1124,3 +1132,5 @@ Make it unique against the list USED-UP-BASENAMES."
(provide 'bbdb-vcard)
;;; bbdb-vcard.el ends here
+
+; LocalWords: vcard firstname
View
@@ -155,7 +155,7 @@ Subunit1"
(anniversary . "1999-12-05 birthday")
(notes . "This vcard uses every type defined in rfc2426.")
(www . "http://first1.host1.org")
- (creation-date . "1995-10-31") (timestamp . "2010-03-04"))]
+ (creation-date . "1995-10-31T22:27:10Z") (timestamp . "2010-03-04"))]
"First1 Last1"
nil nil t)
@@ -224,7 +224,7 @@ Subunit1"
(anniversary . "1999-12-05 birthday")
(notes . "This isn't a decent vCard. It shouldn't render our bbdb unusable. We don't expect it to re-import unchanged, though.")
(www . "http://first1.host1.org; My home")
- (creation-date . "1995-10-31") (timestamp . "2010-03-04"))]
+ (creation-date . "1995-10-31T22:27:10Z") (timestamp . "2010-03-04"))]
"First2 Last2"
nil nil t)
@@ -323,7 +323,7 @@ U.S.A.")
(anniversary . "1996-04-15 birthday")
(notes . "This fax number is operational 0800 to 1715 EST, Mon-Fri.")
(www . "http://www.swbyps.restaurant.french/~chezchic.html")
- (creation-date . "1995-10-31") (timestamp . "2010-03-04"))]
+ (creation-date . "1995-10-31T22:27:10Z") (timestamp . "2010-03-04"))]
"John"
nil nil t)
@@ -423,7 +423,7 @@ U.S.A.")
(mail-alias . "TRAVEL AGENT")
(anniversary . "1996-04-15 birthday")
(notes . "This fax number is operational 0800 to 1715 EST, Mon-Fri.")
- (creation-date . "1995-10-31") (timestamp . "2010-03-04"))]
+ (creation-date . "1995-10-31T22:27:10Z") (timestamp . "2010-03-04"))]
"John"
nil nil t)
@@ -1149,7 +1149,7 @@ END:VCARD
nil
nil
nil
- ((creation-date . "1997-03-27") (timestamp . "2010-03-04")) ]
+ ((creation-date . "1997-03-27T22:27:10Z") (timestamp . "2010-03-04")) ]
"FirstJ FamilyJ"
nil nil t)
@@ -1171,11 +1171,33 @@ END:VCARD
nil
nil
nil
- ((creation-date . "1997-03-27") (timestamp . "2010-03-04")) ]
+ ((creation-date . "1997-03-27T22:27:10Z") (timestamp . "2010-03-04")) ]
"FirstJ FamilyJ"
nil nil t)
+(bbdb-vcard-import-test
+ "
+*** The same, but dashless REV
+------------------------------------------------------------
+BEGIN:VCARD
+VERSION:3.0
+N:FamilyR;FirstR
+ORG:OrgR
+REV:19771203T222710Z
+END:VCARD
+"
+ ["FirstR" "FamilyR"
+ nil
+ "OrgR"
+ nil
+ nil
+ nil
+ ((creation-date . "1977-12-03T22:27:10Z") (timestamp . "2010-03-04")) ]
+ "FirstR FamilyR"
+ nil nil t)
+
+
(bbdb-vcard-import-test
"
@@ -1287,7 +1309,7 @@ END:VCARD
nil
nil
nil
- ((anniversary . "1927-03-27T23:44:54 birthday")
+ ((anniversary . "1927-03-27T23:44:54Z birthday")
(creation-date . "2010-03-04") (timestamp . "2010-03-04"))]
"FirstP FamilyP")
@@ -1646,8 +1668,9 @@ United States of America")
(notes . "This is a note associated with this contact
")
(www . "http://www.doeweb.com")
- (creation-date . "2010-03-04") (timestamp . "2010-03-04"))]
- "John Doe")
+ (creation-date . "1998-01-14T17:05:59Z") (timestamp . "2010-03-04"))]
+ "John Doe"
+ nil nil t)

0 comments on commit 06b2e1e

Please sign in to comment.