/**
 * Get data of returned email
 * 
 * @param string Prepared message text (without text after body terminator)
 * @param string Full message text
 * @param string Headers
 * @return array ( 'address', 'errormsg', 'message', 'headers', 'errtype' )
 */
function dre_get_email_data($content, $message_text, $headers)
{
    global $servertimenow;
    // Extract emails from content:
    $emails = utf8_strtolower(dre_get_emails($content));
    // Get content between email and body terminator:
    $content = dre_get_processing_content($content, $emails);
    // Get Error info:
    $error_info = dre_get_error_info($content);
    $email_returned = array('address' => $emails, 'errormsg' => $error_info['text'], 'timestamp' => date2mysql($servertimenow), 'message' => htmlspecialchars(utf8_clean($message_text)), 'headers' => $headers, 'errtype' => $error_info['type']);
    return $email_returned;
}
/**
 * Insert a returned email's data into DB
 *
 * @param string Prepared message text (without text after body terminator)
 * @param string Full message text
 * @param string Headers
 * @return array|boolean Data of returned email| False
 */
function dre_insert_returned_email($content, $message_text, $headers)
{
    global $DB, $dre_emails;
    // Extract emails from content
    $emails = dre_get_emails($content);
    // Get content between email and body terminator
    $content = dre_get_processing_content($content, $emails);
    // Get Error info
    $error_info = dre_get_error_info($content);
    $email_returned = array('address' => $emails, 'errormsg' => $error_info['text'], 'message' => $message_text, 'headers' => $headers, 'errtype' => $error_info['type']);
    // INSERT RETURNED DATA INTO DB
    $DB->query('INSERT INTO T_email__returns ( emret_address, emret_errormsg, emret_message, emret_headers, emret_errtype )
		VALUES ( ' . $DB->quote($email_returned) . ' )');
    if ($DB->insert_id > 0) {
        // Save a blocked email's data
        dre_save_blocked_email($email_returned);
        // Save saved emails for reports
        $dre_emails[] = $email_returned;
        return $email_returned;
    } else {
        return false;
    }
}