diff xmpp2smtp.js @ 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 e459f344d8bd
children 5cf8a08ef7fe
line wrap: on
line diff
--- 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")