Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion lib/Contracts/IMailManager.php
Original file line number Diff line number Diff line change
Expand Up @@ -45,12 +45,13 @@ public function getMailboxes(Account $account): array;
/**
* @param Account $account
* @param string $name
* @param string[] $specialUse
*
* @return Mailbox
*
* @throws ServiceException
*/
public function createMailbox(Account $account, string $name): Mailbox;
public function createMailbox(Account $account, string $name, array $specialUse = []): Mailbox;

/**
* @param Mailbox $mailbox
Expand Down
7 changes: 4 additions & 3 deletions lib/IMAP/FolderMapper.php
Original file line number Diff line number Diff line change
Expand Up @@ -71,9 +71,10 @@ public function getFolders(Account $account, Horde_Imap_Client_Socket $client,
), $toPersist);
}

public function createFolder(Horde_Imap_Client_Socket $client,
string $name): Folder {
$client->createMailbox($name);
public function createFolder(Horde_Imap_Client_Socket $client, string $name, array $specialUse = []): Folder {
$client->createMailbox($name, [
'special_use' => $specialUse,
]);

$list = $client->listMailboxes($name, Horde_Imap_Client::MBOX_ALL_SUBSCRIBED, [
'delimiter' => true,
Expand Down
11 changes: 2 additions & 9 deletions lib/Service/MailManager.php
Original file line number Diff line number Diff line change
Expand Up @@ -141,18 +141,11 @@ public function getMailboxes(Account $account): array {
return $this->mailboxMapper->findAll($account);
}

/**
* @param Account $account
* @param string $name
*
* @return Mailbox
* @throws ServiceException
*/
#[\Override]
public function createMailbox(Account $account, string $name): Mailbox {
public function createMailbox(Account $account, string $name, array $specialUse = []): Mailbox {
$client = $this->imapClientFactory->getClient($account);
try {
$folder = $this->folderMapper->createFolder($client, $name);
$folder = $this->folderMapper->createFolder($client, $name, $specialUse);
$this->folderMapper->fetchFolderAcls([$folder], $client);
} catch (Horde_Imap_Client_Exception $e) {
throw new ServiceException(
Expand Down
23 changes: 17 additions & 6 deletions lib/Service/MailTransmission.php
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@
use OCA\Mail\Account;
use OCA\Mail\Address;
use OCA\Mail\AddressList;
use OCA\Mail\Contracts\IMailManager;
use OCA\Mail\Contracts\IMailTransmission;
use OCA\Mail\Db\LocalMessage;
use OCA\Mail\Db\Mailbox;
Expand Down Expand Up @@ -67,6 +68,7 @@ public function __construct(
private PerformanceLogger $performanceLogger,
private AliasesService $aliasesService,
private TransmissionService $transmissionService,
private IMailManager $mailManager,
) {
}

Expand Down Expand Up @@ -231,12 +233,7 @@ public function saveLocalDraft(Account $account, LocalMessage $message): void {
$transport = new Horde_Mail_Transport_Null();
$mail->send($transport, false, false);
$perfLogger->step('create IMAP draft message');
// save the message in the drafts folder
$draftsMailboxId = $account->getMailAccount()->getDraftsMailboxId();
if ($draftsMailboxId === null) {
throw new ClientException('No drafts mailbox configured');
}
$draftsMailbox = $this->mailboxMapper->findById($draftsMailboxId);
$draftsMailbox = $this->findOrCreateDraftsMailbox($account);
$this->messageMapper->save(
$client,
$draftsMailbox,
Expand All @@ -258,6 +255,20 @@ public function saveLocalDraft(Account $account, LocalMessage $message): void {
$perfLogger->end();
}

private function findOrCreateDraftsMailbox(Account $account): Mailbox {
$draftsMailboxId = $account->getMailAccount()->getDraftsMailboxId();

if ($draftsMailboxId === null) {
return $this->mailManager->createMailbox(
$account,
'Drafts',
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We should probably translate it, but if the server doesn’t support storing the special-use flag, guessing the special use from the folder name will fail since we don’t know that “Entwürfe” means “Drafts”. So using the untranslated version is the safer option.

[Horde_Imap_Client::SPECIALUSE_DRAFTS]
);
}

return $this->mailboxMapper->findById($draftsMailboxId);
}

/**
* @param NewMessageData $message
* @param Message|null $previousDraft
Expand Down
Loading