Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
41 commits
Select commit Hold shift + click to select a range
21a5cba
basic new view
mmittelb Sep 5, 2019
6d7b0dc
Setup storing of sieve settings
pierlon Jun 22, 2019
bc7c457
Add sieve settings to account form
pierlon Jun 22, 2019
e0d2677
Store sieve settings from account form
pierlon Jun 22, 2019
efe41b3
Apply suggestions from code review
pierlon Jul 2, 2019
04b9ada
Add filter settings section
pierlon Sep 6, 2019
ad68ce1
Change active Sieve script
pierlon Sep 10, 2019
4b1ca97
basic sieve view + managesieve-* entities added
mmittelb Sep 10, 2019
a6e052f
Set custom Sieve script
pierlon Sep 11, 2019
5500191
Add option to choose filter modes
pierlon Sep 11, 2019
5e30083
Apply suggestions from code review
pierlon Sep 12, 2019
e24a7ea
vuexified the sieve component and split it into multiple components
mmittelb Sep 12, 2019
cb22a01
Fix failing tests
pierlon Sep 12, 2019
9b293ef
include file changes forgotten in last commit
mmittelb Sep 13, 2019
87f6a86
fixing whitespaces
mmittelb Sep 13, 2019
4c6731c
prepare for merge to pierlon/mail/feature/sieve-filters
mmittelb Sep 13, 2019
ffce2bf
fix even more whitespaces
mmittelb Sep 13, 2019
0d02f87
Merge branch 'mmittelb/mail/enhancement/sieve_#44' into 'pierlon/mail…
mmittelb Sep 13, 2019
f154227
finishing merge
mmittelb Sep 13, 2019
3fa328f
added an action to fetch scripts from the server
mmittelb Sep 13, 2019
d430498
raw editor added
mmittelb Sep 15, 2019
0ff3a4a
added raw editor and editor
mmittelb Sep 26, 2019
a38ad68
added actions to user interface
mmittelb Sep 29, 2019
e75db36
sieve script creation added
mmittelb Oct 1, 2019
129abc1
added parsing
mmittelb Oct 3, 2019
0e8b058
added: script download from server, active script handling, change wa…
mmittelb Oct 8, 2019
54522c3
added license header, added content and header exist test, added rege…
mmittelb Oct 9, 2019
4d38ce1
fix error if no script active; fix unselectable textinput
mmittelb Oct 10, 2019
a914d10
Setup storing of sieve settings
pierlon Jun 22, 2019
960ccbf
Add sieve settings to account form
pierlon Jun 22, 2019
eff785c
Store sieve settings from account form
pierlon Jun 22, 2019
0e9b506
Apply suggestions from code review
pierlon Jul 2, 2019
45891a2
Add filter settings section
pierlon Sep 6, 2019
51727e2
Change active Sieve script
pierlon Sep 10, 2019
443b1e0
Set custom Sieve script
pierlon Sep 11, 2019
91dff6f
Add option to choose filter modes
pierlon Sep 11, 2019
244f87d
Apply suggestions from code review
pierlon Sep 12, 2019
32046e2
Fix failing tests
pierlon Sep 12, 2019
ea8101a
Add param to set custom script name
pierlon Oct 17, 2019
a3164b4
Merge branch 'feature/sieve-filters' into feature/sieve-filters
mmittelb Oct 18, 2019
7396655
Merge pull request #1 from mmittelb/feature/sieve-filters
mmittelb Oct 18, 2019
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
6 changes: 6 additions & 0 deletions appinfo/routes.php
Original file line number Diff line number Diff line change
Expand Up @@ -113,6 +113,11 @@
'url' => '/proxy',
'verb' => 'GET'
],
[
'name' => 'sieve#setActiveScript',
'url' => '/api/accounts/{accountId}/scripts/active',
'verb' => 'POST'
],
],
'resources' => [
'accounts' => ['url' => '/api/accounts'],
Expand All @@ -122,5 +127,6 @@
'localAttachments' => ['url' => '/api/attachments'],
'messages' => ['url' => '/api/accounts/{accountId}/folders/{folderId}/messages'],
'preferences' => ['url' => '/api/preferences'],
'sieve' => ['url' => '/api/accounts/{accountId}/scripts'],
]
];
4 changes: 3 additions & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -29,11 +29,13 @@
"pear-pear.horde.org/horde_text_flowed": "^2.0.3@stable",
"pear-pear.horde.org/horde_util": "^2.5.8@stable",
"pear-pear.horde.org/horde_smtp": "^1.9.5@stable",
"pear-pear.horde.org/horde_managesieve": "^1.0.2@stable",
"cerdic/css-tidy": "v1.7.1",
"ezyang/htmlpurifier": "4.11.0",
"kwi/urllinker": "dev-bleeding",
"gravatarphp/gravatar": "^2.0",
"arthurhoaro/favicon": "^1.2"
"arthurhoaro/favicon": "^1.2",
"protonlabs/libsieve-php": "^2.0"
},
"require-dev": {
"christophwurst/nextcloud": "v17.0.0-beta3",
Expand Down
95 changes: 95 additions & 0 deletions composer.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

54 changes: 49 additions & 5 deletions lib/Account.php
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@

namespace OCA\Mail;

use Horde\ManageSieve;
Comment thread
pierlon marked this conversation as resolved.
use Horde_Imap_Client_Mailbox;
use Horde_Imap_Client_Socket;
use Horde_Mail_Rfc822_List;
Expand All @@ -55,7 +56,10 @@ class Account implements JsonSerializable {
private $account;

/** @var Horde_Imap_Client_Socket */
private $client;
private $imapClient;

/** @var ManageSieve */
private $sieveClient;

/** @var ICrypto */
private $crypto;
Expand Down Expand Up @@ -114,9 +118,10 @@ public function getEMailAddress() {

/**
* @return Horde_Imap_Client_Socket
* @throws \Horde_Imap_Client_Exception
*/
public function getImapConnection() {
if (is_null($this->client)) {
if (is_null($this->imapClient)) {
$host = $this->account->getInboundHost();
$user = $this->account->getInboundUser();
$password = $this->account->getInboundPassword();
Expand Down Expand Up @@ -144,10 +149,44 @@ public function getImapConnection() {
))];
}
}
$this->client = new \Horde_Imap_Client_Socket($params);
$this->client->login();
$this->imapClient = new \Horde_Imap_Client_Socket($params);
$this->imapClient->login();
}
return $this->client;
return $this->imapClient;
}

/**
* @return ManageSieve
* @throws ManageSieve\Exception
*/
public function getSieveConnection()

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

getImapConnection is using an outdated coding style and we're int process of refactoring our code to get rid of the method. Please see the ImapClientFactory and create something similar for Sieve.

{
if ($this->sieveClient === null) {
$host = $this->account->getSieveHost();

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

  • Handle accounts without Sieve settings

$user = $this->account->getSieveUser();
$password = $this->account->getSievePassword();
$password = $this->crypto->decrypt($password);
$port = $this->account->getSievePort();
$ssl_mode = $this->convertSslMode($this->account->getSieveSslMode());

$params = [
'host' => $host,
'port' => $port,
'user' => $user,
'password' => $password,
'secure' => $ssl_mode,
];

// TODO: configure sieve logging
/*if ($this->config->getSystemValue('debug', false)) {
$params['logger'] = $this->config->getSystemValue('datadirectory') . '/horde_sieve.log';
}*/

$this->sieveClient = new ManageSieve($params);

}

return $this->sieveClient;
}

/**
Expand Down Expand Up @@ -201,6 +240,11 @@ public function testConnectivity(Horde_Mail_Transport $transport) {
if ($transport instanceof Horde_Mail_Transport_Smtphorde) {
$transport->getSMTPObject();
}

// connect to sieve
if ($this->account->getSieveHost() !== null) {
$this->getSieveConnection();
}
}

/**
Expand Down
25 changes: 25 additions & 0 deletions lib/Command/CreateAccount.php
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,11 @@ class CreateAccount extends Command {
const ARGUMENT_SMTP_SSL_MODE = 'smtp-ssl-mode';
const ARGUMENT_SMTP_USER = 'smtp-user';
const ARGUMENT_SMTP_PASSWORD = 'smtp-password';
const ARGUMENT_SIEVE_HOST = 'sieve-host';
const ARGUMENT_SIEVE_PORT = 'sieve-port';
const ARGUMENT_SIEVE_SSL_MODE = 'sieve-ssl-mode';
const ARGUMENT_SIEVE_USER = 'sieve-user';
const ARGUMENT_SIEVE_PASSWORD = 'sieve-password';

/** @var AccountService */
private $accountService;
Expand Down Expand Up @@ -78,6 +83,12 @@ protected function configure() {
$this->addArgument(self::ARGUMENT_SMTP_SSL_MODE, InputArgument::REQUIRED);
$this->addArgument(self::ARGUMENT_SMTP_USER, InputArgument::REQUIRED);
$this->addArgument(self::ARGUMENT_SMTP_PASSWORD, InputArgument::REQUIRED);

$this->addArgument(self::ARGUMENT_SIEVE_HOST, InputArgument::OPTIONAL);
$this->addArgument(self::ARGUMENT_SIEVE_PORT, InputArgument::OPTIONAL);
$this->addArgument(self::ARGUMENT_SIEVE_SSL_MODE, InputArgument::OPTIONAL);
$this->addArgument(self::ARGUMENT_SIEVE_USER, InputArgument::OPTIONAL);
$this->addArgument(self::ARGUMENT_SIEVE_PASSWORD, InputArgument::OPTIONAL);
}

protected function execute(InputInterface $input, OutputInterface $output) {
Expand All @@ -97,6 +108,12 @@ protected function execute(InputInterface $input, OutputInterface $output) {
$smtpUser = $input->getArgument(self::ARGUMENT_SMTP_USER);
$smtpPassword = $input->getArgument(self::ARGUMENT_SMTP_PASSWORD);

$sieveHost = $input->getArgument(self::ARGUMENT_SIEVE_HOST);
$sievePort = $input->getArgument(self::ARGUMENT_SIEVE_PORT);
$sieveSslMode = $input->getArgument(self::ARGUMENT_SIEVE_SSL_MODE);
$sieveUser = $input->getArgument(self::ARGUMENT_SIEVE_USER);
$sievePassword = $input->getArgument(self::ARGUMENT_SIEVE_PASSWORD);

$account = new MailAccount();
$account->setUserId($userId);
$account->setName($name);
Expand All @@ -114,6 +131,14 @@ protected function execute(InputInterface $input, OutputInterface $output) {
$account->setOutboundUser($smtpUser);
$account->setOutboundPassword($this->crypto->encrypt($smtpPassword));

if ($sieveHost !== null) {
$account->setSieveHost($sieveHost);
$account->setSievePort($sievePort);
$account->setSieveSslMode($sieveSslMode);
$account->setSieveUser($sieveUser);
$account->setSievePassword($this->crypto->encrypt($sievePassword));
}

$this->accountService->save($account);

$output->writeln("<info>Account $email created</info>");
Expand Down
5 changes: 5 additions & 0 deletions lib/Command/ExportAccount.php
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,11 @@ protected function execute(InputInterface $input, OutputInterface $output) {
$output->writeln("- IMAP host: " . $account->getMailAccount()->getInboundHost() . ":" . $account->getMailAccount()->getInboundPort() . ", security: " . $account->getMailAccount()->getInboundSslMode());
$output->writeln("- SMTP user: " . $account->getMailAccount()->getOutboundUser());
$output->writeln("- SMTP host: " . $account->getMailAccount()->getOutboundHost() . ":" . $account->getMailAccount()->getOutboundPort() . ", security: " . $account->getMailAccount()->getOutboundSslMode());

if ($account->getMailAccount()->getSieveHost()) {
$output->writeln("- Sieve user: " . $account->getMailAccount()->getSieveUser());
$output->writeln("- Sieve host: " . $account->getMailAccount()->getSieveHost() . ":" . $account->getMailAccount()->getSievePort() . ", security: " . $account->getMailAccount()->getSieveSslMode());
}
}
}

Expand Down
38 changes: 34 additions & 4 deletions lib/Controller/AccountsController.php
Original file line number Diff line number Diff line change
Expand Up @@ -135,6 +135,7 @@ public function show($accountId): JSONResponse {
* @param string $smtpSslMode
* @param string $smtpUser
* @param string $smtpPassword
* @param array|null $sieveConfig
* @param bool $autoDetect
*
* @return JSONResponse
Expand All @@ -154,14 +155,22 @@ public function update(int $id,
int $smtpPort = null,
string $smtpSslMode = null,
string $smtpUser = null,
string $smtpPassword = null): JSONResponse {
string $smtpPassword = null,
array $sieveConfig = null): JSONResponse {
$account = null;
$errorMessage = null;
try {
if ($autoDetect) {
$account = $this->setup->createNewAutoConfiguredAccount($accountName, $emailAddress, $password);
} else {
$account = $this->setup->createNewAccount($accountName, $emailAddress, $imapHost, $imapPort, $imapSslMode, $imapUser, $imapPassword, $smtpHost, $smtpPort, $smtpSslMode, $smtpUser, $smtpPassword, $this->currentUserId, $id);

$account = $this->setup->createNewAccount(
$accountName, $emailAddress,
$imapHost, $imapPort, $imapSslMode, $imapUser, $imapPassword,
$smtpHost,$smtpPort, $smtpSslMode, $smtpUser, $smtpPassword,
$sieveConfig,
$this->currentUserId, $id
);
}
} catch (Exception $ex) {
$errorMessage = $ex->getMessage();
Expand Down Expand Up @@ -249,19 +258,40 @@ public function destroy($id): JSONResponse {
* @param string $smtpSslMode
* @param string $smtpUser
* @param string $smtpPassword
* @param array|null $sieveConfig
* @param bool $autoDetect
*
* @return JSONResponse
* @throws ClientException
*/
public function create(string $accountName, string $emailAddress, string $password = null, string $imapHost = null, int $imapPort = null, string $imapSslMode = null, string $imapUser = null, string $imapPassword = null, string $smtpHost = null, int $smtpPort = null, string $smtpSslMode = null, string $smtpUser = null, string $smtpPassword = null, bool $autoDetect = true): JSONResponse {
public function create(string $accountName,
string $emailAddress,
string $password = null,
string $imapHost = null,
int $imapPort = null,
string $imapSslMode = null,
string $imapUser = null,
string $imapPassword = null,
string $smtpHost = null,
int $smtpPort = null,
string $smtpSslMode = null,
string $smtpUser = null,
string $smtpPassword = null,
array $sieveConfig = null,
bool $autoDetect = true): JSONResponse {
$account = null;
$errorMessage = null;
try {
if ($autoDetect) {
$account = $this->setup->createNewAutoConfiguredAccount($accountName, $emailAddress, $password);
} else {
$account = $this->setup->createNewAccount($accountName, $emailAddress, $imapHost, $imapPort, $imapSslMode, $imapUser, $imapPassword, $smtpHost, $smtpPort, $smtpSslMode, $smtpUser, $smtpPassword, $this->currentUserId);
$account = $this->setup->createNewAccount(
$accountName, $emailAddress,
$imapHost, $imapPort, $imapSslMode, $imapUser, $imapPassword,
$smtpHost, $smtpPort, $smtpSslMode, $smtpUser, $smtpPassword,
$sieveConfig,
$this->currentUserId
);
}
} catch (Exception $ex) {
$errorMessage = $ex->getMessage();
Expand Down
Loading