comparison 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
comparison
equal deleted inserted replaced
4:9dd291d1eebe 5:c1a19866a233
61 result.c("password"); 61 result.c("password");
62 } 62 }
63 else { 63 else {
64 result.c("x", {type: "form", xmlns: "jabber:x:data"}); 64 result.c("x", {type: "form", xmlns: "jabber:x:data"});
65 var fields; 65 var fields;
66 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"}; 66 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"};
67 result.c("field", {type: "hidden", "var": "FORM_TYPE"}).c("value").t("jabber:iq:register"); 67 result.c("field", {type: "hidden", "var": "FORM_TYPE"}).c("value").t("jabber:iq:register");
68 result.c("field", {type: "text-single", label: "Host", "var": "host"}).c("required").up().c("value").t(fields.host); 68 result.c("field", {type: "text-single", label: "Host", "var": "host"}).c("required").up().c("value").t(fields.host);
69 result.c("field", {type: "text-single", label: "Port", "var": "port"}).c("required").up().c("value").t(fields.port); 69 result.c("field", {type: "text-single", label: "Port", "var": "port"}).c("required").up().c("value").t(fields.port);
70 result.c("field", {type: "boolean", label: "Enable SSL", "var": "ssl"}).c("required").up().c("value").t(fields.ssl); 70 result.c("field", {type: "boolean", label: "Enable SSL", "var": "ssl"}).c("required").up().c("value").t(fields.ssl);
71 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"); 71 result.c("field", {type: "boolean", label: "Use authentication", "var": "authentication"}).c("required").up().c("value").t(fields.user_authentication);
72 result.c("field", {type: "text-single", label: "Email address", "var": "from"}).c("required").up().c("value").t(fields.from); 72 result.c("field", {type: "text-single", label: "Email address", "var": "sender"}).c("required").up().c("value").t(fields.from);
73 result.c("field", {type: "text-single", label: "Username", "var": "username"}).c("required").up().c("value").t(fields.username); 73 result.c("field", {type: "text-single", label: "Username", "var": "user"}).c("required").up().c("value").t(fields.username);
74 result.c("field", {type: "text-private", label: "Password", "var": "password"}).c("required").up().c("value").t(fields.password); 74 result.c("field", {type: "text-private", label: "Password", "var": "pass"}).c("required").up().c("value").t(fields.password);
75 } 75 }
76 cl.send(result); 76 cl.send(result);
77 } 77 }
78 ); 78 );
79 } 79 }
92 else { 92 else {
93 var smtp = data.outgoing; 93 var smtp = data.outgoing;
94 test.port = smtp.port; 94 test.port = smtp.port;
95 test.host = smtp.hostname; 95 test.host = smtp.hostname;
96 if(smtp.socketType == "SSL") 96 if(smtp.socketType == "SSL")
97 test.ssl = 1; 97 test.ssl = true;
98 else 98 if((smtp.authentication == "secure") || (smtp.authentication == "plain"))
99 test.ssl = 0; 99 test.use_authentication = true;
100 test.authentication = "login"; 100 test.sender = username;
101 test.from = username; 101 test.user = username;
102 test.username = username; 102 test.pass = password;
103 test.password = password;
104 } 103 }
105 fs.writeFile(path, JSON.stringify(test), function () { 104 fs.writeFile(path, JSON.stringify(test), function () {
106 cl.send(new xmpp.Element("iq", {to: stanza.attrs.from, from: config.XMPP.jid, id: stanza.attrs.id, type: "result"})); 105 cl.send(new xmpp.Element("iq", {to: stanza.attrs.from, from: config.XMPP.jid, id: stanza.attrs.id, type: "result"}));
107 }); 106 });
108 }); 107 });
154 else if (stanza.is('message') && (type == 'chat')||(type == 'normal')) { 153 else if (stanza.is('message') && (type == 'chat')||(type == 'normal')) {
155 fs.readFile("storage/"+stanza.attrs['from'].split("/")[0], 154 fs.readFile("storage/"+stanza.attrs['from'].split("/")[0],
156 function(err, data) { 155 function(err, data) {
157 var settings; 156 var settings;
158 data ? settings = JSON.parse(data) : settings = config.SMTP; 157 data ? settings = JSON.parse(data) : settings = config.SMTP;
159 smtp.SMTP = { 158 smtp.SMTP = settings;
160 host: settings.host,
161 port: settings.port,
162 use_authentication: true,
163 user: settings.username,
164 pass: settings.password
165 }
166 smtp.send_mail( 159 smtp.send_mail(
167 { 160 {
168 sender: settings.from, 161 sender:settings.sender,
169 to: stanza.attrs.to.split("@")[0].replace("%", "@"), 162 to: stanza.attrs.to.split("@")[0].replace("%", "@"),
170 subject: (type == "normal" ? stanza.getChildText("subject") : ""), 163 subject: (type == "normal" ? stanza.getChildText("subject") : ""),
171 body: stanza.getChildText("body") 164 body: stanza.getChildText("body")
172 }, 165 },
173 function(error, success){ 166 function(error, success){