emacs-elpa-diffs
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[elpa] externals/ebdb 4882f66 238/350: Include addresses in vcard output


From: Eric Abrahamsen
Subject: [elpa] externals/ebdb 4882f66 238/350: Include addresses in vcard output, plus escaping
Date: Mon, 14 Aug 2017 11:46:45 -0400 (EDT)

branch: externals/ebdb
commit 4882f66a00f359975c74049918891949c5e42a9c
Author: Eric Abrahamsen <address@hidden>
Commit: Eric Abrahamsen <address@hidden>

    Include addresses in vcard output, plus escaping
    
    * ebdb-vcard.el (ebdb-vcard-escape): Escape commas and semicolons, as
      per vcard RFC. Use where appropriate
      (ebdb-fmt-field): Add formatting method for addresses.
---
 ebdb-vcard.el | 55 ++++++++++++++++++++++++++++++++++++-------------------
 1 file changed, 36 insertions(+), 19 deletions(-)

diff --git a/ebdb-vcard.el b/ebdb-vcard.el
index b08af56..3527358 100644
--- a/ebdb-vcard.el
+++ b/ebdb-vcard.el
@@ -60,6 +60,7 @@
                            ebdb-field-timestamp
                            ebdb-field-mail
                            ebdb-field-name
+                           ebdb-field-address
                            ebdb-field-url
                            ebdb-field-role
                            ebdb-field-anniversary
@@ -81,6 +82,7 @@
                            ebdb-field-timestamp
                            ebdb-field-mail
                            ebdb-field-name
+                           ebdb-field-address
                            ebdb-field-url
                            ebdb-field-role
                            ebdb-field-anniversary
@@ -118,8 +120,19 @@ not always respect these headings."
   :type '(repeat
          (cons string symbol)))
 
+(defsubst ebdb-vcard-escape (str)
+  "Escape commas, semi-colons and newlines in STR."
+  (replace-regexp-in-string
+   "\\(\n\\)" "\\\\n"
+   (replace-regexp-in-string "\\([,;]\\)" "\\\\\\1" str)))
+
+(cl-defmethod ebdb-fmt-process-fields ((_f ebdb-formatter-vcard)
+                                      (_record ebdb-record)
+                                      field-list)
+  field-list)
+
 (cl-defmethod ebdb-fmt-process-fields ((fmt ebdb-formatter-vcard)
-                                      (record ebdb-record)
+                                      (record ebdb-record-person)
                                       field-list)
   "Process fields in FIELD-LIST.
 
@@ -219,7 +232,7 @@ method is just responsible for formatting the record name."
                              (field ebdb-field)
                              _style
                              _record)
-  (ebdb-string field))
+  (ebdb-vcard-escape (ebdb-string field)))
 
 (cl-defmethod ebdb-fmt-field-label ((_f ebdb-formatter-vcard)
                                    (field ebdb-field)
@@ -273,31 +286,34 @@ method is just responsible for formatting the record 
name."
        (t "")))))
 
 (cl-defmethod ebdb-fmt-field-label ((_f ebdb-formatter-vcard)
-                                   (phone ebdb-field-phone)
-                                   _style
-                                   _record)
-  (concat (cl-call-next-method)
-         ";TYPE=" (slot-value phone 'object-name)))
-
-(cl-defmethod ebdb-fmt-field-label ((_f ebdb-formatter-vcard)
-                                   (rel ebdb-field-relation)
+                                   (field ebdb-field-labeled)
                                    _style
                                    _record)
   (concat (cl-call-next-method)
-         ";TYPE=" (slot-value rel 'object-name)))
+         ";TYPE=" (ebdb-vcard-escape
+                   (slot-value field 'object-name))))
 
-(cl-defmethod ebdb-fmt-field-label ((_f ebdb-formatter-vcard)
-                                   (url ebdb-field-url)
-                                   _style
-                                   _record)
-  (concat (cl-call-next-method)
-         ";TYPE=" (slot-value url 'object-name)))
+(cl-defmethod ebdb-fmt-field ((_f ebdb-formatter-vcard)
+                             (addr ebdb-field-address)
+                             _style
+                             _record)
+  (with-slots (streets locality region postcode country) addr
+    (concat ";;"
+           (mapconcat
+            #'ebdb-vcard-escape
+            streets ",")
+           (format
+            ";%s;%s;%s;%s"
+            (or locality "")
+            (or region "")
+            (or postcode "")
+            (or country "")))))
 
 (cl-defmethod ebdb-fmt-field ((_f ebdb-formatter-vcard)
                              (rel ebdb-field-relation)
                              _style
                              _record)
-  (concat ":urn:uuid:" (slot-value rel 'rel-uuid)))
+  (concat "urn:uuid:" (slot-value rel 'rel-uuid)))
 
 (cl-defmethod ebdb-fmt-field ((_f ebdb-formatter-vcard)
                              (tags ebdb-org-field-tags)
@@ -314,7 +330,8 @@ method is just responsible for formatting the record name."
          (if (string= label "birthday")
              "BDAY"
            (concat "ANNIVERSARY;TYPE=" label))))
-    (concat label-string ";CALSCALE=" (slot-value ann 'calendar))))
+    (concat label-string (format ";CALSCALE=%s"
+                                (slot-value ann 'calendar)))))
 
 (provide 'ebdb-vcard)
 ;;; ebdb-vcard.el ends here



reply via email to

[Prev in Thread] Current Thread [Next in Thread]