feature/dist-nuget
claude/smbcloud-github-app-k9641p
development
feature/apps
feature/build-release
feature/ci-docs
feature/ci-ruby-gems
feature/cicd
feature/completion
feature/dist-nuget
feature/fix-ci-sdk-pypi-rubygem
feature/fix-clippy-on-stable-channel
feature/fix-deployment-script
feature/github-email
feature/gresiq-v1
feature/project-new-structure
feature/rsync-deploy
feature/ruby-runner
feature/sdk-npm
feature/sdk-workflows
feature/smbcloud-cli-release-npm
feature/smbcloud-deploy
feature/wasm
main
release/v0.7.4
| 1 | use crate::{ |
| 2 | request::request_empty, |
| 3 | url_builder::{build_mail_inbox_test_url, build_mail_inbox_url, build_mail_inboxes_url}, |
| 4 | }; |
| 5 | use reqwest::Client; |
| 6 | use serde::Serialize; |
| 7 | use smbcloud_model::{ |
| 8 | error_codes::ErrorResponse, |
| 9 | mail::{ |
| 10 | MailInbox, MailInboxCreate, MailInboxUpdate, MailTestEmailDelivery, MailTestEmailRequest, |
| 11 | }, |
| 12 | }; |
| 13 | use smbcloud_network::{environment::Environment, network::request}; |
| 14 | use smbcloud_networking::{constants::SMB_USER_AGENT, smb_client::SmbClient}; |
| 15 | |
| 16 | #[derive(Serialize)] |
| 17 | struct MailInboxEnvelope<T> { |
| 18 | mail_inbox: T, |
| 19 | } |
| 20 | |
| 21 | pub async fn create_mail_inbox( |
| 22 | env: Environment, |
| 23 | client: (&SmbClient, &str), |
| 24 | access_token: String, |
| 25 | mail_app_id: String, |
| 26 | mail_inbox: MailInboxCreate, |
| 27 | ) -> Result<MailInbox, ErrorResponse> { |
| 28 | let builder = Client::new() |
| 29 | .post(build_mail_inboxes_url(env, client, &mail_app_id)) |
| 30 | .json(&MailInboxEnvelope { mail_inbox }) |
| 31 | .header("Authorization", access_token) |
| 32 | .header("User-agent", SMB_USER_AGENT); |
| 33 | request(builder).await |
| 34 | } |
| 35 | |
| 36 | pub async fn update_mail_inbox( |
| 37 | env: Environment, |
| 38 | client: (&SmbClient, &str), |
| 39 | access_token: String, |
| 40 | mail_app_id: String, |
| 41 | inbox_id: String, |
| 42 | mail_inbox: MailInboxUpdate, |
| 43 | ) -> Result<MailInbox, ErrorResponse> { |
| 44 | let builder = Client::new() |
| 45 | .put(build_mail_inbox_url(env, client, &mail_app_id, &inbox_id)) |
| 46 | .json(&MailInboxEnvelope { mail_inbox }) |
| 47 | .header("Authorization", access_token) |
| 48 | .header("User-agent", SMB_USER_AGENT); |
| 49 | request(builder).await |
| 50 | } |
| 51 | |
| 52 | pub async fn delete_mail_inbox( |
| 53 | env: Environment, |
| 54 | client: (&SmbClient, &str), |
| 55 | access_token: String, |
| 56 | mail_app_id: String, |
| 57 | inbox_id: String, |
| 58 | ) -> Result<(), ErrorResponse> { |
| 59 | let builder = Client::new() |
| 60 | .delete(build_mail_inbox_url(env, client, &mail_app_id, &inbox_id)) |
| 61 | .header("Authorization", access_token) |
| 62 | .header("User-agent", SMB_USER_AGENT); |
| 63 | request_empty(builder).await |
| 64 | } |
| 65 | |
| 66 | pub async fn send_test_email( |
| 67 | env: Environment, |
| 68 | client: (&SmbClient, &str), |
| 69 | access_token: String, |
| 70 | mail_app_id: String, |
| 71 | inbox_id: String, |
| 72 | mail_inbox: MailTestEmailRequest, |
| 73 | ) -> Result<MailTestEmailDelivery, ErrorResponse> { |
| 74 | let builder = Client::new() |
| 75 | .post(build_mail_inbox_test_url( |
| 76 | env, |
| 77 | client, |
| 78 | &mail_app_id, |
| 79 | &inbox_id, |
| 80 | )) |
| 81 | .json(&MailInboxEnvelope { mail_inbox }) |
| 82 | .header("Authorization", access_token) |
| 83 | .header("User-agent", SMB_USER_AGENT); |
| 84 | request(builder).await |
| 85 | } |