Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/nextcloud/mail.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAnna Larch <anna@nextcloud.com>2021-02-25 11:30:36 +0300
committerAnna Larch <anna@nextcloud.com>2021-02-26 16:45:01 +0300
commit4cc2dd73fdddabf9299ca91464023d7b706a1e41 (patch)
treeaea66411757fdf5519ce60c41a7717b5078a22e1 /lib/Service
parent649d9b1f384cb088db508a95eeae21dc949617e4 (diff)
Save important flag to IMAP if permflags enabled
Signed-off-by: Anna Larch <anna@nextcloud.com>
Diffstat (limited to 'lib/Service')
-rw-r--r--lib/Service/MailManager.php53
1 files changed, 50 insertions, 3 deletions
diff --git a/lib/Service/MailManager.php b/lib/Service/MailManager.php
index 96c12b5b0..d37278477 100644
--- a/lib/Service/MailManager.php
+++ b/lib/Service/MailManager.php
@@ -26,6 +26,7 @@ namespace OCA\Mail\Service;
use Horde_Imap_Client;
use Horde_Imap_Client_Exception;
use Horde_Imap_Client_Exception_NoSupportExtension;
+use Horde_Imap_Client_Socket;
use OCA\Mail\Account;
use OCA\Mail\Contracts\IMailManager;
use OCA\Mail\Db\Mailbox;
@@ -386,10 +387,13 @@ class MailManager implements IMailManager {
}
// Only send system flags to the IMAP server as other flags might not be supported
- $imapFlags = self::ALLOWED_FLAGS[$flag] ?? [];
+ $imapFlags = $this->filterFlags($account, $flag, $mailbox);
try {
foreach ($imapFlags as $imapFlag) {
- if ($value) {
+ if (empty($imapFlag) === true) {
+ continue;
+ }
+ if ($value === true) {
$this->imapMessageMapper->addFlag($client, $mb, $uid, $imapFlag);
} else {
$this->imapMessageMapper->removeFlag($client, $mb, $uid, $imapFlag);
@@ -509,7 +513,50 @@ class MailManager implements IMailManager {
* @param Message $message
* @return array[]
*/
- public function getMailAttachments(Account $account, Mailbox $mailbox, Message $message) : array {
+ public function getMailAttachments(Account $account, Mailbox $mailbox, Message $message): array {
return $this->imapMessageMapper->getAttachments($this->imapClientFactory->getClient($account), $mailbox->getName(), $message->getUid());
}
+
+ /**
+ * Filter out IMAP flags that aren't supported by the client server
+ *
+ * @param Horde_Imap_Client_Socket $client
+ * @param string $flag
+ * @param string $mailbox
+ * @return array
+ */
+ public function filterFlags(Account $account, string $flag, string $mailbox): array {
+ // check for RFC server flags
+ if (array_key_exists($flag, self::ALLOWED_FLAGS) === true) {
+ return self::ALLOWED_FLAGS[$flag];
+ }
+
+ // Only allow flag setting if IMAP supports Permaflags
+ // @TODO check if there are length & char limits on permflags
+ if ($this->isPermflagsEnabled($account, $mailbox) === true) {
+ return ["$" . $flag];
+ }
+ return [];
+ }
+
+ /**
+ * Check IMAP server for support for PERMANENTFLAGS
+ *
+ * @param Account $account
+ * @param string $mailbox
+ * @return boolean
+ */
+ public function isPermflagsEnabled(Account $account, string $mailbox): bool {
+ $client = $this->imapClientFactory->getClient($account);
+ try {
+ $capabilities = $client->status($mailbox, Horde_Imap_Client::STATUS_PERMFLAGS);
+ } catch (Horde_Imap_Client_Exception $e) {
+ throw new ServiceException(
+ "Could not get message flag options from IMAP: " . $e->getMessage(),
+ (int) $e->getCode(),
+ $e
+ );
+ }
+ return (is_array($capabilities) === true && array_key_exists('permflags', $capabilities) === true && in_array("\*", $capabilities['permflags'], true) === true);
+ }
}