function fetch_message($client, $uid)
 {
     $structure = imap_fetchstructure($client, $uid, FT_UID);
     //Check if email is plaintext or MIME type
     if ($structure->type) {
         //The message is not just plaintext
         $emailMessage = new EmailMessage($client, $uid);
         $emailMessage->fetch();
         process_inline($emailMessage);
         $data = $emailMessage->bodyHTML;
     } else {
         //Is the message a reply?
         $email_header = imap_fetch_overview($client, $uid, FT_UID)[0];
         //The message is plaintext
         if (!isset($email_header->in_reply_to)) {
             $data = imap_fetchbody($client, $uid, 1, FT_UID);
         } else {
             // Message is a reply, need to format returned value
             $data = imap_fetchbody($client, $uid, 1, FT_UID);
             if (preg_match('/>\\s\\t*On/im', $data)) {
                 $data = preg_replace('/>\\s\\t*On/im', '<br/><div class="collapse"> > On', $data);
                 $data .= '</div>';
             }
         }
     }
     return $data;
 }