emacs-orgmode@gnu.org archives
 help / color / mirror / code / Atom feed
From: Feng Shu <tumashu@gmail.com>
To: emacs-orgmode@gnu.org
Subject: Re: Converting org-mode/org-contacts to VCard (importing to Android)
Date: Sat, 23 Nov 2013 16:36:22 +0800	[thread overview]
Message-ID: <87li0fms55.fsf@news.tumashu-localhost.org> (raw)
In-Reply-To: <2013-11-22T17-57-08@devnull.Karl-Voit.at> (Karl Voit's message of "Fri, 22 Nov 2013 18:09:42 +0100")

Karl Voit <devnull@Karl-Voit.at> writes:

> * Rüdiger Sonderfeld <ruediger@c-plusplus.de> wrote:
>> On Friday 22 November 2013 17:37:01 Karl Voit wrote:
>>> The reason I wrote it in Python is that I don't know ELISP well
>>> enough. The reason I wrote the script instead of using existing
>>> export methods: I only want to export a small sub-set (names, phone
>>> numbers, email addresses, contact image) due to privacy reasons.
>> That should be possible with the existing VCard export.  See `org-contacts-
>> ignore-property' to ignore specific properties.  And `org-contacts-export-as-
>> vcard' takes a NAME parameter to limit the names.
> Fair enough :-)
> However, I did additional things like checks, filtering, and so
> forth that were important to my data-set. E.g., my contact template
> does contain "0043/" as a pre-filled content for phone numbers. I
> wanted to ignore those fields that got only this template and not a
> complete phone number. I also wanted to get warnings in case some
> data does not fulfill certain other requirements.

use (replace-regexp-in-string "^[0-9]\\{4,4\\}/" "" "0043/333/333")

(defun org-contacts-vcard-format (contact)
  "Formats CONTACT in VCard 3.0 format."
  (let* ((properties (caddr contact))
	 (name (org-contacts-vcard-escape (car contact)))
	 (n (org-contacts-vcard-encode-name name))
	 (email (cdr (assoc-string org-contacts-email-property properties)))
	 (tel (cdr (assoc-string org-contacts-tel-property properties)))
	 (ignore-list (cdr (assoc-string org-contacts-ignore-property properties)))
	 (ignore-list (when ignore-list
			(org-contacts-split-property ignore-list)))
	 (note (cdr (assoc-string org-contacts-note-property properties)))
	 (bday (org-contacts-vcard-escape (cdr (assoc-string org-contacts-birthday-property properties))))
	 (addr (cdr (assoc-string org-contacts-address-property properties)))
	 (nick (org-contacts-vcard-escape (cdr (assoc-string org-contacts-nickname-property properties))))
	 (head (format "BEGIN:VCARD\nVERSION:3.0\nN:%s\nFN:%s\n" n name))
	 emails-list result phones-list)
    (concat head
	    (when email (progn
			  (setq emails-list (org-contacts-remove-ignored-property-values ignore-list (org-contacts-split-property email)))
			  (setq result "")
			  (while emails-list
			    (setq result (concat result  "EMAIL:" (org-contacts-strip-link (car emails-list)) "\n"))
			    (setq emails-list (cdr emails-list)))
	    (when addr
	      (format "ADR:;;%s\n" (replace-regexp-in-string "\\, ?" ";" addr)))
	    (when tel (progn
			(setq phones-list (org-contacts-remove-ignored-property-values ignore-list (org-contacts-split-property tel)))
			(setq result "")
			(while phones-list
			  (setq result (concat result  "TEL:"  (replace-regexp-in-string "^[0-9]\\{4,4\\}/" ""  (org-link-unescape (org-contacts-strip-link (car phones-list)))) "\n"))
			  (setq phones-list (cdr phones-list)))
	    (when bday
	      (let ((cal-bday (calendar-gregorian-from-absolute (org-time-string-to-absolute bday))))
		(format "BDAY:%04d-%02d-%02d\n"
			(calendar-extract-year cal-bday)
			(calendar-extract-month cal-bday)
			(calendar-extract-day cal-bday))))
	    (when nick (format "NICKNAME:%s\n" nick))
	    (when note (format "NOTE:%s\n" note))


> I have to admit that I don't know the feature-set of the Org-mode
> export. I would be very surprised, if the Org-mode export method is
> able to follow my custom "photo:" link I am using, grab the image
> file, test if it has a image format that works with VCard
> 2.1 on Android, and encodes it in base64 accordingly.
> You see: I want to have ways to tweak the export process. And as
> long as I don't know ELISP that well, I stick to the tools I know.
> A side remark of mine: a couple of months ago I tried to find out
> how to store address information, phone numbers, and so on in
> org-contact properties. AFAIR I could not find anything except the
> :EMAIL: property. Is there a standard out there that answers
> questions like "separate street from house number?", "how to cope
> with multiple addresses for one contact?", and so forth? I created
> something on my own as you can see on [1].
> I am happy if you can get benefit from my little project and I am
> also happy when Org-mode offers a great export functionality for the
> rest of us :-)
>   1. https://raw.github.com/novoid/org-contacts2vcard/master/testdata/testcontacts.org-- 
> mail|git|SVN|photos|postings|SMS|phonecalls|RSS|CSV|XML to Org-mode:
>        > get Memacs from https://github.com/novoid/Memacs <
> https://github.com/novoid/extract_pdf_annotations_to_orgmode + more on github


  parent reply	other threads:[~2013-11-23  8:40 UTC|newest]

Thread overview: 19+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2013-11-22 16:37 Converting org-mode/org-contacts to VCard (importing to Android) Karl Voit
2013-11-22 16:54 ` Rüdiger Sonderfeld
2013-11-22 17:09   ` Karl Voit
2013-11-23  0:00     ` Rüdiger Sonderfeld
2013-11-24 13:06       ` Implementing Org-mode tools in languages other than ELISP (was: Converting org-mode/org-contacts to VCard (importing to Android)) Karl Voit
2014-01-04 14:58         ` Implementing Org-mode tools in languages other than ELISP Bastien
2014-01-04 16:43           ` François Pinard
2014-01-05 16:43             ` Daniel Clemente
2014-01-06 10:44               ` Parsing Org-mode in Python (was: Implementing Org-mode tools in languages other than ELISP) Karl Voit
2014-01-07  2:33                 ` Parsing Org-mode in Python François Pinard
2014-01-07 16:09                 ` Brett Viren
2014-01-08 12:33                   ` François Pinard
2014-01-08 15:42                     ` Brett Viren
2014-01-08 16:11                       ` François Pinard
2014-01-09  4:13                       ` Daniel Clemente
2014-01-09 14:13                         ` Brett Viren
2014-01-07  1:47               ` Implementing Org-mode tools in languages other than ELISP François Pinard
2013-11-23  8:36     ` Feng Shu [this message]
2013-11-23  8:29 ` Converting org-mode/org-contacts to VCard (importing to Android) Feng Shu

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:

  List information: https://www.orgmode.org/

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=87li0fms55.fsf@news.tumashu-localhost.org \
    --to=tumashu@gmail.com \
    --cc=emacs-orgmode@gnu.org \


* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
Code repositories for project(s) associated with this public inbox


This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).