2378-imap #385

Merged
joan merged 8 commits from 2378-imap into dev 2020-09-23 12:46:34 +00:00
2 changed files with 33 additions and 34 deletions
Showing only changes of commit 2b2970bfcd - Show all commits

View File

@ -46,9 +46,7 @@ module.exports = Self => {
let buffer = ''; let buffer = '';
let bufferCopy = ''; let bufferCopy = '';
stream.on('data', function(chunk) { stream.on('data', function(chunk) {
// console.log('chunk', chunk);
buffer = chunk.toString('utf8'); buffer = chunk.toString('utf8');
// console.log('buffer', buffer);
if (info.which === '1' && bufferCopy.length == 0) if (info.which === '1' && bufferCopy.length == 0)
bufferCopy = buffer.replace(/\s/g, ' '); bufferCopy = buffer.replace(/\s/g, ' ');
}); });
@ -66,10 +64,6 @@ module.exports = Self => {
}); });
msg.once('attributes', function(attrs) { msg.once('attributes', function(attrs) {
uid = attrs.uid; uid = attrs.uid;
// let structure = attrs.struct[2][0];
// console.log('attrs.struct', structure);
// console.log('attrs', structure.params);
// console.log('attrs.struct', structure.find(item => item.subtype === 'html'));
}); });
msg.once('end', function() { msg.once('end', function() {
if (info.which === 'HEADER.FIELDS (FROM SUBJECT)') { if (info.which === 'HEADER.FIELDS (FROM SUBJECT)') {
@ -97,7 +91,7 @@ module.exports = Self => {
}; };
async function emailConfirm(buffer) { async function emailConfirm(buffer) {
// try { console.log('buffer', buffer);
const now = new Date(); const now = new Date();
const from = JSON.stringify(Imap.parseHeader(buffer).from); const from = JSON.stringify(Imap.parseHeader(buffer).from);
const subject = JSON.stringify(Imap.parseHeader(buffer).subject); const subject = JSON.stringify(Imap.parseHeader(buffer).subject);
@ -106,27 +100,28 @@ module.exports = Self => {
const week = timeControlDate[0]; const week = timeControlDate[0];
const year = timeControlDate[1]; const year = timeControlDate[1];
const user = await getUser(from); const user = await getUser(from);
let workerMail;
let workerMail = await Self.app.models.WorkerTimeControlMail.findOne({ if (user.id != NULL) {
workerMail = await Self.app.models.WorkerTimeControlMail.findOne({
where: { where: {
week: week, week: week,
year: year, year: year,
workerFk: user.id workerFk: user.id
} }
}); });
}
if (workerMail != NULL) { if (workerMail != NULL) {
await workerMail.updateAttributes({ await workerMail.updateAttributes({
updated: now, updated: now,
state: 'CONFIRMED' state: 'CONFIRMED'
}); });
} }
// } catch (err) {
// throw err;
// }
} }
async function emailReply(buffer, emailBody) { async function emailReply(buffer, emailBody) {
// try { console.log('buffer', buffer);
console.log('emailBody', emailBody);
const now = new Date(); const now = new Date();
const from = JSON.stringify(Imap.parseHeader(buffer).from); const from = JSON.stringify(Imap.parseHeader(buffer).from);
const subject = JSON.stringify(Imap.parseHeader(buffer).subject); const subject = JSON.stringify(Imap.parseHeader(buffer).subject);
@ -135,25 +130,26 @@ module.exports = Self => {
const week = timeControlDate[0]; const week = timeControlDate[0];
const year = timeControlDate[1]; const year = timeControlDate[1];
const user = await getUser(from); const user = await getUser(from);
let workerMail;
let workerMail = await Self.app.models.WorkerTimeControlMail.findOne({ if (user.id != NULL) {
workerMail = await Self.app.models.WorkerTimeControlMail.findOne({
where: { where: {
week: week, week: week,
year: year, year: year,
workerFk: user.id workerFk: user.id
} }
}); });
if (workerMail != NULL) { if (workerMail != NULL) {
await workerMail.updateAttributes({ await workerMail.updateAttributes({
updated: now, updated: now,
state: 'REVISE' state: 'REVISE',
emailResponse: emailBody
}); });
} } else
await sendMail(user, subject, emailBody); await sendMail(user, subject, emailBody);
// } catch (err) { }
// throw err;
// }
} }
async function getUser(workerEmail) { async function getUser(workerEmail) {

View File

@ -26,6 +26,9 @@
}, },
"updated": { "updated": {
"type": "Date" "type": "Date"
},
"emailResponse": {
"type": "String"
} }
}, },
"acls": [ "acls": [