Permalink
Browse files

First real working implementation

  • Loading branch information...
baudehlo committed Mar 12, 2011
1 parent 023cd9b commit 7b3a080e55536c874b24d69978cb16e12649c02a
Showing with 1,079 additions and 0 deletions.
  1. +8 −0 README
  2. +32 −0 config.js
  3. +1 −0 config/databytes
  4. +1 −0 config/dnsbl.zones
  5. +3 −0 config/plugins
  6. +1 −0 config/smtp
  7. +111 −0 configfile.js
  8. +527 −0 connection.js
  9. +9 −0 constants.js
  10. +1 −0 haraka.js
  11. +8 −0 logger.js
  12. +139 −0 plugins.js
  13. +42 −0 plugins/dnsbl.js
  14. +13 −0 plugins/relay_all.js
  15. +23 −0 plugins/test_queue.js
  16. +82 −0 rfc1869.js
  17. +46 −0 server.js
  18. +32 −0 transaction.js
View
8 README
@@ -0,0 +1,8 @@
+Haraka - a Node.js Mail Server
+==============================
+
+Haraka is a plugin capable SMTP server. It uses a highly scalable event
+model to be able to cope with thousands of concurrent connections. Plugins
+are written in Javascript using Node.js, and as such perform extremely
+quickly.
+
View
@@ -0,0 +1,32 @@
+var configloader = require('./configfile');
+var path = require('path');
+var logger = require('./logger');
+
+var config = exports;
+
+var config_path = process.env.HARAKA ? path.join(process.env.HARAKA, 'config') : './config';
+
+config.get = function(name, type) {
+ var full_path = path.resolve(config_path, name);
+
+ logger.log("Loading config file: " + full_path);
+ var results;
+ try {
+ results = configloader.read_config(full_path, type);
+ }
+ catch (err) {
+ if (err.code === 'EBADF') {
+ // do nothing
+ if (type === 'ini') {
+ return configloader.empty_config(type);
+ }
+ else {
+ return null;
+ }
+ }
+ else {
+ console.log(err.name + ': ' + err.message);
+ }
+ }
+ return results;
+};
View
@@ -0,0 +1 @@
+500000
View
@@ -0,0 +1 @@
+zen.spamhaus.org
View
@@ -0,0 +1,3 @@
+dnsbl
+relay_all
+test_queue
View
@@ -0,0 +1 @@
+port=3000
View
@@ -0,0 +1,111 @@
+// Config file loader
+
+var fs = require('fs');
+
+// for "ini" type files
+var regex = {
+ section: /^\s*\[\s*([^\]]*)\s*\]\s*$/,
+ param: /^\s*(\w+)\s*=\s*(.*)\s*$/,
+ comment: /^\s*[;#].*$/,
+ line: /^\s*(.*)\s*$/,
+ blank: /^\s*$/
+};
+
+var cfreader = exports;
+
+cfreader._config_cache = {};
+
+cfreader.read_config = function(name, type) {
+ // Check cache first
+ if (cfreader._config_cache[name]) {
+ return cfreader._config_cache[name];
+ }
+
+
+ // load config file
+ var result = cfreader.load_config(name, type);
+
+ fs.unwatchFile(name);
+ fs.watchFile(name, function (curr, prev) {
+ // file has changed
+ if (curr.mtime.getTime() !== prev.mtime.getTime()) {
+ cfreader.load_config(name, type);
+ }
+ });
+
+ return result;
+}
+
+cfreader.empty_config = function(type) {
+ if (type === 'ini') {
+ return { main: {} };
+ }
+ else {
+ return [];
+ }
+};
+
+cfreader.load_config = function(name, type) {
+
+ if (type === 'ini') {
+ result = cfreader.load_ini_config(name);
+ }
+ else {
+ result = cfreader.load_flat_config(name);
+ }
+
+ cfreader._config_cache[name] = result;
+
+ return result;
+};
+
+cfreader.load_ini_config = function(name) {
+ var result = cfreader.empty_config('ini');
+ var current_sect = result.main;
+
+ var data = new String(fs.readFileSync(name));
+ var lines = data.split(/\r\n|\r|\n/);
+
+ lines.forEach( function(line) {
+ if (regex.comment.test(line)) {
+ return;
+ }
+ else if (regex.blank.test(line)) {
+ return;
+ }
+ else if (regex.param.test(line)) {
+ var match = line.match(regex.param);
+ current_sect[match[1]] = match[2];
+ }
+ else if (regex.section.test(line)) {
+ var match = line.match(regex.section);
+ current_sect = result[match[1]] = {};
+ }
+ else {
+ // error ?
+ };
+ });
+
+ return result;
+};
+
+cfreader.load_flat_config = function(name) {
+ var result = [];
+ var data = new String(fs.readFileSync(name));
+ var lines = data.split(/\r\n|\r|\n/);
+
+ lines.forEach( function(line) {
+ var line_data;
+ if (regex.comment.test(line)) {
+ return;
+ }
+ else if (regex.blank.test(line)) {
+ return;
+ }
+ else if (line_data = regex.line.exec(line)) {
+ result.push(line_data[1]);
+ }
+ });
+
+ return result;
+};
Oops, something went wrong.

0 comments on commit 7b3a080

Please sign in to comment.