mirror of
https://github.com/rustmailer/rustmailer.git
synced 2026-08-24 08:00:35 +00:00
refactor: refactorparent_id to parent_name since the ID is internal and not safe or convenient to use as a number in external environments like JavaScript
This commit is contained in:
@@ -533,7 +533,7 @@ message CreateMailboxRequest {
|
||||
/// Only applicable for **Graph API** accounts.
|
||||
/// For IMAP or Gmail API accounts, this field is always `None`.
|
||||
/// The ID can be retrieved via the **`/list-mailboxes?remote=true`** endpoint.
|
||||
optional uint64 parent_id = 3;
|
||||
optional string parent_name = 3;
|
||||
// Optional color settings for the label (Gmail API only).
|
||||
// Only applicable to Gmail API accounts. See [`LabelColor`] for the allowed
|
||||
// `text_color` and `background_color` values.
|
||||
|
||||
+4
-6
@@ -10,7 +10,6 @@ use crate::{
|
||||
error::{code::ErrorCode, RustMailerResult},
|
||||
message::append::ReplyDraft,
|
||||
oauth2::token::OAuth2AccessToken,
|
||||
utils::mailbox_id,
|
||||
},
|
||||
raise_error,
|
||||
};
|
||||
@@ -389,7 +388,7 @@ impl OutlookClient {
|
||||
pub async fn create_folder(
|
||||
account_id: u64,
|
||||
use_proxy: Option<u64>,
|
||||
parent_id: Option<u64>,
|
||||
parent_name: Option<String>,
|
||||
folder_name: &str,
|
||||
) -> RustMailerResult<()> {
|
||||
let client = HttpClient::new(use_proxy).await?;
|
||||
@@ -397,20 +396,19 @@ impl OutlookClient {
|
||||
let mut url = "https://graph.microsoft.com/v1.0/me/mailFolders".to_string();
|
||||
let body = json!({ "displayName": folder_name });
|
||||
|
||||
if let Some(parent_id) = parent_id {
|
||||
if let Some(parent_name) = parent_name {
|
||||
let mailboxes = Self::list_mailfolders(account_id, use_proxy).await?;
|
||||
if let Some(parent) = mailboxes
|
||||
.into_iter()
|
||||
.find(|m| mailbox_id(account_id, &m.id) == parent_id)
|
||||
.find(|m| m.display_name == parent_name)
|
||||
{
|
||||
// parent.id 是 Graph API 的 folder id(字符串),将请求发到父文件夹的 childFolders 端点
|
||||
url = format!(
|
||||
"https://graph.microsoft.com/v1.0/me/mailFolders/{}/childFolders",
|
||||
parent.id
|
||||
);
|
||||
} else {
|
||||
return Err(raise_error!(
|
||||
format!("Parent folder not found: {}", parent_id),
|
||||
format!("Parent folder not found: {}", parent_name),
|
||||
ErrorCode::InternalError
|
||||
));
|
||||
}
|
||||
|
||||
@@ -95,7 +95,7 @@ impl From<rustmailer_grpc::CreateMailboxRequest> for CreateMailboxRequest {
|
||||
fn from(value: rustmailer_grpc::CreateMailboxRequest) -> Self {
|
||||
Self {
|
||||
mailbox_name: value.mailbox_name,
|
||||
parent_id: value.parent_id,
|
||||
parent_name: value.parent_name,
|
||||
label_color: value.label_color.map(|c| c.into()),
|
||||
}
|
||||
}
|
||||
|
||||
@@ -72,8 +72,8 @@ pub struct CreateMailboxRequest {
|
||||
///
|
||||
/// Only applicable for **Graph API** accounts.
|
||||
/// For IMAP or Gmail API accounts, this field is always `None`.
|
||||
/// The ID can be retrieved via the **`/list-mailboxes?remote=true`** endpoint.
|
||||
pub parent_id: Option<u64>,
|
||||
/// The name can be retrieved via the **`/list-mailboxes?remote=true`** endpoint.
|
||||
pub parent_name: Option<String>,
|
||||
/// Optional color settings for the label (Gmail API only).
|
||||
///
|
||||
/// Only applicable to Gmail API accounts. See [`LabelColor`] for the allowed
|
||||
@@ -101,7 +101,7 @@ pub async fn create_mailbox(
|
||||
OutlookClient::create_folder(
|
||||
account_id,
|
||||
account.use_proxy,
|
||||
request.parent_id,
|
||||
request.parent_name.clone(),
|
||||
&request.mailbox_name,
|
||||
)
|
||||
.await
|
||||
|
||||
Reference in New Issue
Block a user