Skip to content

Mail Check issue #684

@miko007

Description

@miko007

Is this a BUG REPORT or FEATURE REQUEST?:

  • BUG
  • FEATURE

What happened:
I tried to setup mail check with our inbox. the mails get read, but no tickets are created.

What did you expect to happen:
trudesk to fetch unread mails and create tickets from them

How to reproduce it (as minimally and precisely as possible):
set up mail check and try to create a ticket by sending an email to the configured mail account.

Anything else we need to know?:
This seems to be some race condition in the imap library. i put some debug lines into src/mailer/mailCheck.js:

...
                          if (_.isUndefined(mail.textAsHtml)) {
                            var $ = cheerio.load(mail.html)
                            var $body = $('body')
                            message.body = $body.length > 0 ? $body.html() : mail.html
 
                          } else {
                            message.body = mail.textAsHtml
                          }
 
      console.log("--------- PUSHING TICKET", message);
                          mailCheck.messages.push(message)
                        })
                      })
                    })
                  })
 
                    f.once('end', () => {
     console.log("----------- MESSAGES", mailCheck.messages);
                    mailCheck.Imap.addFlags(results, flag, function () {
                      mailCheck.Imap.closeBox(true, function () {
                        mailCheck.Imap.end()
                        handleMessages(mailCheck.messages, function () {
                          mailCheck.Imap.destroy()
                        })
                      })
                    })
...

this showed, that the f.once('end') event is fired before all messages have been processed. the mailCheck.messages array is empty at that point, although it gets filled correctly.

to further solidify my theory, i packed the callback of f.once('end') into a timeout:

                    f.once('end', () => {
                          setTimeout(() => {
 
     console.log("----------- MESSAGES", mailCheck.messages);
                    mailCheck.Imap.addFlags(results, flag, function () {
                      mailCheck.Imap.closeBox(true, function () {
                        mailCheck.Imap.end()
                        handleMessages(mailCheck.messages, function () {
                          mailCheck.Imap.destroy()
                        })
                      })
                    })
                          }, 2000);

after this, mail check worked as expected. i do not know the codebase well enough to suggest if this is some logic error inside mailCheck.js or a bug in the imap library, but one or the other is most likely the case.

Environment:

  • Trudesk Version: current master
  • OS (e.g. from /etc/os-release): CentOS 7
  • Node.JS Version: v20.15.1
  • MongoDB Version: --
  • Is this hosted on cloud.trudesk.io: no

Metadata

Metadata

Assignees

No one assigned

    Labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions