Nice - I have been meaning to write something myself like this myself, so 
thanks Thomas

    Jon N


On Monday, November 24, 2025 at 6:34:17 PM UTC [email protected] wrote:

> Here's a script that lets you send the body of the selected node to email. 
> The body needs to contain the text "email: <address>", where "<address>" is 
> the email address to send the node to.  If there is a text selection, it 
> will be searched for the address.  If not, the entire body will be 
> searched. The script works for both Windows and Linux.  It ought to work on 
> MacOS but I can't try that. The message is handled by the system default 
> email handler. 
>
> I have added this script to my "Local" custom menu defined in 
> myLeoSettings.leo. Here it is:
>
> @language python
> """Extract email address and launch email program on it.
>
> The address is expected to be prefaced like this:
>     
> [optional text first] email: [email protected] [optional text after]
>
> If there is a selection, the selected text is searched for an email
> address.  Otherwise, the entire body is searched.  The system's
> default email program is opened.
> """
>
> import re
> from sys import platform
> import os
> from subprocess import call
>
> EMAILre = r'.*email:[ ]*([^@]+@[^@ \t\n]+)'  # inline
>
> def open_file(filename):
>     try:
>         os.startfile(filename)  # Windows only
>     except Exception as e:
>         print(e)
>         opener = "open" if platform == "darwin" else "xdg-open"
>         call([opener, filename])
>
> # List of line(s) containing cursor or selection
> cursor_lines = c.getBodyLines()[1]
> line = cursor_lines[0] if cursor_lines else ''
>
> matched = re.match(EMAILre, line)
> target = matched[1] if matched else None
>
> if target:
>     target = 'mailto:' + target.strip()
>     open_file(target)
> else:
>     g.es('no address found')
>
>

-- 
You received this message because you are subscribed to the Google Groups 
"leo-editor" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
To view this discussion visit 
https://groups.google.com/d/msgid/leo-editor/fe69750b-09c0-4b54-a5d4-d5f0995d089fn%40googlegroups.com.

Reply via email to