annotate xmpp2smtp.js @ 2:1299e2d8497f

Clarify README.
author Sonny Piers <sonny.piers@gmail.com>
date Wed, 15 Jun 2011 06:24:09 +0200
parents e459f344d8bd
children c1a19866a233
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"}));
e459f344d8bd First commit.
Sonny Piers <sonny.piers@gmail.com>
parents:
diff changeset
16 info.push(new xmpp.Element("identity", {category: "gateway", type: "irc", name: config.XMPP.name}));
e459f344d8bd First commit.
Sonny Piers <sonny.piers@gmail.com>
parents:
diff changeset
17
e459f344d8bd First commit.
Sonny Piers <sonny.piers@gmail.com>
parents:
diff changeset
18 var cl = new xmpp.Component({
e459f344d8bd First commit.
Sonny Piers <sonny.piers@gmail.com>
parents:
diff changeset
19 jid: config.XMPP.jid,
e459f344d8bd First commit.
Sonny Piers <sonny.piers@gmail.com>
parents:
diff changeset
20 password: config.XMPP.password,
e459f344d8bd First commit.
Sonny Piers <sonny.piers@gmail.com>
parents:
diff changeset
21 host: config.XMPP.host,
e459f344d8bd First commit.
Sonny Piers <sonny.piers@gmail.com>
parents:
diff changeset
22 port: config.XMPP.port
e459f344d8bd First commit.
Sonny Piers <sonny.piers@gmail.com>
parents:
diff changeset
23 });
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 cl.on('stanza',
e459f344d8bd First commit.
Sonny Piers <sonny.piers@gmail.com>
parents:
diff changeset
26 function(stanza) {
e459f344d8bd First commit.
Sonny Piers <sonny.piers@gmail.com>
parents:
diff changeset
27 var type = stanza.attrs.type;
e459f344d8bd First commit.
Sonny Piers <sonny.piers@gmail.com>
parents:
diff changeset
28 //jabber:iq:register remove
e459f344d8bd First commit.
Sonny Piers <sonny.piers@gmail.com>
parents:
diff changeset
29 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
30 fs.unlink("storage/"+stanza.attrs['from'].split("/")[0],
e459f344d8bd First commit.
Sonny Piers <sonny.piers@gmail.com>
parents:
diff changeset
31 function() {
e459f344d8bd First commit.
Sonny Piers <sonny.piers@gmail.com>
parents:
diff changeset
32 cl.send(new xmpp.Element(
e459f344d8bd First commit.
Sonny Piers <sonny.piers@gmail.com>
parents:
diff changeset
33 "iq", {
e459f344d8bd First commit.
Sonny Piers <sonny.piers@gmail.com>
parents:
diff changeset
34 id: stanza.attrs.id,
e459f344d8bd First commit.
Sonny Piers <sonny.piers@gmail.com>
parents:
diff changeset
35 to: stanza.attrs.from,
e459f344d8bd First commit.
Sonny Piers <sonny.piers@gmail.com>
parents:
diff changeset
36 from: config.XMPP.jid,
e459f344d8bd First commit.
Sonny Piers <sonny.piers@gmail.com>
parents:
diff changeset
37 type: 'result'
e459f344d8bd First commit.
Sonny Piers <sonny.piers@gmail.com>
parents:
diff changeset
38 }
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 //jabber:iq:register get
e459f344d8bd First commit.
Sonny Piers <sonny.piers@gmail.com>
parents:
diff changeset
44 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
45 var result = new xmpp.Element(
e459f344d8bd First commit.
Sonny Piers <sonny.piers@gmail.com>
parents:
diff changeset
46 "iq", {
e459f344d8bd First commit.
Sonny Piers <sonny.piers@gmail.com>
parents:
diff changeset
47 id: stanza.attrs.id,
e459f344d8bd First commit.
Sonny Piers <sonny.piers@gmail.com>
parents:
diff changeset
48 to: stanza.attrs.from,
e459f344d8bd First commit.
Sonny Piers <sonny.piers@gmail.com>
parents:
diff changeset
49 from: config.XMPP.jid,
e459f344d8bd First commit.
Sonny Piers <sonny.piers@gmail.com>
parents:
diff changeset
50 type: 'result'
e459f344d8bd First commit.
Sonny Piers <sonny.piers@gmail.com>
parents:
diff changeset
51 }
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 .c("query", {xmlns: "jabber:iq:register"});
e459f344d8bd First commit.
Sonny Piers <sonny.piers@gmail.com>
parents:
diff changeset
54
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 fs.readFile("storage/"+stanza.attrs['from'].split("/")[0],
e459f344d8bd First commit.
Sonny Piers <sonny.piers@gmail.com>
parents:
diff changeset
57 function(err, data) {
e459f344d8bd First commit.
Sonny Piers <sonny.piers@gmail.com>
parents:
diff changeset
58 if(config.easySMTPConf && ispdb) {
e459f344d8bd First commit.
Sonny Piers <sonny.piers@gmail.com>
parents:
diff changeset
59 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
60 result.c("username");
e459f344d8bd First commit.
Sonny Piers <sonny.piers@gmail.com>
parents:
diff changeset
61 result.c("password");
e459f344d8bd First commit.
Sonny Piers <sonny.piers@gmail.com>
parents:
diff changeset
62 }
e459f344d8bd First commit.
Sonny Piers <sonny.piers@gmail.com>
parents:
diff changeset
63 else {
e459f344d8bd First commit.
Sonny Piers <sonny.piers@gmail.com>
parents:
diff changeset
64 result.c("x", {type: "form", xmlns: "jabber:x:data"});
e459f344d8bd First commit.
Sonny Piers <sonny.piers@gmail.com>
parents:
diff changeset
65 var fields;
e459f344d8bd First commit.
Sonny Piers <sonny.piers@gmail.com>
parents:
diff changeset
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"};
e459f344d8bd First commit.
Sonny Piers <sonny.piers@gmail.com>
parents:
diff changeset
67 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
68 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
69 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
70 result.c("field", {type: "boolean", label: "Enable SSL", "var": "ssl"}).c("required").up().c("value").t(fields.ssl);
e459f344d8bd First commit.
Sonny Piers <sonny.piers@gmail.com>
parents:
diff changeset
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");
e459f344d8bd First commit.
Sonny Piers <sonny.piers@gmail.com>
parents:
diff changeset
72 result.c("field", {type: "text-single", label: "Email address", "var": "from"}).c("required").up().c("value").t(fields.from);
e459f344d8bd First commit.
Sonny Piers <sonny.piers@gmail.com>
parents:
diff changeset
73 result.c("field", {type: "text-single", label: "Username", "var": "username"}).c("required").up().c("value").t(fields.username);
e459f344d8bd First commit.
Sonny Piers <sonny.piers@gmail.com>
parents:
diff changeset
74 result.c("field", {type: "text-private", label: "Password", "var": "password"}).c("required").up().c("value").t(fields.password);
e459f344d8bd First commit.
Sonny Piers <sonny.piers@gmail.com>
parents:
diff changeset
75 }
e459f344d8bd First commit.
Sonny Piers <sonny.piers@gmail.com>
parents:
diff changeset
76 cl.send(result);
e459f344d8bd First commit.
Sonny Piers <sonny.piers@gmail.com>
parents:
diff changeset
77 }
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 //jabber:iq:register set
e459f344d8bd First commit.
Sonny Piers <sonny.piers@gmail.com>
parents:
diff changeset
81 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
82 var test = {};
e459f344d8bd First commit.
Sonny Piers <sonny.piers@gmail.com>
parents:
diff changeset
83 var path = "storage/"+stanza.attrs["from"].split("/")[0];
e459f344d8bd First commit.
Sonny Piers <sonny.piers@gmail.com>
parents:
diff changeset
84 //easySMTPConfig :)
e459f344d8bd First commit.
Sonny Piers <sonny.piers@gmail.com>
parents:
diff changeset
85 if(stanza.getChild("query").getChild("username")) {
e459f344d8bd First commit.
Sonny Piers <sonny.piers@gmail.com>
parents:
diff changeset
86 var username = stanza.getChild("query").getChild("username").getText();
e459f344d8bd First commit.
Sonny Piers <sonny.piers@gmail.com>
parents:
diff changeset
87 var password = stanza.getChild("query").getChild("password").getText();
e459f344d8bd First commit.
Sonny Piers <sonny.piers@gmail.com>
parents:
diff changeset
88 ispdb.get(username.split("@")[1], function(data) {
e459f344d8bd First commit.
Sonny Piers <sonny.piers@gmail.com>
parents:
diff changeset
89 if(data == null) {
e459f344d8bd First commit.
Sonny Piers <sonny.piers@gmail.com>
parents:
diff changeset
90 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
91 }
e459f344d8bd First commit.
Sonny Piers <sonny.piers@gmail.com>
parents:
diff changeset
92 else {
e459f344d8bd First commit.
Sonny Piers <sonny.piers@gmail.com>
parents:
diff changeset
93 var smtp = data.outgoing;
e459f344d8bd First commit.
Sonny Piers <sonny.piers@gmail.com>
parents:
diff changeset
94 test.port = smtp.port;
e459f344d8bd First commit.
Sonny Piers <sonny.piers@gmail.com>
parents:
diff changeset
95 test.host = smtp.hostname;
e459f344d8bd First commit.
Sonny Piers <sonny.piers@gmail.com>
parents:
diff changeset
96 if(smtp.socketType == "SSL")
e459f344d8bd First commit.
Sonny Piers <sonny.piers@gmail.com>
parents:
diff changeset
97 test.ssl = 1;
e459f344d8bd First commit.
Sonny Piers <sonny.piers@gmail.com>
parents:
diff changeset
98 else
e459f344d8bd First commit.
Sonny Piers <sonny.piers@gmail.com>
parents:
diff changeset
99 test.ssl = 0;
e459f344d8bd First commit.
Sonny Piers <sonny.piers@gmail.com>
parents:
diff changeset
100 test.authentication = "login";
e459f344d8bd First commit.
Sonny Piers <sonny.piers@gmail.com>
parents:
diff changeset
101 test.from = username;
e459f344d8bd First commit.
Sonny Piers <sonny.piers@gmail.com>
parents:
diff changeset
102 test.username = username;
e459f344d8bd First commit.
Sonny Piers <sonny.piers@gmail.com>
parents:
diff changeset
103 test.password = password;
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;
e459f344d8bd First commit.
Sonny Piers <sonny.piers@gmail.com>
parents:
diff changeset
159 smtp.SMTP = {
e459f344d8bd First commit.
Sonny Piers <sonny.piers@gmail.com>
parents:
diff changeset
160 host: settings.host,
e459f344d8bd First commit.
Sonny Piers <sonny.piers@gmail.com>
parents:
diff changeset
161 port: settings.port,
e459f344d8bd First commit.
Sonny Piers <sonny.piers@gmail.com>
parents:
diff changeset
162 use_authentication: true,
e459f344d8bd First commit.
Sonny Piers <sonny.piers@gmail.com>
parents:
diff changeset
163 user: settings.username,
e459f344d8bd First commit.
Sonny Piers <sonny.piers@gmail.com>
parents:
diff changeset
164 pass: settings.password
e459f344d8bd First commit.
Sonny Piers <sonny.piers@gmail.com>
parents:
diff changeset
165 }
e459f344d8bd First commit.
Sonny Piers <sonny.piers@gmail.com>
parents:
diff changeset
166 smtp.send_mail(
e459f344d8bd First commit.
Sonny Piers <sonny.piers@gmail.com>
parents:
diff changeset
167 {
e459f344d8bd First commit.
Sonny Piers <sonny.piers@gmail.com>
parents:
diff changeset
168 sender: settings.from,
e459f344d8bd First commit.
Sonny Piers <sonny.piers@gmail.com>
parents:
diff changeset
169 to: stanza.attrs.to.split("@")[0].replace("%", "@"),
e459f344d8bd First commit.
Sonny Piers <sonny.piers@gmail.com>
parents:
diff changeset
170 subject: (type == "normal" ? stanza.getChildText("subject") : ""),
e459f344d8bd First commit.
Sonny Piers <sonny.piers@gmail.com>
parents:
diff changeset
171 body: stanza.getChildText("body")
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 function(error, success){
e459f344d8bd First commit.
Sonny Piers <sonny.piers@gmail.com>
parents:
diff changeset
174 if(error) {
e459f344d8bd First commit.
Sonny Piers <sonny.piers@gmail.com>
parents:
diff changeset
175 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
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 );
e459f344d8bd First commit.
Sonny Piers <sonny.piers@gmail.com>
parents:
diff changeset
179 }
e459f344d8bd First commit.
Sonny Piers <sonny.piers@gmail.com>
parents:
diff changeset
180 );
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 );
e459f344d8bd First commit.
Sonny Piers <sonny.piers@gmail.com>
parents:
diff changeset
184 cl.on('error',
e459f344d8bd First commit.
Sonny Piers <sonny.piers@gmail.com>
parents:
diff changeset
185 function(e) {
e459f344d8bd First commit.
Sonny Piers <sonny.piers@gmail.com>
parents:
diff changeset
186 console.log(e);
e459f344d8bd First commit.
Sonny Piers <sonny.piers@gmail.com>
parents:
diff changeset
187 }
e459f344d8bd First commit.
Sonny Piers <sonny.piers@gmail.com>
parents:
diff changeset
188 );
e459f344d8bd First commit.
Sonny Piers <sonny.piers@gmail.com>
parents:
diff changeset
189