Hey Simon, you have two problems.
1) jid_bare gives you usern...@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
Here's what your code could look like:
module:log("info", "vCard for %s", username);
local email; -- nil by default
if vCardRaw then
local vcard = st.deserialize(vCardRaw);
email = vcard:get_child_text("EMAIL");
On Fri, Mar 20, 2015 at 7:19 PM, Simon Hill <simonhill...@gmail.com> wrote:
> 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 u...@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:
> Thank you.
> On Friday, March 20, 2015 at 3:28:56 AM UTC-7, Matthew Wild wrote:
>> 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.
> 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+unsubscr...@googlegroups.com.
> To post to this group, send email to firstname.lastname@example.org.
> Visit this group at http://groups.google.com/group/prosody-dev.
> For more options, visit https://groups.google.com/d/optout.
You received this message because you are subscribed to the Google Groups
To unsubscribe from this group and stop receiving emails from it, send an email
To post to this group, send email to email@example.com.
Visit this group at http://groups.google.com/group/prosody-dev.
For more options, visit https://groups.google.com/d/optout.