🐛 fix(gmail): display message date and subject
- Refactor log_message_subjects to log_messages for clarity - Simplify date and subject retrieval in log_messages - Use MessageSummary's list_date_and_subject for logging - Elide subject in MessageSummary for consistent display
This commit is contained in:
committed by
Jeremiah Russell
parent
f9e86bf8d9
commit
37d02bd0bf
@@ -43,7 +43,7 @@ impl MessageCli {
|
|||||||
match self.action {
|
match self.action {
|
||||||
MessageAction::List => {
|
MessageAction::List => {
|
||||||
if log::max_level() >= log::Level::Info {
|
if log::max_level() >= log::Level::Info {
|
||||||
client.log_message_subjects().await
|
client.log_messages().await
|
||||||
} else {
|
} else {
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,3 +1,5 @@
|
|||||||
|
use crate::utils::Elide;
|
||||||
|
|
||||||
#[derive(Debug, Clone)]
|
#[derive(Debug, Clone)]
|
||||||
pub struct MessageSummary {
|
pub struct MessageSummary {
|
||||||
id: String,
|
id: String,
|
||||||
@@ -18,8 +20,8 @@ impl MessageSummary {
|
|||||||
&self.id
|
&self.id
|
||||||
}
|
}
|
||||||
|
|
||||||
pub(crate) fn set_subject(&mut self, subject: &str) {
|
pub(crate) fn set_subject(&mut self, subject: Option<String>) {
|
||||||
self.subject = Some(subject.to_string())
|
self.subject = subject
|
||||||
}
|
}
|
||||||
|
|
||||||
pub(crate) fn subject(&self) -> &str {
|
pub(crate) fn subject(&self) -> &str {
|
||||||
@@ -30,8 +32,8 @@ impl MessageSummary {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
pub(crate) fn set_date(&mut self, date: &str) {
|
pub(crate) fn set_date(&mut self, date: Option<String>) {
|
||||||
self.date = Some(date.to_string())
|
self.date = date
|
||||||
}
|
}
|
||||||
|
|
||||||
pub(crate) fn date(&self) -> &str {
|
pub(crate) fn date(&self) -> &str {
|
||||||
@@ -51,7 +53,7 @@ impl MessageSummary {
|
|||||||
return "***invalid date or subject***".to_string();
|
return "***invalid date or subject***".to_string();
|
||||||
};
|
};
|
||||||
let s = date[5..16].to_string();
|
let s = date[5..16].to_string();
|
||||||
let s = format!("{s}: {subject}");
|
let s = format!("{s}: {}", subject.to_string().elide(24));
|
||||||
s
|
s
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -5,12 +5,10 @@ use google_gmail1::{
|
|||||||
hyper_util::client::legacy::connect::HttpConnector,
|
hyper_util::client::legacy::connect::HttpConnector,
|
||||||
};
|
};
|
||||||
|
|
||||||
use crate::utils::Elide;
|
|
||||||
|
|
||||||
/// Methods to select lists of messages from the mailbox
|
/// Methods to select lists of messages from the mailbox
|
||||||
pub trait MessageList {
|
pub trait MessageList {
|
||||||
/// Log the initial characters of the subjects of the message in the list
|
/// Log the initial characters of the subjects of the message in the list
|
||||||
fn log_message_subjects(&mut self) -> impl std::future::Future<Output = Result<()>> + Send;
|
fn log_messages(&mut self) -> impl std::future::Future<Output = Result<()>> + Send;
|
||||||
/// List of messages
|
/// List of messages
|
||||||
fn messages_list(
|
fn messages_list(
|
||||||
&mut self,
|
&mut self,
|
||||||
@@ -195,7 +193,7 @@ impl MessageList for GmailClient {
|
|||||||
Ok(list)
|
Ok(list)
|
||||||
}
|
}
|
||||||
|
|
||||||
async fn log_message_subjects(&mut self) -> Result<()> {
|
async fn log_messages(&mut self) -> Result<()> {
|
||||||
let hub = self.hub();
|
let hub = self.hub();
|
||||||
for message in &mut self.messages {
|
for message in &mut self.messages {
|
||||||
log::trace!("{}", message.id());
|
log::trace!("{}", message.id());
|
||||||
@@ -210,8 +208,6 @@ impl MessageList for GmailClient {
|
|||||||
.await
|
.await
|
||||||
.map_err(Box::new)?;
|
.map_err(Box::new)?;
|
||||||
|
|
||||||
let mut subject = String::new();
|
|
||||||
let mut date = String::new();
|
|
||||||
let Some(payload) = m.payload else { continue };
|
let Some(payload) = m.payload else { continue };
|
||||||
let Some(headers) = payload.headers else {
|
let Some(headers) = payload.headers else {
|
||||||
continue;
|
continue;
|
||||||
@@ -220,8 +216,8 @@ impl MessageList for GmailClient {
|
|||||||
for header in headers {
|
for header in headers {
|
||||||
if let Some(name) = header.name {
|
if let Some(name) = header.name {
|
||||||
match name.to_lowercase().as_str() {
|
match name.to_lowercase().as_str() {
|
||||||
"subject" => subject = header.value.unwrap_or_default(),
|
"subject" => message.set_subject(header.value),
|
||||||
"date" => date = header.value.unwrap_or_default(),
|
"date" => message.set_date(header.value),
|
||||||
_ => {}
|
_ => {}
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
@@ -229,19 +225,6 @@ impl MessageList for GmailClient {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if date.is_empty() {
|
|
||||||
log::info!("***No orig-date field***");
|
|
||||||
} else {
|
|
||||||
message.set_date(&date);
|
|
||||||
}
|
|
||||||
|
|
||||||
if subject.is_empty() {
|
|
||||||
log::info!("***Email with no subject***");
|
|
||||||
} else {
|
|
||||||
subject.elide(24);
|
|
||||||
message.set_subject(&subject);
|
|
||||||
}
|
|
||||||
|
|
||||||
log::info!("{}", message.list_date_and_subject());
|
log::info!("{}", message.list_date_and_subject());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user