[whatwg] [WF2] action="mailto:" - encoding spaces

Michael A. Puls II shadow2531 at gmail.com
Tue Dec 2 03:45:58 PST 2008


On Tue, 02 Dec 2008 05:00:11 -0500, Ian Hickson <ian at hixie.ch> wrote:

> On Tue, 2 Dec 2008, Michael A. Puls II wrote:
>>
>> Consider this form:
>>
>> <form action="mailto:?subject=1+2" action="POST">
>>    <input type="submit" value="Compose">
>> </form>
>>
>> (which contains a valid mailto URI meaning that "1+2" should be the
>> value of the subject)
>>
>> Imagine in your browser that it supports setting the default mailto URI
>> handler to Gmail (a web-based client that uses *http* URIs).
>>
>> If you submit that form, you'd get
>> <https://mail.google.com/mail/?compose=1&view=cm&fs=1&su=1+2>
>
> Why? How so?
>
> Are you referring to the registerProtocolHandler() API, to mailto: form
> submission, or to something else?

Thanks

I'm talking about a UA associating mailto: links and mailto: form submission with webmail clients (like Gmail for example) by whatever means, just like UAs can do with Thunderbird for example.

This could be done with registerProtocolHandler, but the webmail would have to accept a uri= in its compose URI query string and the function (at least the internal one) couldn't be domain-restricted.

Gmail (and most webmails) currently don't support a uri=, but I have a specific proposal for Gmail if I can find someone to submit it to.

To support Gmail now, registerProtocolHandler would have to be like:

registerProtocolHandler("mailto", function(e) {
    var uri = e.uri;
    // parse the URI to get the individual to, cc, bcc, subject and body hvalues
    // and use them to build a Gmail compose URI
    // Plus, escapeUnsafe and invalid characters and %HH
    // Plus, join multiple occurences of an hvalue
    // using a different algorithm depending on 
    // the type of hvalue.
}, "Compose in Gmail?");

Anyway, goto <http://shadow2531.com/opera/testcases/mailto/register_protocol_handler.html> and click on the first link. If Gmail worked like that, it could totally work around the '+' issue and support a registerProtocolHandler-like function. Of course, Gmail could simply not decode + to ' ' for its to, cc, bcc, body and su hvalues that it currently supports. Then though, there'd still be a bunch of other webmails that'd need to do it also. But, take a look at the source of the pages and the included JS. They show the things that are necessary to implement parsing in a compatible way and will help with your following question.

> Could you lay out the steps that take us from a form submission using a
> mailto: URL to an HTTPS request to GMail?

Maybe this will help:

Download <http://shadow2531.com/opera/userjs/BeforeMailtoURL.js> to a folder.
Edit it and set supportForms to true.

In Opera, goto tools -> preferences -> advanced -> content -> javascript options and set your UserJS folder to the folder BeforeMailtoURL.js is in.

Log in to <http://mail.google.com/>.

Goto <http://shadow2531.com/opera/testcases/mailto/003-post.html> and <http://shadow2531.com/opera/testcases/mailto/003.html> and click compose.

In BeforeMailtoURL.js, you can look at "createMailtoURIFromEnabledFormControls(form)", "if (supportForms)", the MailtoURIParser class and the format() function. And, look at the "if (form.method == "post")" part to see how I convert '+' to "%2B" in the action attribute to avoid this problem. (Note that the way I parse the form isn't complete. Wish: Forms should have a generateDataset() so UAs can do if for you.)

Checking <http://shadow2531.com/opera/testcases/mailto/modern_mailto_uri_scheme.html#forms> and the whole page might help too.

But, basically, with webmail clients, you have to be careful and encode '+' as %2B in all parts of the submitted mailto data, including parts that come from the action attribute.

So, as a suggestion:

On the authoring side, making <form action="mailto:?subject=1+2" method="post"> invalid and <form action="mailto:?subject=1%2B2" method="post"> valid would help.

On a handling side for "mailto:", saying the UA should convert the + to %2B *if* the submitted data will end up in an http URI, might help. This is good because I believe UAs will do this regardless of the spec if they need to support Webmails. Having it specified or hinted at though would be nice.

-- 
Michael



More information about the whatwg mailing list