Skip to content

Commit

Permalink
up
Browse files Browse the repository at this point in the history
  • Loading branch information
Mikhail Sazanov committed Aug 15, 2023
1 parent 0f5ba6d commit c73a2bc
Show file tree
Hide file tree
Showing 6 changed files with 83 additions and 1 deletion.
2 changes: 2 additions & 0 deletions src/Collections/MessageCollection.php
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,8 @@ public function findHeaders(array $fields = [
'Date',
'Message-ID',
'Reply-To',
'References',
'In-Reply-To',
'Return-Path',
'Subject',
'Content-Type'
Expand Down
15 changes: 15 additions & 0 deletions src/Commands/AuthenticateCommand.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
<?php

namespace Sazanof\PhpImapSockets\Commands;

class AuthenticateCommand extends Command
{
protected string $name = 'AUTHENTICATE';

public function __construct($username, $password)
{
$connectionString = 'XOAUTH2 ' . base64_encode("user=$username\1auth=Bearer $password\1\1");
$this->setArguments($connectionString);
}

}
8 changes: 8 additions & 0 deletions src/Commands/CapabilityCommand.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
<?php

namespace Sazanof\PhpImapSockets\Commands;

class CapabilityCommand extends Command
{
protected string $name = 'CAPABILITY';
}
15 changes: 15 additions & 0 deletions src/Connection.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@
use ReflectionException;
use ReflectionMethod;
use Sazanof\PhpImapSockets\Collections\MailboxCollection;
use Sazanof\PhpImapSockets\Commands\AuthenticateCommand;
use Sazanof\PhpImapSockets\Commands\CapabilityCommand;
use Sazanof\PhpImapSockets\Commands\CheckCommand;
use Sazanof\PhpImapSockets\Commands\CloseCommand;
use Sazanof\PhpImapSockets\Commands\Command;
Expand Down Expand Up @@ -305,6 +307,19 @@ public function login(string $login, string $password): self
return $this;
}

public function capability()
{
return $this->command(CapabilityCommand::class);
}

public function authenticate(string $user, string $token): Response
{

return $this->command(AuthenticateCommand::class, [$user, $token]);

}


/**
* Logout and close the connection.
*
Expand Down
2 changes: 1 addition & 1 deletion src/Models/Address.php
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ public static function firstFromString(string $string)
$_address = $addresses[0]->host !== self::NONE_EXISTENT ? $addresses[0] : null; // TODo throw Exception better???
$address->setHost($_address->host);
$address->setUser($_address->mailbox);
$address->setName($_address->personal);
$address->setName($_address->personal ?? null);
$address->setEmail($address->getUser() . '@' . $address->getHost());
$address->toRfc822String();
}
Expand Down
42 changes: 42 additions & 0 deletions src/Models/Message.php
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,8 @@ class Message
protected bool $isImportant = false;
protected array $flags;
protected ?string $body = null;
protected ?string $references = null;
protected ?string $inReplyTo = null;

public function __construct()
{
Expand Down Expand Up @@ -67,6 +69,13 @@ public function setHeaders(array|MessageHeadersCollection $headers): void
$this->getHeaders()->getHeader('to')->getValue()
);

$this->setReferences(
$this->getHeaders()->getHeader('references') ? $this->getHeaders()->getHeader('references')->getValue() : null
);

$this->setInReplyTo(
$this->getHeaders()->getHeader('in-reply-to') ? $this->getHeaders()->getHeader('in-reply-to')->getValue() : null
);
$contentType = $this->getHeaders()->getHeader('content-type')->getValue();
if (preg_match('/^(.*?)\/(.*?);boundary="(.*?)"$/', $contentType, $matches)) {
$this->setBoundary($matches[3]);
Expand All @@ -78,6 +87,39 @@ public function setHeaders(array|MessageHeadersCollection $headers): void

}

/**
* @return string|null
*/
public function getReferences(): ?string
{
return $this->references;
}

/**
* @param string|null $references
*/
public function setReferences(?string $references): void
{
$this->references = $references;
}

/**
* @param string|null $inReplyTo
*/
public function setInReplyTo(?string $inReplyTo): void
{
$this->inReplyTo = $inReplyTo;
}

/**
* @return string|null
*/
public function getInReplyTo(): ?string
{
return $this->inReplyTo;
}


/**
* @param Mailbox $mailbox
*/
Expand Down

0 comments on commit c73a2bc

Please sign in to comment.