mirror of
https://github.com/the-djmaze/snappymail.git
synced 2026-09-07 00:17:03 +03:00
Added IMAP RFC 8508 REPLACE
This commit is contained in:
parent
e5f1c41df0
commit
f4bbd02e69
3 changed files with 88 additions and 36 deletions
|
|
@ -118,7 +118,7 @@ trait Messages
|
||||||
* @throws \MailSo\Net\Exceptions\Exception
|
* @throws \MailSo\Net\Exceptions\Exception
|
||||||
* @throws \MailSo\Imap\Exceptions\Exception
|
* @throws \MailSo\Imap\Exceptions\Exception
|
||||||
*/
|
*/
|
||||||
public function MessageAppendStream(string $sFolderName, $rMessageAppendStream, int $iStreamSize, array $aFlagsList = null, int &$iUid = null, int $iDateTime = 0) : ?int
|
public function MessageAppendStream(string $sFolderName, $rMessageAppendStream, int $iStreamSize, array $aFlagsList = null, int $iDateTime = 0) : ?int
|
||||||
{
|
{
|
||||||
$aParams = array(
|
$aParams = array(
|
||||||
$this->EscapeFolderName($sFolderName),
|
$this->EscapeFolderName($sFolderName),
|
||||||
|
|
@ -138,27 +138,34 @@ trait Messages
|
||||||
|
|
||||||
$this->SendRequestGetResponse('APPEND', $aParams);
|
$this->SendRequestGetResponse('APPEND', $aParams);
|
||||||
|
|
||||||
|
return $this->writeMessageStream($rMessageAppendStream);
|
||||||
|
}
|
||||||
|
|
||||||
|
private function writeMessageStream($rMessageStream) : ?int
|
||||||
|
{
|
||||||
$this->writeLog('Write to connection stream', LogType::NOTE);
|
$this->writeLog('Write to connection stream', LogType::NOTE);
|
||||||
|
|
||||||
\MailSo\Base\Utils::MultipleStreamWriter($rMessageAppendStream, array($this->ConnectionResource()));
|
\MailSo\Base\Utils::MultipleStreamWriter($rMessageStream, array($this->ConnectionResource()));
|
||||||
|
|
||||||
$this->sendRaw('');
|
$this->sendRaw('');
|
||||||
$oResponse = $this->getResponse();
|
$oResponses = $this->getResponse();
|
||||||
|
/**
|
||||||
if (null !== $iUid) {
|
* Can be tagged
|
||||||
$oLast = $oResponse->getLast();
|
S: A003 OK [APPENDUID 1 2001] APPEND completed
|
||||||
if ($oLast
|
* Or untagged
|
||||||
&& ResponseType::TAGGED === $oLast->ResponseType
|
S: * OK [APPENDUID 1 2001] Replacement Message ready
|
||||||
&& \is_array($oLast->OptionalResponse)
|
*/
|
||||||
&& !empty($oLast->OptionalResponse[2])
|
foreach ($oResponses as $oResponse) {
|
||||||
&& \is_numeric($oLast->OptionalResponse[2])
|
if (\is_array($oResponse->OptionalResponse)
|
||||||
&& 'APPENDUID' === \strtoupper($oLast->OptionalResponse[0])
|
&& !empty($oResponse->OptionalResponse[2])
|
||||||
|
&& \is_numeric($oResponse->OptionalResponse[2])
|
||||||
|
&& 'APPENDUID' === \strtoupper($oResponse->OptionalResponse[0])
|
||||||
) {
|
) {
|
||||||
$iUid = (int) $oLast->OptionalResponse[2];
|
return (int) $oResponse->OptionalResponse[2];
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return $iUid;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
@ -206,6 +213,55 @@ trait Messages
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* RFC 8508 REPLACE
|
||||||
|
* Replaces message in specified folder
|
||||||
|
* When $iUid < 1 it only appends the message
|
||||||
|
*
|
||||||
|
* @param resource $rMessageStream
|
||||||
|
*
|
||||||
|
* @throws \MailSo\Base\Exceptions\InvalidArgumentException
|
||||||
|
* @throws \MailSo\Net\Exceptions\Exception
|
||||||
|
* @throws \MailSo\Imap\Exceptions\Exception
|
||||||
|
*/
|
||||||
|
public function MessageReplaceStream(string $sFolderName, int $iUid, $rMessageStream, int $iStreamSize, array $aFlagsList = null, int $iDateTime = 0) : ?int
|
||||||
|
{
|
||||||
|
if (1 > $iUid || !$this->IsSupported('REPLACE')) {
|
||||||
|
$this->FolderSelect($sFolderName);
|
||||||
|
$iNewUid = $this->MessageAppendStream($sFolderName, $rMessageStream, $iStreamSize, $aFlagsList, $iDateTime);
|
||||||
|
if ($iUid) {
|
||||||
|
$oRange = new SequenceSet([$iUid]);
|
||||||
|
$this->MessageStoreFlag($oRange,
|
||||||
|
array(\MailSo\Imap\Enumerations\MessageFlag::DELETED),
|
||||||
|
\MailSo\Imap\Enumerations\StoreAction::ADD_FLAGS_SILENT
|
||||||
|
);
|
||||||
|
$this->FolderExpunge($oRange);
|
||||||
|
}
|
||||||
|
return $iNewUid;
|
||||||
|
}
|
||||||
|
|
||||||
|
$aParams = array(
|
||||||
|
$iUid,
|
||||||
|
$this->EscapeFolderName($sFolderName),
|
||||||
|
$aFlagsList
|
||||||
|
);
|
||||||
|
if (0 < $iDateTime) {
|
||||||
|
$aParams[] = $this->EscapeString(\gmdate('d-M-Y H:i:s', $iDateTime).' +0000');
|
||||||
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
|
// RFC 3516 || RFC 6855 section-4
|
||||||
|
if ($this->IsSupported('BINARY') || $this->IsSupported('UTF8=ACCEPT')) {
|
||||||
|
$aParams[] = '~{'.$iStreamSize.'}';
|
||||||
|
}
|
||||||
|
*/
|
||||||
|
$aParams[] = '{'.$iStreamSize.'}';
|
||||||
|
|
||||||
|
$this->SendRequestGetResponse('UID REPLACE', $aParams);
|
||||||
|
|
||||||
|
return $this->writeMessageStream($rMessageStream);
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @throws \MailSo\Base\Exceptions\InvalidArgumentException
|
* @throws \MailSo\Base\Exceptions\InvalidArgumentException
|
||||||
* @throws \MailSo\Net\Exceptions\Exception
|
* @throws \MailSo\Net\Exceptions\Exception
|
||||||
|
|
|
||||||
|
|
@ -401,8 +401,8 @@ class MailClient
|
||||||
throw new \MailSo\Base\Exceptions\InvalidArgumentException;
|
throw new \MailSo\Base\Exceptions\InvalidArgumentException;
|
||||||
}
|
}
|
||||||
|
|
||||||
$this->oImapClient->MessageAppendStream(
|
$iUid = $this->oImapClient->MessageAppendStream(
|
||||||
$sFolderToSave, $rMessageStream, $iMessageStreamSize, $aAppendFlags, $iUid);
|
$sFolderToSave, $rMessageStream, $iMessageStreamSize, $aAppendFlags);
|
||||||
|
|
||||||
return $this;
|
return $this;
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -141,10 +141,14 @@ class KolabAddressBook implements AddressBookInterface
|
||||||
$oContact->PopulateDisplayAndFullNameValue();
|
$oContact->PopulateDisplayAndFullNameValue();
|
||||||
|
|
||||||
$iUID = $oContact->IdContact;
|
$iUID = $oContact->IdContact;
|
||||||
$sUUID = $oContact->GetUID();
|
|
||||||
|
|
||||||
$oPrevMessage = $this->MailClient()->Message($this->FolderName(), $iUID);
|
$oPrevMessage = $this->MailClient()->Message($this->FolderName(), $iUID);
|
||||||
$oVCard = $oPrevMessage ? $this->fetchXCardFromMessage($oPrevMessage) : null;
|
if ($oPrevMessage) {
|
||||||
|
$oVCard = $this->fetchXCardFromMessage($oPrevMessage);
|
||||||
|
} else {
|
||||||
|
$oVCard = null;
|
||||||
|
$iUID = 0;
|
||||||
|
}
|
||||||
|
|
||||||
$oMessage = new \MailSo\Mime\Message();
|
$oMessage = new \MailSo\Mime\Message();
|
||||||
|
|
||||||
|
|
@ -162,7 +166,7 @@ class KolabAddressBook implements AddressBookInterface
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
$oMessage->SetSubject($sUUID);
|
$oMessage->SetSubject($oContact->GetUID());
|
||||||
// $oMessage->SetDate(\time());
|
// $oMessage->SetDate(\time());
|
||||||
$oMessage->Headers->AddByName('X-Kolab-Type', 'application/x-vnd.kolab.contact');
|
$oMessage->Headers->AddByName('X-Kolab-Type', 'application/x-vnd.kolab.contact');
|
||||||
$oMessage->Headers->AddByName('X-Kolab-Mime-Version', '3.0');
|
$oMessage->Headers->AddByName('X-Kolab-Mime-Version', '3.0');
|
||||||
|
|
@ -185,25 +189,13 @@ class KolabAddressBook implements AddressBookInterface
|
||||||
$oPart->Body = $oContact->ToXCard($oVCard/*, $oLogger*/);
|
$oPart->Body = $oContact->ToXCard($oVCard/*, $oLogger*/);
|
||||||
$oMessage->SubParts->append($oPart);
|
$oMessage->SubParts->append($oPart);
|
||||||
|
|
||||||
if ($oPrevMessage) {
|
|
||||||
// Replace Message
|
|
||||||
if (false && $this->ImapClient()->IsSupported('REPLACE')) {
|
|
||||||
// UID REPLACE
|
|
||||||
} else {
|
|
||||||
$this->MailClient()->MessageDelete(
|
|
||||||
$this->FolderName(),
|
|
||||||
new \MailSo\Imap\SequenceSet([$iUID])
|
|
||||||
);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// Store Message
|
// Store Message
|
||||||
$rMessageStream = \MailSo\Base\ResourceRegistry::CreateMemoryResource();
|
$rMessageStream = \MailSo\Base\ResourceRegistry::CreateMemoryResource();
|
||||||
$iMessageStreamSize = \MailSo\Base\Utils::MultipleStreamWriter(
|
$iMessageStreamSize = \MailSo\Base\Utils::MultipleStreamWriter(
|
||||||
$oMessage->ToStream(false), array($rMessageStream), 8192, true, true);
|
$oMessage->ToStream(false), array($rMessageStream), 8192, true, true);
|
||||||
if (false !== $iMessageStreamSize) {
|
if (false !== $iMessageStreamSize) {
|
||||||
\rewind($rMessageStream);
|
\rewind($rMessageStream);
|
||||||
$this->ImapClient()->MessageAppendStream($this->sFolderName, $rMessageStream, $iMessageStreamSize);
|
$this->ImapClient()->MessageReplaceStream($this->sFolderName, $iUID, $rMessageStream, $iMessageStreamSize);
|
||||||
}
|
}
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
|
|
@ -211,10 +203,14 @@ class KolabAddressBook implements AddressBookInterface
|
||||||
|
|
||||||
public function DeleteContacts(string $sEmail, array $aContactIds) : bool
|
public function DeleteContacts(string $sEmail, array $aContactIds) : bool
|
||||||
{
|
{
|
||||||
$this->MailClient()->MessageDelete(
|
try {
|
||||||
$this->FolderName(),
|
$this->MailClient()->MessageDelete(
|
||||||
new \MailSo\Imap\SequenceSet($aContactIds)
|
$this->FolderName(),
|
||||||
);
|
new \MailSo\Imap\SequenceSet($aContactIds)
|
||||||
|
);
|
||||||
|
return true;
|
||||||
|
} catch (\Throwable $e) {
|
||||||
|
}
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue