Skip to content

Commit

Permalink
Add MailHelper::parseEml() function
Browse files Browse the repository at this point in the history
  • Loading branch information
freescout-help-desk committed Jun 10, 2024
1 parent 1fd00de commit 08a5d5f
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down Expand Up @@ -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);
Expand Down
16 changes: 16 additions & 0 deletions app/Misc/Mail.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down

0 comments on commit 08a5d5f

Please sign in to comment.