Skip to content

Commit

Permalink
v1.19.0
Browse files Browse the repository at this point in the history
  • Loading branch information
andris9 committed Sep 15, 2016
1 parent 35bce32 commit 0896e9f
Show file tree
Hide file tree
Showing 6 changed files with 124 additions and 18 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG.txt
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
# Changelog

## 1.19.0 2016-09-15

* Changed license from GPL-V3 to MIT

## 1.18.0 2016-09-08

* Updated installation script to bundle ZoneMTA as the default sending engine
Expand Down
28 changes: 14 additions & 14 deletions LICENSE
Original file line number Diff line number Diff line change
@@ -1,16 +1,16 @@
Mailtrain, self hosted email newsletter app
Copyright (C) 2016 Kreata OÜ
Copyright (c) 2016 Andris Reinman

This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.

This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.

You should have received a copy of the GNU General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
3 changes: 2 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -183,4 +183,5 @@ This command generates a CSV file with 100 000 subscriber accounts

## License

**GPL-V3.0**
* Versions 1.19.0 and up: **MIT**
* Up to versions 1.18.0 **GPL-V3.0**
100 changes: 100 additions & 0 deletions lib/models/subscriptions.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ let settings = require('./settings');
let mailer = require('../mailer');
let urllib = require('url');
let log = require('npmlog');
let csvGenerate = require('csv-generate');

module.exports.list = (listId, start, limit, callback) => {
listId = Number(listId) || 0;
Expand Down Expand Up @@ -1115,3 +1116,102 @@ module.exports.listImports = (listId, callback) => {
});
});
};

module.exports.exportList = (listId, request, columns, segmentId, callback) => {
listId = Number(listId) || 0;
segmentId = Number(segmentId) || 0;

if (!listId) {
return callback(new Error('Missing List ID'));
}

let processQuery = queryData => {

db.getConnection((err, connection) => {
if (err) {
return callback(err);
}

let query = 'SELECT COUNT(id) AS total FROM `subscription__' + listId + '`';
let values = [];

if (queryData.where) {
query += ' WHERE ' + queryData.where;
values = values.concat(queryData.values || []);
}

connection.query(query, values, (err, total) => {
if (err) {
connection.release();
return callback(err);
}
total = total && total[0] && total[0].total || 0;

let ordering = [];

if (request.order && request.order.length) {

request.order.forEach(order => {
let orderField = columns[Number(order.column)];
let orderDirection = (order.dir || '').toString().toLowerCase() === 'desc' ? 'DESC' : 'ASC';
if (orderField) {
ordering.push('`' + orderField + '` ' + orderDirection);
}
});
}

if (!ordering.length) {
ordering.push('`email` ASC');
}

let args = [Number(request.length) || 50, Number(request.start) || 0];
let query;


let generator = csvGenerate({
columns: ,
length: 2
});

if (request.search && request.search.value) {
query = 'SELECT SQL_CALC_FOUND_ROWS * FROM `subscription__' + listId + '` WHERE email LIKE ? OR first_name LIKE ? OR last_name LIKE ? ' + (queryData.where ? ' AND (' + queryData.where + ')' : '') + ' ORDER BY ' + ordering.join(', ') + ' LIMIT ? OFFSET ?';

let searchVal = '%' + request.search.value.replace(/\\/g, '\\\\').replace(/([%_])/g, '\\$1') + '%';
args = [searchVal, searchVal, searchVal].concat(queryData.values || []).concat(args);
} else {
query = 'SELECT SQL_CALC_FOUND_ROWS * FROM `subscription__' + listId + '` WHERE 1 ' + (queryData.where ? ' AND (' + queryData.where + ')' : '') + ' ORDER BY ' + ordering.join(', ') + ' LIMIT ? OFFSET ?';
args = [].concat(queryData.values || []).concat(args);
}

connection.query(query, args, (err, rows) => {
if (err) {
connection.release();
return callback(err);
}
connection.query('SELECT FOUND_ROWS() AS total', (err, filteredTotal) => {
connection.release();
if (err) {
return callback(err);
}

let subscriptions = rows.map(row => tools.convertKeys(row));

filteredTotal = filteredTotal && filteredTotal[0] && filteredTotal[0].total || 0;
return callback(null, subscriptions, total, filteredTotal);
});
});
});
});
};

if (segmentId) {
segments.getQuery(segmentId, false, (err, queryData) => {
if (err) {
return callback(err);
}
processQuery(queryData);
});
} else {
processQuery(false);
}
};
5 changes: 3 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "mailtrain",
"private": true,
"version": "1.18.0",
"version": "1.19.0",
"description": "Self hosted email newsletter app",
"main": "index.js",
"scripts": {
Expand All @@ -17,7 +17,7 @@
"url": "git://github.com/andris9/mailtrain.git"
},
"author": "Andris Reinman",
"license": "GPL-3.0",
"license": "MIT",
"homepage": "http://mailtrain.org",
"engines": {
"node": ">=5.0.0"
Expand All @@ -38,6 +38,7 @@
"connect-redis": "^3.1.0",
"cookie-parser": "^1.4.3",
"csurf": "^1.9.0",
"csv-generate": "^1.0.0",
"csv-parse": "^1.1.7",
"escape-html": "^1.0.3",
"express": "^4.14.0",
Expand Down
2 changes: 1 addition & 1 deletion views/index.hbs
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@
<div class="row">
<div class="col-md-4">
<h2>Open source</h2>
<p>Mailtrain is available under <a href="http://www.gnu.org/licenses/gpl-3.0.en.html">GPLv3</a> license and completely open source.</p>
<p>Mailtrain is available under <a href="https://spdx.org/licenses/MIT.html#licenseText">MIT</a> license and completely open source.</p>
</div>
<div class="col-md-4">
<h2>Send via any provider</h2>
Expand Down

0 comments on commit 0896e9f

Please sign in to comment.