Whitelisting mailto: links in Cordova

Hey folks,

I’m having a hard time allowing Cordova to open mailto links.

Adding App.accessRule('*', { external: true }); to mobile-config.js has enabled me to load things from other websites.

I’ve tried App.accessRule('mailto:*', { external: "yes" }); and then App.accessRule('mailto:*', { launchExternal: "yes" }); with no luck getting it work. I’ve also tried swapping “yes” for true.

Does anyone know what I am doing wrong, or another way to get this working?

Is this on iOS? I just tried this with Meteor 1.2.1, and I indeed get an exception:

*** WebKit discarded an uncaught exception in the webView:decidePolicyForNavigationAction:request:frame:decisionListener: delegate: <NSInvalidArgumentException> *** -[NSRegularExpression enumerateMatchesInString:options:range:usingBlock:]: nil argument

This also led me to this forum post describing the same issue, which I somehow missed before.

I’ll investigate further and see if there’s anything I can do about it.

If you execute window.location=“mailto:genius@meteor.toys” in your JS what happens?

@martijnwalraven iOS indeed - have not tried on Android yet. Can open GitHub issue if needed.

@benstr I have tried that and tried to target the system as well - no luck :panda_face:

Looks like this is a Cordova bug. The offending code is in CDVWhitelistPattern in Cordova iOS. Because mailto URLs do not have a host, this crashes the regular expression match.

Not sure what to do about this and whether there are any workarounds. I did confirm that the issue does not occur on the master (4.0) version of Cordova iOS, which is what I hope we can switch to for Meteor 1.3.

Is there a way to completely disable the whitelisting stuff? Trying to think of how else I can get this in production without going for the "so when is 1.3 coming out" question :stuck_out_tongue:

As far as I know, there is no way to disable the whitelisting stuff.

This is a real hack, but it does work if you change the offending code (in CordovaLib/Classes/Commands/CDVWhitelist.m in the Xcode project) to:

- (bool)matches:(NSURL*)url
{
    return (_scheme == nil || [_scheme numberOfMatchesInString:[url scheme] options:NSMatchingAnchored range:NSMakeRange(0, [[url scheme] length])]) &&
           (_host == nil || [url host] == nil || [_host numberOfMatchesInString:[url host] options:NSMatchingAnchored range:NSMakeRange(0, [[url host] length])]) &&
           (_port == nil || [[url port] isEqualToNumber:_port]) &&
           (_path == nil || [_path numberOfMatchesInString:[url path] options:NSMatchingAnchored range:NSMakeRange(0, [[url path] length])])
    ;
}
1 Like

Perfect - thanks man!