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

View File

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