From cce8298b8288f29ab621537a92c4b25f5b66e30f Mon Sep 17 00:00:00 2001 From: ushahidlee Date: Thu, 14 Mar 2024 10:01:28 +0100 Subject: [PATCH 01/17] New functionality and a big bug fix --- config/data-provider.php | 2 + src/Ushahidi/DataSource/DataSourceManager.php | 3 +- src/Ushahidi/DataSource/Email/Email.php | 42 +++++++++++++++++-- 3 files changed, 43 insertions(+), 4 deletions(-) diff --git a/config/data-provider.php b/config/data-provider.php index 0fbfcf073b..a7b41683d0 100644 --- a/config/data-provider.php +++ b/config/data-provider.php @@ -30,6 +30,8 @@ 'incoming_security' => '', 'incoming_username' => '', 'incoming_password' => '', + 'incoming_unread_only' => 'Unread', + 'incoming_last_uid' => 0 ], 'twilio' => [], 'smssync' => [], diff --git a/src/Ushahidi/DataSource/DataSourceManager.php b/src/Ushahidi/DataSource/DataSourceManager.php index e0cd39616d..134f0ec74b 100644 --- a/src/Ushahidi/DataSource/DataSourceManager.php +++ b/src/Ushahidi/DataSource/DataSourceManager.php @@ -287,7 +287,8 @@ protected function createEmailSource(array $config) return new Email\Email( $config, app('mailer'), - app(MessageRepository::class) + app(MessageRepository::class), + $this->configRepo ); } diff --git a/src/Ushahidi/DataSource/Email/Email.php b/src/Ushahidi/DataSource/Email/Email.php index 671afa228d..eda2310cf0 100644 --- a/src/Ushahidi/DataSource/Email/Email.php +++ b/src/Ushahidi/DataSource/Email/Email.php @@ -17,6 +17,7 @@ use Ushahidi\DataSource\Contracts\IncomingDataSource; use Ushahidi\DataSource\Concerns\MapsInboundFields; use Ushahidi\Contracts\Repository\Entity\MessageRepository; +use Ushahidi\Contracts\Repository\Entity\ConfigRepository; use Ushahidi\DataSource\Contracts\MessageType; class Email extends OutgoingEmail implements IncomingDataSource @@ -26,6 +27,7 @@ class Email extends OutgoingEmail implements IncomingDataSource protected $config; protected $mailer; protected $messageRepo; + protected $configRepo; /** * Constructor function for DataSource @@ -36,11 +38,13 @@ class Email extends OutgoingEmail implements IncomingDataSource public function __construct( array $config, Mailer $mailer = null, - MessageRepository $messageRepo = null + MessageRepository $messageRepo = null, + ConfigRepository $configRepo = null ) { $this->config = $config; $this->mailer = $mailer; $this->messageRepo = $messageRepo; + $this->configRepo = $configRepo; } public function getName() @@ -104,6 +108,13 @@ public function getOptions() 'description' => '', 'placeholder' => 'Email account password', 'rules' => ['required'] + ], + 'incoming_all_unread' => [ + 'label' => 'Fetch Emails', + 'input' => 'radio', + 'description' => 'Fetch every email from the inbox, or only unread.', + 'options' => ['All', 'Unread'], + 'rules' => ['required'] ] ]; } @@ -154,6 +165,9 @@ public function fetch($limit = false) $encryption = $this->config['incoming_security'] ?? ''; $username = $this->config['incoming_username'] ?? ''; $password = $this->config['incoming_password'] ?? ''; + $unread_only = $this->config['incoming_all_unread'] ?? 'Unread'; + $last_uid = $this->config['incoming_last_uid']; + $new_last_uid = 0; // Encryption type $encryption = (strcasecmp($encryption, 'none') != 0) ? '/'.$encryption : ''; @@ -161,7 +175,7 @@ public function fetch($limit = false) // To connect to an SSL IMAP or POP3 server with a self-signed certificate, // add /novalidate-cert after the encryption protocol specification: $no_cert_validation = !empty($encryption) ? '/novalidate-cert' : ''; - + try { // Try to connect $inbox = '{'.$server.':'.$port.'/'.$type.$encryption.$no_cert_validation.'}INBOX'; @@ -182,7 +196,10 @@ public function fetch($limit = false) Log::info("Connected to $inbox", [$mailboxinfo]); - $last_uid = $this->messageRepo->getLastUID('email'); + // Allow an existing installation to transition to config based without forcing the platform to download everything again. + if (! $last_uid) + $last_uid = $this->messageRepo->getLastUID('email'); + if ($last_uid > 0) { $max_range = $last_uid + $limit; $search_string = $last_uid ? $last_uid + 1 . ':' . $max_range : '1:' . $max_range; @@ -208,6 +225,9 @@ public function fetch($limit = false) break; } + if ($unread_only == 'Unread' and $email->seen == 1) + continue; + $message = $html_message = ""; $structure = imap_fetchstructure($connection, $email->uid, FT_UID); @@ -235,9 +255,16 @@ public function fetch($limit = false) $message = imap_qprint($message); $messages[] = $this->processIncoming($email, $message); } + if (isset($email->uid)) { + $new_last_uid = isset($email->uid) ? $email->uid : null; + } } } + if ($new_last_uid && $new_last_uid != $last_uid) { + $this->updateLastUid($this->config, $new_last_uid); + } + imap_errors(); imap_alerts(); @@ -253,6 +280,15 @@ public function fetch($limit = false) return $messages; } + private function updateLastUid($config, $last_uid) { + $providerConfig = $this->configRepo->get('data-provider'); + $config['incoming_last_uid'] = $last_uid; + $providerConfigArray = $providerConfig->asArray(); + $providerConfigArray[$this->getId()] = $config; + $providerConfig->setState($providerConfigArray); + $this->configRepo->update($providerConfig); + } + /** * Process individual incoming email * From d82d083263fbe503c318bbe7d4af13740aa4432c Mon Sep 17 00:00:00 2001 From: ushahidlee Date: Thu, 14 Mar 2024 10:17:50 +0100 Subject: [PATCH 02/17] Added some missing config for tests --- tests/Unit/DataSource/EmailDataSourceTest.php | 2 ++ 1 file changed, 2 insertions(+) diff --git a/tests/Unit/DataSource/EmailDataSourceTest.php b/tests/Unit/DataSource/EmailDataSourceTest.php index d8f11dc688..2b059eb2a9 100644 --- a/tests/Unit/DataSource/EmailDataSourceTest.php +++ b/tests/Unit/DataSource/EmailDataSourceTest.php @@ -100,6 +100,8 @@ public function testFetch() 'incoming_security' => 'ssl', 'incoming_username' => 'someuser', 'incoming_password' => 'mypassword', + 'incoming_all_unread' => 'All', + 'incoming_last_uid' => 0 ], $mockMailer, $mockMessageRepo From 4881c5e4e878ba096dbc3031d408de8bb748de9c Mon Sep 17 00:00:00 2001 From: ushahidlee Date: Thu, 14 Mar 2024 11:08:28 +0100 Subject: [PATCH 03/17] Load configrepo in constructor --- src/Ushahidi/DataSource/DataSourceManager.php | 1 - src/Ushahidi/DataSource/Email/Email.php | 3 +-- 2 files changed, 1 insertion(+), 3 deletions(-) diff --git a/src/Ushahidi/DataSource/DataSourceManager.php b/src/Ushahidi/DataSource/DataSourceManager.php index 134f0ec74b..dfb70dd205 100644 --- a/src/Ushahidi/DataSource/DataSourceManager.php +++ b/src/Ushahidi/DataSource/DataSourceManager.php @@ -288,7 +288,6 @@ protected function createEmailSource(array $config) $config, app('mailer'), app(MessageRepository::class), - $this->configRepo ); } diff --git a/src/Ushahidi/DataSource/Email/Email.php b/src/Ushahidi/DataSource/Email/Email.php index eda2310cf0..f689ca2e54 100644 --- a/src/Ushahidi/DataSource/Email/Email.php +++ b/src/Ushahidi/DataSource/Email/Email.php @@ -39,12 +39,11 @@ public function __construct( array $config, Mailer $mailer = null, MessageRepository $messageRepo = null, - ConfigRepository $configRepo = null ) { $this->config = $config; $this->mailer = $mailer; $this->messageRepo = $messageRepo; - $this->configRepo = $configRepo; + $this->configRepo = service('repository.config'); } public function getName() From 8b1c62232d6f9e2152990dcb6c05011b73786fc3 Mon Sep 17 00:00:00 2001 From: ushahidlee Date: Thu, 14 Mar 2024 11:10:20 +0100 Subject: [PATCH 04/17] minor --- src/Ushahidi/DataSource/Email/Email.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Ushahidi/DataSource/Email/Email.php b/src/Ushahidi/DataSource/Email/Email.php index f689ca2e54..6c4efd06a1 100644 --- a/src/Ushahidi/DataSource/Email/Email.php +++ b/src/Ushahidi/DataSource/Email/Email.php @@ -38,7 +38,7 @@ class Email extends OutgoingEmail implements IncomingDataSource public function __construct( array $config, Mailer $mailer = null, - MessageRepository $messageRepo = null, + MessageRepository $messageRepo = null ) { $this->config = $config; $this->mailer = $mailer; From 77b8b2b6291a8202e3f9715f0e5f589a02f215e2 Mon Sep 17 00:00:00 2001 From: ushahidlee Date: Thu, 14 Mar 2024 11:24:25 +0100 Subject: [PATCH 05/17] Small changes to accommodate tests --- tests/datasets/ushahidi/Base.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/datasets/ushahidi/Base.yml b/tests/datasets/ushahidi/Base.yml index 8d8945617d..d4de675e66 100644 --- a/tests/datasets/ushahidi/Base.yml +++ b/tests/datasets/ushahidi/Base.yml @@ -2198,7 +2198,7 @@ config: - group_name: "data-provider" config_key: email - config_value: '{"incoming_type":"","incoming_server":"","incoming_port":"","incoming_security":"","incoming_username":"","incoming_password":""}' + config_value: '{"incoming_type":"","incoming_server":"","incoming_port":"","incoming_security":"","incoming_username":"","incoming_password":"","incoming_last_uid":"","incoming_all_unread":""}' - group_name: "data-provider" config_key: frontlinesms From 3838c32cb00efdb066b3e05c5a54e84c7e586dfa Mon Sep 17 00:00:00 2001 From: ushahidlee Date: Thu, 14 Mar 2024 11:32:17 +0100 Subject: [PATCH 06/17] lint --- src/Ushahidi/DataSource/Email/Email.php | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/src/Ushahidi/DataSource/Email/Email.php b/src/Ushahidi/DataSource/Email/Email.php index 6c4efd06a1..701bf43f00 100644 --- a/src/Ushahidi/DataSource/Email/Email.php +++ b/src/Ushahidi/DataSource/Email/Email.php @@ -196,8 +196,9 @@ public function fetch($limit = false) Log::info("Connected to $inbox", [$mailboxinfo]); // Allow an existing installation to transition to config based without forcing the platform to download everything again. - if (! $last_uid) + if (! $last_uid) { $last_uid = $this->messageRepo->getLastUID('email'); + } if ($last_uid > 0) { $max_range = $last_uid + $limit; @@ -224,8 +225,9 @@ public function fetch($limit = false) break; } - if ($unread_only == 'Unread' and $email->seen == 1) + if ($unread_only == 'Unread' and $email->seen == 1) { continue; + } $message = $html_message = ""; $structure = imap_fetchstructure($connection, $email->uid, FT_UID); @@ -279,7 +281,8 @@ public function fetch($limit = false) return $messages; } - private function updateLastUid($config, $last_uid) { + private function updateLastUid($config, $last_uid) + { $providerConfig = $this->configRepo->get('data-provider'); $config['incoming_last_uid'] = $last_uid; $providerConfigArray = $providerConfig->asArray(); From 558cdc7cb37a9602f011876b07f89f0775306702 Mon Sep 17 00:00:00 2001 From: ushahidlee Date: Thu, 14 Mar 2024 12:40:19 +0100 Subject: [PATCH 07/17] testing data --- tests/datasets/ushahidi/Base.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/datasets/ushahidi/Base.yml b/tests/datasets/ushahidi/Base.yml index d4de675e66..31b2f1989e 100644 --- a/tests/datasets/ushahidi/Base.yml +++ b/tests/datasets/ushahidi/Base.yml @@ -2198,7 +2198,7 @@ config: - group_name: "data-provider" config_key: email - config_value: '{"incoming_type":"","incoming_server":"","incoming_port":"","incoming_security":"","incoming_username":"","incoming_password":"","incoming_last_uid":"","incoming_all_unread":""}' + config_value: '{"incoming_type":"","incoming_server":"","incoming_port":"","incoming_security":"","incoming_username":"","incoming_password":"","incoming_last_uid":0,"incoming_all_unread":""}' - group_name: "data-provider" config_key: frontlinesms From e22379b0f6a57f55dd484a0344509961e8127f99 Mon Sep 17 00:00:00 2001 From: ushahidlee Date: Thu, 14 Mar 2024 14:18:12 +0100 Subject: [PATCH 08/17] 4 tests --- tests/datasets/ushahidi/Base.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/datasets/ushahidi/Base.yml b/tests/datasets/ushahidi/Base.yml index 31b2f1989e..0df2272c60 100644 --- a/tests/datasets/ushahidi/Base.yml +++ b/tests/datasets/ushahidi/Base.yml @@ -2198,7 +2198,7 @@ config: - group_name: "data-provider" config_key: email - config_value: '{"incoming_type":"","incoming_server":"","incoming_port":"","incoming_security":"","incoming_username":"","incoming_password":"","incoming_last_uid":0,"incoming_all_unread":""}' + config_value: '{"incoming_type":"","incoming_server":"","incoming_port":"","incoming_security":"","incoming_username":"","incoming_password":"","incoming_last_uid":"0","incoming_all_unread":""}' - group_name: "data-provider" config_key: frontlinesms From 09b7e126d37fe9c73b4ed9d385d869005b178465 Mon Sep 17 00:00:00 2001 From: ushahidlee Date: Thu, 14 Mar 2024 14:31:19 +0100 Subject: [PATCH 09/17] testy --- tests/Unit/DataSource/EmailDataSourceTest.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/Unit/DataSource/EmailDataSourceTest.php b/tests/Unit/DataSource/EmailDataSourceTest.php index 2b059eb2a9..9d690aff5e 100644 --- a/tests/Unit/DataSource/EmailDataSourceTest.php +++ b/tests/Unit/DataSource/EmailDataSourceTest.php @@ -101,7 +101,7 @@ public function testFetch() 'incoming_username' => 'someuser', 'incoming_password' => 'mypassword', 'incoming_all_unread' => 'All', - 'incoming_last_uid' => 0 + 'incoming_last_uid' => '0' ], $mockMailer, $mockMessageRepo From ec008a44ddf1cb927541ffb815b422a4b690d385 Mon Sep 17 00:00:00 2001 From: ushahidlee Date: Thu, 14 Mar 2024 14:36:12 +0100 Subject: [PATCH 10/17] more guff --- config/data-provider.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/config/data-provider.php b/config/data-provider.php index a7b41683d0..8189c54bbe 100644 --- a/config/data-provider.php +++ b/config/data-provider.php @@ -31,7 +31,7 @@ 'incoming_username' => '', 'incoming_password' => '', 'incoming_unread_only' => 'Unread', - 'incoming_last_uid' => 0 + 'incoming_last_uid' => '0' ], 'twilio' => [], 'smssync' => [], From 6ad3b02d3166e40bcef0353f64c1b4609c35ffa9 Mon Sep 17 00:00:00 2001 From: ushahidlee Date: Thu, 14 Mar 2024 15:04:17 +0100 Subject: [PATCH 11/17] same same but different --- tests/datasets/ushahidi/Base.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/datasets/ushahidi/Base.yml b/tests/datasets/ushahidi/Base.yml index 0df2272c60..d4de675e66 100644 --- a/tests/datasets/ushahidi/Base.yml +++ b/tests/datasets/ushahidi/Base.yml @@ -2198,7 +2198,7 @@ config: - group_name: "data-provider" config_key: email - config_value: '{"incoming_type":"","incoming_server":"","incoming_port":"","incoming_security":"","incoming_username":"","incoming_password":"","incoming_last_uid":"0","incoming_all_unread":""}' + config_value: '{"incoming_type":"","incoming_server":"","incoming_port":"","incoming_security":"","incoming_username":"","incoming_password":"","incoming_last_uid":"","incoming_all_unread":""}' - group_name: "data-provider" config_key: frontlinesms From 8936607a08d85a2ff8f9c8fef6de6314b762b1b7 Mon Sep 17 00:00:00 2001 From: ushahidlee Date: Thu, 14 Mar 2024 15:20:17 +0100 Subject: [PATCH 12/17] ... --- tests/datasets/ushahidi/Base.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/datasets/ushahidi/Base.yml b/tests/datasets/ushahidi/Base.yml index d4de675e66..7dfb12818b 100644 --- a/tests/datasets/ushahidi/Base.yml +++ b/tests/datasets/ushahidi/Base.yml @@ -2198,7 +2198,7 @@ config: - group_name: "data-provider" config_key: email - config_value: '{"incoming_type":"","incoming_server":"","incoming_port":"","incoming_security":"","incoming_username":"","incoming_password":"","incoming_last_uid":"","incoming_all_unread":""}' + config_value: '{"incoming_type":"","incoming_server":"","incoming_port":"","incoming_security":"","incoming_username":"","incoming_password":"","incoming_all_unread":"","incoming_last_uid":""}' - group_name: "data-provider" config_key: frontlinesms From 4cd005b8e51f9b05dab3745822f7d857283f4fed Mon Sep 17 00:00:00 2001 From: ushahidlee Date: Thu, 14 Mar 2024 15:36:08 +0100 Subject: [PATCH 13/17] gah --- src/Ushahidi/DataSource/Email/Email.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Ushahidi/DataSource/Email/Email.php b/src/Ushahidi/DataSource/Email/Email.php index 701bf43f00..1cd0d96f47 100644 --- a/src/Ushahidi/DataSource/Email/Email.php +++ b/src/Ushahidi/DataSource/Email/Email.php @@ -165,7 +165,7 @@ public function fetch($limit = false) $username = $this->config['incoming_username'] ?? ''; $password = $this->config['incoming_password'] ?? ''; $unread_only = $this->config['incoming_all_unread'] ?? 'Unread'; - $last_uid = $this->config['incoming_last_uid']; + $last_uid = $this->config['incoming_last_uid'] ?? 0; $new_last_uid = 0; // Encryption type From 3e45d98b1cbb38b3987223c221922c258662d442 Mon Sep 17 00:00:00 2001 From: ushahidlee Date: Tue, 19 Mar 2024 15:57:59 +0100 Subject: [PATCH 14/17] Small fix to help existing installs --- src/Ushahidi/DataSource/Email/Email.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Ushahidi/DataSource/Email/Email.php b/src/Ushahidi/DataSource/Email/Email.php index 1cd0d96f47..8fd8528e24 100644 --- a/src/Ushahidi/DataSource/Email/Email.php +++ b/src/Ushahidi/DataSource/Email/Email.php @@ -196,7 +196,7 @@ public function fetch($limit = false) Log::info("Connected to $inbox", [$mailboxinfo]); // Allow an existing installation to transition to config based without forcing the platform to download everything again. - if (! $last_uid) { + if (! isset($last_uid)) { $last_uid = $this->messageRepo->getLastUID('email'); } From 42fc8e2335d530f1e82090793964a0b27d50ce8d Mon Sep 17 00:00:00 2001 From: ushahidlee Date: Tue, 19 Mar 2024 17:28:01 +0100 Subject: [PATCH 15/17] Fixed tests --- src/Ushahidi/DataSource/DataSourceManager.php | 1 + src/Ushahidi/DataSource/Email/Email.php | 10 ++++---- tests/Unit/DataSource/EmailDataSourceTest.php | 24 ++++++++++++++++--- 3 files changed, 28 insertions(+), 7 deletions(-) diff --git a/src/Ushahidi/DataSource/DataSourceManager.php b/src/Ushahidi/DataSource/DataSourceManager.php index dfb70dd205..134f0ec74b 100644 --- a/src/Ushahidi/DataSource/DataSourceManager.php +++ b/src/Ushahidi/DataSource/DataSourceManager.php @@ -288,6 +288,7 @@ protected function createEmailSource(array $config) $config, app('mailer'), app(MessageRepository::class), + $this->configRepo ); } diff --git a/src/Ushahidi/DataSource/Email/Email.php b/src/Ushahidi/DataSource/Email/Email.php index 8fd8528e24..b6a80b5af9 100644 --- a/src/Ushahidi/DataSource/Email/Email.php +++ b/src/Ushahidi/DataSource/Email/Email.php @@ -34,16 +34,18 @@ class Email extends OutgoingEmail implements IncomingDataSource * @param array $config * @param Mailer|null $mailer * @param MessageRepository|null $messageRepo + * @param ConfigRepository|null $configRepo */ public function __construct( array $config, Mailer $mailer = null, - MessageRepository $messageRepo = null + MessageRepository $messageRepo = null, + ConfigRepository $configRepo = null ) { $this->config = $config; $this->mailer = $mailer; $this->messageRepo = $messageRepo; - $this->configRepo = service('repository.config'); + $this->configRepo = $configRepo; } public function getName() @@ -165,7 +167,7 @@ public function fetch($limit = false) $username = $this->config['incoming_username'] ?? ''; $password = $this->config['incoming_password'] ?? ''; $unread_only = $this->config['incoming_all_unread'] ?? 'Unread'; - $last_uid = $this->config['incoming_last_uid'] ?? 0; + $last_uid = $this->config['incoming_last_uid'] ?? ''; $new_last_uid = 0; // Encryption type @@ -196,7 +198,7 @@ public function fetch($limit = false) Log::info("Connected to $inbox", [$mailboxinfo]); // Allow an existing installation to transition to config based without forcing the platform to download everything again. - if (! isset($last_uid)) { + if (empty($last_uid)) { $last_uid = $this->messageRepo->getLastUID('email'); } diff --git a/tests/Unit/DataSource/EmailDataSourceTest.php b/tests/Unit/DataSource/EmailDataSourceTest.php index 9d690aff5e..ef114115eb 100644 --- a/tests/Unit/DataSource/EmailDataSourceTest.php +++ b/tests/Unit/DataSource/EmailDataSourceTest.php @@ -16,6 +16,8 @@ use phpmock\mockery\PHPMockery; use Ushahidi\Tests\TestCase; use Ushahidi\Contracts\Repository\Entity\MessageRepository; +use Ushahidi\Contracts\Repository\Entity\ConfigRepository; +use Ushahidi\Core\Entity\Config; use Ushahidi\DataSource\Email\Email; use Ushahidi\Multisite\Site; @@ -51,10 +53,13 @@ public function testSend() $this->app->make('multisite')->setSite($site); $mockMailer = M::mock(\Illuminate\Contracts\Mail\Mailer::class); + $mockConfigRepo = M::mock(ConfigRepository::class); $email = new Email( [], - $mockMailer + $mockMailer, + null, + $mockConfigRepo ); $mockMailer->shouldReceive('send')->once()->with( @@ -92,6 +97,19 @@ public function testFetch() $mockMessageRepo->shouldReceive('getLastUID')->once()->andReturn(712); + $mockConfigRepo = M::mock(ConfigRepository::class); + $mockConfigRepo->shouldReceive('get')->once()->andReturn(new Config([ + 'incoming_type' => 'imap', + 'incoming_server' => 'imap.somewhere.com', + 'incoming_port' => '993', + 'incoming_security' => 'ssl', + 'incoming_username' => 'someuser', + 'incoming_password' => 'mypassword', + 'incoming_all_unread' => 'All', + 'incoming_last_uid' => '712' + ])); + $mockConfigRepo->shouldReceive('update')->once()->andReturnUndefined(); + $email = new Email( [ 'incoming_type' => 'imap', @@ -101,10 +119,10 @@ public function testFetch() 'incoming_username' => 'someuser', 'incoming_password' => 'mypassword', 'incoming_all_unread' => 'All', - 'incoming_last_uid' => '0' ], $mockMailer, - $mockMessageRepo + $mockMessageRepo, + $mockConfigRepo ); $mockImapOpen = PHPMockery::mock("Ushahidi\DataSource\Email", 'imap_open'); From 21283327acd1b28cfb25f4d3bdd7608bafdf1a71 Mon Sep 17 00:00:00 2001 From: ushahidlee Date: Wed, 20 Mar 2024 05:26:12 +0100 Subject: [PATCH 16/17] slight change --- src/Ushahidi/DataSource/Email/Email.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Ushahidi/DataSource/Email/Email.php b/src/Ushahidi/DataSource/Email/Email.php index b6a80b5af9..cd041af74e 100644 --- a/src/Ushahidi/DataSource/Email/Email.php +++ b/src/Ushahidi/DataSource/Email/Email.php @@ -198,7 +198,7 @@ public function fetch($limit = false) Log::info("Connected to $inbox", [$mailboxinfo]); // Allow an existing installation to transition to config based without forcing the platform to download everything again. - if (empty($last_uid)) { + if ($last_uid == '') { $last_uid = $this->messageRepo->getLastUID('email'); } From 177ec78c468bb717313c405fefa3dcdeab5fd369 Mon Sep 17 00:00:00 2001 From: ushahidlee Date: Wed, 10 Apr 2024 17:17:21 +0200 Subject: [PATCH 17/17] Added hidden config field and fixed a wee bug --- src/Ushahidi/DataSource/Email/Email.php | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/src/Ushahidi/DataSource/Email/Email.php b/src/Ushahidi/DataSource/Email/Email.php index cd041af74e..8f43166428 100644 --- a/src/Ushahidi/DataSource/Email/Email.php +++ b/src/Ushahidi/DataSource/Email/Email.php @@ -116,6 +116,10 @@ public function getOptions() 'description' => 'Fetch every email from the inbox, or only unread.', 'options' => ['All', 'Unread'], 'rules' => ['required'] + ], + 'incoming_last_uid' => [ + 'label' => '', + 'input' => 'hidden', ] ]; } @@ -188,7 +192,7 @@ public function fetch($limit = false) // Return on connection error if (! $connection || $errors || $alerts) { $errors = is_array($errors) ? implode(', ', $errors) : ""; - $alerts = is_array($alerts) ? implode(', ', $errors) : ""; + $alerts = is_array($alerts) ? implode(', ', $alerts) : ""; Log::info("Could not connect to incoming email server", compact('errors', 'alerts')); return []; }