With each mailbox, connect to the mailbox and get all the emails from the box
With each email, get the email info (to address, from address, subject, content, ...)
If the email cannot be read - failure (the email is too big or any reason) → an error ticket is created, this ticket does not have contact
Get all the items not yet processed from the current mailbox and create a ticket for each, note only emails with a To, CC or BCC Address matching the valid ticket types will create a ticket
Determine whether this email is a new email or a reply to a previous ticket.
Each outbound email from the ticketing engine has a generated subject line for the ticket type
example [Support #123-789] - This is a "Support" type ticket, the Ticket ID is 123 and the Support Log ID is 789.
If this email has a ticket-generated subject line it is a reply and is added to the existing ticket, if not a new ticket is created.