fix: path issues on linux
This commit is contained in:
@@ -1005,8 +1005,8 @@ impl InitCli {
|
||||
let config_path = parse_config_root(config_root);
|
||||
|
||||
let client_config = ClientConfig::builder()
|
||||
.with_credential_file(InitDefaults::credential_filename())
|
||||
.with_config_path(config_path.to_string_lossy().as_ref())
|
||||
.with_credential_file(InitDefaults::credential_filename())
|
||||
.build();
|
||||
|
||||
// Initialize Gmail client which will trigger OAuth flow if needed
|
||||
|
||||
@@ -289,17 +289,13 @@ impl MessagesCli {
|
||||
|
||||
match self.action {
|
||||
MessageAction::List => {
|
||||
if log::max_level() >= log::Level::Info {
|
||||
client.log_messages("", "").await
|
||||
} else {
|
||||
Ok(())
|
||||
}
|
||||
let messages = client.messages();
|
||||
println!("Found {} messages matching query", messages.len());
|
||||
Ok(())
|
||||
}
|
||||
MessageAction::Trash => client.batch_trash().await,
|
||||
MessageAction::Delete => client.batch_delete().await,
|
||||
}
|
||||
|
||||
// Ok(())
|
||||
}
|
||||
|
||||
/// Configures the Gmail client with filtering and pagination parameters.
|
||||
|
||||
@@ -333,7 +333,7 @@ impl ClientConfig {
|
||||
console.installed.unwrap()
|
||||
};
|
||||
|
||||
let persist_path = format!("{}/gmail1", config_root.full_path().display());
|
||||
let persist_path = format!("{}/gmail1/tokencache.json", config_root.full_path().display());
|
||||
|
||||
Ok(ClientConfig {
|
||||
config_root,
|
||||
@@ -605,7 +605,7 @@ impl ConfigBuilder {
|
||||
}
|
||||
|
||||
pub fn build(&self) -> ClientConfig {
|
||||
let persist_path = format!("{}/gmail1", self.full_path());
|
||||
let persist_path = format!("{}/gmail1/tokencache.json", self.full_path());
|
||||
|
||||
ClientConfig {
|
||||
secret: self.secret.clone(),
|
||||
@@ -889,7 +889,7 @@ mod tests {
|
||||
.with_config_path("/custom/path")
|
||||
.build();
|
||||
|
||||
assert_eq!(config.persist_path(), "/custom/path/gmail1");
|
||||
assert_eq!(config.persist_path(), "/custom/path/gmail1/tokencache.json");
|
||||
}
|
||||
|
||||
#[test]
|
||||
@@ -906,7 +906,7 @@ mod tests {
|
||||
assert_eq!(secret.client_secret, "accessor-test-secret");
|
||||
|
||||
// Test persist_path() accessor
|
||||
assert_eq!(config.persist_path(), "/test/path/gmail1");
|
||||
assert_eq!(config.persist_path(), "/test/path/gmail1/tokencache.json");
|
||||
|
||||
// Test full_path() accessor
|
||||
assert_eq!(config.full_path(), "/test/path");
|
||||
|
||||
@@ -405,7 +405,9 @@ impl GmailService for GmailClient {
|
||||
if let Some(token) = page_token {
|
||||
call = call.page_token(&token);
|
||||
}
|
||||
eprintln!("[DEBUG] Making Gmail API call: messages_list(query='{}', max_results={})", query, max_results);
|
||||
let (_response, list) = call.doit().await.map_err(Box::new)?;
|
||||
eprintln!("[DEBUG] API call completed");
|
||||
Ok(list)
|
||||
}
|
||||
|
||||
@@ -483,7 +485,12 @@ impl MessageList for GmailClient {
|
||||
|
||||
/// Run the Gmail api as configured
|
||||
async fn get_messages(&mut self, pages: u32) -> Result<()> {
|
||||
eprintln!("[DEBUG] Starting message fetch: pages={}, query='{}', labels={:?}",
|
||||
pages, self.query, self.label_ids);
|
||||
let list = self.list_messages(None).await?;
|
||||
eprintln!("[DEBUG] Got response: {} messages (estimated: {})",
|
||||
list.messages.as_ref().map(|m| m.len()).unwrap_or(0),
|
||||
list.result_size_estimate.unwrap_or(0));
|
||||
match pages {
|
||||
1 => {}
|
||||
0 => {
|
||||
@@ -553,6 +560,7 @@ impl MessageList for GmailClient {
|
||||
}
|
||||
|
||||
async fn log_messages(&mut self, pre: &str, post: &str) -> Result<()> {
|
||||
eprintln!("[INFO] Processing {} messages for output...", self.messages.len());
|
||||
for i in 0..self.messages.len() {
|
||||
let id = self.messages[i].id().to_string();
|
||||
log::trace!("{id}");
|
||||
@@ -575,7 +583,9 @@ impl MessageList for GmailClient {
|
||||
continue;
|
||||
}
|
||||
}
|
||||
log::info!("{pre}{}{post}", message.list_date_and_subject());
|
||||
let output = format!("{pre}{}{post}", message.list_date_and_subject());
|
||||
println!("{}", output);
|
||||
log::info!("{}", output);
|
||||
}
|
||||
|
||||
Ok(())
|
||||
|
||||
@@ -481,12 +481,13 @@ impl RuleProcessor for GmailClient {
|
||||
return Ok(());
|
||||
}
|
||||
|
||||
self.log_messages("Message with subject `", "` permanently deleted")
|
||||
.await?;
|
||||
eprintln!("[INFO] Deleting {} messages using batch delete API...", message_ids.len());
|
||||
log::info!("Permanently deleting {} messages using batch API", message_ids.len());
|
||||
|
||||
self.process_in_chunks(message_ids, EolAction::Delete)
|
||||
.await?;
|
||||
|
||||
eprintln!("[INFO] Batch delete completed");
|
||||
Ok(())
|
||||
}
|
||||
/// Moves all prepared messages to Gmail's trash folder using batch modify API.
|
||||
@@ -512,12 +513,13 @@ impl RuleProcessor for GmailClient {
|
||||
return Ok(());
|
||||
}
|
||||
|
||||
self.log_messages("Message with subject `", "` moved to trash")
|
||||
.await?;
|
||||
eprintln!("[INFO] Moving {} messages to trash using batch modify API...", message_ids.len());
|
||||
log::info!("Moving {} messages to trash using batch API", message_ids.len());
|
||||
|
||||
self.process_in_chunks(message_ids, EolAction::Trash)
|
||||
.await?;
|
||||
|
||||
eprintln!("[INFO] Batch trash completed");
|
||||
Ok(())
|
||||
}
|
||||
|
||||
@@ -550,6 +552,7 @@ impl RuleProcessor for GmailClient {
|
||||
}
|
||||
|
||||
async fn call_batch_delete(&self, ids: &[String]) -> Result<()> {
|
||||
let count = ids.len();
|
||||
let ids = Some(Vec::from(ids));
|
||||
let batch_request = BatchDeleteMessagesRequest { ids };
|
||||
log::trace!("{batch_request:#?}");
|
||||
@@ -566,11 +569,13 @@ impl RuleProcessor for GmailClient {
|
||||
log::trace!("Batch delete response {res:?}");
|
||||
|
||||
res?;
|
||||
eprintln!("[DEBUG] Batch delete completed: {} messages", count);
|
||||
|
||||
Ok(())
|
||||
}
|
||||
|
||||
async fn call_batch_trash(&self, ids: &[String]) -> Result<()> {
|
||||
let count = ids.len();
|
||||
let ids = Some(Vec::from(ids));
|
||||
let add_label_ids = Some(vec![TRASH_LABEL.to_string()]);
|
||||
let remove_label_ids = Some(vec![INBOX_LABEL.to_string()]);
|
||||
@@ -592,6 +597,7 @@ impl RuleProcessor for GmailClient {
|
||||
.await
|
||||
.map_err(Box::new)?;
|
||||
|
||||
eprintln!("[DEBUG] Batch trash completed: {} messages", count);
|
||||
Ok(())
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user