aboutsummaryrefslogtreecommitdiffstats
path: root/filters
Commit message (Collapse)AuthorAgeFilesLines
* calendar: hide empty attendee listTimon Reinold2024-08-042-24/+30
| | | | | | | | | | | | | | Include the ATTENDEE and DETAILED LIST section in the calendar filter's output only if there are actually attendees to list. I was especially confused by the empty DETAILED LIST, as it wasn't clear which kind of detail it was supposed to list (and it also looked a bit like a heading for the description following immediately below), see e.g. the test output in filters/vectors/calendar-invite.expected. Fixes: 777bbb77e806 ("contrib: improve readability of meeting requests") Changelog-fixed: Builtin `calendar` filter shows empty attendee list. Signed-off-by: Timon Reinold <tirei+aerc@agon.one> Acked-by: Robin Jarry <robin@jarry.cc>
* filters: test calendar filter also with POSIX-AwkTimon Reinold2024-08-041-7/+31
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | The builtin "calendar" filter is written in the Awk language, for which multiple interpreters exist. The most common is probably GNU Awk (aka "gawk"), which also implements some features that other interpreters do not support. That means that the calendar filter could run fine in gawk, but fail in another interpreter (compare e.g. commit a604acceac0f "calendar: fix error with non-gnu awk"). Using the "-W posix" option, gawk can be put into a POSIX-compatibility mode, which attempts to stay as close as possible to the POSIX-specified version of Awk, which should then hopefully also be supported by other Awk interpreters. Running the filter's tests using "gawk -W posix" should help identify potential incompatibilities with other interpreters. Other interpreters also support "-W posix" (e.g. mawk, or ignore it like busybox awk). Using "awk -W posix" allows these to be used as well. If "-W posix" causes the interpreter to fail, skip this test. This new test in POSIX-compatibility mode runs in addition the existing test, which directly executes the filter, using the Awk interpreter's default mode ("-W posix" cannot just be added to the filter's shebang line, as only a single argument may be supported, and "-f" is also needed). The later is the mode most users will actually be using, so I don't want to remove that test. I'm not doing this for the other Awk-filters (hldiff and plaintext), as they have ben obsoleted by the colorize filter. Besides, they don't have any test vectors. Signed-off-by: Timon Reinold <tirei+aerc@agon.one> Acked-by: Robin Jarry <robin@jarry.cc>
* filters: add calendar test vectorTimon Reinold2024-08-043-2/+35
| | | | | | | | | | | | | | | | | | | | | | | | | | | Add a test vector for the builtin "calendar" filter. Use the filter's current output as expected output. My aim is mostly just to run the calendar filter during "make tests", this vector doesn't necessarily cover the most interesting sections of its code. But at least running the filter once on what could be a common input (a meeting PUBLISH) and checking that its output matches what was expected should still be better than testing nothing. Previously, only compiled filters were tested. Testing the calendar filter (which is interpreted, not compiled) necessitated two changes: * Compilation output goes into the project root (filters/test.sh: "$here/../"), but the source code to interpret is in the filters/ subdirectory (filters/test.sh: "$here"/). The executable to invoke is thus in a different location. * .builds/alpine-edge.yml uses $FILTERS_TEST_PREFIX to wrap filters in valgrind, to check that filters written in e.g C don't leak memory. But for the calendar filter, that would check that the Awk interpreter doesn't leak memory, failing the test for at least gawk, mawk and busybox awk. Thus, a $FILTERS_TEST_BIN_PREFIX variable is introduced, which only applies to binary filters. Signed-off-by: Timon Reinold <tirei+aerc@agon.one> Acked-by: Robin Jarry <robin@jarry.cc>
* filters: print "error" if filter failedTimon Reinold2024-08-041-5/+4
| | | | | | | | | Print "error" instead of "ok" also if the filter (or the $FILTERS_TEST_PREFIX, i.e. valgrind) failed, not just if its output is unexpected. Also include that exist status in the error message. Signed-off-by: Timon Reinold <tirei+aerc@agon.one> Acked-by: Robin Jarry <robin@jarry.cc>
* colorize: allow pipe '|' as uri characterRobin Jarry2024-07-291-1/+1
| | | | | | | | | | | | | | | Some HTML emails contain weird URLs that contain unescaped pipes '|'. For example: https://foo.baz.fr/?data=05|02|foo@bar.fr|1|0|Unknown|=|0|||&reserved=0 Sadly, this does not seem standard but there's probably not much we can do about it. Let's adapt colorize to also consider '|' as a valid URI character. Reported-by: Bence Ferdinandy <bence@ferdinandy.com> Signed-off-by: Robin Jarry <robin@jarry.cc> Tested-by: Johannes Thyssen Tishman <johannes@thyssentishman.com>
* calendar: fix error with non-gnu awkTimon Reinold2024-07-161-1/+2
| | | | | | | | | | | | | | | | | | | | | | | | | | | Use the POSIX-specified function Awk keyword instead of the non-standard func to define the prepare function in the text/calendar filter. The GNU Awk manual[1] mentions that gawk supports abbreviating function to func, but recommends against using the func abbreviation, as POSIX only specifies function. On my system (Debian sid), gawk isn't installed and mawk (Debian priority "required", i.e. installed by default) provides /usr/bin/awk instead. mawk appears to not support the abbreviated func keyword. When viewing a text/calendar part, I only see the following: awk: /usr/libexec/aerc/filters/calendar: line 211: return outside function body Using the standardized function keyword allows mawk to parse the prepare function (including its return) and execute the script as intended. [1]: https://www.gnu.org/software/gawk/manual/html_node/Definition-Syntax.html (section 9.2.1 "Function Definition Syntax") Fixes: 0db924dc14a3 ("filters: fix calendar filter parsing") Changelog-fixed: Builtin `calendar` filter error with non-GNU Awk. Signed-off-by: Timon Reinold <tirei+aerc@agon.one> Acked-by: Robin Jarry <robin@jarry.cc>
* wrap: fix cjk prose ratio on macosRobin Jarry2024-06-251-15/+46
| | | | | | | | | | | | | | | Depending on the locale and the libc implementation, iswalpha() may return true or false for CJK symbols. Reuse the same logic as in the split point detection introduced in commit 99bc69918ea7 ("wrap: fix wide CJK characters support"). Include all missing Korean and Japanese specific Unicode blocks. Handle syllabic symbols with a parameter to avoid wrapping in the middle of syllables. Signed-off-by: Robin Jarry <robin@jarry.cc> Tested-by: Gregory Anders <greg@gpanders.com>
* wrap: fix wide CJK characters supportRobin Jarry2024-06-163-5/+139
| | | | | | | | | | | | | | | | | | | | Neither Chinese, Japanese nor Korean use spaces as words separators. It is OK to hard wrap before any symbol (except CJK punctuation which should probably stay attached to its previous symbol and not be left alone at the start of a line). I did not include Japanese Hiragana and Katakana symbols as word breaks on purpose since these are phonetic alphabets. It didn't make sense to wrap a line in the middle of a "word" made of these phonetic symbols. Update the code to allow considering either a space or a CJK known symbol as a split point for hard wrapping. Add test case with Chinese, Japanese and Korean generated lorem ipsum style text. Signed-off-by: Robin Jarry <robin@jarry.cc> Tested-by: Runxi Yu <me@runxiyu.org>
* wrap: include xlocale.h header on macOSGregory Anders2024-05-291-0/+4
| | | | | | | | | | | | Compiling the wrap filter fails on macOS because the locale.h header does not include declarations for locale_t, freelocale, or newlocale. Instead, these are included in the xlocale.h header. We use a conditional include because glibc no longer ships the xlocale.h header in its distribution. Signed-off-by: Gregory Anders <greg@gpanders.com> Acked-by: Robin Jarry <robin@jarry.cc>
* wrap: use nl_langinfo to get locale codesetMatěj Cepl2024-05-281-2/+6
| | | | | | | | | | | | Using more and more complicated constructs comparing locale strings doesn't lead to anywhere. Even with the current two steps long comparison the program is wrong on systems which use "utf8" in their locale names (e.g., my openSUSE/Tumbleweed). It is better to use proper locale functions to get canonical name of the current codeset. Link: https://lists.sr.ht/~rjarry/aerc-devel/%3CD1L7746XIJ3Z.3SN11SOVO175Q@cepl.eu%3E Signed-off-by: Matěj Cepl <mcepl@cepl.eu> Acked-by: Robin Jarry <robin@jarry.cc>
* contrib: improve readability of meeting requestsBence Ferdinandy2024-04-131-10/+23
| | | | | | | | | | | | | | | | | | | | Meeting requests may contain dozens of participants, making the attendee list potentially very long, hiding one of the most important piece of information in the request, namely the time of the meeting. Also the RSVP statuses of participants usually does not carry any information, since when the meeting is created all participants RSVP status will be the same (needs-action). The current layout uses three rows for a single participant, making it hard to glance over quickly. Move the start and end time of the meeting up into a more prominent place and leave the variable length attendee list last. Add a quick overview list of attendees before listing the participations status. Changelog-changed: Improved readability of the builtin `calendar` filter. Signed-off-by: Bence Ferdinandy <bence@ferdinandy.com> Tested-by: "Matěj Cepl" <mcepl@cepl.eu> Tested-by: inwit <inwit@sindominio.net> Acked-by: Robin Jarry <robin@jarry.cc>
* colorize: preserve defaults unless overriddenRobin Jarry2024-02-142-3/+2
| | | | | | | | | | | | | | | To be consistent with stylesets for the rest of aerc's UI, settings in the [viewer] section now only override the default colorize theme. Implements: https://todo.sr.ht/~rjarry/aerc/222 Changelog-changed: The `[viewer]` section of stylesets now preserve default values as documented in `aerc-stylesets(7)` unless explicitly overridden. Requested-by: Karel Balej <balejk@matfyz.cz> Signed-off-by: Robin Jarry <robin@jarry.cc> Tested-by: Karel Balej <balejk@matfyz.cz> Tested-by: Matěj Cepl <mcepl@cepl.eu> Tested-by: Nicolas Dichtel <nicolas.dichtel@6wind.com>
* colorize: adapt default style for light backgroundsRobin Jarry2024-02-141-13/+13
| | | | | | | | | | | | | | | | | | | | | The current default theme is unusable on light backgrounds. Some colors are too light and are almost invisible. Use only palette colors to ensure that everything is customizable by the user. I tested this with white on black, grey on dark purple, black on yellow, black on white. Text remains readable everywhere. Update stylesets that don't use these new defaults to explicitly override them. Changelog-changed: The default `colorize` theme has been changed to use the base terminal colors. Cc: Jason Cox <me@jasoncarloscox.com> Reported-by: Matěj Cepl <mcepl@cepl.eu> Signed-off-by: Robin Jarry <robin@jarry.cc> Tested-by: Nicolas Dichtel <nicolas.dichtel@6wind.com>
* colorize: add small description in helpRobin Jarry2024-01-061-0/+2
| | | | | | For some reason there was none. Be consistent with wrap. Signed-off-by: Robin Jarry <robin@jarry.cc>
* lint,validate: fix for openbsdRobin Jarry2023-12-142-7/+8
| | | | | | | | | | | | | | - Remove GNU specific stuff (ln -v, mktemp --tempdir, grep --color) - Remove GCC specific flags in sendemail-validate (-Warith-conversion) - Add -std=c99 and -Wpedantic and fix the reported warnings. - Explicitly call gmake everywhere. - Run our custom analyzer standalone. Golangci lint plugins are not supported on OpenBSD. Indirect dependency to golang.org/x/mod is required somehow... Reported-by: Johannes Thyssen Tishman <johannes@thyssentishman.com> Signed-off-by: Robin Jarry <robin@jarry.cc> Tested-by: Johannes Thyssen Tishman <johannes@thyssentishman.com>
* colorize: only colorize real usenet signaturesRobin Jarry2023-12-041-3/+2
| | | | | | | | Only consider the start of a signature if a line is exactly "-- " with a trailing space character. Signed-off-by: Robin Jarry <robin@jarry.cc> Tested-by: Johannes Thyssen Tishman <johannes@thyssentishman.com>
* colorize: better detect diffsRobin Jarry2023-12-045-18/+217
| | | | | | | | | | | | Be more tolerant with diffs that were produced by other version control systems than git. OpenBSD for instance, uses CVS. Add more test cases from the OpenBSD mailing lists. Link: https://marc.info/?l=openbsd-ports&m=169989204001628&w=2 Link: https://marc.info/?l=openbsd-ports&m=169987607521242&w=2 Reported-by: Johannes Thyssen Tishman <johannes@thyssentishman.com> Signed-off-by: Robin Jarry <robin@jarry.cc> Tested-by: Johannes Thyssen Tishman <johannes@thyssentishman.com>
* colorize: accept wildcards in stylesJason Cox2023-10-132-36/+36
| | | | | | | | | Allow using * and ? to match multiple style objects for colorize, as stated in the man page and consistent with aerc's main styles. Fixes: a5c4f5d (colorize: handle spaces in styleset) Signed-off-by: Jason Cox <me@jasoncarloscox.com> Acked-by: Robin Jarry <robin@jarry.cc>
* colorize: support trailing comments after valuesRobin Jarry2023-09-194-16/+16
| | | | | | | | Strip trailing comments after attribute values in stylesets. Update the test styleset to check it works. Signed-off-by: Robin Jarry <robin@jarry.cc> Tested-by: Inwit <inwit@sindominio.net>
* colorize: handle spaces in stylesetRobin Jarry2023-09-044-77/+105
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | Avoid failure when the styleset [viewer] section contains spaces: ~$ cat foo [viewer] url.fg = #ffffaf url.underline = true header.fg = #af87ff signature.fg = #af87ff diff_meta.fg = #ffffff diff_meta.bold = true diff_chunk.fg = #00cdcd diff_add.fg = #00cd00 diff_del.fg = #cd0000 quote_1.fg = #5fafff quote_2.fg = #ff8700 quote_3.fg = #af87ff quote_4.fg = #ff5fd7 quote_x.fg = #808080 ~$ ./colorize -s foo < bar.eml error: invalid style attribute 'fg ' Be more restrictive with what characters are part of a style attribute. Add test styleset with as much weirdness as possible. Update vectors accordingly. Update sendemail-validate hook to export pedantic CFLAGS. Reported-by: Tristan Partin <tristan@partin.io> Signed-off-by: Robin Jarry <robin@jarry.cc> Reviewed-by: Tristan Partin <tristan@partin.io> Tested-by: Tristan Partin <tristan@partin.io>
* colorize: only emit osc8 if [general].enable-osc8=trueRobin Jarry2023-08-242-5/+18
| | | | | | | | | | | | | | | | Some old versions of less do not handle OSC 8 escape sequences. Even if aerc's embedded terminal is configured to handle them, less corrupts them making the output unreadable. 8;id=colorize-1;https://foobar.com/stuff/https://foobar.com/stuff/ When [general].enable-osc8 is set to false (its default value) do not attempt to generate OSC 8 sequences with the built-in colorize filter. These sequences would be stripped out anyway. Reported-by: Omar Polo <op@omarpolo.com> Signed-off-by: Robin Jarry <robin@jarry.cc> Acked-by: Kirill Chibisov <contact@kchibisov.com>
* colorize: style chunk function nameJason Cox2023-05-162-2/+7
| | | | | | | | | It's nice to use a different style for the chunk's function name to make it clear that the name is not necessarily adjacent to the chunk's actual lines. Signed-off-by: Jason Cox <me@jasoncarloscox.com> Acked-by: Robin Jarry <robin@jarry.cc>
* filters: fix option parsing on arm cpusRobin Jarry2023-05-112-36/+39
| | | | | | | | | | | | | | | | | | | | | | | | | | | When running colorize or wrap on ARM, both programs exit immediately displaying their help message whatever the provided arguments. This is caused by an implicit downcast of the getopt return value. On most architectures, char is signed by default. On ARM, char is unsigned for performance reasons. Since the signed int return value of getopt is forced into a char, the results differ on ARM compared to x86. * Add -Wconversion -Warith-conversion to CFLAGS in CI builds to ensure catching such issues in the future. * Fix all -Wconversion -Warith-conversion reported issues. * Wide char functions need to deal with wint_t and wchar_t and it is guaranteed that a wchar_t can always fit into a wint_t. Add explicit casts to silence the reported warnings. Link: https://www.arm.linux.org.uk/docs/faqs/signedchar.php Link: https://lwn.net/Articles/911914/ Fixes: https://todo.sr.ht/~rjarry/aerc/164 Reported-by: Bence Ferdinandy <bence@ferdinandy.com> Suggested-by: Allen Sobot <chilledfrogs@disroot.org> Signed-off-by: Robin Jarry <robin@jarry.cc> Tested-by: Bence Ferdinandy <bence@ferdinandy.com>
* colorize: support email domains that start/end with digitsRobin Jarry2023-04-221-1/+1
| | | | | | | | | | | | According to RFC 1123: "... a host domain name is now allowed to begin with a digit and could legally be entirely numeric ..." Link: https://datatracker.ietf.org/doc/html/rfc1123#section-2 Cc: Nicolas Dichtel <nicolas.dichtel@6wind.com> Signed-off-by: Robin Jarry <robin@jarry.cc> Reviewed-by: Bence Ferdinandy <bence@ferdinandy.com>
* colorize: don't print an id in osc8 terminatorTim Culverhouse2023-04-153-9/+13
| | | | | | | | | | | Printing an ID in the OSC8 terminator can cause issues in some pagers and/or terminals. The "spec" doesn't allow for an ID in the terminator, but most applications and terminals will ignore it if it's there. Prevent printing it in the first place for better compatibility. Signed-off-by: Tim Culverhouse <tim@timculverhouse.com> Signed-off-by: Robin Jarry <robin@jarry.cc> Acked-by: Robin Jarry <robin@jarry.cc>
* wrap: do not strip signature delimiter trailing spaceRobin Jarry2023-04-103-5/+13
| | | | | | | | | | Some tools expect this trailing space to be present to detect email signatures start. Reported-by: Jd <john1doe@ya.ru> Fixes: https://todo.sr.ht/~rjarry/aerc/131 Signed-off-by: Robin Jarry <robin@jarry.cc> Tested-by: Jd <john1doe@ya.ru>
* colorize: make url parsing more robustRobin Jarry2023-04-023-25/+84
| | | | | | | | | | | | | | | | | | Reuse the URL parsing algorithm from foot. Basically, it involves recording the opening [, (, < and take into account their closing counterparts. If a closing character is encountered with no matching opening one, assume the URL ends. This allows handling markdown link syntax such as: [http://foobaz.org/xxx](http://foobaz.org/xxx) Avoid coloring bare URL protocols such as http:// or https:// Update test vector to handle more corner cases. Link: https://codeberg.org/dnkl/foot/src/tag/1.13.1/url-mode.c#L331-L471 Signed-off-by: Robin Jarry <robin@jarry.cc> Tested-by: Kirill Chibisov <contact@kchibisov.com>
* colorize: emit OSC 8 for URLs and emailsKirill Chibisov2023-03-263-7/+27
| | | | | | | | | | Mark URLs with OSC 8 escape sequence to help terminal emulators with opening multi-line URLs with the mouse and attach the hyperlink to email addresses, so the users could open them. Link: https://gist.github.com/egmontkob/eb114294efbcd5adb1944c9f3cb5feda Signed-off-by: Kirill Chibisov <contact@kchibisov.com> Acked-by: Robin Jarry <robin@jarry.cc>
* colorize: use bool for boolean variablesRobin Jarry2023-03-261-27/+28
| | | | | | Do not use int for true/false values. Signed-off-by: Robin Jarry <robin@jarry.cc>
* colorize: stop parsing theme when other section startsRobin Jarry2023-03-021-1/+6
| | | | | | | | In order to allow multiple sections in a styleset, colorize must stop parsing the theme when it encounters a new section. Signed-off-by: Robin Jarry <robin@jarry.cc> Tested-by: Tim Culverhouse <tim@timculverhouse.com>
* colorize: restore previous default themeRobin Jarry2023-02-023-81/+81
| | | | | | | | | | | Restore the default theme from the previous colorize awk script. It is more colorful and may be more appealing to new users out of the box. Since colorize is now configurable via stylesets, power users can do whatever they like. Requested-by: Andrea Pappacoda <andrea@pappacoda.it> Signed-off-by: Robin Jarry <robin@jarry.cc> Agreed-by: Bence Ferdinandy <bence@ferdinandy.com>
* wrap: be more robust with localeRobin Jarry2023-01-281-7/+36
| | | | | | | | | | | | | | | | | | | | | | | On (some?) MacOS systems there is no C.UTF-8 locale available. Instead there is a non-standard "UTF-8" (encoding only) replacement. Running wrap on MacOS results in an error: error: failed to set locale: Bad file descriptor Instead of expecting that C.UTF-8 will always be available, try to use the user set locale (either from the $LC_ALL or $LANG environment variables). If these variables are unset or if they are set to an invalid/non-existent locale, fallback on C.UTF-8. If C.UTF-8 is not available, make one last desperate attempt for this UTF-8 non-standard locale (MacOS only). aerc will always send UTF-8 encoded text to the filter commands, If the locale that we managed to load does not use the UTF-8 character encoding, exit with an explicit error instead of risking undefined behaviour. Reported-by: Ben Cohen <ben@bencohen.net> Signed-off-by: Robin Jarry <robin@jarry.cc>
* filters: make colorize URL regex more strictAndrea Pappacoda2023-01-281-4/+4
| | | | | | | | | | | | | | | | | | | | | | | The previous URL regex was too lax, allowing all "[:graph:]" characters after the protocol:// part. This caused the script to mark as part of an URL also things like ">", which is commonly used as a URL delimiter in plain text and Markdown; the url() function tried to account for this with some heuristic to remove trailing characters, but it didn't always work (see the screenshots below). As RFC 3986 specifies the list of allowed characters in URLs, we can simply make our regex stricter and only mark characters as part of an URL if they match the allowed set. As the number of allowed characters has been reduced, the aforementioned heuristic has been slightly simplified. I've also removed the backslash escapes from the bracket expressions, as POSIX regular expressions do not require them; the only characters that need special handling are ']' and '-', which need to be placed at the start and at the end of the expression, respectively. Signed-off-by: Andrea Pappacoda <andrea@pappacoda.it> Acked-by: Robin Jarry <robin@jarry.cc>
* filters: rewrite colorize in cRobin Jarry2023-01-266-177/+909
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | Since its introduction, we had multiple issues with the colorize awk script with regard to non-GNU awk compatibility. Also, this script is standalone and the color theme must be hard coded into it. Reading from an external configuration file (aerc's styleset) from a non-GNU awk is close to impossible (and even far from trivial with GNU awk). Rewrite the builtin colorize filter in C to allow getting the color theme from aerc's active styleset. The theme is configured using the existing styleset syntax and attributes under a separate [viewer] section (see examples and man page). Export the active styleset file path to AERC_STYLESET env var when invoking the filter command so that colorize can access it and use it. I have tested compilation (with clang-analyzer and gcc -fanalyzer) and basic operation on FreeBSD, Fedora (glibc) and Alpine (muslibc). More tests would probably be required on MacOSX and older Linux distros. I also added test vectors to give some confidence that this works as expected. The execution with these vectors passed valgrind --leak-check=full without errors. NB: the default theme has changed to be more minimal. Sample stylesets have more colorful examples. The awk -v theme=xxx option is no longer supported. usage: colorize [-h] [-s FILE] [-f FILE] options: -h show this help message -s FILE use styleset file (default $AERC_STYLESET) -f FILE read from filename (default stdin) Signed-off-by: Robin Jarry <robin@jarry.cc> Tested-by: Bence Ferdinandy <bence@ferdinandy.com> Acked-by: Moritz Poldrack <moritz@poldrack.dev>
* filters: rewrite wrap in cRobin Jarry2023-01-2616-479/+1432
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | This utility introduced in commit c9524d265793 ("filters: add wrap utility written in go") allows to reflow text to view emails that have very long lines without breaking quotes, lists and indentation. For such a simple task, go produces a binary that is 2.0M bytes on disk. After stripping debugging symbols, it can be reduced to 1.2M bytes. All of this for 267 lines of source code. This is a bit ridiculous, provided people may load this binary into memory multiple times per minute. This tool is a small side-project that seems not suitable for golang. Rewrite it in C. It now only depends on a POSIX libc to run. It is safe to assume that there is one available on all *NIX systems in the world of 2023. The resulting binary is now 27K bytes (15K after stripping). To build it, a C compiler and libc headers are required. These should most likely be available since they are dependencies of the go compiler toolchain. I have tested compilation (with clang-analyzer and gcc -fanalyzer) and basic operation on FreeBSD, Fedora (glibc) and Alpine (musl libc). More tests would probably be required on MacOSX and older Linux distros. I also added test vectors to give some confidence that this works as expected. Update CI with aggressive gcc hardening flags and to run these tests with valgrind --leak-check=full. Command line options are unchanged: usage: wrap [-h] [-w INT] [-r] [-l INT] [-f FILE] Wrap text without messing up email quotes. options: -h show this help message -w INT preferred wrap margin (default 80) -r reflow all paragraphs even if no trailing space -l INT minimum percentage of letters in a line to be considered a paragaph -f FILE read from filename (default stdin) Signed-off-by: Robin Jarry <robin@jarry.cc> Tested-by: Bence Ferdinandy <bence@ferdinandy.com> Tested-by: Maxwell G <gotmax@e.email>
* colorize: add 'terminal' theme which respects termcolorsTim Culverhouse2022-12-211-0/+16
| | | | | | | | | | | | Add a "terminal" theme to colorize script. The "terminal" theme respects the users' configured terminal color scheme. Also links are blue underlined. Usage: colorize -v theme=terminal Signed-off-by: Tim Culverhouse <tim@timculverhouse.com> Acked-by: Robin Jarry <robin@jarry.cc>
* wrap: handle letters as list itemsRobin Jarry2022-12-141-1/+1
| | | | | | | | | | | In addition of digits, handle lower case letters as list items: a) foo b) baz c) bar Signed-off-by: Robin Jarry <robin@jarry.cc> Tested-by: Bence Ferdinandy <bence@ferdinandy.com>
* filters: add wrap utility written in goRobin Jarry2022-12-052-0/+479
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | I had started writing this as an awk script but quickly got stuck with obscure code which did not even work properly. I jumped the gun and re did it in go. Bonus, we will not have MacOS's 1987 BSD awk issues. On the other hand, instead of a 20.0K awk script, we now have a 2.2M static go binary. If this makes people scream, I challenge them to do that with BSD awk :) Basically, this takes text from stdin or from a file and wraps long lines on word boundaries. It takes care of not breaking up email quotes nor list items (numbered as well). Also, it is conservative by default and only wraps long lines and lines that end with a space (indicating a format=flowed message). If the AERC_SUBJECT environment variable is defined and contains the word PATCH, the text is not modified at all (i.e. wrap behaves as cat(1)). There are a few command line options to control behavior: Usage of ./wrap: -f string read from file instead of stdin -l int minimum percentage of letters in a line to be considered a paragaph (default 50) -r reflow all paragraphs even if no trailing space -w int preferred wrap margin (default 80) Update docs, makefile and default config file with examples. Add a torture test to ensure it works as expected. Signed-off-by: Robin Jarry <robin@jarry.cc> Tested-by: Bence Ferdinandy <bence@ferdinandy.com>
* colorize: add solarized themeJens Grassel2022-11-301-15/+42
| | | | | | | | | | | | | | | This modifies the colorize script to accept a command line parameter to change the colour theme. Currently only a solarized version is added. Due to the nature of awk the theme has to be defined via the `-v` flag. Due to the `switch` statement only being available in GNU awk we use a `if else` statement to ensure that the default colours are used if either the `THEME` variable is not set at all or set to `default`. Solarized colour scheme: https://ethanschoonover.com/solarized/ Signed-off-by: Jens Grassel <jens@wegtam.com> Signed-off-by: Robin Jarry <robin@jarry.cc>
* colorize: make it compatible with BSD awkRobin Jarry2022-10-231-6/+6
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | Fix the following error seen on MacOS: /usr/bin/awk: syntax error at source line 22 source file header_pattern = >>> @ <<< /^[A-Z][[:alnum:]-]+:/ The @ character in front of regular expressions to pre-compile them seems not in the POSIX specification. Replace them with regular strings and call match() instead of the ~ operator. Also, adjust the url_pattern expression for BSD awk which explicitly states: The awk utility is compliant with the IEEE Std 1003.1-2008 (“POSIX.1”) specification, except awk does not support {n,m} pattern matching. Use [[:lower:]]+ instead of [a-z]{2,6}. Tested with: GNU Awk 5.1.1 awk version 20121220 (FreeBSD) Link: https://pubs.opengroup.org/onlinepubs/9699919799/utilities/awk.html Fixes: https://todo.sr.ht/~rjarry/aerc/96 Signed-off-by: Robin Jarry <robin@jarry.cc> Acked-by: Koni Marti <koni.marti@gmail.com>
* filters/colorize: various fixesRobin Jarry2022-10-201-27/+19
| | | | | | | | | | | | | | | | Diff chunks can occur in the middle of email conversations followed by regular and/or quoted text. Handle that properly. Change diff meta lines inside quotes to bold. Update the meta lines with more combination for renamed, copied and deleted files. Fix the diff_chunk invalid color code, only colorize the chunk characters, not the whole line. Remove redundant variable resets to 0. Signed-off-by: Robin Jarry <robin@jarry.cc> Acked-on-irc-by: Tim Culverhouse <tim@timculverhouse.com>
* filters: fix calendar filter parsingKoni Marti2022-08-221-5/+16
| | | | | | | | | | Fix parsing of colons. Since the field separator is also the colon, it could mess up the parsed fields, i.e. a subject line like "WG: dinner" could end up as "WG" instead of keeping the entire string. Fixes: ab941eb ("filters: posix compliant rewrite of calendar filter") Signed-off-by: Koni Marti <koni.marti@gmail.com> Acked-by: Robin Jarry <robin@jarry.cc>
* filters: make it explicit that encoding is UTF-8q3cpma2022-08-032-0/+2
| | | | | | | | | | Document filter input charset Add w3m filter example to default config Adapt html and html-unsafe filters Fixes: https://todo.sr.ht/~rjarry/aerc/65 Signed-off-by: q3cpma <q3cpma@posteo.net> Acked-by: Robin Jarry <robin@jarry.cc>
* filters: posix compliant rewrite of calendar filterKoni Marti2022-07-241-178/+109
| | | | | | | | | | | | Rewrite of the awk calendar filter to make it posix compliant. Tested with awk --posix (awk -V = GNU Awk 5.1.1). Also added some improvements to readability and formatting. This complements commit 3ef4a3ca051a ("filters: try and make awk scripts posix compliant"). Signed-off-by: Koni Marti <koni.marti@gmail.com> Acked-by: Robin Jarry <robin@jarry.cc>
* filters: try and make awk scripts posix compliantRobin Jarry2022-07-182-16/+16
| | | | | | | | | | \x escape sequences are GNU specific. Use the octal escape code instead. filters/calendar is beyond help. It would need a complete rewrite to make it work with POSIX awk. Signed-off-by: Robin Jarry <robin@jarry.cc> Acked-by: Moritz Poldrack <moritz@poldrack.dev>
* filters/colorize: use /usr/bin/awk shebangRobin Jarry2022-07-111-1/+1
| | | | | | | | /bin is reserved for essential commands that may be used when in single user mode. Link: https://refspecs.linuxfoundation.org/FHS_3.0/fhs-3.0.html#binEssentialUserCommandBinaries Signed-off-by: Robin Jarry <robin@jarry.cc>
* filters: Add missing shebangsTom Schwindl2022-07-112-2/+4
| | | | | | | | | The hldiff and plaintext filter scripts are missing their shebangs. Add those to be correct and consistent. Additionally, remove the vim comment, it's unnecessary. Signed-off-by: Tom Schwindl <schwindl@posteo.de> Acked-by: Moritz Poldrack <moritz@poldrack.dev>
* filters: awk filter to parse text/calendarKoni Marti2022-05-311-0/+328
| | | | | | | | | Implement a filter to read text/calendar (ics) data with awk. Parses multiple events and shows the date recurrence if available. Awk alternative to the python filter. Signed-off-by: Koni Marti <koni.marti@gmail.com> Acked-by: Robin Jarry <robin@jarry.cc>
* Add html "unsafe" filter to work also without danteJens Grassel2022-04-171-0/+16
| | | | | | | | If socksify (from dante) is not installed then the filter uses w3m without it to render an html message part. Signed-off-by: Jens Grassel <jens@wegtam.com> Acked-by: Robin Jarry <robin@jarry.cc>
* show-ics-details.py: fix error with python < 3.9Jens Grassel2022-03-241-16/+16
| | | | | | | | Change the pattern matching into a if/elif construct because pattern matching is not supported on python < 3.9. Signed-off-by: Jens Grassel <jens@wegtam.com> Acked-by: Robin Jarry <robin@jarry.cc>