Imported contacts can not be exported to vcard format.
I was able to import contacts.vcf file into contacts.org from google contacts. But I can't export to vcard from the contacts.org
I think org-vcard needs to test converting back and forth.
- org-vcard version: 4.0(?) fab5ea81d8a4bb1123cdc0287b9b58c062d5b372
- Emacs version: GNU Emacs 29.2 (build 1, x86_64-pc-linux-gnu, GTK+ Version 3.24.40, cairo version 1.18.0)
- org version: Org mode version 9.7 (9.7-??-e9c288dfa)
Below is a simple example snippet converted to vcf(for ios) from google contacts. Just below a snippet makes an error.
* #G9
:PROPERTIES:
:VERSION: 3.0
:N: #G9;;;;
:CELL: 1111-2222
:CATEGORIES: myContacts
:END:
M-x org-vcard-export choose source: buffer and destination: buffer (or file). Then, I got below error.
Debugger entered--Lisp error: (wrong-type-argument stringp [org-element-deferred org-element--headline-parse-title (nil) nil])
string-match("\\\\" [org-element-deferred org-element--headline-parse-title (nil) nil] 0)
replace-regexp-in-string("\\\\" "\\\\" [org-element-deferred org-element--headline-parse-title (nil) nil] nil t)
org-vcard--escape-value-string(("," ";" "\\") [org-element-deferred org-element--headline-parse-title (nil) nil])
org-vcard--export-line("FN" [org-element-deferred org-element--headline-parse-title (nil) nil])
(concat output (org-vcard--export-line "BEGIN" "VCARD") (org-vcard--export-line "VERSION" org-vcard-active-version) (org-vcard--export-line org-vcard-default-property-for-heading (plist-get (nth 1 (org-element-headline-parser (line-end-position))) :raw-value)) content (org-vcard--export-line "END" "VCARD"))
(setq output (concat output (org-vcard--export-line "BEGIN" "VCARD") (org-vcard--export-line "VERSION" org-vcard-active-version) (org-vcard--export-line org-vcard-default-property-for-heading (plist-get (nth 1 (org-element-headline-parser (line-end-position))) :raw-value)) content (org-vcard--export-line "END" "VCARD")))
(progn (if (and (string= "FN" org-vcard-default-property-for-heading) (or (string= "3.0" org-vcard-active-version) (string= "2.1" org-vcard-active-version)) (not (member "N" (mapcar 'car properties)))) (setq content (concat content (org-vcard--export-line "N" "")))) (let ((tail properties)) (while tail (let ((p (car tail))) (if (and (not (string= "VERSION" ...)) (assoc (car p) flat-style-properties)) (setq content (concat content (org-vcard--export-line ... ...)))) (setq tail (cdr tail))))) (setq output (concat output (org-vcard--export-line "BEGIN" "VCARD") (org-vcard--export-line "VERSION" org-vcard-active-version) (org-vcard--export-line org-vcard-default-property-for-heading (plist-get (nth 1 (org-element-headline-parser (line-end-position))) :raw-value)) content (org-vcard--export-line "END" "VCARD"))))
(if in-contact-entry (progn (if (and (string= "FN" org-vcard-default-property-for-heading) (or (string= "3.0" org-vcard-active-version) (string= "2.1" org-vcard-active-version)) (not (member "N" (mapcar 'car properties)))) (setq content (concat content (org-vcard--export-line "N" "")))) (let ((tail properties)) (while tail (let ((p (car tail))) (if (and (not ...) (assoc ... flat-style-properties)) (setq content (concat content ...))) (setq tail (cdr tail))))) (setq output (concat output (org-vcard--export-line "BEGIN" "VCARD") (org-vcard--export-line "VERSION" org-vcard-active-version) (org-vcard--export-line org-vcard-default-property-for-heading (plist-get (nth 1 (org-element-headline-parser ...)) :raw-value)) content (org-vcard--export-line "END" "VCARD")))))
(let ((properties (org-entry-properties)) (in-contact-entry nil) (flat-style-properties (or (car (cdr (assoc org-vcard-active-version (car ...)))) (error "No mapping available for specified vCard version"))) (content (encode-coding-string "" encoding))) (let ((tail properties)) (while tail (let ((p (car tail))) (if (assoc (car p) flat-style-properties) (setq in-contact-entry t)) (setq tail (cdr tail))))) (if in-contact-entry (progn (if (and (string= "FN" org-vcard-default-property-for-heading) (or (string= "3.0" org-vcard-active-version) (string= "2.1" org-vcard-active-version)) (not (member "N" (mapcar ... properties)))) (setq content (concat content (org-vcard--export-line "N" "")))) (let ((tail properties)) (while tail (let ((p ...)) (if (and ... ...) (setq content ...)) (setq tail (cdr tail))))) (setq output (concat output (org-vcard--export-line "BEGIN" "VCARD") (org-vcard--export-line "VERSION" org-vcard-active-version) (org-vcard--export-line org-vcard-default-property-for-heading (plist-get (nth 1 ...) :raw-value)) content (org-vcard--export-line "END" "VCARD"))))))
(lambda nil (let ((properties (org-entry-properties)) (in-contact-entry nil) (flat-style-properties (or (car (cdr (assoc org-vcard-active-version ...))) (error "No mapping available for specified vCard version"))) (content (encode-coding-string "" encoding))) (let ((tail properties)) (while tail (let ((p (car tail))) (if (assoc (car p) flat-style-properties) (setq in-contact-entry t)) (setq tail (cdr tail))))) (if in-contact-entry (progn (if (and (string= "FN" org-vcard-default-property-for-heading) (or (string= "3.0" org-vcard-active-version) (string= "2.1" org-vcard-active-version)) (not (member "N" ...))) (setq content (concat content (org-vcard--export-line "N" "")))) (let ((tail properties)) (while tail (let (...) (if ... ...) (setq tail ...)))) (setq output (concat output (org-vcard--export-line "BEGIN" "VCARD") (org-vcard--export-line "VERSION" org-vcard-active-version) (org-vcard--export-line org-vcard-default-property-for-heading (plist-get ... :raw-value)) content (org-vcard--export-line "END" "VCARD")))))))()
#f(compiled-function (el) #<bytecode 0x1605c7e9a3ac51a6>)((headline (:standard-properties [1 1 7 93 93 0 (:title) first-section element t nil nil nil 1 #<buffer contacts.org> nil nil (org-data (:standard-properties [1 1 1 93 93 0 nil org-data nil t nil 3 93 nil #<buffer contacts.org> nil nil nil] :path "/home/timlee/org/contacts.org" :CATEGORY "contacts"))] :pre-blank 0 :raw-value [org-element-deferred org-element--headline-raw-value (2 5) nil] :title [org-element-deferred org-element-property-2 (:raw-value) nil] :level 1 :priority nil :tags nil :todo-keyword nil :todo-type nil :footnote-section-p [org-element-deferred org-element--headline-footnote-section-p nil nil] :archivedp [org-element-deferred org-element--headline-archivedp nil nil] :commentedp nil :VERSION [org-element-deferred org-element--substring (29 32) nil] :N [org-element-deferred org-element--substring (37 44) nil] :CELL [org-element-deferred org-element--substring (52 61) nil] :CATEGORIES [org-element-deferred org-element--substring (75 85) nil])))
org-element-cache-map(#f(compiled-function (el) #<bytecode 0x1605c7e9a3ac51a6>) :next-re "^\\*+ " :fail-re "^\\*+ " :narrow t)
org-scan-tags((lambda nil (let ((properties (org-entry-properties)) (in-contact-entry nil) (flat-style-properties (or (car (cdr ...)) (error "No mapping available for specified vCard version"))) (content (encode-coding-string "" encoding))) (let ((tail properties)) (while tail (let ((p ...)) (if (assoc ... flat-style-properties) (setq in-contact-entry t)) (setq tail (cdr tail))))) (if in-contact-entry (progn (if (and (string= "FN" org-vcard-default-property-for-heading) (or ... ...) (not ...)) (setq content (concat content ...))) (let ((tail properties)) (while tail (let ... ... ...))) (setq output (concat output (org-vcard--export-line "BEGIN" "VCARD") (org-vcard--export-line "VERSION" org-vcard-active-version) (org-vcard--export-line org-vcard-default-property-for-heading ...) content (org-vcard--export-line "END" "VCARD"))))))) t nil nil)
org-map-entries((lambda nil (let ((properties (org-entry-properties)) (in-contact-entry nil) (flat-style-properties (or (car (cdr ...)) (error "No mapping available for specified vCard version"))) (content (encode-coding-string "" encoding))) (let ((tail properties)) (while tail (let ((p ...)) (if (assoc ... flat-style-properties) (setq in-contact-entry t)) (setq tail (cdr tail))))) (if in-contact-entry (progn (if (and (string= "FN" org-vcard-default-property-for-heading) (or ... ...) (not ...)) (setq content (concat content ...))) (let ((tail properties)) (while tail (let ... ... ...))) (setq output (concat output (org-vcard--export-line "BEGIN" "VCARD") (org-vcard--export-line "VERSION" org-vcard-active-version) (org-vcard--export-line org-vcard-default-property-for-heading ...) content (org-vcard--export-line "END" "VCARD"))))))) nil nil)
(let* ((scope (cond ((string= "buffer" source) nil) ((string= "region" source) 'region) ((string= "subtree" source) 'tree) (t (error "Invalid source type")))) (encoding (cond ((string= "4.0" org-vcard-active-version) 'utf-8) ((string= "3.0" org-vcard-active-version) 'utf-8) ((string= "2.1" org-vcard-active-version) 'us-ascii))) (output (encode-coding-string "" encoding))) (org-mode) (org-map-entries #'(lambda nil (let ((properties (org-entry-properties)) (in-contact-entry nil) (flat-style-properties (or ... ...)) (content (encode-coding-string "" encoding))) (let ((tail properties)) (while tail (let ... ... ...))) (if in-contact-entry (progn (if ... ...) (let ... ...) (setq output ...))))) nil scope) (org-vcard--transfer-write 'export output destination))
org-vcard-export-from-flat("buffer" "buffer")
org-vcard-transfer-helper("buffer" "buffer" "flat" "en" "4.0" export)
org-vcard-export(nil)
funcall-interactively(org-vcard-export nil)
call-interactively(org-vcard-export record nil)
command-execute(org-vcard-export record)
execute-extended-command(nil "org-vcard-export" nil)
funcall-interactively(execute-extended-command nil "org-vcard-export" nil)
call-interactively(execute-extended-command nil nil)
command-execute(execute-extended-command)
My apologies for the slow response - I can't seem to reproduce this on current master, would you like to try and see whether this regression has been fixed?
@pinoaffe It has not been fixed. Check your org-mode version. Org 9.7 changed their API. There is already similar issue. https://github.com/alphapapa/org-ql/issues/364
It needs to update org-vcard for latest org-mode.
@pinoaffe Simple fix from the org-ql repo.
(defalias 'org-vcard--resolve-element-properties
(if (version<= "9.7" org-version)
(lambda (node)
"Resolve NODE's properties using `org-element-properties-resolve'."
;; Silence warnings about `org-element-properties-resolve'
;; being unresolved on earlier Org versions.
(with-no-warnings
(org-element-properties-resolve node 'force-undefer)))
#'identity))
modified styles/flat/functions.el
@@ -96,7 +96,7 @@ DESTINATION must be either \"buffer\" or \"file\"."
(org-vcard--export-line
org-vcard-default-property-for-heading
(plist-get
- (nth 1 (org-element-headline-parser (line-end-position)))
+ (cadr (org-vcard--resolve-element-properties (org-element-headline-parser (line-end-position))))
:raw-value))
content
(org-vcard--export-line "END" "VCARD"))))))
Thanks a lot, once I installed org 9.7 I was able to reproduce both the error and the fix, will merge