Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.python > #101552 > unrolled thread
| Started by | jkn <jkn_gg@nicorp.f9.co.uk> |
|---|---|
| First post | 2016-01-12 08:51 -0800 |
| Last post | 2016-01-12 13:12 -0600 |
| Articles | 7 — 4 participants |
Back to article view | Back to comp.lang.python
use Python and an outlook: protocol URL to bring up a specific email jkn <jkn_gg@nicorp.f9.co.uk> - 2016-01-12 08:51 -0800
Re: use Python and an outlook: protocol URL to bring up a specific email Chris Angelico <rosuav@gmail.com> - 2016-01-13 04:10 +1100
Re: use Python and an outlook: protocol URL to bring up a specific email jkn <jkn_gg@nicorp.f9.co.uk> - 2016-01-12 09:22 -0800
Re: use Python and an outlook: protocol URL to bring up a specific email eryk sun <eryksun@gmail.com> - 2016-01-12 11:37 -0600
Re: use Python and an outlook: protocol URL to bring up a specific email Chris Angelico <rosuav@gmail.com> - 2016-01-13 04:52 +1100
Re: use Python and an outlook: protocol URL to bring up a specific email Christian Gollwitzer <auriocus@gmx.de> - 2016-01-12 19:04 +0100
Re: use Python and an outlook: protocol URL to bring up a specific email eryk sun <eryksun@gmail.com> - 2016-01-12 13:12 -0600
| From | jkn <jkn_gg@nicorp.f9.co.uk> |
|---|---|
| Date | 2016-01-12 08:51 -0800 |
| Subject | use Python and an outlook: protocol URL to bring up a specific email |
| Message-ID | <ab47c98f-69af-49ee-b1c4-bced0c48a001@googlegroups.com> |
Hi all
a little OS/windows specific, I'm afraid:
In Windows, there exists a part-supported 'outlook protocol' to obtain and use
email references within Outlook as URL. You have to go through various shenanagins to enable this and to get Outlook to give you access to the URLs - see for instance:
http://www.slipstick.com/problems/outlook-missing-outlook-protocol/
http://superuser.com/questions/834019/using-outlook-protocol-open-current-instance-of-outlook-not-new-instance
http://www.davidtan.org/create-hyperlinks-to-outlook-messages-folders-contacts-events/
Having gone through all of this I get a refernce URL on my clipboard or whatever:
"outlook:00000000BB1BBDFACA3A4D41A98037A1D85A8DA50700E6FBFC004227134D97632785EE69C220003C0208DEA10000DAC09B3B9C648E4597BE2A013A6E8B84000026F87CCA0000"
(This refers to a particular email in Outlook)
What I want to do is then use Python to invoke this URL to cause Outlook to
bring up the referenced email. I'm stumbling here; I've tried urllib.urlopen(),
and os.startfile(), but I am getting errors from urllib in either case:
def open_unknown(self, fullurl, data=None):
"""Overridable interface to open unknown URL type."""
type, url = splittype(fullurl)
raise IOError, ('url error', 'unknown url type', type)
ie. the 'outlook' protocol is unknown.
I happy to carve some code without using urllib, but I am not clear what I
actually need to do to 'open' such a URL using this protocol. FWIW I can paste
this URL into Windows Explorer and I get the referenced email popping up ;-)
Thanks for any pointers
Regards
Jon N
[toc] | [next] | [standalone]
| From | Chris Angelico <rosuav@gmail.com> |
|---|---|
| Date | 2016-01-13 04:10 +1100 |
| Message-ID | <mailman.72.1452618660.13488.python-list@python.org> |
| In reply to | #101552 |
On Wed, Jan 13, 2016 at 3:51 AM, jkn <jkn_gg@nicorp.f9.co.uk> wrote: > I happy to carve some code without using urllib, but I am not clear what I > actually need to do to 'open' such a URL using this protocol. FWIW I can paste > this URL into Windows Explorer and I get the referenced email popping up ;-) > What happens if you invoke the 'start' command using subprocess? subprocess.check_call(["start", url]) In theory, that should be equivalent to pasting it into Explorer. In theory. ChrisA
[toc] | [prev] | [next] | [standalone]
| From | jkn <jkn_gg@nicorp.f9.co.uk> |
|---|---|
| Date | 2016-01-12 09:22 -0800 |
| Message-ID | <f20e3ce6-3426-41dd-926e-3c0c745b3006@googlegroups.com> |
| In reply to | #101555 |
Hi Chris
On Tuesday, January 12, 2016 at 5:11:18 PM UTC, Chris Angelico wrote:
> On Wed, Jan 13, 2016 at 3:51 AM, jkn <jkn_gg@nicorp.f9.co.uk> wrote:
> > I happy to carve some code without using urllib, but I am not clear what I
> > actually need to do to 'open' such a URL using this protocol. FWIW I can paste
> > this URL into Windows Explorer and I get the referenced email popping up ;-)
> >
>
> What happens if you invoke the 'start' command using subprocess?
>
> subprocess.check_call(["start", url])
>
> In theory, that should be equivalent to pasting it into Explorer. In theory.
>
> ChrisA
I'll try that, but (typically!) I found some things that worked shortly after
posting...
These both work:
PROTOCOL = "outlook:"
TEST_URL = "00000000BB1BBDFACA3A... 84000026F87CCA0000" # elided for example
import os
os.startfile(PROTOCOL + TEST_URL, 'open') # second parameter not needed
# and
import win32api
win32api.ShellExecute(0, 'open', PROTOCOL + TEST_URL, "", "", 0)
I thought I had already tried the first one, not sure what happened.
Sorry for the noise...
Cheers
Jon N
[toc] | [prev] | [next] | [standalone]
| From | eryk sun <eryksun@gmail.com> |
|---|---|
| Date | 2016-01-12 11:37 -0600 |
| Message-ID | <mailman.76.1452620277.13488.python-list@python.org> |
| In reply to | #101552 |
On Tue, Jan 12, 2016 at 11:10 AM, Chris Angelico <rosuav@gmail.com> wrote:
> On Wed, Jan 13, 2016 at 3:51 AM, jkn <jkn_gg@nicorp.f9.co.uk> wrote:
>> I happy to carve some code without using urllib, but I am not clear what I
>> actually need to do to 'open' such a URL using this protocol. FWIW I can paste
>> this URL into Windows Explorer and I get the referenced email popping up ;-)
>
> What happens if you invoke the 'start' command using subprocess?
>
> subprocess.check_call(["start", url])
>
> In theory, that should be equivalent to pasting it into Explorer. In theory.
start is a shell command. It also has a quirk that the first quoted
argument is the window title. Here's the correct call:
subprocess.check_call('start "title" "%s"' % url, shell=True)
That said, since no arguments are being passed the simpler and more
secure way to call ShellExecute in this case is os.startfile(url).
[toc] | [prev] | [next] | [standalone]
| From | Chris Angelico <rosuav@gmail.com> |
|---|---|
| Date | 2016-01-13 04:52 +1100 |
| Message-ID | <mailman.79.1452621162.13488.python-list@python.org> |
| In reply to | #101552 |
On Wed, Jan 13, 2016 at 4:37 AM, eryk sun <eryksun@gmail.com> wrote:
> On Tue, Jan 12, 2016 at 11:10 AM, Chris Angelico <rosuav@gmail.com> wrote:
>> On Wed, Jan 13, 2016 at 3:51 AM, jkn <jkn_gg@nicorp.f9.co.uk> wrote:
>>> I happy to carve some code without using urllib, but I am not clear what I
>>> actually need to do to 'open' such a URL using this protocol. FWIW I can paste
>>> this URL into Windows Explorer and I get the referenced email popping up ;-)
>>
>> What happens if you invoke the 'start' command using subprocess?
>>
>> subprocess.check_call(["start", url])
>>
>> In theory, that should be equivalent to pasting it into Explorer. In theory.
>
> start is a shell command. It also has a quirk that the first quoted
> argument is the window title. Here's the correct call:
>
> subprocess.check_call('start "title" "%s"' % url, shell=True)
Is that properly escaped to handle any arbitrary URL? I doubt it.
Do you actually need shell=True? I would strongly recommend using the
form that I used, unless it can be proven that that doesn't work.
> That said, since no arguments are being passed the simpler and more
> secure way to call ShellExecute in this case is os.startfile(url).
Yes. The OP mentioned having tried this, though, so I went for an alternative.
ChrisA
[toc] | [prev] | [next] | [standalone]
| From | Christian Gollwitzer <auriocus@gmx.de> |
|---|---|
| Date | 2016-01-12 19:04 +0100 |
| Message-ID | <n73f2f$t5m$1@dont-email.me> |
| In reply to | #101564 |
Am 12.01.16 um 18:52 schrieb Chris Angelico:
> On Wed, Jan 13, 2016 at 4:37 AM, eryk sun <eryksun@gmail.com> wrote:
>>
>> start is a shell command. It also has a quirk that the first quoted
>> argument is the window title. Here's the correct call:
>>
>> subprocess.check_call('start "title" "%s"' % url, shell=True)
>
> Is that properly escaped to handle any arbitrary URL? I doubt it.
>
> Do you actually need shell=True? I would strongly recommend using the
> form that I used, unless it can be proven that that doesn't work.
As stated, start is not an executable on Windows, but it is a built-in
command of cmd.exe. And thus it has very quirky quotation rules. This is
unlike Linux, where "xdg-open" is a shell script, and OSX, where "open"
is a binary executable.
Christian
[toc] | [prev] | [next] | [standalone]
| From | eryk sun <eryksun@gmail.com> |
|---|---|
| Date | 2016-01-12 13:12 -0600 |
| Message-ID | <mailman.84.1452626009.13488.python-list@python.org> |
| In reply to | #101552 |
On Tue, Jan 12, 2016 at 11:52 AM, Chris Angelico <rosuav@gmail.com> wrote: > Is that properly escaped to handle any arbitrary URL? I doubt it. subprocess doesn't know how to quote a command line for the Windows shell, which doesn't follow the rules used by subprocess.list2cmdline. To make matters worse, one often has to follow both sets of rules or even some arbitrary rules used by an executable. > Do you actually need shell=True? I would strongly recommend using the > form that I used, unless it can be proven that that doesn't work. AFAIK, the "start" command has been built in to the shell since cmd.exe originated on OS/2 in like 1987. It was enhanced when cmd.exe was ported to Win32 for NT 3.1.
[toc] | [prev] | [standalone]
Back to top | Article view | comp.lang.python
csiph-web