changeset 5:c1a19866a233 default/master

Fix some bugs with SMTP settings.
author Sonny Piers <sonny.piers@gmail.com>
date Wed, 15 Jun 2011 07:55:28 +0200
parents 9dd291d1eebe
children 5cf8a08ef7fe
files configuration.js xmpp2smtp.js
diffstat 2 files changed, 18 insertions(+), 25 deletions(-) [+]
line wrap: on
line diff
--- a/configuration.js
+++ b/configuration.js
@@ -12,11 +12,11 @@ config.XMPP = {
 config.SMTP = {
 	host: "smtp.example.com",
 	port: 465,
-	authentication: "login",
-	username: "example(@example.com)",
-	from: "example@example.com",
-	password: "exemple",
-	ssl: true
+	ssl: true,
+	use_authentication: true,
+	user: "example(@example)",
+	pass: "example",
+	sender: "example@example"
 };
 //Enable easy SMTP configuration for user when register to the component (use http://ispdb.mozillamessaging.com/ database)
 config.easySMTPConf = true;
--- a/xmpp2smtp.js
+++ b/xmpp2smtp.js
@@ -63,15 +63,15 @@ cl.on('stanza',
 					else {
 						result.c("x", {type: "form", xmlns: "jabber:x:data"});
 						var fields;
-						data ? fields = JSON.parse(data) : fields = {host:"smtp.example.com",authentication: "login", port:"465", ssl: true, username: "example(@example.com)",password: "example", from: "example@example.com"};
+						data ? fields = JSON.parse(data) : fields = {host:"smtp.example.com",use_authentication: "login", port:"465", ssl: false, user: "example(@example.com)", pass: "example", sender: "example@example.com"};
 						result.c("field", {type: "hidden", "var": "FORM_TYPE"}).c("value").t("jabber:iq:register");
 						result.c("field", {type: "text-single", label: "Host", "var": "host"}).c("required").up().c("value").t(fields.host);
 						result.c("field", {type: "text-single", label: "Port", "var": "port"}).c("required").up().c("value").t(fields.port);
 						result.c("field", {type: "boolean", label: "Enable SSL", "var": "ssl"}).c("required").up().c("value").t(fields.ssl);
-						result.c("field", {type: "list-single", label: "Authentication method", "var": "authentication"}).c("required").up().c("value").t(fields.authentication).up().c("option", {label: "login"}).c("value").t("login").up().up().c("option", {label: "anonymous"}).c("value").t("anonymous");
-						result.c("field", {type: "text-single", label: "Email address", "var": "from"}).c("required").up().c("value").t(fields.from);
-						result.c("field", {type: "text-single", label: "Username", "var": "username"}).c("required").up().c("value").t(fields.username);
-						result.c("field", {type: "text-private", label: "Password", "var": "password"}).c("required").up().c("value").t(fields.password);
+						result.c("field", {type: "boolean", label: "Use authentication", "var": "authentication"}).c("required").up().c("value").t(fields.user_authentication);
+						result.c("field", {type: "text-single", label: "Email address", "var": "sender"}).c("required").up().c("value").t(fields.from);
+						result.c("field", {type: "text-single", label: "Username", "var": "user"}).c("required").up().c("value").t(fields.username);
+						result.c("field", {type: "text-private", label: "Password", "var": "pass"}).c("required").up().c("value").t(fields.password);
 					}
 					cl.send(result);
 				}
@@ -94,13 +94,12 @@ cl.on('stanza',
 						test.port = smtp.port;
 						test.host = smtp.hostname;
 						if(smtp.socketType == "SSL")
-							test.ssl = 1;
-						else
-							test.ssl = 0;
-						test.authentication = "login";
-						test.from = username;
-						test.username = username;
-						test.password = password;
+							test.ssl = true;
+						if((smtp.authentication == "secure") || (smtp.authentication == "plain"))
+							test.use_authentication = true;
+						test.sender = username;
+						test.user = username;
+						test.pass = password;
 					}
 					fs.writeFile(path, JSON.stringify(test), function () {
 						cl.send(new xmpp.Element("iq", {to: stanza.attrs.from, from: config.XMPP.jid, id: stanza.attrs.id, type: "result"}));
@@ -156,16 +155,10 @@ cl.on('stanza',
 				function(err, data) {
 					var settings;
 					data ? settings = JSON.parse(data) : settings = config.SMTP;
-					smtp.SMTP = {
-						host: settings.host,
-						port: settings.port,
-						use_authentication: true,
-						user: settings.username,
-						pass: settings.password
-					}
+					smtp.SMTP = settings;
 					smtp.send_mail(
 						{
-							sender: settings.from, 
+							sender:settings.sender, 
 							to: stanza.attrs.to.split("@")[0].replace("%", "@"),
 							subject: (type == "normal" ? stanza.getChildText("subject") : ""),
 							body: stanza.getChildText("body")