Browse Source

Add show_date_in_my_timezone pager config flag

Closes #28
master
Manos Pitsidianakis 2 months ago
parent
commit
32901f57d2
Signed by: epilys GPG Key ID: 73627C2F690DF710
  1. 5
      docs/meli.conf.5
  2. 46
      src/components/mail/view.rs
  3. 6
      src/conf/overrides.rs
  4. 5
      src/conf/pager.rs

5
docs/meli.conf.5

@ -880,6 +880,11 @@ Minimum text width in columns.
Choose `text/html` alternative if `text/plain` is empty in `multipart/alternative` attachments.
.\" default value
.Pq Em true
.It Ic show_date_in_my_timezone Ar boolean
.Pq Em optional
Show Date: in local timezone
.\" default value
.Pq Em true
.El
.Sh LISTING
.Bl -tag -width 36n

46
src/components/mail/view.rs

@ -1111,8 +1111,52 @@ impl Component for MailView {
})+
};
}
let find_offset = |s: &str| -> (bool, (i64, i64)) {
let mut diff = (true, (0, 0));
if let Some(pos) = s.as_bytes().iter().position(|b| *b == b'+' || *b == b'-') {
let offset = &s[pos..];
diff.0 = offset.starts_with('+');
if let (Ok(hr_offset), Ok(min_offset)) =
(offset[1..3].parse::<i64>(), offset[3..5].parse::<i64>())
{
diff.1 .0 = hr_offset;
diff.1 .1 = min_offset;
}
}
diff
};
let orig_date = envelope.date_as_str();
let date_str: std::borrow::Cow<str> = if mailbox_settings!(
context[self.coordinates.0][&self.coordinates.1]
.pager
.show_date_in_my_timezone
)
.is_true()
{
let local_date = melib::datetime::timestamp_to_string(
envelope.timestamp,
Some(melib::datetime::RFC822_DATE),
false,
);
let orig_offset = find_offset(orig_date);
let local_offset = find_offset(&local_date);
if orig_offset == local_offset {
orig_date.into()
} else {
format!(
"{} [actual timezone: {}{:02}{:02}]",
local_date,
if orig_offset.0 { '+' } else { '-' },
orig_offset.1 .0,
orig_offset.1 .1
)
.into()
}
} else {
orig_date.into()
};
print_header!(
("Date:", envelope.date_as_str()),
("Date:", date_str),
("From:", envelope.field_from_to_string()),
("To:", envelope.field_to_to_string()),
);

6
src/conf/overrides.rs

@ -76,6 +76,11 @@ pub struct PagerSettingsOverride {
#[serde(alias = "auto-choose-multipart-alternative")]
#[serde(default)]
pub auto_choose_multipart_alternative: Option<ToggleFlag>,
#[doc = " Show Date: in my timezone"]
#[doc = " Default: true"]
#[serde(alias = "show-date-in-my-timezone")]
#[serde(default)]
pub show_date_in_my_timezone: Option<ToggleFlag>,
}
impl Default for PagerSettingsOverride {
fn default() -> Self {
@ -90,6 +95,7 @@ impl Default for PagerSettingsOverride {
split_long_lines: None,
minimum_width: None,
auto_choose_multipart_alternative: None,
show_date_in_my_timezone: None,
}
}
}

5
src/conf/pager.rs

@ -87,6 +87,10 @@ pub struct PagerSettings {
alias = "auto-choose-multipart-alternative"
)]
pub auto_choose_multipart_alternative: ToggleFlag,
/// Show Date: in my timezone
/// Default: true
#[serde(default = "internal_value_true", alias = "show-date-in-my-timezone")]
pub show_date_in_my_timezone: ToggleFlag,
}
impl Default for PagerSettings {
@ -102,6 +106,7 @@ impl Default for PagerSettings {
split_long_lines: true,
minimum_width: 80,
auto_choose_multipart_alternative: ToggleFlag::InternalVal(true),
show_date_in_my_timezone: ToggleFlag::InternalVal(true),
}
}
}

Loading…
Cancel
Save