annotate xmpp2smtp.js @ 7:1776fb122b80 default tip master

Aknowlegements.
author Sonny Piers <sonny.piers@gmail.com>
date Mon, 20 Jun 2011 17:07:25 +0200
parents 5cf8a08ef7fe
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
0
e459f344d8bd First commit.
Sonny Piers <sonny.piers@gmail.com>
parents:
diff changeset
1 var os = require('os');
e459f344d8bd First commit.
Sonny Piers <sonny.piers@gmail.com>
parents:
diff changeset
2 var fs = require('fs');
e459f344d8bd First commit.
Sonny Piers <sonny.piers@gmail.com>
parents:
diff changeset
3
e459f344d8bd First commit.
Sonny Piers <sonny.piers@gmail.com>
parents:
diff changeset
4 var xmpp = require('node-xmpp');
e459f344d8bd First commit.
Sonny Piers <sonny.piers@gmail.com>
parents:
diff changeset
5 var ispdb = require('./node-ispdb');
e459f344d8bd First commit.
Sonny Piers <sonny.piers@gmail.com>
parents:
diff changeset
6 var smtp = require("./Nodemailer/lib/mail");
e459f344d8bd First commit.
Sonny Piers <sonny.piers@gmail.com>
parents:
diff changeset
7
e459f344d8bd First commit.
Sonny Piers <sonny.piers@gmail.com>
parents:
diff changeset
8 var config = require("./configuration");
e459f344d8bd First commit.
Sonny Piers <sonny.piers@gmail.com>
parents:
diff changeset
9
e459f344d8bd First commit.
Sonny Piers <sonny.piers@gmail.com>
parents:
diff changeset
10 var info = [];
e459f344d8bd First commit.
Sonny Piers <sonny.piers@gmail.com>
parents:
diff changeset
11 //~ info.push(new xmpp.Element("feature", {"var": "http://jabber.org/protocol/caps"}));
e459f344d8bd First commit.
Sonny Piers <sonny.piers@gmail.com>
parents:
diff changeset
12 //~ info.push(new xmpp.Element("feature", {"var": "http://jabber.org/protocol/commands"}));
e459f344d8bd First commit.
Sonny Piers <sonny.piers@gmail.com>
parents:
diff changeset
13 info.push(new xmpp.Element("feature", {"var": "http://jabber.org/protocol/disco#info"}));
e459f344d8bd First commit.
Sonny Piers <sonny.piers@gmail.com>
parents:
diff changeset
14 info.push(new xmpp.Element("feature", {"var": "jabber:iq:register"}));
e459f344d8bd First commit.
Sonny Piers <sonny.piers@gmail.com>
parents:
diff changeset
15 info.push(new xmpp.Element("feature", {"var": "jabber:iq:version"}));
6
5cf8a08ef7fe Fix errors in disco#info.
Sonny Piers <sonny.piers@gmail.com>
parents: 5
diff changeset
16 info.push(new xmpp.Element("feature", {"var": "jabber:iq:gateway"}));
5cf8a08ef7fe Fix errors in disco#info.
Sonny Piers <sonny.piers@gmail.com>
parents: 5
diff changeset
17 info.push(new xmpp.Element("identity", {category: "gateway", type: "smtp", name: config.XMPP.name}));
0
e459f344d8bd First commit.
Sonny Piers <sonny.piers@gmail.com>
parents:
diff changeset
18
e459f344d8bd First commit.
Sonny Piers <sonny.piers@gmail.com>
parents:
diff changeset
19 var cl = new xmpp.Component({
e459f344d8bd First commit.
Sonny Piers <sonny.piers@gmail.com>
parents:
diff changeset
20 jid: config.XMPP.jid,
e459f344d8bd First commit.
Sonny Piers <sonny.piers@gmail.com>
parents:
diff changeset
21 password: config.XMPP.password,
e459f344d8bd First commit.
Sonny Piers <sonny.piers@gmail.com>
parents:
diff changeset
22 host: config.XMPP.host,
e459f344d8bd First commit.
Sonny Piers <sonny.piers@gmail.com>
parents:
diff changeset
23 port: config.XMPP.port
e459f344d8bd First commit.
Sonny Piers <sonny.piers@gmail.com>
parents:
diff changeset
24 });
e459f344d8bd First commit.
Sonny Piers <sonny.piers@gmail.com>
parents:
diff changeset
25
e459f344d8bd First commit.
Sonny Piers <sonny.piers@gmail.com>
parents:
diff changeset
26 cl.on('stanza',
e459f344d8bd First commit.
Sonny Piers <sonny.piers@gmail.com>
parents:
diff changeset
27 function(stanza) {
e459f344d8bd First commit.
Sonny Piers <sonny.piers@gmail.com>
parents:
diff changeset
28 var type = stanza.attrs.type;
e459f344d8bd First commit.
Sonny Piers <sonny.piers@gmail.com>
parents:
diff changeset
29 //jabber:iq:register remove
e459f344d8bd First commit.
Sonny Piers <sonny.piers@gmail.com>
parents:
diff changeset
30 if((stanza.is("iq")) && (type == "set") && (stanza.getChild("query", "jabber:iq:register")) && (stanza.getChild("query").getChild("remove"))) {
e459f344d8bd First commit.
Sonny Piers <sonny.piers@gmail.com>
parents:
diff changeset
31 fs.unlink("storage/"+stanza.attrs['from'].split("/")[0],
e459f344d8bd First commit.
Sonny Piers <sonny.piers@gmail.com>
parents:
diff changeset
32 function() {
e459f344d8bd First commit.
Sonny Piers <sonny.piers@gmail.com>
parents:
diff changeset
33 cl.send(new xmpp.Element(
e459f344d8bd First commit.
Sonny Piers <sonny.piers@gmail.com>
parents:
diff changeset
34 "iq", {
e459f344d8bd First commit.
Sonny Piers <sonny.piers@gmail.com>
parents:
diff changeset
35 id: stanza.attrs.id,
e459f344d8bd First commit.
Sonny Piers <sonny.piers@gmail.com>
parents:
diff changeset
36 to: stanza.attrs.from,
e459f344d8bd First commit.
Sonny Piers <sonny.piers@gmail.com>
parents:
diff changeset
37 from: config.XMPP.jid,
e459f344d8bd First commit.
Sonny Piers <sonny.piers@gmail.com>
parents:
diff changeset
38 type: 'result'
e459f344d8bd First commit.
Sonny Piers <sonny.piers@gmail.com>
parents:
diff changeset
39 }
e459f344d8bd First commit.
Sonny Piers <sonny.piers@gmail.com>
parents:
diff changeset
40 ));
e459f344d8bd First commit.
Sonny Piers <sonny.piers@gmail.com>
parents:
diff changeset
41 }
e459f344d8bd First commit.
Sonny Piers <sonny.piers@gmail.com>
parents:
diff changeset
42 );
e459f344d8bd First commit.
Sonny Piers <sonny.piers@gmail.com>
parents:
diff changeset
43 }
e459f344d8bd First commit.
Sonny Piers <sonny.piers@gmail.com>
parents:
diff changeset
44 //jabber:iq:register get
e459f344d8bd First commit.
Sonny Piers <sonny.piers@gmail.com>
parents:
diff changeset
45 else if((stanza.is("iq")) && (type == "get") && (stanza.getChild("query", "jabber:iq:register"))) {
e459f344d8bd First commit.
Sonny Piers <sonny.piers@gmail.com>
parents:
diff changeset
46 var result = new xmpp.Element(
e459f344d8bd First commit.
Sonny Piers <sonny.piers@gmail.com>
parents:
diff changeset
47 "iq", {
e459f344d8bd First commit.
Sonny Piers <sonny.piers@gmail.com>
parents:
diff changeset
48 id: stanza.attrs.id,
e459f344d8bd First commit.
Sonny Piers <sonny.piers@gmail.com>
parents:
diff changeset
49 to: stanza.attrs.from,
e459f344d8bd First commit.
Sonny Piers <sonny.piers@gmail.com>
parents:
diff changeset
50 from: config.XMPP.jid,
e459f344d8bd First commit.
Sonny Piers <sonny.piers@gmail.com>
parents:
diff changeset
51 type: 'result'
e459f344d8bd First commit.
Sonny Piers <sonny.piers@gmail.com>
parents:
diff changeset
52 }
e459f344d8bd First commit.
Sonny Piers <sonny.piers@gmail.com>
parents:
diff changeset
53 )
e459f344d8bd First commit.
Sonny Piers <sonny.piers@gmail.com>
parents:
diff changeset
54 .c("query", {xmlns: "jabber:iq:register"});
e459f344d8bd First commit.
Sonny Piers <sonny.piers@gmail.com>
parents:
diff changeset
55
e459f344d8bd First commit.
Sonny Piers <sonny.piers@gmail.com>
parents:
diff changeset
56
e459f344d8bd First commit.
Sonny Piers <sonny.piers@gmail.com>
parents:
diff changeset
57 fs.readFile("storage/"+stanza.attrs['from'].split("/")[0],
e459f344d8bd First commit.
Sonny Piers <sonny.piers@gmail.com>
parents:
diff changeset
58 function(err, data) {
e459f344d8bd First commit.
Sonny Piers <sonny.piers@gmail.com>
parents:
diff changeset
59 if(config.easySMTPConf && ispdb) {
e459f344d8bd First commit.
Sonny Piers <sonny.piers@gmail.com>
parents:
diff changeset
60 result.c("instructions").t("Please enter your email and password, we will try to find the SMTP configuration for you.");
e459f344d8bd First commit.
Sonny Piers <sonny.piers@gmail.com>
parents:
diff changeset
61 result.c("username");
e459f344d8bd First commit.
Sonny Piers <sonny.piers@gmail.com>
parents:
diff changeset
62 result.c("password");
e459f344d8bd First commit.
Sonny Piers <sonny.piers@gmail.com>
parents:
diff changeset
63 }
e459f344d8bd First commit.
Sonny Piers <sonny.piers@gmail.com>
parents:
diff changeset
64 else {
e459f344d8bd First commit.
Sonny Piers <sonny.piers@gmail.com>
parents:
diff changeset
65 result.c("x", {type: "form", xmlns: "jabber:x:data"});
e459f344d8bd First commit.
Sonny Piers <sonny.piers@gmail.com>
parents:
diff changeset
66 var fields;
5
c1a19866a233 Fix some bugs with SMTP settings.
Sonny Piers <sonny.piers@gmail.com>
parents: 0
diff changeset
67 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"};
0
e459f344d8bd First commit.
Sonny Piers <sonny.piers@gmail.com>
parents:
diff changeset
68 result.c("field", {type: "hidden", "var": "FORM_TYPE"}).c("value").t("jabber:iq:register");
e459f344d8bd First commit.
Sonny Piers <sonny.piers@gmail.com>
parents:
diff changeset
69 result.c("field", {type: "text-single", label: "Host", "var": "host"}).c("required").up().c("value").t(fields.host);
e459f344d8bd First commit.
Sonny Piers <sonny.piers@gmail.com>
parents:
diff changeset
70 result.c("field", {type: "text-single", label: "Port", "var": "port"}).c("required").up().c("value").t(fields.port);
e459f344d8bd First commit.
Sonny Piers <sonny.piers@gmail.com>
parents:
diff changeset
71 result.c("field", {type: "boolean", label: "Enable SSL", "var": "ssl"}).c("required").up().c("value").t(fields.ssl);
5
c1a19866a233 Fix some bugs with SMTP settings.
Sonny Piers <sonny.piers@gmail.com>
parents: 0
diff changeset
72 result.c("field", {type: "boolean", label: "Use authentication", "var": "authentication"}).c("required").up().c("value").t(fields.user_authentication);
c1a19866a233 Fix some bugs with SMTP settings.
Sonny Piers <sonny.piers@gmail.com>
parents: 0
diff changeset
73 result.c("field", {type: "text-single", label: "Email address", "var": "sender"}).c("required").up().c("value").t(fields.from);
c1a19866a233 Fix some bugs with SMTP settings.
Sonny Piers <sonny.piers@gmail.com>
parents: 0
diff changeset
74 result.c("field", {type: "text-single", label: "Username", "var": "user"}).c("required").up().c("value").t(fields.username);
c1a19866a233 Fix some bugs with SMTP settings.
Sonny Piers <sonny.piers@gmail.com>
parents: 0
diff changeset
75 result.c("field", {type: "text-private", label: "Password", "var": "pass"}).c("required").up().c("value").t(fields.password);
0
e459f344d8bd First commit.
Sonny Piers <sonny.piers@gmail.com>
parents:
diff changeset
76 }
e459f344d8bd First commit.
Sonny Piers <sonny.piers@gmail.com>
parents:
diff changeset
77 cl.send(result);
e459f344d8bd First commit.
Sonny Piers <sonny.piers@gmail.com>
parents:
diff changeset
78 }
e459f344d8bd First commit.
Sonny Piers <sonny.piers@gmail.com>
parents:
diff changeset
79 );
e459f344d8bd First commit.
Sonny Piers <sonny.piers@gmail.com>
parents:
diff changeset
80 }
e459f344d8bd First commit.
Sonny Piers <sonny.piers@gmail.com>
parents:
diff changeset
81 //jabber:iq:register set
e459f344d8bd First commit.
Sonny Piers <sonny.piers@gmail.com>
parents:
diff changeset
82 else if((stanza.is("iq")) && (type == "set") && (stanza.getChild("query", "jabber:iq:register"))) {
e459f344d8bd First commit.
Sonny Piers <sonny.piers@gmail.com>
parents:
diff changeset
83 var test = {};
e459f344d8bd First commit.
Sonny Piers <sonny.piers@gmail.com>
parents:
diff changeset
84 var path = "storage/"+stanza.attrs["from"].split("/")[0];
e459f344d8bd First commit.
Sonny Piers <sonny.piers@gmail.com>
parents:
diff changeset
85 //easySMTPConfig :)
e459f344d8bd First commit.
Sonny Piers <sonny.piers@gmail.com>
parents:
diff changeset
86 if(stanza.getChild("query").getChild("username")) {
e459f344d8bd First commit.
Sonny Piers <sonny.piers@gmail.com>
parents:
diff changeset
87 var username = stanza.getChild("query").getChild("username").getText();
e459f344d8bd First commit.
Sonny Piers <sonny.piers@gmail.com>
parents:
diff changeset
88 var password = stanza.getChild("query").getChild("password").getText();
e459f344d8bd First commit.
Sonny Piers <sonny.piers@gmail.com>
parents:
diff changeset
89 ispdb.get(username.split("@")[1], function(data) {
e459f344d8bd First commit.
Sonny Piers <sonny.piers@gmail.com>
parents:
diff changeset
90 if(data == null) {
e459f344d8bd First commit.
Sonny Piers <sonny.piers@gmail.com>
parents:
diff changeset
91 cl.send(new xmpp.Element("iq", {to: stanza.attrs.from, from: config.XMPP.jid, id: stanza.attrs.id, type: "error"}));
e459f344d8bd First commit.
Sonny Piers <sonny.piers@gmail.com>
parents:
diff changeset
92 }
e459f344d8bd First commit.
Sonny Piers <sonny.piers@gmail.com>
parents:
diff changeset
93 else {
e459f344d8bd First commit.
Sonny Piers <sonny.piers@gmail.com>
parents:
diff changeset
94 var smtp = data.outgoing;
e459f344d8bd First commit.
Sonny Piers <sonny.piers@gmail.com>
parents:
diff changeset
95 test.port = smtp.port;
e459f344d8bd First commit.
Sonny Piers <sonny.piers@gmail.com>
parents:
diff changeset
96 test.host = smtp.hostname;
e459f344d8bd First commit.
Sonny Piers <sonny.piers@gmail.com>
parents:
diff changeset
97 if(smtp.socketType == "SSL")
5
c1a19866a233 Fix some bugs with SMTP settings.
Sonny Piers <sonny.piers@gmail.com>
parents: 0
diff changeset
98 test.ssl = true;
c1a19866a233 Fix some bugs with SMTP settings.
Sonny Piers <sonny.piers@gmail.com>
parents: 0
diff changeset
99 if((smtp.authentication == "secure") || (smtp.authentication == "plain"))
c1a19866a233 Fix some bugs with SMTP settings.
Sonny Piers <sonny.piers@gmail.com>
parents: 0
diff changeset
100 test.use_authentication = true;
c1a19866a233 Fix some bugs with SMTP settings.
Sonny Piers <sonny.piers@gmail.com>
parents: 0
diff changeset
101 test.sender = username;
c1a19866a233 Fix some bugs with SMTP settings.
Sonny Piers <sonny.piers@gmail.com>
parents: 0
diff changeset
102 test.user = username;
c1a19866a233 Fix some bugs with SMTP settings.
Sonny Piers <sonny.piers@gmail.com>
parents: 0
diff changeset
103 test.pass = password;
0
e459f344d8bd First commit.
Sonny Piers <sonny.piers@gmail.com>
parents:
diff changeset
104 }
e459f344d8bd First commit.
Sonny Piers <sonny.piers@gmail.com>
parents:
diff changeset
105 fs.writeFile(path, JSON.stringify(test), function () {
e459f344d8bd First commit.
Sonny Piers <sonny.piers@gmail.com>
parents:
diff changeset
106 cl.send(new xmpp.Element("iq", {to: stanza.attrs.from, from: config.XMPP.jid, id: stanza.attrs.id, type: "result"}));
e459f344d8bd First commit.
Sonny Piers <sonny.piers@gmail.com>
parents:
diff changeset
107 });
e459f344d8bd First commit.
Sonny Piers <sonny.piers@gmail.com>
parents:
diff changeset
108 });
e459f344d8bd First commit.
Sonny Piers <sonny.piers@gmail.com>
parents:
diff changeset
109
e459f344d8bd First commit.
Sonny Piers <sonny.piers@gmail.com>
parents:
diff changeset
110 }
e459f344d8bd First commit.
Sonny Piers <sonny.piers@gmail.com>
parents:
diff changeset
111 //not easy
e459f344d8bd First commit.
Sonny Piers <sonny.piers@gmail.com>
parents:
diff changeset
112 else {
e459f344d8bd First commit.
Sonny Piers <sonny.piers@gmail.com>
parents:
diff changeset
113 var fields = stanza.getChild("query").getChild("x").getChildren("field");
e459f344d8bd First commit.
Sonny Piers <sonny.piers@gmail.com>
parents:
diff changeset
114 for (var i=0;i<fields.length;i++) {
e459f344d8bd First commit.
Sonny Piers <sonny.piers@gmail.com>
parents:
diff changeset
115 if(fields[i].attrs["var"] != "FORM_TYPE")
e459f344d8bd First commit.
Sonny Piers <sonny.piers@gmail.com>
parents:
diff changeset
116 test[fields[i].attrs["var"]] = fields[i].getChild("value").getText();
e459f344d8bd First commit.
Sonny Piers <sonny.piers@gmail.com>
parents:
diff changeset
117 }
e459f344d8bd First commit.
Sonny Piers <sonny.piers@gmail.com>
parents:
diff changeset
118 fs.writeFile(path, JSON.stringify(test), function () {
e459f344d8bd First commit.
Sonny Piers <sonny.piers@gmail.com>
parents:
diff changeset
119 cl.send(new xmpp.Element("iq", {to: stanza.attrs.from, from: config.XMPP.jid, id: stanza.attrs.id, type: "result"}));
e459f344d8bd First commit.
Sonny Piers <sonny.piers@gmail.com>
parents:
diff changeset
120 });
e459f344d8bd First commit.
Sonny Piers <sonny.piers@gmail.com>
parents:
diff changeset
121 }
e459f344d8bd First commit.
Sonny Piers <sonny.piers@gmail.com>
parents:
diff changeset
122 }
e459f344d8bd First commit.
Sonny Piers <sonny.piers@gmail.com>
parents:
diff changeset
123 //jabber:iq:version
e459f344d8bd First commit.
Sonny Piers <sonny.piers@gmail.com>
parents:
diff changeset
124 else if((stanza.is("iq")) && (type == "get") && (stanza.getChild("query", "jabber:iq:version"))) {
e459f344d8bd First commit.
Sonny Piers <sonny.piers@gmail.com>
parents:
diff changeset
125 var result = new xmpp.Element(
e459f344d8bd First commit.
Sonny Piers <sonny.piers@gmail.com>
parents:
diff changeset
126 "iq", {
e459f344d8bd First commit.
Sonny Piers <sonny.piers@gmail.com>
parents:
diff changeset
127 to: stanza.attrs.from,
e459f344d8bd First commit.
Sonny Piers <sonny.piers@gmail.com>
parents:
diff changeset
128 from: config.XMPP.jid,
e459f344d8bd First commit.
Sonny Piers <sonny.piers@gmail.com>
parents:
diff changeset
129 id: stanza.attrs.id,
e459f344d8bd First commit.
Sonny Piers <sonny.piers@gmail.com>
parents:
diff changeset
130 type: 'result'
e459f344d8bd First commit.
Sonny Piers <sonny.piers@gmail.com>
parents:
diff changeset
131 }
e459f344d8bd First commit.
Sonny Piers <sonny.piers@gmail.com>
parents:
diff changeset
132 ).c("query", {xmlns: "jabber:iq:version"})
e459f344d8bd First commit.
Sonny Piers <sonny.piers@gmail.com>
parents:
diff changeset
133 stanza.c("name").t("xmpp2smtp");
e459f344d8bd First commit.
Sonny Piers <sonny.piers@gmail.com>
parents:
diff changeset
134 stanza.c("version").t("0.1");
e459f344d8bd First commit.
Sonny Piers <sonny.piers@gmail.com>
parents:
diff changeset
135 stanza.c("os").t(os.type()+" "+os.release());
e459f344d8bd First commit.
Sonny Piers <sonny.piers@gmail.com>
parents:
diff changeset
136 cl.send(result);
e459f344d8bd First commit.
Sonny Piers <sonny.piers@gmail.com>
parents:
diff changeset
137 }
e459f344d8bd First commit.
Sonny Piers <sonny.piers@gmail.com>
parents:
diff changeset
138 //disco#info
e459f344d8bd First commit.
Sonny Piers <sonny.piers@gmail.com>
parents:
diff changeset
139 else if((stanza.is("iq")) && (type == "get") && (stanza.getChild("query", "http://jabber.org/protocol/disco#info"))) {
e459f344d8bd First commit.
Sonny Piers <sonny.piers@gmail.com>
parents:
diff changeset
140 var stanza = new xmpp.Element(
e459f344d8bd First commit.
Sonny Piers <sonny.piers@gmail.com>
parents:
diff changeset
141 'iq', {
e459f344d8bd First commit.
Sonny Piers <sonny.piers@gmail.com>
parents:
diff changeset
142 to: stanza.attrs.from,
e459f344d8bd First commit.
Sonny Piers <sonny.piers@gmail.com>
parents:
diff changeset
143 from: config.XMPP.jid,
e459f344d8bd First commit.
Sonny Piers <sonny.piers@gmail.com>
parents:
diff changeset
144 id: stanza.attrs.id,
e459f344d8bd First commit.
Sonny Piers <sonny.piers@gmail.com>
parents:
diff changeset
145 type: 'result'
e459f344d8bd First commit.
Sonny Piers <sonny.piers@gmail.com>
parents:
diff changeset
146 }
e459f344d8bd First commit.
Sonny Piers <sonny.piers@gmail.com>
parents:
diff changeset
147 );
e459f344d8bd First commit.
Sonny Piers <sonny.piers@gmail.com>
parents:
diff changeset
148 for(var i=0;i<info.length;i++) {
e459f344d8bd First commit.
Sonny Piers <sonny.piers@gmail.com>
parents:
diff changeset
149 stanza.cnode(info[i]);
e459f344d8bd First commit.
Sonny Piers <sonny.piers@gmail.com>
parents:
diff changeset
150 }
e459f344d8bd First commit.
Sonny Piers <sonny.piers@gmail.com>
parents:
diff changeset
151 cl.send(stanza);
e459f344d8bd First commit.
Sonny Piers <sonny.piers@gmail.com>
parents:
diff changeset
152 }
e459f344d8bd First commit.
Sonny Piers <sonny.piers@gmail.com>
parents:
diff changeset
153 //message
e459f344d8bd First commit.
Sonny Piers <sonny.piers@gmail.com>
parents:
diff changeset
154 else if (stanza.is('message') && (type == 'chat')||(type == 'normal')) {
e459f344d8bd First commit.
Sonny Piers <sonny.piers@gmail.com>
parents:
diff changeset
155 fs.readFile("storage/"+stanza.attrs['from'].split("/")[0],
e459f344d8bd First commit.
Sonny Piers <sonny.piers@gmail.com>
parents:
diff changeset
156 function(err, data) {
e459f344d8bd First commit.
Sonny Piers <sonny.piers@gmail.com>
parents:
diff changeset
157 var settings;
e459f344d8bd First commit.
Sonny Piers <sonny.piers@gmail.com>
parents:
diff changeset
158 data ? settings = JSON.parse(data) : settings = config.SMTP;
5
c1a19866a233 Fix some bugs with SMTP settings.
Sonny Piers <sonny.piers@gmail.com>
parents: 0
diff changeset
159 smtp.SMTP = settings;
0
e459f344d8bd First commit.
Sonny Piers <sonny.piers@gmail.com>
parents:
diff changeset
160 smtp.send_mail(
e459f344d8bd First commit.
Sonny Piers <sonny.piers@gmail.com>
parents:
diff changeset
161 {
5
c1a19866a233 Fix some bugs with SMTP settings.
Sonny Piers <sonny.piers@gmail.com>
parents: 0
diff changeset
162 sender:settings.sender,
0
e459f344d8bd First commit.
Sonny Piers <sonny.piers@gmail.com>
parents:
diff changeset
163 to: stanza.attrs.to.split("@")[0].replace("%", "@"),
e459f344d8bd First commit.
Sonny Piers <sonny.piers@gmail.com>
parents:
diff changeset
164 subject: (type == "normal" ? stanza.getChildText("subject") : ""),
e459f344d8bd First commit.
Sonny Piers <sonny.piers@gmail.com>
parents:
diff changeset
165 body: stanza.getChildText("body")
e459f344d8bd First commit.
Sonny Piers <sonny.piers@gmail.com>
parents:
diff changeset
166 },
e459f344d8bd First commit.
Sonny Piers <sonny.piers@gmail.com>
parents:
diff changeset
167 function(error, success){
e459f344d8bd First commit.
Sonny Piers <sonny.piers@gmail.com>
parents:
diff changeset
168 if(error) {
e459f344d8bd First commit.
Sonny Piers <sonny.piers@gmail.com>
parents:
diff changeset
169 cl.send(new xmpp.Element('message', {type: stanza.attrs.type, to: stanza.attrs.from, from: config.XMPP.jid}).c("body").t("Sorry we haven't been able to deliver the mail, check your settings."));
e459f344d8bd First commit.
Sonny Piers <sonny.piers@gmail.com>
parents:
diff changeset
170 }
e459f344d8bd First commit.
Sonny Piers <sonny.piers@gmail.com>
parents:
diff changeset
171 }
e459f344d8bd First commit.
Sonny Piers <sonny.piers@gmail.com>
parents:
diff changeset
172 );
e459f344d8bd First commit.
Sonny Piers <sonny.piers@gmail.com>
parents:
diff changeset
173 }
e459f344d8bd First commit.
Sonny Piers <sonny.piers@gmail.com>
parents:
diff changeset
174 );
e459f344d8bd First commit.
Sonny Piers <sonny.piers@gmail.com>
parents:
diff changeset
175 }
e459f344d8bd First commit.
Sonny Piers <sonny.piers@gmail.com>
parents:
diff changeset
176 }
e459f344d8bd First commit.
Sonny Piers <sonny.piers@gmail.com>
parents:
diff changeset
177 );
e459f344d8bd First commit.
Sonny Piers <sonny.piers@gmail.com>
parents:
diff changeset
178 cl.on('error',
e459f344d8bd First commit.
Sonny Piers <sonny.piers@gmail.com>
parents:
diff changeset
179 function(e) {
e459f344d8bd First commit.
Sonny Piers <sonny.piers@gmail.com>
parents:
diff changeset
180 console.log(e);
e459f344d8bd First commit.
Sonny Piers <sonny.piers@gmail.com>
parents:
diff changeset
181 }
e459f344d8bd First commit.
Sonny Piers <sonny.piers@gmail.com>
parents:
diff changeset
182 );
e459f344d8bd First commit.
Sonny Piers <sonny.piers@gmail.com>
parents:
diff changeset
183