Org-mode mailing list
 help / color / mirror / Atom feed
* difficulty extracting email address from property field containing gmail link
@ 2020-11-30  2:18 Ian Garmaise
  2020-11-30  3:39 ` Kyle Meyer
  0 siblings, 1 reply; 4+ messages in thread
From: Ian Garmaise @ 2020-11-30  2:18 UTC (permalink / raw)
  To: emacs-orgmode

[-- Attachment #1: Type: text/plain, Size: 1491 bytes --]

I have created a kind of mini CRM using properties.
Now I need to extract data from the entries to create a CSV file for use
with an external email tool.

I have used org-collector.el to extract tagged entries to a table, on which
I then use orgtbl-to-csv to create the CSV file.

This is working well, except for the property used for the email address.
Unfortunately, I stored this as a gmail link.  This makes it difficult to
extract the actual email address using org-collector as follows:

#+BEGIN: propview :cols ((car (s-split " " ITEM))  EMAIL_ADDRESS)  :id
"candidates" :match "testthis" :wrap example

the result produced looks like this:

| (car (s-split " " ITEM)) | EMAIL_ADDRESS
                                  |
|--------------------------+---------------------------------------------------------------------------------|
| "Ciara"                  | [[
https://mail.google.com/mail/?view=cm&fs=1&to=ciaraxyz@gmail\.com]]
    |
| "Duncan"                 | [[
https://mail.google.com/mail/?view=cm&fs=1&to=duncanxyz@indeedemail\.com]] |

I have looked at several methods that I found on the web to extract the
email address from the link in the property, but haven't yet found a
solution that I could get to work.  Still building up my elisp skillset,
would appreciate suggestions.



-- 
=====
Ian Garmaise
Consultant
Phorix Solutions Group
ian.g@phorixsol.com
Toronto cell: 416.432.2251
NYC: 917.512.9535

https://www.linkedin.com/in/igarmaise/

http://www.PhorixSol.com

[-- Attachment #2: Type: text/html, Size: 3609 bytes --]

^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: difficulty extracting email address from property field containing gmail link
  2020-11-30  2:18 difficulty extracting email address from property field containing gmail link Ian Garmaise
@ 2020-11-30  3:39 ` Kyle Meyer
  2020-11-30 12:41   ` Ian Garmaise
  0 siblings, 1 reply; 4+ messages in thread
From: Kyle Meyer @ 2020-11-30  3:39 UTC (permalink / raw)
  To: Ian Garmaise; +Cc: emacs-orgmode

Ian Garmaise writes:

> This is working well, except for the property used for the email address.
> Unfortunately, I stored this as a gmail link.  This makes it difficult to
> extract the actual email address using org-collector as follows:
>
> #+BEGIN: propview :cols ((car (s-split " " ITEM))  EMAIL_ADDRESS)  :id
> "candidates" :match "testthis" :wrap example
>
> the result produced looks like this:
> 
> | (car (s-split " " ITEM)) | EMAIL_ADDRESS                                                                   |
> |--------------------------+---------------------------------------------------------------------------------|
> | "Ciara"                  | [[https://mail.google.com/mail/?view=cm&fs=1&to=ciaraxyz@gmail\.com]]             |
> | "Duncan"                 | [[https://mail.google.com/mail/?view=cm&fs=1&to=duncanxyz@indeedemail\.com]] |
>
> I have looked at several methods that I found on the web to extract the
> email address from the link in the property, but haven't yet found a
> solution that I could get to work.  Still building up my elisp skillset,
> would appreciate suggestions.

I've never used org-collector, but quickly trying to wire up a function
to extract the email part of the text you show, I suspect some of the
trouble you're having is that the value comes in as a vector because
org-propview-collect processes it with org-babel-read.  So perhaps
something like this would get you on the right track:

  (require 'subr-x)
  
  (defun my/extract-email-from-link (value)
    (setq value (format "%S" value))
    (when-let ((link (and (string-match org-link-bracket-re value)
                          (org-link-unescape
                           (match-string-no-properties 1 value)))))
      (thread-last
          link
        (replace-regexp-in-string
         (rx string-start (one-or-more not-newline) "to="
             (group (one-or-more not-newline)) string-end)
         "\\1")
        (replace-regexp-in-string (rx "\\.") "."))))


--8<---------------cut here---------------start------------->8---
#+BEGIN: propview :cols ((car (s-split " " ITEM)) (my/extract-email-from-link EMAIL_ADDRESS)) :id global
| (car (s-split " " ITEM)) | (my/extract-email-from-link EMAIL_ADDRESS) |
|--------------------------+--------------------------------------------|
| "Ciara"                  | "ciaraxyz@gmail.com"                       |
| "Duncan"                 | "duncanxyz@indeedemail.com"                |
|--------------------------+--------------------------------------------|
|                          |                                            |
#+END:

* Ciara
:PROPERTIES:
:EMAIL_ADDRESS: [[https://mail.google.com/mail/?view=cm&fs=1&to=ciaraxyz@gmail\.com]]
:END:

* Duncan
:PROPERTIES:
:EMAIL_ADDRESS: [[https://mail.google.com/mail/?view=cm&fs=1&to=duncanxyz@indeedemail\.com]]
:END:
--8<---------------cut here---------------end--------------->8---


^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: difficulty extracting email address from property field containing gmail link
  2020-11-30  3:39 ` Kyle Meyer
@ 2020-11-30 12:41   ` Ian Garmaise
  2020-11-30 13:42     ` John Kitchin
  0 siblings, 1 reply; 4+ messages in thread
From: Ian Garmaise @ 2020-11-30 12:41 UTC (permalink / raw)
  To: emacs-orgmode

[-- Attachment #1: Type: text/plain, Size: 3857 bytes --]

Thanks Kyle, got it to work this way:

#+BEGIN: propview :cols ((car (s-split " " ITEM))  (s-chop-prefix "gmail:"
(my/extract-email-from-link EMAIL_ADDRESS)))  :id "candidates" :match
"testthis" :wrap example
| (car (s-split " " ITEM)) | (s-chop-prefix "gmail:"
(my/extract-email-from-link EMAIL_ADDRESS)) |
|--------------------------+---------------------------------------------------------------------|
| "Ciara"                  | "ciaraxxxx@gmail.com"
                     |
| "Duncan"                 | "duncanxxxx@indeedemail.com"
               |

Thanks a million!

Ian


On Sun, Nov 29, 2020 at 10:39 PM Kyle Meyer <kyle@kyleam.com> wrote:

> Ian Garmaise writes:
>
> > This is working well, except for the property used for the email address.
> > Unfortunately, I stored this as a gmail link.  This makes it difficult to
> > extract the actual email address using org-collector as follows:
> >
> > #+BEGIN: propview :cols ((car (s-split " " ITEM))  EMAIL_ADDRESS)  :id
> > "candidates" :match "testthis" :wrap example
> >
> > the result produced looks like this:
> >
> > | (car (s-split " " ITEM)) | EMAIL_ADDRESS
>                                      |
> >
> |--------------------------+---------------------------------------------------------------------------------|
> > | "Ciara"                  | [[
> https://mail.google.com/mail/?view=cm&fs=1&to=ciaraxyz@gmail\.com]]
>        |
> > | "Duncan"                 | [[
> https://mail.google.com/mail/?view=cm&fs=1&to=duncanxyz@indeedemail\.com]]
> |
> >
> > I have looked at several methods that I found on the web to extract the
> > email address from the link in the property, but haven't yet found a
> > solution that I could get to work.  Still building up my elisp skillset,
> > would appreciate suggestions.
>
> I've never used org-collector, but quickly trying to wire up a function
> to extract the email part of the text you show, I suspect some of the
> trouble you're having is that the value comes in as a vector because
> org-propview-collect processes it with org-babel-read.  So perhaps
> something like this would get you on the right track:
>
>   (require 'subr-x)
>
>   (defun my/extract-email-from-link (value)
>     (setq value (format "%S" value))
>     (when-let ((link (and (string-match org-link-bracket-re value)
>                           (org-link-unescape
>                            (match-string-no-properties 1 value)))))
>       (thread-last
>           link
>         (replace-regexp-in-string
>          (rx string-start (one-or-more not-newline) "to="
>              (group (one-or-more not-newline)) string-end)
>          "\\1")
>         (replace-regexp-in-string (rx "\\.") "."))))
>
>
> --8<---------------cut here---------------start------------->8---
> #+BEGIN: propview :cols ((car (s-split " " ITEM))
> (my/extract-email-from-link EMAIL_ADDRESS)) :id global
> | (car (s-split " " ITEM)) | (my/extract-email-from-link EMAIL_ADDRESS) |
> |--------------------------+--------------------------------------------|
> | "Ciara"                  | "ciaraxyz@gmail.com"                       |
> | "Duncan"                 | "duncanxyz@indeedemail.com"                |
> |--------------------------+--------------------------------------------|
> |                          |                                            |
> #+END:
>
> * Ciara
> :PROPERTIES:
> :EMAIL_ADDRESS: [[
> https://mail.google.com/mail/?view=cm&fs=1&to=ciaraxyz@gmail\.com]]
> :END:
>
> * Duncan
> :PROPERTIES:
> :EMAIL_ADDRESS: [[
> https://mail.google.com/mail/?view=cm&fs=1&to=duncanxyz@indeedemail\.com]]
> :END:
> --8<---------------cut here---------------end--------------->8---
>


-- 
=====
Ian Garmaise
Consultant
Phorix Solutions Group
ian.g@phorixsol.com
Toronto cell: 416.432.2251
NYC: 917.512.9535

https://www.linkedin.com/in/igarmaise/

http://www.PhorixSol.com

[-- Attachment #2: Type: text/html, Size: 6750 bytes --]

^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: difficulty extracting email address from property field containing gmail link
  2020-11-30 12:41   ` Ian Garmaise
@ 2020-11-30 13:42     ` John Kitchin
  0 siblings, 0 replies; 4+ messages in thread
From: John Kitchin @ 2020-11-30 13:42 UTC (permalink / raw)
  To: Ian Garmaise; +Cc: emacs-orgmode

[-- Attachment #1: Type: text/plain, Size: 4616 bytes --]

I think code like this would also work:

#+BEGIN_SRC emacs-lisp
(let* ((url "
https://mail.google.com/mail?view=cm&fs=1&to=duncanxyz@indeedemail.com")
       (struct (url-generic-parse-url url))
       (filename (url-filename struct)))

  (cadr (assoc "to" (url-parse-query-string filename))))
#+END_SRC


John

-----------------------------------
Professor John Kitchin
Doherty Hall A207F
Department of Chemical Engineering
Carnegie Mellon University
Pittsburgh, PA 15213
412-268-7803
@johnkitchin
http://kitchingroup.cheme.cmu.edu



On Mon, Nov 30, 2020 at 7:51 AM Ian Garmaise <ian.g@phorixsol.com> wrote:

> Thanks Kyle, got it to work this way:
>
> #+BEGIN: propview :cols ((car (s-split " " ITEM))  (s-chop-prefix "gmail:"
> (my/extract-email-from-link EMAIL_ADDRESS)))  :id "candidates" :match
> "testthis" :wrap example
> | (car (s-split " " ITEM)) | (s-chop-prefix "gmail:"
> (my/extract-email-from-link EMAIL_ADDRESS)) |
>
> |--------------------------+---------------------------------------------------------------------|
> | "Ciara"                  | "ciaraxxxx@gmail.com"
>                        |
> | "Duncan"                 | "duncanxxxx@indeedemail.com"
>                  |
>
> Thanks a million!
>
> Ian
>
>
> On Sun, Nov 29, 2020 at 10:39 PM Kyle Meyer <kyle@kyleam.com> wrote:
>
>> Ian Garmaise writes:
>>
>> > This is working well, except for the property used for the email
>> address.
>> > Unfortunately, I stored this as a gmail link.  This makes it difficult
>> to
>> > extract the actual email address using org-collector as follows:
>> >
>> > #+BEGIN: propview :cols ((car (s-split " " ITEM))  EMAIL_ADDRESS)  :id
>> > "candidates" :match "testthis" :wrap example
>> >
>> > the result produced looks like this:
>> >
>> > | (car (s-split " " ITEM)) | EMAIL_ADDRESS
>>                                      |
>> >
>> |--------------------------+---------------------------------------------------------------------------------|
>> > | "Ciara"                  | [[
>> https://mail.google.com/mail/?view=cm&fs=1&to=ciaraxyz@gmail\.com]]
>>        |
>> > | "Duncan"                 | [[
>> https://mail.google.com/mail/?view=cm&fs=1&to=duncanxyz@indeedemail\.com]]
>> |
>> >
>> > I have looked at several methods that I found on the web to extract the
>> > email address from the link in the property, but haven't yet found a
>> > solution that I could get to work.  Still building up my elisp skillset,
>> > would appreciate suggestions.
>>
>> I've never used org-collector, but quickly trying to wire up a function
>> to extract the email part of the text you show, I suspect some of the
>> trouble you're having is that the value comes in as a vector because
>> org-propview-collect processes it with org-babel-read.  So perhaps
>> something like this would get you on the right track:
>>
>>   (require 'subr-x)
>>
>>   (defun my/extract-email-from-link (value)
>>     (setq value (format "%S" value))
>>     (when-let ((link (and (string-match org-link-bracket-re value)
>>                           (org-link-unescape
>>                            (match-string-no-properties 1 value)))))
>>       (thread-last
>>           link
>>         (replace-regexp-in-string
>>          (rx string-start (one-or-more not-newline) "to="
>>              (group (one-or-more not-newline)) string-end)
>>          "\\1")
>>         (replace-regexp-in-string (rx "\\.") "."))))
>>
>>
>> --8<---------------cut here---------------start------------->8---
>> #+BEGIN: propview :cols ((car (s-split " " ITEM))
>> (my/extract-email-from-link EMAIL_ADDRESS)) :id global
>> | (car (s-split " " ITEM)) | (my/extract-email-from-link EMAIL_ADDRESS) |
>> |--------------------------+--------------------------------------------|
>> | "Ciara"                  | "ciaraxyz@gmail.com"                       |
>> | "Duncan"                 | "duncanxyz@indeedemail.com"                |
>> |--------------------------+--------------------------------------------|
>> |                          |                                            |
>> #+END:
>>
>> * Ciara
>> :PROPERTIES:
>> :EMAIL_ADDRESS: [[
>> https://mail.google.com/mail/?view=cm&fs=1&to=ciaraxyz@gmail\.com]]
>> :END:
>>
>> * Duncan
>> :PROPERTIES:
>> :EMAIL_ADDRESS: [[
>> https://mail.google.com/mail/?view=cm&fs=1&to=duncanxyz@indeedemail\.com
>> ]]
>> :END:
>> --8<---------------cut here---------------end--------------->8---
>>
>
>
> --
> =====
> Ian Garmaise
> Consultant
> Phorix Solutions Group
> ian.g@phorixsol.com
> Toronto cell: 416.432.2251
> NYC: 917.512.9535
>
> https://www.linkedin.com/in/igarmaise/
>
> http://www.PhorixSol.com
>

[-- Attachment #2: Type: text/html, Size: 8139 bytes --]

^ permalink raw reply	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2020-11-30 13:55 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2020-11-30  2:18 difficulty extracting email address from property field containing gmail link Ian Garmaise
2020-11-30  3:39 ` Kyle Meyer
2020-11-30 12:41   ` Ian Garmaise
2020-11-30 13:42     ` John Kitchin

Org-mode mailing list

This inbox may be cloned and mirrored by anyone:

	git clone --mirror https://orgmode.org/list/0 list/git/0.git

	# If you have public-inbox 1.1+ installed, you may
	# initialize and index your mirror using the following commands:
	public-inbox-init -V2 list list/ https://orgmode.org/list \
		emacs-orgmode@gnu.org
	public-inbox-index list

Example config snippet for mirrors.
Newsgroups are available over NNTP:
	nntp://news.yhetil.org/yhetil.emacs.orgmode
	nntp://news.gmane.io/gmane.emacs.orgmode


AGPL code for this site: git clone https://public-inbox.org/public-inbox.git