Changeset

936:7236cdec3ea1

mod_default_vcard: Guess FN from FIRST + LAST and vice versa
author Kim Alvefur <zash@zash.se>
date Mon, 25 Mar 2013 00:44:54 +0100
parents 935:f66a08f208ad
children 937:5276e1fc26b6
files mod_default_vcard/mod_default_vcard.lua
diffstat 1 files changed, 19 insertions(+), 9 deletions(-) [+]
line wrap: on
line diff
--- a/mod_default_vcard/mod_default_vcard.lua	Mon Mar 25 00:43:30 2013 +0100
+++ b/mod_default_vcard/mod_default_vcard.lua	Mon Mar 25 00:44:54 2013 +0100
@@ -9,17 +9,27 @@
 	--module:log("debug", "Has account details: %s", data and "yes" or "no");
 	--module:log("debug", "Has vCard: %s", vcard and "yes" or "no");
 	if data and not vcard then
-		-- MAYBE
-		-- first .. " " .. last
-		-- first, last = name:match("^(%w+) (%w+)$")
+		local name, first, last = data.name, data.first, data.last;
+		if not name and (first and last) then
+			name = first .. " " .. last;
+		elseif name and not (first and last) then
+			first, last = name:match("^(%w+)%s+(%w+)$")
+		end
 		local vcard = st.stanza("vCard", { xmlns = "vcard-temp" })
-			:tag("VERSION"):text("3.0"):up()
-			:tag("N")
-				:tag("FAMILY"):text(data.last or ""):up()
-				:tag("GIVEN"):text(data.first or ""):up()
+			:tag("VERSION"):text("3.0"):up();
+		if first or last then
+			vcard:tag("N")
+				:tag("FAMILY"):text(last or ""):up()
+				:tag("GIVEN"):text(first or ""):up()
 			:up()
-			:tag("FN"):text(data.name or ""):up()
-			:tag("NICKNAME"):text(data.nick or username):up();
+		end
+		if name then
+			vcard:tag("FN"):text(name or ""):up()
+		end
+		vcard:tag("NICKNAME"):text(data.nick or username):up();
+		if data.email then
+			vcard:tag("EMAIL"):tag("USERID"):text(data.email):up():up();
+		end
 		local ok, err = datamanager.store(username, host, "vcard", st.preserialize(vcard));
 		if not ok then
 			module:log("error", "Couldn't save vCard data, %s", err);