Worona App mailto links do not launch device mail client

Hi,

I have purchased a hybrid app template that displays posts from a Wordpress site and accepts push notifications. It all works very well apart from:-

When a post is displayed from the app’s defined wordpress website within the app and it has a mailto: link, when the link is clicked the app does not launch the devices mail client.

Also ‘a href’ web links do not launch the devices web browser, the new webpage just opens within the app.

What is very strange is that if you navigate away from the Apps defined wordpress website to a webpage with a mailto link and click the link, it does launch the devices mail client.

Could do with a bit of help as I have no idea where in the app this behaviour is defined.

Thanks

Hello and welcome to the Forums!

What template are you using? 

Have you reached out to the template creator about this issue?

Rob

The template is from Worona.

I really like it, just has this issue. Yes I have asked them but they don’t seem to have any answers.

I think what has happened is that the chaps at Worona wanted to build an app that would allow users to browse the web from within the app. Somewhere in the process they have not considered the mailto issue. From my reading it seems that webView and a listener function is where the issue lies. It is my view that unless you are developing a fully functional browser app that a href links should probably launch the devices browser or e-mail client as they will do a better job than the blog reader app.

I am not a software developer so I’m struggling with finding example code and where to insert the code.

The Worona app is one of the best I’ve seen for the simple task of receiving push notifications and displaying a list of posts from a wp site. Our goals for the app mean that the posts do not have a requirement for web links but we have definitely have a requirement for an mailto link to open the devices mail client.

In another forum post  I came across this:-

native.showPopup(“mail”, options)

As I understand it this will allow mailto links to be caught and dealt with in a different way from other a href links. To be honest if there was a high level function that would override every other rule in the app to make all links launch the relevant native app on the device that would be great.

The can see the app at worona.org

Thanks for taking an interest. 

As far as Worona goes, it seems to be a pretty cool product and concept, however we didn’t build it and we don’t know what goes on under the hood with it. Maybe some other forum members have experience with it and could help. It would be helpful if you update the title to contain “Worona” in it so that people will now that’s what this tread is about.

Purely speculating, if it’s using native.newWebView under the hood then there is a listener function that gets called when URL’s are tapped giving you a chance to intercept them and do other things. You could get it, detect a mailto: and parse the address out of it to send to have.showPopup(“mail”). But this is likely something the team at Worona would have to implement.

Rob

Hi Rob, thanks your reply. I’ve added Worona in the key words.

I have tried using the following:-

local function webListener(event) print("showWebPopup callback") local url = event.url if( string.find( url, "http:" ) ~= nil or string.find( url, "mailto:" ) ~= 1 ) then print("url: ".. url) system.openURL(mailto:) end return true end

This does not achieve clickable mailto links.

The App has a file called html_server.lua, I have copied the code below.

This seems to be where the issue is. Line 146 to 157 seems to where you could perhaps control the behaviour of a tapped mailto link. I don’t what you would do though. The code is of course lua. Any ideas on what this file does and a work around to get mailto: links working would be greatly appreciated. I think the file has something to do with serving the json data to the device screen. I am way out of my depth here so that maybe rubbish. This is great little app and I would happily buy it if I could get this working. The App developers don’t seem to understand my issue which is why I’m posting on here. My use of the app required mailto links to pop the device mail client.

local worona = require "worona" local function newService() local socket = require "socket" local html\_server = {} -- Parse values from query local function getArgs( query ) query\_pos = string.find( query, "/?" ) --: get position of the ? query = string.sub( query, query\_pos+2 ) --: remove everything before that local parsed = {} local pos = 0 query = string.gsub(query, "&amp;", "&") query = string.gsub(query, "&lt;", "\<") query = string.gsub(query, "&gt;", "\>") local function ginsert(qstr) local first, last = string.find(qstr, "=") if first then parsed[string.sub(qstr, 0, first-1)] = string.sub(qstr, first+1) end end while true do local first, last = string.find(query, "&", pos) if first then ginsert(string.sub(query, pos, first-1)); pos = last+1 else ginsert(string.sub(query, pos)); break; end end return parsed end --: creates a retrieves a new server function html\_server:newServer( options ) --: local variables local success, err, server --: defaults local options = options or {} local host = options.host or "localhost" local port = options.port or "1024" local backlog = options.backlog or 32 local timeout = options.timeout or 0 --: start the tcp server server, err = socket.tcp() --: reuse the address if it exist server:setoption( "reuseaddr" , true ) if server ~= nil then worona.log:info("html\_server: starting initialization") --: define a host and port for the server success, err = server:bind( host, port ) if success == 1 then worona.log:info("html\_server: bind to " .. host .. ":" .. port) --: start listening to a number of incoming connections success, err = server:listen( backlog ) if success == 1 then worona.log:info("html\_server: listening to a max of " .. backlog .. " connections" ) --: set the timeout of the accept() process. this is a blocking process, so until it receives something it will block the execution --: we are going to use the corona Runtime:addEventListener( "enterFrame" , function ) so we can set the timeout to nothing (0) success, err = server:settimeout( timeout ) if success == 1 then worona.log:info("html\_server: success setting a timeout of " .. timeout ) --: everything went fine, return the server worona.log:info("html\_server: initialised succesfully, returning") --: add the server to the html\_server table html\_server.server = server --: return the server and end function return server end end end end --: something went wrong, return nil and the error return nil, "html\_server: failed with error " .. err end --: function to retrieve clients function html\_server:processPetition( server ) local server = server or html\_server.server return function() --: local variables local client, message local err = "server is nil" local headers = [[HTTP/1.1 200 OK Date:]] .. worona.date:convertTimestampToDate( os.time() ) .. [[Server: WoronaServer Content-Type: text/html Connection: Closed]] if server ~= nil then --: accept an incoming connection creating a client we can use to receive and send data client, err = server:accept() if client ~= nil then worona.log:info("html\_server: found a connection to accept" ) --: receive the data which has been sent to the server message, err = client:receive('\*l') if message ~= nil then local method, uri, protocol = string.match( message, "([A-Z]+) (.+) (.+)" ) local args = getArgs( uri ) worona.log:info("html\_server: received. " .. message ) if args.render ~= nil then worona.log:info( "html\_server: Rendering the internal url '" .. args.render .. "'" ) local html\_Path = system.pathForFile( "content/html/" .. args.render .. ".html", system.CachesDirectory ) local html\_File = io.open( html\_Path, "r" ) local html\_Data = html\_File:read( "\*a" ) html\_File:close() client:send( headers .. html\_Data ) client:close() elseif args.url ~= nil then worona.log:info( "html\_server: We are on iPhone and user clicked on a link with url '" .. args.url .. "'" ) worona:do\_action( "load\_url", args ) end return end else return nil end end worona.log:warning("Something went wrong. Error: " .. err ) end end return html\_server end worona:do\_action( "register\_service", { service = "html\_server", creator = newService } ) local function initialiseServer() worona.log:info( "html\_server: about to start the html server" ) local server, err = worona.html\_server:newServer() if server ~= nil then Runtime:addEventListener( "enterFrame", worona.html\_server:processPetition() ) else worona.log:warning("html\_server: failed to start due to error " .. err ) end end --: start the server local function startHtmlServer() initialiseServer() local function onSystemEvent( event ) if event.type == "applicationResume" then initialiseServer() end end Runtime:addEventListener( "system", onSystemEvent ) end worona:add\_action( "init", startHtmlServer )

Well in your first block, this:

system.openURL(mailto:)

should be:

system.openURL(url)

Rob

Hello and welcome to the Forums!

What template are you using? 

Have you reached out to the template creator about this issue?

Rob

The template is from Worona.

I really like it, just has this issue. Yes I have asked them but they don’t seem to have any answers.

I think what has happened is that the chaps at Worona wanted to build an app that would allow users to browse the web from within the app. Somewhere in the process they have not considered the mailto issue. From my reading it seems that webView and a listener function is where the issue lies. It is my view that unless you are developing a fully functional browser app that a href links should probably launch the devices browser or e-mail client as they will do a better job than the blog reader app.

I am not a software developer so I’m struggling with finding example code and where to insert the code.

The Worona app is one of the best I’ve seen for the simple task of receiving push notifications and displaying a list of posts from a wp site. Our goals for the app mean that the posts do not have a requirement for web links but we have definitely have a requirement for an mailto link to open the devices mail client.

In another forum post  I came across this:-

native.showPopup(“mail”, options)

As I understand it this will allow mailto links to be caught and dealt with in a different way from other a href links. To be honest if there was a high level function that would override every other rule in the app to make all links launch the relevant native app on the device that would be great.

The can see the app at worona.org

Thanks for taking an interest. 

As far as Worona goes, it seems to be a pretty cool product and concept, however we didn’t build it and we don’t know what goes on under the hood with it. Maybe some other forum members have experience with it and could help. It would be helpful if you update the title to contain “Worona” in it so that people will now that’s what this tread is about.

Purely speculating, if it’s using native.newWebView under the hood then there is a listener function that gets called when URL’s are tapped giving you a chance to intercept them and do other things. You could get it, detect a mailto: and parse the address out of it to send to have.showPopup(“mail”). But this is likely something the team at Worona would have to implement.

Rob

Hi Rob, thanks your reply. I’ve added Worona in the key words.

I have tried using the following:-

local function webListener(event) print("showWebPopup callback") local url = event.url if( string.find( url, "http:" ) ~= nil or string.find( url, "mailto:" ) ~= 1 ) then print("url: ".. url) system.openURL(mailto:) end return true end

This does not achieve clickable mailto links.

The App has a file called html_server.lua, I have copied the code below.

This seems to be where the issue is. Line 146 to 157 seems to where you could perhaps control the behaviour of a tapped mailto link. I don’t what you would do though. The code is of course lua. Any ideas on what this file does and a work around to get mailto: links working would be greatly appreciated. I think the file has something to do with serving the json data to the device screen. I am way out of my depth here so that maybe rubbish. This is great little app and I would happily buy it if I could get this working. The App developers don’t seem to understand my issue which is why I’m posting on here. My use of the app required mailto links to pop the device mail client.

local worona = require "worona" local function newService() local socket = require "socket" local html\_server = {} -- Parse values from query local function getArgs( query ) query\_pos = string.find( query, "/?" ) --: get position of the ? query = string.sub( query, query\_pos+2 ) --: remove everything before that local parsed = {} local pos = 0 query = string.gsub(query, "&amp;", "&") query = string.gsub(query, "&lt;", "\<") query = string.gsub(query, "&gt;", "\>") local function ginsert(qstr) local first, last = string.find(qstr, "=") if first then parsed[string.sub(qstr, 0, first-1)] = string.sub(qstr, first+1) end end while true do local first, last = string.find(query, "&", pos) if first then ginsert(string.sub(query, pos, first-1)); pos = last+1 else ginsert(string.sub(query, pos)); break; end end return parsed end --: creates a retrieves a new server function html\_server:newServer( options ) --: local variables local success, err, server --: defaults local options = options or {} local host = options.host or "localhost" local port = options.port or "1024" local backlog = options.backlog or 32 local timeout = options.timeout or 0 --: start the tcp server server, err = socket.tcp() --: reuse the address if it exist server:setoption( "reuseaddr" , true ) if server ~= nil then worona.log:info("html\_server: starting initialization") --: define a host and port for the server success, err = server:bind( host, port ) if success == 1 then worona.log:info("html\_server: bind to " .. host .. ":" .. port) --: start listening to a number of incoming connections success, err = server:listen( backlog ) if success == 1 then worona.log:info("html\_server: listening to a max of " .. backlog .. " connections" ) --: set the timeout of the accept() process. this is a blocking process, so until it receives something it will block the execution --: we are going to use the corona Runtime:addEventListener( "enterFrame" , function ) so we can set the timeout to nothing (0) success, err = server:settimeout( timeout ) if success == 1 then worona.log:info("html\_server: success setting a timeout of " .. timeout ) --: everything went fine, return the server worona.log:info("html\_server: initialised succesfully, returning") --: add the server to the html\_server table html\_server.server = server --: return the server and end function return server end end end end --: something went wrong, return nil and the error return nil, "html\_server: failed with error " .. err end --: function to retrieve clients function html\_server:processPetition( server ) local server = server or html\_server.server return function() --: local variables local client, message local err = "server is nil" local headers = [[HTTP/1.1 200 OK Date:]] .. worona.date:convertTimestampToDate( os.time() ) .. [[Server: WoronaServer Content-Type: text/html Connection: Closed]] if server ~= nil then --: accept an incoming connection creating a client we can use to receive and send data client, err = server:accept() if client ~= nil then worona.log:info("html\_server: found a connection to accept" ) --: receive the data which has been sent to the server message, err = client:receive('\*l') if message ~= nil then local method, uri, protocol = string.match( message, "([A-Z]+) (.+) (.+)" ) local args = getArgs( uri ) worona.log:info("html\_server: received. " .. message ) if args.render ~= nil then worona.log:info( "html\_server: Rendering the internal url '" .. args.render .. "'" ) local html\_Path = system.pathForFile( "content/html/" .. args.render .. ".html", system.CachesDirectory ) local html\_File = io.open( html\_Path, "r" ) local html\_Data = html\_File:read( "\*a" ) html\_File:close() client:send( headers .. html\_Data ) client:close() elseif args.url ~= nil then worona.log:info( "html\_server: We are on iPhone and user clicked on a link with url '" .. args.url .. "'" ) worona:do\_action( "load\_url", args ) end return end else return nil end end worona.log:warning("Something went wrong. Error: " .. err ) end end return html\_server end worona:do\_action( "register\_service", { service = "html\_server", creator = newService } ) local function initialiseServer() worona.log:info( "html\_server: about to start the html server" ) local server, err = worona.html\_server:newServer() if server ~= nil then Runtime:addEventListener( "enterFrame", worona.html\_server:processPetition() ) else worona.log:warning("html\_server: failed to start due to error " .. err ) end end --: start the server local function startHtmlServer() initialiseServer() local function onSystemEvent( event ) if event.type == "applicationResume" then initialiseServer() end end Runtime:addEventListener( "system", onSystemEvent ) end worona:add\_action( "init", startHtmlServer )

Well in your first block, this:

system.openURL(mailto:)

should be:

system.openURL(url)

Rob