From 5394774022d5bf769a53155c97058b0e7a10fcf9 Mon Sep 17 00:00:00 2001 From: inishchith Date: Mon, 4 Jun 2018 19:03:06 +0530 Subject: [PATCH 01/57] add receiver --- email/config.json | 7 ++++++ email/receiver.js | 54 +++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 61 insertions(+) create mode 100644 email/config.json create mode 100644 email/receiver.js diff --git a/email/config.json b/email/config.json new file mode 100644 index 00000000..3d6cefaa --- /dev/null +++ b/email/config.json @@ -0,0 +1,7 @@ +{ + "user": "your_email", + "password": "your_password", + "host": "imap.gmail.com", + "port": 993, + "tls": true +} diff --git a/email/receiver.js b/email/receiver.js new file mode 100644 index 00000000..c1847262 --- /dev/null +++ b/email/receiver.js @@ -0,0 +1,54 @@ +var config = require('./config'); + +var Imap = require('imap'), + inspect = require('util').inspect; + +var imap = new Imap(config); + +function openInbox(cb) { + imap.openBox('INBOX', true, cb); +} + +imap.once('ready', function() { + var fs = require('fs'), fileStream; + + openInbox(function(err, box) { + if (err) throw err; + // test for May 28, 2018 + imap.search([ 'UNSEEN', ['SINCE', 'May 28, 2018'] ], function(err, results) { + if (err) throw err; + var f = imap.fetch(results, { bodies: '' }); + f.on('message', function(msg, seqno) { + console.log('Message #%d', seqno); + var prefix = '(#' + seqno + ') '; + msg.on('body', function(stream, info) { + console.log(prefix + 'Body'); + stream.pipe(fs.createWriteStream('msg-' + seqno + '-body.txt')); + }); + msg.once('attributes', function(attrs) { + console.log(prefix + 'Attributes: %s', inspect(attrs, false, 8)); + }); + msg.once('end', function() { + console.log(prefix + 'Finished'); + }); + }); + f.once('error', function(err) { + console.log('Fetch error: ' + err); + }); + f.once('end', function() { + console.log('Done fetching all messages!'); + imap.end(); + }); + }); + }); +}); + +imap.once('error', function(err) { + console.log(err); +}); + +imap.once('end', function() { + console.log('Connection ended'); +}); + +imap.connect(); From 1181bb85a69d0b4273251b3677ff57305516ce7f Mon Sep 17 00:00:00 2001 From: accakks Date: Tue, 5 Jun 2018 23:33:55 +0530 Subject: [PATCH 02/57] Added sender.js --- email/sender.js | 43 +++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 43 insertions(+) create mode 100644 email/sender.js diff --git a/email/sender.js b/email/sender.js new file mode 100644 index 00000000..56640981 --- /dev/null +++ b/email/sender.js @@ -0,0 +1,43 @@ + +const nodemailer = require('nodemailer'); +const xoauth2 = require('xoauth2'); +const smtp = require('nodemailer-smtp-transport'); +const config = require('config.json')('./config.json'); + +//var userEmail, receiverEmail, clientId_input, clientSecret_input, refreshToken_Input, subjectText, contentText,userPassword, attachments; + +let transporter = nodemailer.createTransport({ + service: 'gmail', + host: 'smtp.gmail.com', + secure: 'true', + port: '465', + auth: { + type: 'OAuth2', + user: config.userMail, + clientId: config.clientId_input, + clientSecret:config.clientSecret_input, + refreshToken:config.refreshToken_input } + + } +); + +let mailOptions = { + from: config.userMail, + to: config.receiverMail, + cc: config.receiverCC, + bcc: config.receiverBCC, + subject: config.subjectText, + text: config.contentText, + attachments: config._attachments + }; + + +transporter.sendMail(mailOptions, function(e, r) { + if (e) { + console.log(e); + } else { + console.log(r); + } + transporter.close(); +}); + From 23a9bb6e1d421ef63be584157732ed918f4c0cb0 Mon Sep 17 00:00:00 2001 From: accakks Date: Tue, 5 Jun 2018 23:39:53 +0530 Subject: [PATCH 03/57] added package.json --- email/package.json | 10 ++++++++++ 1 file changed, 10 insertions(+) create mode 100644 email/package.json diff --git a/email/package.json b/email/package.json new file mode 100644 index 00000000..9f8bb482 --- /dev/null +++ b/email/package.json @@ -0,0 +1,10 @@ +{ + "name": "GmailMailer", + "version": "0.0.1", + "dependencies": { + "xoauth2": "1.2.0", + "nodemailer": "4.6.5", + "nodemailer-smtp-transport": "2.7.4", + "imap": "v0.8.x " + } +} From ce49e0079948cc6f48c44533de7f6174958a2874 Mon Sep 17 00:00:00 2001 From: accakks Date: Tue, 5 Jun 2018 23:42:13 +0530 Subject: [PATCH 04/57] Edited config.json --- email/config.json | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/email/config.json b/email/config.json index 3d6cefaa..af3bf88d 100644 --- a/email/config.json +++ b/email/config.json @@ -5,3 +5,18 @@ "port": 993, "tls": true } + +{ + "userMail" : "aakanksha.isp8buddy@gmail.com", + "receiverMail": "aakanksha.jain8@gmail.com", + "subjectText":"Wow it worked", + "contentText":"hahahhahaha", + "_attachments":"", + "receiverCC":"", + "receiverBCC":"", + "userPassword":"isp82828", + "clientId_input":"923388861604-9vnclirkoi9t7nsijrrq7r6g2rvv88f5.apps.googleusercontent.com", + "clientSecret_input":"'JvdpRgDP2xRsudMJmE24LgVz'", + "refreshToken_input":"1/Bj5tAhN593rBsV8uYdVLVDZW8bUpvCOgeE43jYVdEaw" + +} \ No newline at end of file From 1afa191e8304a14eface747a1fd7586d48f50980 Mon Sep 17 00:00:00 2001 From: Aakanksha Jain Date: Thu, 7 Jun 2018 17:27:28 +0530 Subject: [PATCH 05/57] Update config.json --- email/config.json | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) diff --git a/email/config.json b/email/config.json index af3bf88d..de2f80a8 100644 --- a/email/config.json +++ b/email/config.json @@ -7,16 +7,16 @@ } { - "userMail" : "aakanksha.isp8buddy@gmail.com", - "receiverMail": "aakanksha.jain8@gmail.com", - "subjectText":"Wow it worked", - "contentText":"hahahhahaha", + "userMail" : "your_email", + "receiverMail": "receiver_email", + "subjectText":"", + "contentText":"", "_attachments":"", "receiverCC":"", "receiverBCC":"", - "userPassword":"isp82828", - "clientId_input":"923388861604-9vnclirkoi9t7nsijrrq7r6g2rvv88f5.apps.googleusercontent.com", - "clientSecret_input":"'JvdpRgDP2xRsudMJmE24LgVz'", - "refreshToken_input":"1/Bj5tAhN593rBsV8uYdVLVDZW8bUpvCOgeE43jYVdEaw" + "userPassword":"", + "clientId_input":"", + "clientSecret_input":"", + "refreshToken_input":"" -} \ No newline at end of file +} From 83be32eb16db396319496768ffab32baf5af8749 Mon Sep 17 00:00:00 2001 From: inishchith Date: Thu, 7 Jun 2018 20:05:11 +0530 Subject: [PATCH 06/57] add email model --- models/doctype/Email/Email.js | 43 +++++++++++++++++++++++++++++++++++ models/index.js | 3 ++- 2 files changed, 45 insertions(+), 1 deletion(-) create mode 100644 models/doctype/Email/Email.js diff --git a/models/doctype/Email/Email.js b/models/doctype/Email/Email.js new file mode 100644 index 00000000..2edf6b27 --- /dev/null +++ b/models/doctype/Email/Email.js @@ -0,0 +1,43 @@ +module.exports = { + "name": "Email", + "doctype": "DocType", + "isSingle": 0, + "isChild": 0, + "keywordFields": [ + "name", + "emailAddress" + ], + "fields": [ + { + "fieldname": "name", + "label": "Name", + "fieldtype": "Data", + "required": 1 + }, + { + "fieldname": "emailAddress", + "label": "Email Address", + "fieldtype": "Data", + "required": 1 + }, + { + "fieldname": "password", + "label": "Password", + "fieldtype": "Password", + "required": 1, + "hidden": 1, + }, + { + "fieldname": "host", + "label": "Host", + "fieldtype": "Link", + "required": 1 + }, + { + "fieldname": "port", + "label": "Port", + "fieldtype": "Int", + "required": 1 + } + ] +} \ No newline at end of file diff --git a/models/index.js b/models/index.js index 0040080f..70e967f4 100644 --- a/models/index.js +++ b/models/index.js @@ -11,6 +11,7 @@ module.exports = { SystemSettings: require('./doctype/SystemSettings/SystemSettings.js'), ToDo: require('./doctype/ToDo/ToDo.js'), User: require('./doctype/User/User.js'), - UserRole: require('./doctype/UserRole/UserRole.js') + UserRole: require('./doctype/UserRole/UserRole.js'), + Email: require('./doctype/Email/Email.js') } } From 0182c15295ca34b717862d699624e131291fe3e9 Mon Sep 17 00:00:00 2001 From: Aakanksha Jain Date: Sun, 10 Jun 2018 12:12:30 +0530 Subject: [PATCH 07/57] Update Email.js --- models/doctype/Email/Email.js | 38 ++++++++++++++++++++++++++++++++--- 1 file changed, 35 insertions(+), 3 deletions(-) diff --git a/models/doctype/Email/Email.js b/models/doctype/Email/Email.js index 2edf6b27..21adaf22 100644 --- a/models/doctype/Email/Email.js +++ b/models/doctype/Email/Email.js @@ -16,7 +16,7 @@ module.exports = { }, { "fieldname": "emailAddress", - "label": "Email Address", + "label": "from", "fieldtype": "Data", "required": 1 }, @@ -38,6 +38,38 @@ module.exports = { "label": "Port", "fieldtype": "Int", "required": 1 - } + }, + { + "fieldname": "emailAddress", + "label": "to", + "fieldtype": "Data", + "required": 1 + }, + { + "fieldname": "emailAddress", + "label": "cc", + "fieldtype": "Data", + "required": 1 + }, + { + "fieldname": "emailAddress", + "label": "bcc", + "fieldtype": "Data", + "required": 1 + }, + { + "fieldname": "Subject", + "label": "Subject", + "fieldtype" : "Text", + "required": 0 + }, + { + "fieldname": "Content", + "label": "", + "fieldtype" : "Text", + "required": 0 + } + + ] -} \ No newline at end of file +} From 9410484d05ed027b4a3dffea32fb0c102b906b11 Mon Sep 17 00:00:00 2001 From: accakks Date: Sun, 10 Jun 2018 12:35:21 +0530 Subject: [PATCH 08/57] Changes made in cc, bcc fields in models --- models/doctype/Email/Email.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/models/doctype/Email/Email.js b/models/doctype/Email/Email.js index 21adaf22..ca6dbc4a 100644 --- a/models/doctype/Email/Email.js +++ b/models/doctype/Email/Email.js @@ -49,13 +49,13 @@ module.exports = { "fieldname": "emailAddress", "label": "cc", "fieldtype": "Data", - "required": 1 + "required": 0 }, { "fieldname": "emailAddress", "label": "bcc", "fieldtype": "Data", - "required": 1 + "required": 0 }, { "fieldname": "Subject", From a2ae74d614e0d747e2c04ac5e2764b77e18ad74d Mon Sep 17 00:00:00 2001 From: Aakanksha Jain Date: Sun, 10 Jun 2018 13:39:23 +0530 Subject: [PATCH 09/57] Added more models to Email.js (#8) * Update Email.js * Changes made in cc, bcc fields in models --- models/doctype/Email/Email.js | 38 ++++++++++++++++++++++++++++++++--- 1 file changed, 35 insertions(+), 3 deletions(-) diff --git a/models/doctype/Email/Email.js b/models/doctype/Email/Email.js index 2edf6b27..ca6dbc4a 100644 --- a/models/doctype/Email/Email.js +++ b/models/doctype/Email/Email.js @@ -16,7 +16,7 @@ module.exports = { }, { "fieldname": "emailAddress", - "label": "Email Address", + "label": "from", "fieldtype": "Data", "required": 1 }, @@ -38,6 +38,38 @@ module.exports = { "label": "Port", "fieldtype": "Int", "required": 1 - } + }, + { + "fieldname": "emailAddress", + "label": "to", + "fieldtype": "Data", + "required": 1 + }, + { + "fieldname": "emailAddress", + "label": "cc", + "fieldtype": "Data", + "required": 0 + }, + { + "fieldname": "emailAddress", + "label": "bcc", + "fieldtype": "Data", + "required": 0 + }, + { + "fieldname": "Subject", + "label": "Subject", + "fieldtype" : "Text", + "required": 0 + }, + { + "fieldname": "Content", + "label": "", + "fieldtype" : "Text", + "required": 0 + } + + ] -} \ No newline at end of file +} From 965ea472a503691105af125ca6d15e84fbc19a4f Mon Sep 17 00:00:00 2001 From: inishchith Date: Sun, 10 Jun 2018 14:39:17 +0530 Subject: [PATCH 10/57] clean up receiver.js --- email/receiver.js | 19 +++++++------------ 1 file changed, 7 insertions(+), 12 deletions(-) diff --git a/email/receiver.js b/email/receiver.js index c1847262..d09ed6a3 100644 --- a/email/receiver.js +++ b/email/receiver.js @@ -17,25 +17,20 @@ imap.once('ready', function() { // test for May 28, 2018 imap.search([ 'UNSEEN', ['SINCE', 'May 28, 2018'] ], function(err, results) { if (err) throw err; - var f = imap.fetch(results, { bodies: '' }); - f.on('message', function(msg, seqno) { - console.log('Message #%d', seqno); + var fetch = imap.fetch(results, { bodies: '' }); + fetch.on('message', function(msg, seqno) { + // console.log('Message #%d', seqno); var prefix = '(#' + seqno + ') '; msg.on('body', function(stream, info) { - console.log(prefix + 'Body'); + // console.log(prefix + 'Body'); stream.pipe(fs.createWriteStream('msg-' + seqno + '-body.txt')); - }); - msg.once('attributes', function(attrs) { - console.log(prefix + 'Attributes: %s', inspect(attrs, false, 8)); - }); - msg.once('end', function() { - console.log(prefix + 'Finished'); + // TODO : have to dump this in db }); }); - f.once('error', function(err) { + fetch.once('error', function(err) { console.log('Fetch error: ' + err); }); - f.once('end', function() { + fetch.once('end', function() { console.log('Done fetching all messages!'); imap.end(); }); From 6b73021b56e95c98944586a3bbd9589e5685ce58 Mon Sep 17 00:00:00 2001 From: inishchith Date: Tue, 12 Jun 2018 11:52:51 +0530 Subject: [PATCH 11/57] add EmailList.js and change fields in Email.js --- models/doctype/Email/Email.js | 12 +++++------ models/doctype/Email/EmailList.js | 36 +++++++++++++++++++++++++++++++ models/index.js | 3 ++- 3 files changed, 44 insertions(+), 7 deletions(-) create mode 100644 models/doctype/Email/EmailList.js diff --git a/models/doctype/Email/Email.js b/models/doctype/Email/Email.js index ca6dbc4a..6206eb56 100644 --- a/models/doctype/Email/Email.js +++ b/models/doctype/Email/Email.js @@ -5,7 +5,7 @@ module.exports = { "isChild": 0, "keywordFields": [ "name", - "emailAddress" + "from_emailAddress" ], "fields": [ { @@ -15,7 +15,7 @@ module.exports = { "required": 1 }, { - "fieldname": "emailAddress", + "fieldname": "from_emailAddress", "label": "from", "fieldtype": "Data", "required": 1 @@ -40,19 +40,19 @@ module.exports = { "required": 1 }, { - "fieldname": "emailAddress", + "fieldname": "to_emailAddress", "label": "to", "fieldtype": "Data", "required": 1 }, { - "fieldname": "emailAddress", + "fieldname": "cc_emailAddress", "label": "cc", "fieldtype": "Data", "required": 0 }, { - "fieldname": "emailAddress", + "fieldname": "bcc_emailAddress", "label": "bcc", "fieldtype": "Data", "required": 0 @@ -64,7 +64,7 @@ module.exports = { "required": 0 }, { - "fieldname": "Content", + "fieldname": "Body", "label": "", "fieldtype" : "Text", "required": 0 diff --git a/models/doctype/Email/EmailList.js b/models/doctype/Email/EmailList.js new file mode 100644 index 00000000..0e8b0872 --- /dev/null +++ b/models/doctype/Email/EmailList.js @@ -0,0 +1,36 @@ +module.exports = { + "name": "EmailItem", + "doctype": "DocType", + "isSingle": 0, + "isChild": 0, // isChild of Email ? + "keywordFields": [ + "emailAddress" + ], + "fields": [ + { + "fieldname": "from_emailAddress", + "label": "from", + "fieldtype": "Data", + "required": 1 + }, + { + "fieldname": "to_emailAddress", + "label": "to", + "fieldtype": "Data", + "required": 1 + }, + { + "fieldname": "Subject", + "label": "Subject", + "fieldtype" : "Text", + "required": 0 + }, + { + "fieldname": "Body", + "label": "", + "fieldtype" : "Text", + "required": 0 + } + // haven't captured attachments ? + ] +} diff --git a/models/index.js b/models/index.js index 70e967f4..0b0e8cf8 100644 --- a/models/index.js +++ b/models/index.js @@ -12,6 +12,7 @@ module.exports = { ToDo: require('./doctype/ToDo/ToDo.js'), User: require('./doctype/User/User.js'), UserRole: require('./doctype/UserRole/UserRole.js'), - Email: require('./doctype/Email/Email.js') + Email: require('./doctype/Email/Email.js'), + EmailList: require('./doctype/Email/EmailList.js') } } From 275c32a90495442fa8043acc0452537b0d378984 Mon Sep 17 00:00:00 2001 From: inishchith Date: Tue, 12 Jun 2018 19:48:21 +0530 Subject: [PATCH 12/57] updated Models --- models/doctype/Email/Email.js | 40 +++++++------------ .../EmailSummary.js} | 16 ++++---- models/index.js | 2 +- 3 files changed, 24 insertions(+), 34 deletions(-) rename models/doctype/{Email/EmailList.js => EmailSummary/EmailSummary.js} (71%) diff --git a/models/doctype/Email/Email.js b/models/doctype/Email/Email.js index 6206eb56..0c586f78 100644 --- a/models/doctype/Email/Email.js +++ b/models/doctype/Email/Email.js @@ -16,16 +16,16 @@ module.exports = { }, { "fieldname": "from_emailAddress", - "label": "from", + "label": "Email", "fieldtype": "Data", "required": 1 }, { "fieldname": "password", "label": "Password", - "fieldtype": "Password", + "fieldtype": "Data", "required": 1, - "hidden": 1, + // "hidden": 1, uncomment when s: OAuth }, { "fieldname": "host", @@ -40,36 +40,24 @@ module.exports = { "required": 1 }, { - "fieldname": "to_emailAddress", - "label": "to", + "fieldname": "clientId", + "label": "Client Id", "fieldtype": "Data", "required": 1 }, { - "fieldname": "cc_emailAddress", - "label": "cc", + "fieldname": "clientSecret", + "label": "Client Secret", "fieldtype": "Data", - "required": 0 + "required": 1 }, { - "fieldname": "bcc_emailAddress", - "label": "bcc", + "fieldname": "refreshToken", + "label": "Refresh Token", "fieldtype": "Data", - "required": 0 - }, - { - "fieldname": "Subject", - "label": "Subject", - "fieldtype" : "Text", - "required": 0 - }, - { - "fieldname": "Body", - "label": "", - "fieldtype" : "Text", - "required": 0 - } - - + "required": 1 + } + ] } + diff --git a/models/doctype/Email/EmailList.js b/models/doctype/EmailSummary/EmailSummary.js similarity index 71% rename from models/doctype/Email/EmailList.js rename to models/doctype/EmailSummary/EmailSummary.js index 0e8b0872..72d90afd 100644 --- a/models/doctype/Email/EmailList.js +++ b/models/doctype/EmailSummary/EmailSummary.js @@ -1,36 +1,38 @@ module.exports = { - "name": "EmailItem", + "name": "EmailSummary", "doctype": "DocType", "isSingle": 0, "isChild": 0, // isChild of Email ? "keywordFields": [ - "emailAddress" + "from_emailAddress" ], "fields": [ { + // here comes question of default values "fieldname": "from_emailAddress", - "label": "from", + "label": "From", "fieldtype": "Data", "required": 1 }, { "fieldname": "to_emailAddress", - "label": "to", + "label": "To", "fieldtype": "Data", "required": 1 }, { - "fieldname": "Subject", + "fieldname": "subject", "label": "Subject", "fieldtype" : "Text", "required": 0 }, { - "fieldname": "Body", - "label": "", + "fieldname": "body", + "label": "Body", "fieldtype" : "Text", "required": 0 } // haven't captured attachments ? ] } + diff --git a/models/index.js b/models/index.js index 0b0e8cf8..3a8de58c 100644 --- a/models/index.js +++ b/models/index.js @@ -13,6 +13,6 @@ module.exports = { User: require('./doctype/User/User.js'), UserRole: require('./doctype/UserRole/UserRole.js'), Email: require('./doctype/Email/Email.js'), - EmailList: require('./doctype/Email/EmailList.js') + EmailSummary: require('./doctype/EmailSummary/EmailSummary.js') } } From 74579d36e8722c9d406e2f7f8b73c6d8c9957de5 Mon Sep 17 00:00:00 2001 From: Aakanksha Jain Date: Wed, 13 Jun 2018 10:02:07 +0530 Subject: [PATCH 13/57] Update EmailSummary.js (#18) --- models/doctype/EmailSummary/EmailSummary.js | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/models/doctype/EmailSummary/EmailSummary.js b/models/doctype/EmailSummary/EmailSummary.js index 72d90afd..d346a737 100644 --- a/models/doctype/EmailSummary/EmailSummary.js +++ b/models/doctype/EmailSummary/EmailSummary.js @@ -21,6 +21,18 @@ module.exports = { "required": 1 }, { ++ "fieldname": "cc_emailAddress", ++ "label": "cc", ++ "fieldtype": "Data", ++ "required": 0 ++ }, ++ { ++ "fieldname": "bcc_emailAddress", ++ "label": "bcc", ++ "fieldtype": "Data", ++ "required": 0 ++ }, + { "fieldname": "subject", "label": "Subject", "fieldtype" : "Text", From 790663e4e934e6eda91ec5dbb7c1f114183295bf Mon Sep 17 00:00:00 2001 From: Aakanksha Jain Date: Wed, 13 Jun 2018 10:40:44 +0530 Subject: [PATCH 14/57] Added missing '}' at the end of Email.js & in corrected by mistake copied '+++' while adding cc, bcc to 'EmailSummary.js' (#19) * Update EmailSummary.js * '+' by mistake * Missing '}' --- models/doctype/Email/Email.js | 1 + models/doctype/EmailSummary/EmailSummary.js | 24 +++++++++++---------- 2 files changed, 14 insertions(+), 11 deletions(-) diff --git a/models/doctype/Email/Email.js b/models/doctype/Email/Email.js index 1d574fca..8c2b024d 100644 --- a/models/doctype/Email/Email.js +++ b/models/doctype/Email/Email.js @@ -59,3 +59,4 @@ module.exports = { } ] +} diff --git a/models/doctype/EmailSummary/EmailSummary.js b/models/doctype/EmailSummary/EmailSummary.js index d346a737..4c13e4aa 100644 --- a/models/doctype/EmailSummary/EmailSummary.js +++ b/models/doctype/EmailSummary/EmailSummary.js @@ -21,17 +21,19 @@ module.exports = { "required": 1 }, { -+ "fieldname": "cc_emailAddress", -+ "label": "cc", -+ "fieldtype": "Data", -+ "required": 0 -+ }, -+ { -+ "fieldname": "bcc_emailAddress", -+ "label": "bcc", -+ "fieldtype": "Data", -+ "required": 0 -+ }, + + "fieldname": "cc_emailAddress", + "label": "cc", + "fieldtype": "Data", + "required": 0 + }, + { + "fieldname": "bcc_emailAddress", + "label": "bcc", + "fieldtype": "Data", + "required": 0 + }, + { "fieldname": "subject", "label": "Subject", From 19e1c8eb146bc76dd2eff345736618d8a9a98cb7 Mon Sep 17 00:00:00 2001 From: inishchith Date: Mon, 9 Jul 2018 20:23:19 +0530 Subject: [PATCH 15/57] incorp. for vue functionality --- email/getConfig.js | 8 +++ email/index.js | 25 ++++++++ email/receiver.js | 81 ++++++++++++++++++++++++ email/sender.js | 31 +++++++++ email/validator.js | 27 ++++++++ package-lock.json | 13 ++++ package.json | 1 + server/index.js | 3 + ui/components/controls/Base.vue | 3 +- ui/components/controls/FrappeControl.vue | 1 + 10 files changed, 192 insertions(+), 1 deletion(-) create mode 100644 email/getConfig.js create mode 100644 email/index.js create mode 100644 email/receiver.js create mode 100644 email/sender.js create mode 100644 email/validator.js create mode 100644 package-lock.json diff --git a/email/getConfig.js b/email/getConfig.js new file mode 100644 index 00000000..b550205d --- /dev/null +++ b/email/getConfig.js @@ -0,0 +1,8 @@ +const frappe = require('frappejs'); +module.exports = async function getData(emailAddress) { + account = await frappe.db.getAll({ + doctype: 'EmailAccount', + fields: ['*'] + }) + return account; +} \ No newline at end of file diff --git a/email/index.js b/email/index.js new file mode 100644 index 00000000..0b41db39 --- /dev/null +++ b/email/index.js @@ -0,0 +1,25 @@ +const sender = require('./sender'); +const receiver = require('./receiver'); +const validator = require('./validator'); +const frappe = require('frappejs'); + +module.exports = () => { + frappe.registerMethod({ + method: 'send-mail', + handler: sender.sendMail + }); + + frappe.registerMethod({ + method: 'sync-mail', + handler: receiver.sync + }); + + frappe.registerMethod({ + method: 'validate-mail', + handler: validator.validate + }); + frappe.registerMethod({ + method: 'validate-auth', + handler: validator.authValidate + }); +}; \ No newline at end of file diff --git a/email/receiver.js b/email/receiver.js new file mode 100644 index 00000000..fbf6b049 --- /dev/null +++ b/email/receiver.js @@ -0,0 +1,81 @@ +const frappe = require('frappejs'); +const simpleParser = require('mailparser').simpleParser; +const Imap = require('imap'); +const getConfig = require("./getConfig"); + +module.exports = { + sync: async () => { + + let account = await getConfig(); + let emailSyncOption = account[0].emailSync; + var config = { + "user": account[0].email, + "password": account[0].password, + "host": account[0].imapHost, + "port": account[0].imapPort, + "tls": true, + }; + var imap = new Imap(config); + function openInbox(cb) { + imap.openBox('INBOX', true, cb); + } + + imap.once('ready', function () { + + openInbox(function (err, box) { + + if (err) throw err; + imap.search([emailSyncOption, ['SINCE', account[0].initialDate]], function (err, results) { + if (err) throw err; + var fetch = imap.fetch(results, { + bodies: '' + }); + + fetch.on('message', function (msg, seqno) { + msg.on('body', function (stream, info) { + + simpleParser(stream) + .then(async function (mail_object) { + const mail = await frappe.insert({ + doctype: 'Email', + name: "Received from : " + mail_object.to.value[0].address + " " + mail_object.subject.slice(0, 10), // needs change : THINK + fromEmailAddress: mail_object.from.value[0].address, + toEmailAddress: mail_object.to.value[0].address, + ccEmailAddress: mail_object.cc, + bccEmailAddress: mail_object.bcc, + date: mail_object.date, + subject: mail_object.subject, + bodyHtml: mail_object.html, + bodyText: mail_object.text, + sent: "1", + }); + }) + .catch(function (err) { + console.log('An error occurred:', err.message); + }); + }); + }); + + fetch.once('error', function (err) { + console.log('Fetch error: ' + err); + }); + + fetch.once('end', function () { + console.log('Done fetching all messages!'); + imap.end(); + }); + }); + }); + }); + + imap.once('error', function (err) { + console.log(err); + }); + + imap.once('end', function () { + console.log('Connection ended'); + }); + + imap.connect(); + } +} \ No newline at end of file diff --git a/email/sender.js b/email/sender.js new file mode 100644 index 00000000..14d73a94 --- /dev/null +++ b/email/sender.js @@ -0,0 +1,31 @@ +const nodemailer = require('nodemailer'); +const getConfig = require("./getConfig"); + +module.exports = { + 'sendMail': async function (mailDetails) { + let account = await getConfig(mailDetails.fromEmailAddress); + for (var i = 0; i < account.length; i++) { + if (mailDetails.fromEmailAddress == account[i].email) { + var mailKey = "Sent to : " + mailDetails.toEmailAddress + " " + mailDetails.subject.slice(0, 10); // needs change : THINK + mailDetails = { + from: mailDetails.fromEmailAddress, + to: mailDetails.toEmailAddress, + cc: mailDetails.ccEmailAddress, + bcc: mailDetails.bccEmailAddress, + subject: mailDetails.subject, + text: mailDetails.bodyText, + }; + let transporter = nodemailer.createTransport({ + service: 'gmail', + auth: { + user: account[i].email, + pass: account[i].password, + } + }); + transporter.sendMail(mailDetails); + return mailKey; + } + } + console.log(mailDetails.fromEmailAddress + " NOT FOUND IN RECORDS"); + } +}; \ No newline at end of file diff --git a/email/validator.js b/email/validator.js new file mode 100644 index 00000000..b5c53a1a --- /dev/null +++ b/email/validator.js @@ -0,0 +1,27 @@ +// Verify this with mentor +// REF. https://github.com/nodemailer/nodemailer/issues/206 + +module.exports = { + validate: async function (mailDetails) { + var reg = /^([A-Za-z0-9_\-\.])+\@([A-Za-z0-9_\-\.])+\.([A-Za-z]{2,4})$/; + if (reg.test(mailDetails.email) == false) { + return false; + } + return true; + }, + authValidate: async function (mailDetails) { + return new Promise((resolve,reject) => { + var Imap = require('imap'); + var imap = new Imap({ + user: mailDetails.email, + password: mailDetails.password, + host: mailDetails.imapHost, + port: mailDetails.imapPort, + tls: true + }); + imap.once('ready',resolve); + imap.once('error',reject); + imap.connect(); + }) + } +} \ No newline at end of file diff --git a/package-lock.json b/package-lock.json new file mode 100644 index 00000000..6fc1a654 --- /dev/null +++ b/package-lock.json @@ -0,0 +1,13 @@ +{ + "name": "frappejs", + "version": "0.0.8", + "lockfileVersion": 1, + "requires": true, + "dependencies": { + "nodemailer": { + "version": "4.6.6", + "resolved": "https://registry.npmjs.org/nodemailer/-/nodemailer-4.6.6.tgz", + "integrity": "sha512-sIcM/Do0XBJmu7ruENLoR+4TCk0B4C1ftqRjWrVeoez9Dt23SmL9bXKqswVqyxuT/RdK8TKWciZvxHykerXCRw==" + } + } +} diff --git a/package.json b/package.json index bfa1d6dc..2dc594f0 100644 --- a/package.json +++ b/package.json @@ -33,6 +33,7 @@ "mysql": "^2.15.0", "node-fetch": "^1.7.3", "node-sass": "^4.7.2", + "nodemailer": "^4.6.6", "nodemon": "^1.14.7", "nunjucks": "^3.1.0", "octicons": "^7.2.0", diff --git a/server/index.js b/server/index.js index 10ac5775..5e6e7327 100644 --- a/server/index.js +++ b/server/index.js @@ -16,6 +16,7 @@ const fs = require('fs'); const { setupExpressRoute: setRouteForPDF } = require('frappejs/server/pdf'); const auth = require('./../auth/auth')(); const morgan = require('morgan') +const setupEmail = require('../email'); require.extensions['.html'] = function (module, filename) { module.exports = fs.readFileSync(filename, 'utf8'); @@ -64,6 +65,8 @@ module.exports = { frappe.server = server; setRouteForPDF(); + console.log("HEY THERE"); + setupEmail(); }, async init() { diff --git a/ui/components/controls/Base.vue b/ui/components/controls/Base.vue index ac0d7160..5f7125fc 100644 --- a/ui/components/controls/Base.vue +++ b/ui/components/controls/Base.vue @@ -70,7 +70,8 @@ export default { type: 'text', placeholder: '', value: this.value, - required: this.docfield.required + required: this.docfield.required, + disabled: this.docfield.disabled } }, getInputListeners() { diff --git a/ui/components/controls/FrappeControl.vue b/ui/components/controls/FrappeControl.vue index db6cb830..b2651653 100644 --- a/ui/components/controls/FrappeControl.vue +++ b/ui/components/controls/FrappeControl.vue @@ -3,6 +3,7 @@ :docfield="docfield" :value="value" :onlyInput="onlyInput" + v-if="!docfield.hidden" @change="$emit('change', $event)" /> From e83ccbbb91ed4af7bdd80398539bdcfeb2eb6d5a Mon Sep 17 00:00:00 2001 From: inishchith Date: Thu, 12 Jul 2018 21:28:34 +0530 Subject: [PATCH 16/57] rm. redundant lines --- email/getConfig.js | 2 +- email/receiver.js | 5 ++--- email/sender.js | 5 +++-- email/validator.js | 4 +--- ui/components/controls/FrappeControl.vue | 1 - 5 files changed, 7 insertions(+), 10 deletions(-) diff --git a/email/getConfig.js b/email/getConfig.js index b550205d..47a7c8df 100644 --- a/email/getConfig.js +++ b/email/getConfig.js @@ -1,5 +1,5 @@ const frappe = require('frappejs'); -module.exports = async function getData(emailAddress) { +module.exports = async function getData() { account = await frappe.db.getAll({ doctype: 'EmailAccount', fields: ['*'] diff --git a/email/receiver.js b/email/receiver.js index 8951c7d6..1c91d12f 100644 --- a/email/receiver.js +++ b/email/receiver.js @@ -5,7 +5,6 @@ const getConfig = require("./getConfig"); module.exports = { sync: async () => { - let account = await getConfig(); let emailSyncOption = account[0].emailSync; var config = { @@ -30,14 +29,14 @@ module.exports = { var fetch = imap.fetch(results, { bodies: '' }); - fetch.on('message', function (msg, seqno) { msg.on('body', function (stream, info) { simpleParser(stream) .then(async function (mail_object) { - const mail = await frappe.insert({ + await frappe.insert({ doctype: 'Email', + // EDITS name: "Received from : " + mail_object.to.value[0].address + " " + mail_object.subject.slice(0, 10), // needs change : THINK fromEmailAddress: mail_object.from.value[0].address, toEmailAddress: mail_object.to.value[0].address, diff --git a/email/sender.js b/email/sender.js index caa39dc7..cef864f7 100644 --- a/email/sender.js +++ b/email/sender.js @@ -3,10 +3,11 @@ const getConfig = require("./getConfig"); module.exports = { 'sendMail': async function (mailDetails) { - let account = await getConfig(mailDetails.fromEmailAddress); + let account = await getConfig(); for (var i = 0; i < account.length; i++) { if (mailDetails.fromEmailAddress == account[i].email) { - var mailKey = "Sent to : " + mailDetails.toEmailAddress + " " + mailDetails.subject.slice(0, 10); // needs change : THINK + // EDITS + var mailKey = "Sent to : " + mailDetails.toEmailAddress + " " + mailDetails.subject.slice(0, 10); mailDetails = { from: mailDetails.fromEmailAddress, to: mailDetails.toEmailAddress, diff --git a/email/validator.js b/email/validator.js index b5c53a1a..91263a3a 100644 --- a/email/validator.js +++ b/email/validator.js @@ -1,8 +1,6 @@ -// Verify this with mentor -// REF. https://github.com/nodemailer/nodemailer/issues/206 module.exports = { - validate: async function (mailDetails) { + validate: function (mailDetails) { var reg = /^([A-Za-z0-9_\-\.])+\@([A-Za-z0-9_\-\.])+\.([A-Za-z]{2,4})$/; if (reg.test(mailDetails.email) == false) { return false; diff --git a/ui/components/controls/FrappeControl.vue b/ui/components/controls/FrappeControl.vue index 8c868a44..9f67e594 100644 --- a/ui/components/controls/FrappeControl.vue +++ b/ui/components/controls/FrappeControl.vue @@ -4,7 +4,6 @@ :docfield="docfield" :value="value" :onlyInput="onlyInput" - v-if="!docfield.hidden" @change="$emit('change', $event)" /> From 640866aa525bc5db902b1b1666093311c2b41615 Mon Sep 17 00:00:00 2001 From: inishchith Date: Fri, 13 Jul 2018 17:05:31 +0530 Subject: [PATCH 17/57] update email module --- email/index.js | 9 -------- email/sender.js | 53 ++++++++++++++++++++++++++++------------------ email/validator.js | 20 ++--------------- 3 files changed, 34 insertions(+), 48 deletions(-) diff --git a/email/index.js b/email/index.js index 0b41db39..e7416bef 100644 --- a/email/index.js +++ b/email/index.js @@ -1,6 +1,5 @@ const sender = require('./sender'); const receiver = require('./receiver'); -const validator = require('./validator'); const frappe = require('frappejs'); module.exports = () => { @@ -14,12 +13,4 @@ module.exports = () => { handler: receiver.sync }); - frappe.registerMethod({ - method: 'validate-mail', - handler: validator.validate - }); - frappe.registerMethod({ - method: 'validate-auth', - handler: validator.authValidate - }); }; \ No newline at end of file diff --git a/email/sender.js b/email/sender.js index cef864f7..fadcedb5 100644 --- a/email/sender.js +++ b/email/sender.js @@ -1,32 +1,43 @@ const nodemailer = require('nodemailer'); const getConfig = require("./getConfig"); +const validator = require('./validator'); module.exports = { 'sendMail': async function (mailDetails) { + if(!validator.validate(mailDetails.fromEmailAddress)){ + console.log("invalid from email"); + return false; + } + let account = await getConfig(); for (var i = 0; i < account.length; i++) { if (mailDetails.fromEmailAddress == account[i].email) { - // EDITS - var mailKey = "Sent to : " + mailDetails.toEmailAddress + " " + mailDetails.subject.slice(0, 10); - mailDetails = { - from: mailDetails.fromEmailAddress, - to: mailDetails.toEmailAddress, - cc: mailDetails.ccEmailAddress, - bcc: mailDetails.bccEmailAddress, - subject: mailDetails.subject, - text: mailDetails.bodyText, - }; - let transporter = nodemailer.createTransport({ - service: 'gmail', - auth: { - user: account[i].email, - pass: account[i].password, - } - }); - transporter.sendMail(mailDetails); - return mailKey; + if(validator.validate(mailDetails.toEmailAddress)){ + mailDetails = { + from: mailDetails.fromEmailAddress, + to: mailDetails.toEmailAddress, + cc: mailDetails.ccEmailAddress, + bcc: mailDetails.bccEmailAddress, + subject: mailDetails.subject, + text: mailDetails.bodyText, + }; + let transporter = nodemailer.createTransport({ + service: 'gmail', + auth: { + user: account[i].email, + pass: account[i].password, + } + }); + transporter.sendMail(mailDetails); + return true; + } + else{ + console.log("Sender Email Invalid"); + return false; } } - console.log(mailDetails.fromEmailAddress + " NOT FOUND IN RECORDS"); + } + return false; + console.log(mailDetails.fromEmailAddress + " NOT FOUND IN RECORDS"); } -}; +}; diff --git a/email/validator.js b/email/validator.js index 91263a3a..00c8aa4a 100644 --- a/email/validator.js +++ b/email/validator.js @@ -1,25 +1,9 @@ - module.exports = { - validate: function (mailDetails) { + validate: function (email) { var reg = /^([A-Za-z0-9_\-\.])+\@([A-Za-z0-9_\-\.])+\.([A-Za-z]{2,4})$/; - if (reg.test(mailDetails.email) == false) { + if (reg.test(email) == false) { return false; } return true; - }, - authValidate: async function (mailDetails) { - return new Promise((resolve,reject) => { - var Imap = require('imap'); - var imap = new Imap({ - user: mailDetails.email, - password: mailDetails.password, - host: mailDetails.imapHost, - port: mailDetails.imapPort, - tls: true - }); - imap.once('ready',resolve); - imap.once('error',reject); - imap.connect(); - }) } } \ No newline at end of file From 8a1717d8c9e500b978b919b817738d247cc34db2 Mon Sep 17 00:00:00 2001 From: inishchith Date: Fri, 13 Jul 2018 20:32:25 +0530 Subject: [PATCH 18/57] Add Default Pull Email List --- email/receiver.js | 29 ++++++++++++++++++----------- 1 file changed, 18 insertions(+), 11 deletions(-) diff --git a/email/receiver.js b/email/receiver.js index 1c91d12f..24c00f46 100644 --- a/email/receiver.js +++ b/email/receiver.js @@ -4,17 +4,24 @@ const Imap = require('imap'); const getConfig = require("./getConfig"); module.exports = { - sync: async () => { + sync: async (email) => { let account = await getConfig(); - let emailSyncOption = account[0].emailSync; - var config = { - "user": account[0].email, - "password": account[0].password, - "host": account[0].imapHost, - "port": account[0].imapPort, - "tls": true, - }; - var imap = new Imap(config); + var i ; + for (i = 0; i < account.length; i++) { + if (account[i].email == email.Id) { + break; + } + } + let emailSyncOption = account[i].emailSync; + var config = { + "user": account[i].email, + "password": account[i].password, + "host": account[i].imapHost, + "port": account[i].imapPort, + "tls": true, + } + var imap = new Imap(config); + function openInbox(cb) { imap.openBox('INBOX', true, cb); } @@ -24,7 +31,7 @@ module.exports = { openInbox(function (err, box) { if (err) throw err; - imap.search([emailSyncOption, ['SINCE', account[0].initialDate]], function (err, results) { + imap.search([emailSyncOption, ['SINCE', account[i].initialDate]], function (err, results) { if (err) throw err; var fetch = imap.fetch(results, { bodies: '' From 6a9ce7e9e3621356c7cf8eee5a06d182909bd409 Mon Sep 17 00:00:00 2001 From: inishchith Date: Fri, 13 Jul 2018 20:32:25 +0530 Subject: [PATCH 19/57] Add Default Pull Email List --- email/receiver.js | 29 ++++++++++++++++++----------- models/index.js | 2 +- 2 files changed, 19 insertions(+), 12 deletions(-) diff --git a/email/receiver.js b/email/receiver.js index 1c91d12f..24c00f46 100644 --- a/email/receiver.js +++ b/email/receiver.js @@ -4,17 +4,24 @@ const Imap = require('imap'); const getConfig = require("./getConfig"); module.exports = { - sync: async () => { + sync: async (email) => { let account = await getConfig(); - let emailSyncOption = account[0].emailSync; - var config = { - "user": account[0].email, - "password": account[0].password, - "host": account[0].imapHost, - "port": account[0].imapPort, - "tls": true, - }; - var imap = new Imap(config); + var i ; + for (i = 0; i < account.length; i++) { + if (account[i].email == email.Id) { + break; + } + } + let emailSyncOption = account[i].emailSync; + var config = { + "user": account[i].email, + "password": account[i].password, + "host": account[i].imapHost, + "port": account[i].imapPort, + "tls": true, + } + var imap = new Imap(config); + function openInbox(cb) { imap.openBox('INBOX', true, cb); } @@ -24,7 +31,7 @@ module.exports = { openInbox(function (err, box) { if (err) throw err; - imap.search([emailSyncOption, ['SINCE', account[0].initialDate]], function (err, results) { + imap.search([emailSyncOption, ['SINCE', account[i].initialDate]], function (err, results) { if (err) throw err; var fetch = imap.fetch(results, { bodies: '' diff --git a/models/index.js b/models/index.js index 8c702d14..0040080f 100644 --- a/models/index.js +++ b/models/index.js @@ -11,6 +11,6 @@ module.exports = { SystemSettings: require('./doctype/SystemSettings/SystemSettings.js'), ToDo: require('./doctype/ToDo/ToDo.js'), User: require('./doctype/User/User.js'), - UserRole: require('./doctype/UserRole/UserRole.js'), + UserRole: require('./doctype/UserRole/UserRole.js') } } From 1f7f6217cc765c5806884e396cdb6740b5a38ed8 Mon Sep 17 00:00:00 2001 From: inishchith Date: Mon, 23 Jul 2018 23:37:18 +0530 Subject: [PATCH 20/57] add sync param --- email/receiver.js | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/email/receiver.js b/email/receiver.js index 24c00f46..856a3494 100644 --- a/email/receiver.js +++ b/email/receiver.js @@ -12,7 +12,6 @@ module.exports = { break; } } - let emailSyncOption = account[i].emailSync; var config = { "user": account[i].email, "password": account[i].password, @@ -21,7 +20,6 @@ module.exports = { "tls": true, } var imap = new Imap(config); - function openInbox(cb) { imap.openBox('INBOX', true, cb); } @@ -31,7 +29,7 @@ module.exports = { openInbox(function (err, box) { if (err) throw err; - imap.search([emailSyncOption, ['SINCE', account[i].initialDate]], function (err, results) { + imap.search([email.syncOption, ['SINCE', account[i].initialDate]], function (err, results) { if (err) throw err; var fetch = imap.fetch(results, { bodies: '' From 7afa6ad4a2b17a051af96c7efb41acb67b0adac3 Mon Sep 17 00:00:00 2001 From: inishchith Date: Mon, 23 Jul 2018 23:37:18 +0530 Subject: [PATCH 21/57] add sync param + reframe name --- email/receiver.js | 7 ++----- 1 file changed, 2 insertions(+), 5 deletions(-) diff --git a/email/receiver.js b/email/receiver.js index 24c00f46..ae9ece10 100644 --- a/email/receiver.js +++ b/email/receiver.js @@ -12,7 +12,6 @@ module.exports = { break; } } - let emailSyncOption = account[i].emailSync; var config = { "user": account[i].email, "password": account[i].password, @@ -21,7 +20,6 @@ module.exports = { "tls": true, } var imap = new Imap(config); - function openInbox(cb) { imap.openBox('INBOX', true, cb); } @@ -31,7 +29,7 @@ module.exports = { openInbox(function (err, box) { if (err) throw err; - imap.search([emailSyncOption, ['SINCE', account[i].initialDate]], function (err, results) { + imap.search([email.syncOption, ['SINCE', account[i].initialDate]], function (err, results) { if (err) throw err; var fetch = imap.fetch(results, { bodies: '' @@ -43,8 +41,7 @@ module.exports = { .then(async function (mail_object) { await frappe.insert({ doctype: 'Email', - // EDITS - name: "Received from : " + mail_object.to.value[0].address + " " + mail_object.subject.slice(0, 10), // needs change : THINK + name: mail_object.to.value[0].address + " " + mail_object.subject.slice(0, 10), fromEmailAddress: mail_object.from.value[0].address, toEmailAddress: mail_object.to.value[0].address, ccEmailAddress: mail_object.cc, From 7774756157e5abd3844b875f390b7a1a9391b4ae Mon Sep 17 00:00:00 2001 From: Suraj Shetty Date: Thu, 9 Aug 2018 22:49:30 +0530 Subject: [PATCH 22/57] Fix bugs - Add mailparser to package.json - Add quotes around default value to prevent migration errors --- backends/sqlite.js | 4 ++-- package.json | 1 + ui/components/Form/Form.vue | 3 ++- 3 files changed, 5 insertions(+), 3 deletions(-) diff --git a/backends/sqlite.js b/backends/sqlite.js index a6438874..94cbb16f 100644 --- a/backends/sqlite.js +++ b/backends/sqlite.js @@ -59,7 +59,7 @@ module.exports = class sqliteDatabase extends Database { async runCreateTableQuery(doctype, columns, indexes) { const query = `CREATE TABLE IF NOT EXISTS ${doctype} ( ${columns.join(", ")} ${indexes.length ? (", " + indexes.join(", ")) : ''})`; - + return await this.run(query); } @@ -79,7 +79,7 @@ module.exports = class sqliteDatabase extends Database { this.typeMap[field.fieldtype], field.fieldname === 'name' ? 'PRIMARY KEY NOT NULL' : '', field.required ? 'NOT NULL' : '', - field.default ? `DEFAULT ${field.default}` : '' + field.default ? `DEFAULT '${field.default}'` : '' ].join(' '); return def; diff --git a/package.json b/package.json index 5f69f834..5df5f599 100644 --- a/package.json +++ b/package.json @@ -36,6 +36,7 @@ "jquery": "^3.3.1", "jwt-simple": "^0.5.1", "luxon": "^1.0.0", + "mailparser": "^2.3.2", "mkdirp": "^0.5.1", "morgan": "^1.9.0", "mysql": "^2.15.0", diff --git a/ui/components/Form/Form.vue b/ui/components/Form/Form.vue index e9ac15f0..2b24ac35 100644 --- a/ui/components/Form/Form.vue +++ b/ui/components/Form/Form.vue @@ -40,7 +40,8 @@ export default { notFound: false, invalid: false, invalidFields: [], - links: [] + links: [], + doc: {} }; }, computed: { From c7db36770a4f92a9ad24fbd5ee57575d0325fc02 Mon Sep 17 00:00:00 2001 From: Suraj Shetty Date: Thu, 9 Aug 2018 23:03:54 +0530 Subject: [PATCH 23/57] Add filter and fields to getAll email account in receiver.js --- email/receiver.js | 36 +++++++++++++++++++----------------- 1 file changed, 19 insertions(+), 17 deletions(-) diff --git a/email/receiver.js b/email/receiver.js index ae9ece10..d51fc9fe 100644 --- a/email/receiver.js +++ b/email/receiver.js @@ -1,24 +1,27 @@ const frappe = require('frappejs'); const simpleParser = require('mailparser').simpleParser; const Imap = require('imap'); -const getConfig = require("./getConfig"); module.exports = { - sync: async (email) => { - let account = await getConfig(); - var i ; - for (i = 0; i < account.length; i++) { - if (account[i].email == email.Id) { - break; + sync: async ({email, syncOption}) => { + // could be replaced with getDoc if account name is set same as email + let account = await frappe.db.getAll({ + doctype: 'EmailAccount', + fields: ['email', 'password', 'imapHost', 'imapPort', 'initialDate'], + filters: { + email } + }); + account = account[0] + + var config = { + "user": account.email, + "password": account.password, + "host": account.imapHost, + "port": account.imapPort, + "tls": true, } - var config = { - "user": account[i].email, - "password": account[i].password, - "host": account[i].imapHost, - "port": account[i].imapPort, - "tls": true, - } + var imap = new Imap(config); function openInbox(cb) { imap.openBox('INBOX', true, cb); @@ -29,7 +32,7 @@ module.exports = { openInbox(function (err, box) { if (err) throw err; - imap.search([email.syncOption, ['SINCE', account[i].initialDate]], function (err, results) { + imap.search([syncOption, ['SINCE', account.initialDate]], function (err, results) { if (err) throw err; var fetch = imap.fetch(results, { bodies: '' @@ -41,7 +44,6 @@ module.exports = { .then(async function (mail_object) { await frappe.insert({ doctype: 'Email', - name: mail_object.to.value[0].address + " " + mail_object.subject.slice(0, 10), fromEmailAddress: mail_object.from.value[0].address, toEmailAddress: mail_object.to.value[0].address, ccEmailAddress: mail_object.cc, @@ -50,7 +52,7 @@ module.exports = { subject: mail_object.subject, bodyHtml: mail_object.html, bodyText: mail_object.text, - sent: "1", + sent: 0, }); }) .catch(function (err) { From ed360ce87878462d806c4fc893407a4b078fc4fd Mon Sep 17 00:00:00 2001 From: Suraj Shetty Date: Fri, 10 Aug 2018 11:18:23 +0530 Subject: [PATCH 24/57] Emit event even if child element in listItem is clicked --- ui/components/List/ListItem.vue | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/ui/components/List/ListItem.vue b/ui/components/List/ListItem.vue index b874b76f..0ab25bd0 100644 --- a/ui/components/List/ListItem.vue +++ b/ui/components/List/ListItem.vue @@ -1,6 +1,6 @@ @@ -30,13 +31,6 @@ export default { this.$emit('change', this.filterValues); } }, - provide() { - return { - dynamicLinkTarget: reference => { - return this.filterValues[reference]; - } - }; - }, methods: { updateValue(fieldname, value) { this.filterValues[fieldname] = value; From b380812c57d0d1b76c48311c3c96320b9484f0a6 Mon Sep 17 00:00:00 2001 From: Faris Ansari Date: Tue, 23 Oct 2018 02:20:35 +0530 Subject: [PATCH 42/57] Dont convert md to html in fieldtype Text --- utils/format.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/utils/format.js b/utils/format.js index de80a707..e944fa25 100644 --- a/utils/format.js +++ b/utils/format.js @@ -1,5 +1,5 @@ const numberFormat = require('./numberFormat'); -const markdown = new (require('showdown').Converter)(); +// const markdown = new (require('showdown').Converter)(); const luxon = require('luxon'); const frappe = require('frappejs'); @@ -13,7 +13,7 @@ module.exports = { value = numberFormat.formatNumber(value); } else if (field.fieldtype === 'Text') { - value = markdown.makeHtml(value || ''); + // value = markdown.makeHtml(value || ''); } else if (field.fieldtype === 'Date') { let dateFormat; From 058011ebe998921bb191d206a4d90d825fd56430 Mon Sep 17 00:00:00 2001 From: Faris Ansari Date: Tue, 23 Oct 2018 02:20:50 +0530 Subject: [PATCH 43/57] Get filters from docfield in Link --- ui/components/controls/Link.vue | 15 ++++++++++----- 1 file changed, 10 insertions(+), 5 deletions(-) diff --git a/ui/components/controls/Link.vue b/ui/components/controls/Link.vue index e0de70fd..f37c5b15 100644 --- a/ui/components/controls/Link.vue +++ b/ui/components/controls/Link.vue @@ -10,13 +10,18 @@ export default { extends: Autocomplete, methods: { async getList(query) { + let filters = this.docfield.getFilters ? + this.docfield.getFilters(query) : + null; + + if (query) { + if (!filters) filters = {}; + filters.keywords = ['like', query]; + } + const list = await frappe.db.getAll({ doctype: this.getTarget(), - filters: query - ? { - keywords: ['like', query] - } - : null, + filters, fields: ['name'], limit: 50 }); From 9fdc94bd93cada675248bb106128a07ae3340439 Mon Sep 17 00:00:00 2001 From: Faris Ansari Date: Tue, 23 Oct 2018 02:21:19 +0530 Subject: [PATCH 44/57] Link bootstrap css in puppeteer for generating pdf --- server/pdf.js | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/server/pdf.js b/server/pdf.js index d4a9545e..bdf3aec9 100644 --- a/server/pdf.js +++ b/server/pdf.js @@ -10,6 +10,9 @@ async function makePDF(html, filepath) { const browser = await puppeteer.launch(); const page = await browser.newPage(); await page.setContent(html); + await page.addStyleTag({ + url: 'https://stackpath.bootstrapcdn.com/bootstrap/4.1.3/css/bootstrap.min.css' + }) await page.pdf({ path: filepath, format: 'A4' @@ -17,9 +20,9 @@ async function makePDF(html, filepath) { await browser.close(); } -async function getPDFForElectron(doctype, name, destination) { +async function getPDFForElectron(doctype, name, destination, htmlContent) { const { shell } = require('electron'); - const html = await getHTML(doctype, name); + const html = htmlContent || await getHTML(doctype, name); const filepath = path.join(destination, name + '.pdf'); await makePDF(html, filepath); shell.openItem(filepath); From 610d592310a41a82ffefcdb473467523c4faed35 Mon Sep 17 00:00:00 2001 From: Faris Ansari Date: Tue, 23 Oct 2018 02:21:34 +0530 Subject: [PATCH 45/57] minor --- ui/components/Form/FormActions.vue | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/ui/components/Form/FormActions.vue b/ui/components/Form/FormActions.vue index 1e3d9fe7..4e052997 100644 --- a/ui/components/Form/FormActions.vue +++ b/ui/components/Form/FormActions.vue @@ -34,13 +34,14 @@ export default { }, created() { this.doc.on('change', () => { - this.isDirty = this.doc._dirty; this.updateShowSubmittable(); }); this.updateShowSubmittable(); }, methods: { updateShowSubmittable() { + this.isDirty = this.doc._dirty; + this.showSubmit = this.meta.isSubmittable && !this.isDirty From 2884c157ec06459fe5ed79c9c3323c6b9ac27ab4 Mon Sep 17 00:00:00 2001 From: Faris Ansari Date: Tue, 23 Oct 2018 09:46:50 +0530 Subject: [PATCH 46/57] Emit updateDoc event from FormLayout --- ui/components/Form/FormLayout.vue | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/ui/components/Form/FormLayout.vue b/ui/components/Form/FormLayout.vue index 58048f5f..7eed8b6c 100644 --- a/ui/components/Form/FormLayout.vue +++ b/ui/components/Form/FormLayout.vue @@ -66,6 +66,10 @@ export default { }, updateDoc(fieldname, value) { this.doc.set(fieldname, value); + this.$emit('updateDoc', { + fieldname, + value + }); }, showSection(i) { if (this.layoutConfig.paginated) { From 8ee664e81ed66c56f828cde910fe9f3bb9ff7433 Mon Sep 17 00:00:00 2001 From: Faris Ansari Date: Tue, 23 Oct 2018 09:47:30 +0530 Subject: [PATCH 47/57] Report filters 4 column --- ui/pages/Report/ReportFilters.vue | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/ui/pages/Report/ReportFilters.vue b/ui/pages/Report/ReportFilters.vue index dc1cc5a2..5e6dcd15 100644 --- a/ui/pages/Report/ReportFilters.vue +++ b/ui/pages/Report/ReportFilters.vue @@ -1,6 +1,6 @@