diff options
author | Koni Marti <koni.marti@gmail.com> | 2022-06-14 21:10:48 +0200 |
---|---|---|
committer | Robin Jarry <robin@jarry.cc> | 2022-06-14 22:12:48 +0200 |
commit | e1d8bc4d17cb7bd79e19fdf866d1da2fedda4de5 (patch) | |
tree | ececff85e82e42a2b95b27b03e53c79768ad0709 /widgets | |
parent | 4753cfd3e33f985ec22c5600a8d7e68b72175607 (diff) | |
download | aerc-e1d8bc4d17cb7bd79e19fdf866d1da2fedda4de5.tar.gz |
msgviewer: open http links from messages
Parse http links from a message and display them as completions in the
:open-link command.
Add the following binds to the [view] section in your binds.conf:
<C-l> = :open-link <space>
Parsing can be disabled in aerc.conf by setting parse-http-links to
false in the viewer section.
Thanks to Moritz for the help with the regular expression.
Signed-off-by: Koni Marti <koni.marti@gmail.com>
Reviewed-by: Moritz Poldrack <git@moritz.sh>
Acked-by: Robin Jarry <robin@jarry.cc>
Diffstat (limited to 'widgets')
-rw-r--r-- | widgets/msgviewer.go | 14 | ||||
-rw-r--r-- | widgets/providesmessage.go | 1 |
2 files changed, 14 insertions, 1 deletions
diff --git a/widgets/msgviewer.go b/widgets/msgviewer.go index 98764672..b41b57c0 100644 --- a/widgets/msgviewer.go +++ b/widgets/msgviewer.go @@ -19,6 +19,7 @@ import ( "git.sr.ht/~rjarry/aerc/lib" "git.sr.ht/~rjarry/aerc/lib/auth" "git.sr.ht/~rjarry/aerc/lib/format" + "git.sr.ht/~rjarry/aerc/lib/parse" "git.sr.ht/~rjarry/aerc/lib/ui" "git.sr.ht/~rjarry/aerc/logging" "git.sr.ht/~rjarry/aerc/models" @@ -325,6 +326,7 @@ func (mv *MessageViewer) SelectedMessagePart() *PartInfo { Index: part.index, Msg: part.msg.MessageInfo(), Part: part.part, + Links: part.links, } } @@ -518,6 +520,8 @@ type PartViewer struct { term *Terminal grid *ui.Grid uiConfig config.UIConfig + + links []string } func NewPartViewer(acct *AccountView, conf *config.AercConfig, @@ -670,6 +674,14 @@ func (pv *PartViewer) writeMailHeaders() { } } +func (pv *PartViewer) hyperlinks(r io.Reader) (reader io.Reader) { + if !pv.conf.Viewer.ParseHttpLinks { + return r + } + reader, pv.links = parse.HttpLinks(r) + return reader +} + func (pv *PartViewer) copyFilterOutToPager() { stdout, _ := pv.filter.StdoutPipe() stderr, _ := pv.filter.StderrPipe() @@ -708,7 +720,7 @@ func (pv *PartViewer) copyFilterOutToPager() { } func (pv *PartViewer) copySourceToSinkStripAnsi() { - scanner := bufio.NewScanner(pv.source) + scanner := bufio.NewScanner(pv.hyperlinks(pv.source)) // some people send around huge html without any newline in between // this did overflow the default 64KB buffer of bufio.Scanner. // If something can't fit in a GB there's no hope left diff --git a/widgets/providesmessage.go b/widgets/providesmessage.go index c1d821c7..b0f261d9 100644 --- a/widgets/providesmessage.go +++ b/widgets/providesmessage.go @@ -10,6 +10,7 @@ type PartInfo struct { Index []int Msg *models.MessageInfo Part *models.BodyStructure + Links []string } type ProvidesMessage interface { |