aboutsummaryrefslogtreecommitdiffstats
path: root/lib/templates/functions.go
Commit message (Collapse)AuthorAgeFilesLines
* templates: process reversed names betterVitaly Ovchinnikov2023-06-291-3/+12
| | | | | | | | | | | | | | | | | | | Change the behavior of `names`, `firstnames` and `initials` functions in templates so they better process names formatted like this: "Last Name, First Name" Basically, if the name contains one (and only one) comma, its parts are flipped so the first name always goes first. This helps to do "Hello Name" in templates regardless of the name format in email address. Also if the template uses a full name it will make it "Hello FirstName LastName" instead of "Hello LastName, FirstName". Add tests to cover more complex names in the future. Signed-off-by: Vitaly Ovchinnikov <v@postbox.nz> Acked-by: Robin Jarry <robin@jarry.cc>
* templates: add map functionsRobin Jarry2023-06-101-0/+30
| | | | | | | | | Similar to switch and .StyleSwitch, add map and .StyleMap to work on lists. An extra "exclude" item is available to filter elements out of the list. Signed-off-by: Robin Jarry <robin@jarry.cc> Tested-by: Inwit <inwit@sindominio.net>
* templates: add switch/case functionsRobin Jarry2023-03-081-0/+31
| | | | | | | This allows much shorter templates. Signed-off-by: Robin Jarry <robin@jarry.cc> Acked-by: Tim Culverhouse <tim@timculverhouse.com>
* templates: add match functionRobin Jarry2023-03-081-0/+2
| | | | | | | | | | | | | | 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>
* templates: add compactDir functionRobin Jarry2023-02-201-0/+5
| | | | | | | This will be used in the dirtree-format replacement by templates. Signed-off-by: Robin Jarry <robin@jarry.cc> Acked-by: Tim Culverhouse <tim@timculverhouse.com>
* templates: add now functionRobin Jarry2023-02-201-0/+1
| | | | | | | This allows to get the current local time. Signed-off-by: Robin Jarry <robin@jarry.cc> Acked-by: Moritz Poldrack <moritz@poldrack.dev>
* templates: add firstnames and shortmboxes functionsRobin Jarry2023-02-201-1/+31
| | | | | | | These can be handy for tab-title-composer. Signed-off-by: Robin Jarry <robin@jarry.cc> Reviewed-by: Moritz Poldrack <moritz@poldrack.dev>
* templates: fix mboxes functionRobin Jarry2023-02-201-1/+1
| | | | | | | | | | mboxes currently returns the same value that emails. The SplitN API is misleading, to actually split something, the N value must be greater than 1... Fixes: d758441fe0c4 ("templates: add more fields and functions") Signed-off-by: Robin Jarry <robin@jarry.cc> Acked-by: Moritz Poldrack <moritz@poldrack.dev>
* templates: unify data interfaceRobin Jarry2023-02-201-4/+9
| | | | | | | | | | | | | | | | | | | | | | | Require that all aerc template data objects implement the same TemplateData interface. Implement that interface in two different places: 1) state.TemplateData (renamed/moved from templates.TemplateData). This structure (along with all its methods) needs to be decoupled from the templates package to break the import cycle with the config package. This allows much simpler construction of this object and ensure that values are calculated only when requested. 2) config.dummyData (extracted from templates). This is only used in the config package to validate user templates. Putting it here allows also to break an import cycle. Use state.TemplateData everywhere (including for account tabs title rendering). Signed-off-by: Robin Jarry <robin@jarry.cc> Reviewed-by: Moritz Poldrack <moritz@poldrack.dev>
* templates: add initials functionBence Ferdinandy2023-02-121-0/+15
| | | | | | | | | | When listing all addresses with names, in for example the To field, one might end up with a very long string. Add the initials function, which extracts the names from addresses and then shortens each of them to the initials of the name. Signed-off-by: Bence Ferdinandy <bence@ferdinandy.com> Acked-by: Robin Jarry <robin@jarry.cc>
* templates: add trimSignature functionMoritz Poldrack2023-01-291-0/+19
| | | | | | | | | | | Some contacts, especially corporate, include a wall of text in their signatures. To not clutter the reply chain, this commit introduces a new function to the templating engine that removes the signature from a message. Link: https://learn.microsoft.com/en-us/microsoft-365/admin/setup/create-signatures-and-disclaimers Signed-off-by: Moritz Poldrack <git@moritz.sh> Acked-by: Robin Jarry <robin@jarry.cc>
* templates: add more fields and functionsRobin Jarry2023-01-041-7/+93
| | | | | | | | | | | Add functions and fields in preparation for more than only message templates. The idea is to reuse the same symbols for the message list format and other parts of the UI. Update the man page accordingly. Signed-off-by: Robin Jarry <robin@jarry.cc> Acked-by: Tim Culverhouse <tim@timculverhouse.com>
* templates: split code in multiple filesRobin Jarry2023-01-041-0/+113
This makes room in preparation for more code in here. Signed-off-by: Robin Jarry <robin@jarry.cc> Acked-by: Tim Culverhouse <tim@timculverhouse.com>