Skip to content

Commit bb56646

Browse files
committed
fix(mailcheck): crash processing inbound imap email #619
1 parent 78cd6bd commit bb56646

File tree

1 file changed

+18
-3
lines changed

1 file changed

+18
-3
lines changed

src/mailer/mailCheck.js

Lines changed: 18 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ const emitter = require('../emitter')
2323
const userSchema = require('../models/user')
2424
const groupSchema = require('../models/group')
2525
const ticketTypeSchema = require('../models/tickettype')
26+
const statusSchema = require('../models').Status
2627
const Ticket = require('../models/ticket')
2728

2829
const mailCheck = {}
@@ -199,9 +200,9 @@ function bindImapReady () {
199200
})
200201

201202
f.on('end', function () {
202-
mailCheck.Imap.addFlags(results, flag, function() {
203+
mailCheck.Imap.addFlags(results, flag, function () {
203204
mailCheck.Imap.closeBox(true, function () {
204-
mailCheck.Imap.end();
205+
mailCheck.Imap.end()
205206
handleMessages(mailCheck.messages, function () {
206207
mailCheck.Imap.destroy()
207208
})
@@ -346,9 +347,23 @@ function handleMessages (messages, done) {
346347
return callback(null, firstPriority._id)
347348
}
348349
],
350+
handleStatus: function (callback) {
351+
statusSchema.getStatus(function (err, statuses) {
352+
if (err) return callback(err)
353+
354+
const status = _.first(statuses)
355+
356+
if (!status) return callback(new Error('Invalid status'))
357+
358+
message.status = status._id
359+
360+
return callback(null, status._id)
361+
})
362+
},
349363
handleCreateTicket: [
350364
'handleGroup',
351365
'handlePriority',
366+
'handleStatus',
352367
function (results, callback) {
353368
var HistoryItem = {
354369
action: 'ticket:created',
@@ -361,7 +376,7 @@ function handleMessages (messages, done) {
361376
owner: message.owner._id,
362377
group: message.group._id,
363378
type: message.type._id,
364-
status: 0,
379+
status: results.handleStatus,
365380
priority: results.handlePriority,
366381
subject: message.subject,
367382
issue: message.body,

0 commit comments

Comments
 (0)