php - Keeping track of entire email thread with laravel-imap

I'm using webklex's laravel-imap package and I'm doing a pretty standard pull on all the info, parsing, then storing info for each mail into the database.
It works functionally, but I'm having trouble figuring out how to keep track of entire mail threads related to a single originating message. So if Someone sends in a request that results in a thread of 7 more replies, I wanted to have 8 database entries for this (one for each resulting reply/message)
I've pulled in the header info to get the message ID but it doesn't seem to match like I expected and I think I'm just misunderstanding the usage here
How can I properly use the header info to keep track of each single response in a thread?
$aMessages = $inboxFolder->messages()->all()->get();
foreach($aMessages as $oMessage) {
$uid = $oMessage->getUid();
$body = $oMessage->getHTMLBody();
$date_sent = $oMessage->getDate();
$subject = $oMessage->getSubject();
$senderArray = $oMessage->getFrom();
$senderName = strval($senderArray[0]->personal);
$senderEmail = $senderArray[0]->mail;
$header = $oMessage->getHeaderInfo();
$message_header_id = $header->message_id;
$sql = "INSERT INTO MAIL
( MESSAGE_UID, MESSAGE_SENDER, MESSAGE_SENDER_EMAIL, MESSAGE_SUBJECT, MESSAGE_SENT_TIME, MESSAGE_CONTENT,MESSAGE_HEADER_ID, MESSAGE_PROCESSED )
VALUES ( ?, ?, ?,?, ?,?, ?, 'N' )";
DB::connection('odbc')->statement($sql, [$uid, (string)$senderName, (string)$senderEmail, (string)$subject, (string)$date_sent, (string)$formatted_body, (string)$message_header_id]);
}
Share solution ↓
Additional Information:
Link To Answer People are also looking for solutions of the problem: foreign key constraint is incorrectly formed laravel
Didn't find the answer?
Our community is visited by hundreds of web development professionals every day. Ask your question and get a quick answer for free.
Similar questions
Find the answer in similar questions on our website.
Write quick answer
Do you know the answer to this question? Write a quick response to it. With your help, we will make our community stronger.