mail/view: store Link URL value in Link type
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
parent
3adba40e32
commit
e37997d697
|
@ -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(
|
||||
|
|
|
@ -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>>();
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue