diff --git a/app/Console/Commands/TestWebklex.php b/app/Console/Commands/ParseEml.php similarity index 89% rename from app/Console/Commands/TestWebklex.php rename to app/Console/Commands/ParseEml.php index a8009b6d4..7ffd45aba 100644 --- a/app/Console/Commands/TestWebklex.php +++ b/app/Console/Commands/ParseEml.php @@ -8,24 +8,23 @@ use Illuminate\Console\Command; -class TestWebklex extends Command +class ParseEml extends Command { /** * The name and signature of the console command. * * --mailbox Any mailbox able to connect via IMAP to its mail server. - * --uid Pass any UID from the Webklex/PHP-IMAP fetching output. * * @var string */ - protected $signature = 'freescout:test-webklex {--mailbox=2} {--uid=914}'; + protected $signature = 'freescout:parse-eml {--mailbox=2}'; /** * The console command description. * * @var string */ - protected $description = 'Test Webklex/php-imap library'; + protected $description = 'Parse EML file'; /** * Current mailbox. @@ -63,7 +62,7 @@ public function __construct() */ public function handle() { - $email = file_get_contents(storage_path('logs/test_webklex.eml')); + $email = file_get_contents(storage_path('logs/email.eml')); if (!str_contains($email, "\r\n")){ $email = str_replace("\n", "\r\n", $email); diff --git a/app/Misc/Mail.php b/app/Misc/Mail.php index 62ff1e7cd..7a0632add 100644 --- a/app/Misc/Mail.php +++ b/app/Misc/Mail.php @@ -1064,6 +1064,22 @@ public static function sanitizeSmtpStatusMessage($status_message) { return $status_message; } + public static function parseEml($content, $mailbox) { + if (!str_contains($content, "\r\n")){ + $content = str_replace("\n", "\r\n", $content); + } + + $raw_header = substr($content, 0, strpos($content, "\r\n\r\n")); + $raw_body = substr($content, strlen($raw_header)+8); + + \Config::set('app.new_fetching_library', 'true'); + + $client = \MailHelper::getMailboxClient($mailbox); + $client->openFolder("INBOX"); + + return \Webklex\PHPIMAP\Message::make(null, null, $client, $raw_header, $raw_body, [], \Webklex\PHPIMAP\IMAP::ST_UID); + } + // public static function oauthGetProvider($provider_code, $params) // { // $provider = null;