Problems adding vCard to support for email forwarding on v.10

46 views
Skip to first unread message

Simon Hill

unread,
Mar 20, 2015, 6:14:43 AM3/20/15
to proso...@googlegroups.com
I promise to get better at Lua and Prosody - currently I am a noob and ask a lot of stupid questions. Here's my question:

I am trying to add vCard support to mod_offline_email. Zash kindly suggested:

local vcards = module:open_store("vcard");
 -- in a hook 
local vcard = vcards:get(username);
 
local email = vcards:get_child_text("EMAIL"); 


My vCards look like this:

[{"name":"EMAIL","attr":{"xmlns":"vcard-temp"},"__array":[{"attr":{"xmlns":"vcard-temp"},"name":"USERID","__array":["si...@domain.net"]},{"name":"PREF","attr":{"xmlns":"vcard-temp"}}]}]

I get the error:


[xmpp-1] 2015-03-20T00:53:13.198613705Z mod_bosh                                  error Traceback[bosh]: ...sody-modules/mod_offline_email/mod_offline_email.lua:24: attempt to call method 'get_child_text' (a nil value)
[xmpp-1] 2015-03-20T00:53:13.198613705Z stack traceback:
[xmpp-1] 2015-03-20T00:53:13.198613705Z ...sody-modules/mod_offline_email/mod_offline_email.lua:24: in function '?'
[xmpp-1] 2015-03-20T00:53:13.198613705Z /usr/lib/prosody/util/events.lua:67: in function </usr/lib/prosody/util/events.lua:63>
[xmpp-1] 2015-03-20T00:53:13.198613705Z (tail call): ?
[xmpp-1] 2015-03-20T00:53:13.198613705Z /usr/lib/prosody/modules/mod_message.lua:53: in function </usr/lib/prosody/modules/mod_message.lua:18>
[xmpp-1] 2015-03-20T00:53:13.198613705Z (tail call): ?
[xmpp-1] 2015-03-20T00:53:13.198613705Z /usr/lib/prosody/util/events.lua:67: in function 'fire_event'
[xmpp-1] 2015-03-20T00:53:13.198613705Z /usr/lib/prosody/core/stanza_router.lua:187: in function 'core_post_stanza'
[xmpp-1] 2015-03-20T00:53:13.198613705Z /usr/lib/prosody/core/stanza_router.lua:135: in function </usr/lib/prosody/core/stanza_router.lua:56>
[xmpp-1] 2015-03-20T00:53:13.198613705Z (tail call): ?
[xmpp-1] 2015-03-20T00:53:13.198613705Z [C]: in function 'xpcall'
[xmpp-1] 2015-03-20T00:53:13.198613705Z ...
[xmpp-1] 2015-03-20T00:53:13.198613705Z /usr/lib/prosody/net/http/server.lua:108: in function 'process_next'
[xmpp-1] 2015-03-20T00:53:13.198613705Z /usr/lib/prosody/net/http/server.lua:124: in function 'success_cb'
[xmpp-1] 2015-03-20T00:53:13.198613705Z /usr/lib/prosody/net/http/parser.lua:154: in function 'feed'
[xmpp-1] 2015-03-20T00:53:13.198613705Z /usr/lib/prosody/net/http/server.lua:150: in function </usr/lib/prosody/net/http/server.lua:149>
[xmpp-1] 2015-03-20T00:53:13.198613705Z (tail call): ?
[xmpp-1] 2015-03-20T00:53:13.198613705Z /usr/lib/prosody/net/server_select.lua:861: in function </usr/lib/prosody/net/server_select.lua:843>
[xmpp-1] 2015-03-20T00:53:13.198613705Z [C]: in function 'xpcall'
[xmpp-1] 2015-03-20T00:53:13.198613705Z /usr/lib/prosody/../../bin/prosody:373: in function 'loop'
[xmpp-1] 2015-03-20T00:53:13.198613705Z /usr/lib/prosody/../../bin/prosody:404: in main chunk


What am I doing wrong? I don't fully understand the syntax accessing the vcard object, so it is hard to troubleshoot. Javascript and node.js is more my area hitherto.

Thanks!

Simon

Matthew Wild

unread,
Mar 20, 2015, 6:28:56 AM3/20/15
to Prosody IM Developers Group
On 20 March 2015 at 00:56, Simon Hill <simonh...@gmail.com> wrote:
> I promise to get better at Lua and Prosody - currently I am a noob and ask a
> lot of stupid questions. Here's my question:
>
> I am trying to add vCard support to mod_offline_email. Zash kindly
> suggested:
>
>> local vcards = module:open_store("vcard");
>> -- in a hook
>> local vcard = vcards:get(username);
>
>
>>
>> local email = vcards:get_child_text("EMAIL");

This should be vcard:get_child_text() - vcards is the data store,
vcard is the user's vcard.

You might also need to deserialize the stanza object before you can
use it though. Run it through st.deserialize():

local vcard = st.deserialize(vcards:get(username));

Finally, although what you are doing seems like an obvious feature to
add, and quite simple, I have always refrained from adding it to
mod_offline_email. This is because the user's email address in the
vcard is not verified, they could put anybody's address there. This
would allow your server to be used as an open XMPP->email relay. It's
fine if your vcards are locked down to verified details and can't be
modified directly by the user though.

Regards,
Matthew

Simon Hill

unread,
Mar 20, 2015, 12:44:03 PM3/20/15
to proso...@googlegroups.com
Thanks Matt! Chuffed to get a response from the author! Your caveats are agreed and understood - my modification is for a closed implementation. Prosody is backing a social network / game launching soon.

Simon Hill

unread,
Mar 20, 2015, 7:19:37 PM3/20/15
to proso...@googlegroups.com
Hi Matthew, I have not exactly gotten it working and wondered if you had any further thoughts.

Must be doing something stupid.

In the logs:

info vCard  for us...@domain.com
[xmpp-1] 2015-03-20T21:59:51.813731734Z mod_bosh                                  error Traceback[bosh]: ...sody-modules/mod_offline_email/mod_offline_email.lua:28: attempt to index local 'vcard' (a nil value)


local username=jid_bare(stanza.attr.to);
module:log("info", "vCard for %s", username);

local vCardRaw=vcards:get(username);
local vcard = st.deserialize(vCardRaw);
local email = vcard:get_child_text("EMAIL"); <-- error

I haven't succeeded in logging out the contents of the vCard either. Keeps complaining of a nil index. But I am absolutely positive that the jid has the vCard - I see it in the db, and I can view it using Adium and retrieve it using stanza.io.

The only other thing I did was add 

local st = require "util.stanza";
 
Any thoughts on how to debug? Here's a gist of your bastardized code: mod_offline_email.lua

Thank you.

Si



On Friday, March 20, 2015 at 3:28:56 AM UTC-7, Matthew Wild wrote:

Waqas Hussain

unread,
Mar 20, 2015, 10:33:54 PM3/20/15
to Prosody IM Developers Group
Hey Simon, you have two problems.

1) jid_bare gives you user...@example.com. You just want username, without the @hostname, so use jid_split
2) You don't check for the vCard being nil (i.e., the user has no vCard data stored)

Here's what your code could look like:

local username=jid_split(stanza.attr.to);

module:log("info", "vCard  for %s", username);

local email; -- nil by default
local vCardRaw=vcards:get(username);
if vCardRaw then
  local vcard = st.deserialize(vCardRaw);

  email = vcard:get_child_text("EMAIL");
end

--
Waqas Hussain


--
You received this message because you are subscribed to the Google Groups "prosody-dev" group.
To unsubscribe from this group and stop receiving emails from it, send an email to prosody-dev...@googlegroups.com.
To post to this group, send email to proso...@googlegroups.com.
Visit this group at http://groups.google.com/group/prosody-dev.
For more options, visit https://groups.google.com/d/optout.

Simon Hill

unread,
Mar 21, 2015, 11:19:03 AM3/21/15
to proso...@googlegroups.com
Thanks Waqas! I got this far (after adding jid_split function):

if text then
local username = jid_split(stanza.attr.to);

module:log("info", "vCard for %s", username);

local email; -- nil by default
    local vCardRaw = vcards:get(username);

if vCardRaw then
local vcard = st.deserialize(vCardRaw);
email = vcard:get_child_text("EMAIL");
        module:log("info", "vCard raw %s", vCardRaw);
text = text .. "\n\n /to:" .. jid_bare(stanza.attr.to) .. "/from:" .. jid_bare(stanza.attr.from) .. "/";
if email then
return send_message_as_email(email, smtp_daemon, text);
end
end
end

The email var is returning as empty. I try to log out the contents of vCardRaw, but get this error:


What's the best way to inspect the contents of the vCard so I can see if it has the attributes that I assume it has?


Thanks!!

--
You received this message because you are subscribed to a topic in the Google Groups "prosody-dev" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/prosody-dev/hOD-FzM1pY0/unsubscribe.
To unsubscribe from this group and all its topics, send an email to prosody-dev...@googlegroups.com.

Kim Alvefur

unread,
Mar 21, 2015, 11:33:35 AM3/21/15
to proso...@googlegroups.com
On 2015-03-21 16:19, Simon Hill wrote:
> The /email/ var is returning as empty.

Note that <EMAIL> does not contain the email address directly, but as a
child element <USERID>. So you will need to do

email = vcard:get_child("EMAIL");
email = email and email:get_child_text("USERID");

to get the actual email address, if there is one.

--
Hope that helps,
Kim "Zash" Alvefur

signature.asc

Simon Hill

unread,
Mar 21, 2015, 12:26:06 PM3/21/15
to proso...@googlegroups.com
Thank you. That worked! Here's the working code:


Reply all
Reply to author
Forward
0 new messages