mail/view: store Link URL value in Link type
Tests / Test on ${{ matrix.build }} (linux-amd64, ubuntu-latest, stable, x86_64-unknown-linux-gnu) (pull_request) Successful in 11m10s Details
Tests / Test on ${{ matrix.build }} (linux-amd64, ubuntu-latest, stable, x86_64-unknown-linux-gnu) (push) Successful in 18m3s Details

Due to changes in how decoded email body is stored in `ViewFilter`s,
the previous way of accessing URL values (by using the `start` and `end`
offset in the e-mail body) meant the offset values might not be correct.

Store the value right away to prevent this from happening.

Signed-off-by: Manos Pitsidianakis <manos@pitsidianak.is>
pull/320/head
Manos Pitsidianakis 2023-12-09 15:06:51 +02:00
parent 3adba40e32
commit e37997d697
Signed by: Manos Pitsidianakis
GPG Key ID: 7729C7707F7E09D0
2 changed files with 14 additions and 22 deletions

View File

@ -1530,13 +1530,9 @@ impl Component for EnvelopeView {
context
.replies
.push_back(UIEvent::StatusEvent(StatusEvent::BufClear));
let body_text = &self.body_text;
let links = &self.links;
let (_kind, url) = {
if let Some(l) = links
.get(lidx)
.and_then(|l| Some((l.kind, body_text.get(l.start..l.end)?)))
{
if let Some(l) = links.get(lidx).map(|l| (l.kind, l.value.as_str())) {
l
} else {
context.replies.push_back(UIEvent::StatusEvent(

View File

@ -73,11 +73,12 @@ pub enum LinkKind {
Email,
}
#[derive(Eq, PartialEq, Copy, Clone, Debug)]
#[derive(Eq, PartialEq, Clone, Debug)]
pub struct Link {
pub start: usize,
pub end: usize,
pub kind: self::LinkKind,
pub value: String,
pub kind: LinkKind,
}
#[derive(Debug, Default)]
@ -169,21 +170,16 @@ impl ViewOptions {
*links = finder
.links(&text)
.filter_map(|l| {
if *l.kind() == linkify::LinkKind::Url {
Some(Link {
start: l.start(),
end: l.end(),
kind: LinkKind::Url,
})
} else if *l.kind() == linkify::LinkKind::Email {
Some(Link {
start: l.start(),
end: l.end(),
kind: LinkKind::Email,
})
} else {
None
}
Some(Link {
start: l.start(),
end: l.end(),
value: l.as_str().to_string(),
kind: match l.kind() {
linkify::LinkKind::Url => LinkKind::Url,
linkify::LinkKind::Email => LinkKind::Email,
_ => return None,
},
})
})
.collect::<Vec<Link>>();
}