2378-imap #385
|
@ -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) {
|
||||||
where: {
|
workerMail = await Self.app.models.WorkerTimeControlMail.findOne({
|
||||||
week: week,
|
where: {
|
||||||
year: year,
|
week: week,
|
||||||
workerFk: user.id
|
year: year,
|
||||||
}
|
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) {
|
||||||
where: {
|
workerMail = await Self.app.models.WorkerTimeControlMail.findOne({
|
||||||
week: week,
|
where: {
|
||||||
year: year,
|
week: week,
|
||||||
workerFk: user.id
|
year: year,
|
||||||
}
|
workerFk: user.id
|
||||||
});
|
}
|
||||||
if (workerMail != NULL) {
|
|
||||||
await workerMail.updateAttributes({
|
|
||||||
updated: now,
|
|
||||||
state: 'REVISE'
|
|
||||||
});
|
});
|
||||||
}
|
|
||||||
|
|
||||||
await sendMail(user, subject, emailBody);
|
if (workerMail != NULL) {
|
||||||
// } catch (err) {
|
await workerMail.updateAttributes({
|
||||||
// throw err;
|
updated: now,
|
||||||
// }
|
state: 'REVISE',
|
||||||
|
emailResponse: emailBody
|
||||||
|
});
|
||||||
|
} else
|
||||||
|
await sendMail(user, subject, emailBody);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
async function getUser(workerEmail) {
|
async function getUser(workerEmail) {
|
||||||
|
|
|
@ -26,6 +26,9 @@
|
||||||
},
|
},
|
||||||
"updated": {
|
"updated": {
|
||||||
"type": "Date"
|
"type": "Date"
|
||||||
|
},
|
||||||
|
"emailResponse": {
|
||||||
|
"type": "String"
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
"acls": [
|
"acls": [
|
||||||
|
|
Loading…
Reference in New Issue