22 Commits

Author SHA1 Message Date
Robin Jarry
0ca8087ec9 treewide: replace interface{} with any
Since go 1.18, interface{} can be replaced with any.

Signed-off-by: Robin Jarry <robin@jarry.cc>
Reviewed-by: Karel Balej <balejk@matfyz.cz>
2025-04-07 10:51:05 +02:00
Karel Balej
02324e9d9c lib: disallow < in URLs when parsing HTML
Make sure that links placed verbatim inside HTML elements' bodies are
not parsed along with adjacent HTML tags as illustrated in the new test
case.

Also change the existing code to use the idiomatic Go way to get a
set-like functionality.

Changelog-fixed: Parsed links in HTML message parts now do not include
 trailing HTML tags.
Signed-off-by: Karel Balej <balejk@matfyz.cz>
Tested-by: Jakub Růžička <jakub.ruzicka@matfyz.cz>
2025-02-04 15:18:01 +01:00
Robin Jarry
8edf7b0e4d log: move package to lib
This has nothing to do at the root of the source tree.

Signed-off-by: Robin Jarry <robin@jarry.cc>
Acked-by: Bence Ferdinandy <bence@ferdinandy.com>
2024-02-14 23:04:38 +01:00
Tim Culverhouse
6314e2dc67 vaxis: update to v0.7.2 and update ansi parser
Update Vaxis to v0.7.2 to gain performance improvements and StyledString
parsing. The Vaxis parser fully accounts for the terminal's capability
to display wide characters.

Use the Vaxis StyledString parser to parse and style ansi-encoded
strings. Remove unneeded code and tests.

Signed-off-by: Tim Culverhouse <tim@timculverhouse.com>
Acked-by: Robin Jarry <robin@jarry.cc>
2024-02-12 13:49:14 +01:00
Tim Culverhouse
a60f2c19a0 style: use vaxis style everywhere
Replace all tcell.Style objects with vaxis.Style objects

Signed-off-by: Tim Culverhouse <tim@timculverhouse.com>
Acked-by: Robin Jarry <robin@jarry.cc>
2024-02-12 13:48:50 +01:00
Tim Culverhouse
a11e0bf692 parse/ansi: remove tcell/terminfo dependency
The parse library builds an ansi-escaped string based on a buffer of
styled cells. Use constants which aerc will still parse properly (and
are the same as the terminfo package was pulling in) to remove
dependency on tcell/terminfo. Additionally, we can use the internal go
"fmt" package to write strings instead of the terminfo.TParm method
(which is much slower at formatting strings).

Signed-off-by: Tim Culverhouse <tim@timculverhouse.com>
Acked-by: Robin Jarry <robin@jarry.cc>
2024-02-12 13:46:18 +01:00
Robin Jarry
57088312fd worker: move shared code to lib
Avoid importing code from worker/lib into lib. It should only be the
other way around. Move the message parsing code used by maildir,
notmuch, mbox and the eml viewer into a lib/rfc822 package.

Adapt imports accordingly.

Signed-off-by: Robin Jarry <robin@jarry.cc>
Reviewed-by: Koni Marti <koni.marti@gmail.com>
Tested-by: Moritz Poldrack <moritz@poldrack.dev>
Tested-by: Inwit <inwit@sindominio.net>
2023-10-28 19:24:55 +02:00
Vitaly Ovchinnikov
8f15b804d1 hyperlinks: better parsing of emails without mailto prefixes
Add some new tests from the emails I have and make them work by
adjusting the code that looks for hyperlinks.

The idea is to treat "inline" emails (those without mailto:) a little
bit different and stop a little earlier while looking for their ends.

Signed-off-by: Vitaly Ovchinnikov <v@postbox.nz>
Acked-by: Robin Jarry <robin@jarry.cc>
2023-09-19 01:20:11 +02:00
Robin Jarry
9cbfb190f6 parse-links: be more strict with url parsing
Reuse the same logic than colorize.c to allow parsing markdown links.

Signed-off-by: Robin Jarry <robin@jarry.cc>
Acked-by: Moritz Poldrack <moritz@poldrack.dev>
2023-06-25 22:53:19 +02:00
Robin Jarry
c5468febb5 templates: change layered fg & bg color priorities
This is mostly a revert of commit ae4d742c5a ("templates: fix layered
fg & bg color for inline styles").

As it turns out, context colors (msglist_selected, msglist_marked,
msglist_deleted, etc.) need to have priority over inline colors.
Otherwise strange and confusing results occur.

Reported-by: Skejg <grolleman@zoho.com>
Signed-off-by: Robin Jarry <robin@jarry.cc>
Tested-by: Tim Culverhouse <tim@timculverhouse.com>
2023-04-15 17:27:41 +02:00
Robin Jarry
ae4d742c5a templates: fix layered fg & bg color for inline styles
The logic was inverted. The style argument is actually the "under" layer
style. Each character in the RuneBuffer style must be applied on *top*
of it, not the other way around.

Use colors from style and override them with each character's colors if
they are set. Keep attributes handling unchanged.

Fixes: ab8f433e17 ("templates: allow layered fg & bg color for inline styles")
Signed-off-by: Robin Jarry <robin@jarry.cc>
Tested-by: Bence Ferdinandy <bence@ferdinandy.com>
2023-03-31 21:02:14 +02:00
Nguyễn Gia Phong
94a763920f parse msg-id lists more liberally
Some user agents deliberately generate non-standard
message identifier lists in In-Reply-To and References headers.

Instead of failing silently, aerc now falls back to a desperate parser
scavaging whatever looking like <id-left@id-right>.

As the more liberal parser being substituted with, References header
are now stored for IMAP not only when there's a parsing error.

Fixes: 31d2f5be3c ("message-info: add explicit References field")
Signed-off-by: Nguyễn Gia Phong <mcsinyx@disroot.org>
Acked-by: Robin Jarry <robin@jarry.cc>
2023-03-26 21:02:18 +02:00
Robin Jarry
56a6ed0cf7 templates: add match function
Add a match function that returns true if a string matches the provided
regular expression. The compiled regular expressions are cached in
a sync.Map to avoid repetitive compilations of the same expressions.

Caveat: if the user mixes the arguments order, it may cause the cache to
consume a lot of memory filled with garbage regular expression objects.
Ideally, we would need to limit the size of this cache and/or use a LRU
cache implementation. Maybe someday?

Signed-off-by: Robin Jarry <robin@jarry.cc>
Acked-by: Tim Culverhouse <tim@timculverhouse.com>
2023-03-08 00:43:02 +01:00
Robin Jarry
ab8f433e17 templates: allow layered fg & bg color for inline styles
If a user style has no fg and/or no bg color defined, use the color from
the underlying style.

Signed-off-by: Robin Jarry <robin@jarry.cc>
Acked-by: Tim Culverhouse <tim@timculverhouse.com>
2023-03-08 00:42:42 +01:00
Robin Jarry
a603d3de03 table: fix center padding
When a column has ALIGN_CENTER and the number of white space character
of padding is not a multiple of two, the last cell(character) is not
padded and that can cause coloring glitches. Make sure to pad all the
way.

Fixes: 49de9b09ca ("ui: parse strings for ansi styles")
Signed-off-by: Robin Jarry <robin@jarry.cc>
Acked-by: Tim Culverhouse <tim@timculverhouse.com>
2023-03-04 18:03:28 +01:00
Tim Culverhouse
49de9b09ca ui: parse strings for ansi styles
Parse UI strings for ANSI styles. If there are styles in the string, use
those as the display style in tcell. This is in preparation for a
template function which can apply arbitrary styles to UI elements.

Signed-off-by: Tim Culverhouse <tim@timculverhouse.com>
Acked-by: Robin Jarry <robin@jarry.cc>
2023-03-02 22:49:57 +01:00
Robin Jarry
23a05d17ac logging: rename package to log
Use the same name than the builtin "log" package. That way, we do not
risk logging in the wrong place.

Suggested-by: Tim Culverhouse <tim@timculverhouse.com>
Signed-off-by: Robin Jarry <robin@jarry.cc>
Tested-by: Bence Ferdinandy <bence@ferdinandy.com>
Acked-by: Tim Culverhouse <tim@timculverhouse.com>
2022-12-02 22:10:49 +01:00
Tim Culverhouse
556f346f96 msgviewer: simplify filter and pager command handling
Refactor the filtering and paging logic to use several fewer goroutines.
Fixes data race condition with the timing of filter -> pager ->
terminal, can be found when switching message views fast.

Check if filter -> pager process is currently running before calling it
to start again. Fixes data race between fetching message body and
terminal starting. Both can initiate the copying process, and for long
running filters and fast message fetching, it is possible to have
fetched a message but still be running the filter when the terminal
starts.

Move StripAnsi to it's own file in lib/parse, similar to the hyperlinks
parser.

Signed-off-by: Tim Culverhouse <tim@timculverhouse.com>
Acked-by: Robin Jarry <robin@jarry.cc>
2022-10-18 22:20:37 +02:00
Moritz Poldrack
fad90c2956 open-link: make URL parsing more lenient
URLs are extremely loosely defined and can take many shapes which may
not be parsed at all if unusual characters like the exclamation mark are
present. To ensure lists and odd use of spaces are not parsed as links
some sanity-checks are in place:
	- the URL's schema must be at least two characters long
	- the URL's authority, path, and fragment must have a combined
	  length of 8 characters or longer
	- the URL must not contain a whitespace character, >, ), or "
	- the URL may only contain a ] when followed by a different allowed
	  character or at the end of the line (necessary for IPv6
	  authorities)

The tests for this function now include links with an exclamation point
and IPv6 addresses. The tests are given names to be easier identifiable.

Link: https://www.iana.org/assignments/uri-schemes/uri-schemes.xhtml
Reported-by: "Bence Ferdinandy" <bence@ferdinandy.com>
Cc: "Koni Marti" <koni.marti@gmail.com>
Fixes: e1d8bc4d17 ("msgviewer: open http links from messages")
Signed-off-by: Moritz Poldrack <git@moritz.sh>
Acked-by: Tim Culverhouse <tim@timculverhouse.com>
2022-09-13 23:58:53 +02:00
Moritz Poldrack
9cffc45f03 go: removed io/ioutil
Since the minimum required version of Go has been bumped to 1.16, the
deprecation of io/ioutil can now be acted upon. This Commit removes the
remaining dependencies on ioutil and replaces them with their io or os
counterparts.

Signed-off-by: Moritz Poldrack <git@moritz.sh>
Acked-by: Robin Jarry <robin@jarry.cc>
2022-08-22 09:30:19 +02:00
Moritz Poldrack
aaf0a0c656 lint: apply new formatting rules
Run `make fmt`.

Signed-off-by: Moritz Poldrack <git@moritz.sh>
Acked-by: Robin Jarry <robin@jarry.cc>
2022-08-01 10:44:52 +02:00
Koni Marti
e1d8bc4d17 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>
2022-06-14 22:12:48 +02:00