[PR #2579] [MERGED] [PM-192] Refactor forwarded email providers #51875

Closed
opened 2026-05-01 15:35:02 -05:00 by GiteaMirror · 0 comments
Owner

📋 Pull Request Information

Original PR: https://github.com/bitwarden/android/pull/2579
Author: @fedemkr
Created: 6/21/2023
Status: Merged
Merged: 6/27/2023
Merged by: @fedemkr

Base: masterHead: PM-192-refactor-forwarded-email-providers


📝 Commits (4)

  • 6b71e7a PM-192 Refactor Forwarded email providers to use better patterns and code reuse.
  • ec5cb60 Merge branch 'master' into PM-192-refactor-forwarded-email-providers
  • 61d7428 PM-192 fix format
  • fa73c19 Merge branch 'master' into PM-192-refactor-forwarded-email-providers

📊 Changes

20 files changed (+534 additions, -446 deletions)

View changed files

📝 src/App/Pages/Generator/GeneratorPage.xaml (+9 -103)
📝 src/App/Pages/Generator/GeneratorPageViewModel.cs (+102 -135)
📝 src/App/Resources/AppResources.Designer.cs (+18 -0)
📝 src/App/Resources/AppResources.resx (+6 -0)
📝 src/Core/Abstractions/IApiService.cs (+4 -2)
📝 src/Core/Abstractions/ICryptoService.cs (+1 -0)
📝 src/Core/Core.csproj (+2 -0)
src/Core/Exceptions/ForwardedEmailInvalidSecretException.cs (+11 -0)
📝 src/Core/Models/Domain/UsernameGenerationOptions.cs (+29 -0)
src/Core/Models/Domain/UsernameGeneratorConfig.cs (+0 -9)
📝 src/Core/Services/ApiService.cs (+15 -125)
📝 src/Core/Services/CryptoService.cs (+18 -0)
src/Core/Services/EmailForwarders/AnonAddyForwarder.cs (+42 -0)
src/Core/Services/EmailForwarders/BaseForwarder.cs (+63 -0)
src/Core/Services/EmailForwarders/DuckDuckGoForwarder.cs (+25 -0)
src/Core/Services/EmailForwarders/FastmailForwarder.cs (+98 -0)
src/Core/Services/EmailForwarders/FirefoxRelayForwarder.cs (+36 -0)
src/Core/Services/EmailForwarders/ForwarderOptions.cs (+7 -0)
src/Core/Services/EmailForwarders/SimpleLoginForwarder.cs (+25 -0)
📝 src/Core/Services/UsernameGenerationService.cs (+23 -72)

📄 Description

Type of change

  • Bug fix
  • New feature development
  • Tech debt (refactoring, code cleanup, dependency upgrades, etc)
  • Build/deploy pipeline (DevOps)
  • Other

Objective

Refactor forwarded email providers to use better patterns, reuse code and improve maintainability.

Code changes

  • GeneratorPage.xaml: Refactor all forwarded email providers to unify all the API token/key into one field binded which changes its value depending on the provider type selected. This makes the view tree lighter and changing from one type to the other smoother.
  • GeneratorPageViewModel.cs: Unified all the API Token/Key into ForwardedEmailApiSecret alongside the label and the show toggle as well. Inside it gets/sets the correct one depending on the type selected. Simplified the api secret toggle command and improved the errors to the user when we get a 401/403 from the provider.
  • ForwardedEmailInvalidSecretException.cs: Special exception to be raised when a 401/403 is gotten from the provider.
  • UsernameGenerationOptions.cs: Added the "mapper" of the particular options for the forwarded email services.
  • UsernameGeneratorConfig.cs: No longer necessary -> Removed.
  • ApiService.cs: Moved all the particular forwarded email logic to the new ...Forwarder classes and added a new SendAsync(HttpRequestMessage, CancellationToken) to be used for these kind of things where we don't call our API. Only left GetFastmailAccountIdAsync(...) cause I didn't want to move the HttpClient outside this class in this PR. ♻️ Eventually, we should refactor this class and split it, it's getting pretty big.
  • CryptoService.cs: Moved RandomStringAsync here cause it made more sense to be in the same place as random number.
  • BaseForwarder.cs: Base class for all forwarders where it makes the call to the service with custom configurations from its children.
  • AnonAddyForwarder.cs, DuckDuckGoForwarder.cs, FastmailForwarder.cs, FirefoxRelayForwarder.cs, SimpleLoginForwarder.cs: Forwarder providers particular logic and configurations.
  • ForwarderOptions.cs: Options to configure the forwarders.
  • UsernameGenerationService.cs: Refactor the forwarder email to create the appropriate forwarder and generate accordingly.

Before you submit

  • Please check for formatting errors (dotnet format --verify-no-changes) (required)
  • Please add unit tests where it makes sense to do so (encouraged but not required)
  • If this change requires a documentation update - notify the documentation team
  • If this change has particular deployment requirements - notify the DevOps team

🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.

## 📋 Pull Request Information **Original PR:** https://github.com/bitwarden/android/pull/2579 **Author:** [@fedemkr](https://github.com/fedemkr) **Created:** 6/21/2023 **Status:** ✅ Merged **Merged:** 6/27/2023 **Merged by:** [@fedemkr](https://github.com/fedemkr) **Base:** `master` ← **Head:** `PM-192-refactor-forwarded-email-providers` --- ### 📝 Commits (4) - [`6b71e7a`](https://github.com/bitwarden/android/commit/6b71e7a61486fc4f2e9045b18c0057c74b5e3e5d) PM-192 Refactor Forwarded email providers to use better patterns and code reuse. - [`ec5cb60`](https://github.com/bitwarden/android/commit/ec5cb60aa1567014c1477b80d821ebb36524187c) Merge branch 'master' into PM-192-refactor-forwarded-email-providers - [`61d7428`](https://github.com/bitwarden/android/commit/61d7428742610d2f7b34de72cb9c889f22a983d6) PM-192 fix format - [`fa73c19`](https://github.com/bitwarden/android/commit/fa73c1939b30996e8d74306b6f080d564feb3773) Merge branch 'master' into PM-192-refactor-forwarded-email-providers ### 📊 Changes **20 files changed** (+534 additions, -446 deletions) <details> <summary>View changed files</summary> 📝 `src/App/Pages/Generator/GeneratorPage.xaml` (+9 -103) 📝 `src/App/Pages/Generator/GeneratorPageViewModel.cs` (+102 -135) 📝 `src/App/Resources/AppResources.Designer.cs` (+18 -0) 📝 `src/App/Resources/AppResources.resx` (+6 -0) 📝 `src/Core/Abstractions/IApiService.cs` (+4 -2) 📝 `src/Core/Abstractions/ICryptoService.cs` (+1 -0) 📝 `src/Core/Core.csproj` (+2 -0) ➕ `src/Core/Exceptions/ForwardedEmailInvalidSecretException.cs` (+11 -0) 📝 `src/Core/Models/Domain/UsernameGenerationOptions.cs` (+29 -0) ➖ `src/Core/Models/Domain/UsernameGeneratorConfig.cs` (+0 -9) 📝 `src/Core/Services/ApiService.cs` (+15 -125) 📝 `src/Core/Services/CryptoService.cs` (+18 -0) ➕ `src/Core/Services/EmailForwarders/AnonAddyForwarder.cs` (+42 -0) ➕ `src/Core/Services/EmailForwarders/BaseForwarder.cs` (+63 -0) ➕ `src/Core/Services/EmailForwarders/DuckDuckGoForwarder.cs` (+25 -0) ➕ `src/Core/Services/EmailForwarders/FastmailForwarder.cs` (+98 -0) ➕ `src/Core/Services/EmailForwarders/FirefoxRelayForwarder.cs` (+36 -0) ➕ `src/Core/Services/EmailForwarders/ForwarderOptions.cs` (+7 -0) ➕ `src/Core/Services/EmailForwarders/SimpleLoginForwarder.cs` (+25 -0) 📝 `src/Core/Services/UsernameGenerationService.cs` (+23 -72) </details> ### 📄 Description ## Type of change - [ ] Bug fix - [ ] New feature development - [X] Tech debt (refactoring, code cleanup, dependency upgrades, etc) - [ ] Build/deploy pipeline (DevOps) - [ ] Other ## Objective <!--Describe what the purpose of this PR is. For example: what bug you're fixing or what new feature you're adding--> Refactor forwarded email providers to use better patterns, reuse code and improve maintainability. ## Code changes <!--Explain the changes you've made to each file or major component. This should help the reviewer understand your changes--> <!--Also refer to any related changes or PRs in other repositories--> * **GeneratorPage.xaml:** Refactor all forwarded email providers to unify all the API token/key into one field binded which changes its value depending on the provider type selected. This makes the view tree lighter and changing from one type to the other smoother. * **GeneratorPageViewModel.cs:** Unified all the API Token/Key into `ForwardedEmailApiSecret` alongside the label and the show toggle as well. Inside it gets/sets the correct one depending on the type selected. Simplified the api secret toggle command and improved the errors to the user when we get a 401/403 from the provider. * **ForwardedEmailInvalidSecretException.cs:** Special exception to be raised when a 401/403 is gotten from the provider. * **UsernameGenerationOptions.cs:** Added the "mapper" of the particular options for the forwarded email services. * **UsernameGeneratorConfig.cs:** No longer necessary -> Removed. * **ApiService.cs:** Moved all the particular forwarded email logic to the new `...Forwarder` classes and added a new `SendAsync(HttpRequestMessage, CancellationToken)` to be used for these kind of things where we don't call our API. Only left `GetFastmailAccountIdAsync(...)` cause I didn't want to move the `HttpClient` outside this class in this PR. ♻️ Eventually, we should refactor this class and split it, it's getting pretty big. * **CryptoService.cs:** Moved `RandomStringAsync` here cause it made more sense to be in the same place as random number. * **BaseForwarder.cs:** Base class for all forwarders where it makes the call to the service with custom configurations from its children. * **AnonAddyForwarder.cs, DuckDuckGoForwarder.cs, FastmailForwarder.cs, FirefoxRelayForwarder.cs, SimpleLoginForwarder.cs:** Forwarder providers particular logic and configurations. * **ForwarderOptions.cs:** Options to configure the forwarders. * **UsernameGenerationService.cs:** Refactor the forwarder email to create the appropriate forwarder and generate accordingly. ## Before you submit - Please check for formatting errors (`dotnet format --verify-no-changes`) (required) - Please add **unit tests** where it makes sense to do so (encouraged but not required) - If this change requires a **documentation update** - notify the documentation team - If this change has particular **deployment requirements** - notify the DevOps team --- <sub>🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.</sub>
GiteaMirror added the pull-request label 2026-05-01 15:35:03 -05:00
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: github-starred/android#51875