Skip to content

Commit

Permalink
feat: support Lua 5.4 for configuration files
Browse files Browse the repository at this point in the history
This commit enables the use of Lua (version 5.4) for configuration
files, providing greater flexibility and customization options for
users.
  • Loading branch information
michaeladler committed Oct 2, 2024
1 parent fe73b11 commit 0edae3e
Show file tree
Hide file tree
Showing 13 changed files with 325 additions and 99 deletions.
4 changes: 4 additions & 0 deletions .ci/install-deps.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
#!/bin/sh
set -eux
apt-get update -q
apt-get install -y libnotmuch-dev liblua5.4-dev
6 changes: 4 additions & 2 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ jobs:
fetch-depth: 0 # needed to embed version information
- uses: actions-rust-lang/setup-rust-toolchain@v1
- name: Install deps
run: sudo apt-get update -q && sudo apt-get install -y libnotmuch-dev
run: sudo .ci/install-deps.sh
- run: cargo build --release
- run: cargo test --all-features
- uses: actions/upload-artifact@v4
Expand Down Expand Up @@ -38,6 +38,8 @@ jobs:
- uses: actions-rust-lang/setup-rust-toolchain@v1
with:
components: clippy
- name: Install deps
run: sudo .ci/install-deps.sh
- run: cargo clippy

coverage:
Expand All @@ -50,7 +52,7 @@ jobs:
- name: Install cargo-llvm-cov
uses: taiki-e/install-action@cargo-llvm-cov
- name: Install deps
run: sudo apt-get update -q && sudo apt-get install -y libnotmuch-dev
run: sudo .ci/install-deps.sh
- name: Generate code coverage
run: cargo llvm-cov --all-features --workspace --lcov --output-path lcov.info
- name: Upload coverage to Codecov
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ jobs:
- uses: actions-rust-lang/setup-rust-toolchain@v1

- name: Install build deps
run: sudo apt-get update -q && sudo apt-get install -y libnotmuch-dev
run: sudo .ci/install-deps.sh

- name: Run GoReleaser
uses: goreleaser/goreleaser-action@v6
Expand Down
21 changes: 16 additions & 5 deletions .goreleaser.yml
Original file line number Diff line number Diff line change
Expand Up @@ -41,8 +41,19 @@ nfpms:
maintainer: Michael Adler <[email protected]>
homepage: https://github.com/michaeladler/notmuch-mailmover
description: move notmuch tagged mails into Maildir folders
dependencies:
- notmuch
overrides:
deb:
dependencies:
- libnotmuch5
- liblua5.4-0
rpm:
dependencies:
- lua
- notmuch
archlinux:
dependencies:
- notmuch-runtime
- lua
section: mail
priority: extra
contents:
Expand All @@ -67,9 +78,9 @@ nfpms:
- src: share/notmuch-mailmover.1.gz
dst: /usr/share/man/man1/notmuch-mailmover.1.gz

# example config
- src: example/config.yaml
dst: /usr/share/doc/notmuch-mailmover/config.yaml
# example configurations
- src: example/
dst: /usr/share/doc/notmuch-mailmover/

checksum:
name_template: 'checksums.txt'
Expand Down
130 changes: 130 additions & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ shellexpand = "3.0.0"
clap = { version = "4.5.18", features = [ "derive", "cargo" ] }
git-version = "0.3.9"
konst = "0.3"
mlua = { version = "0.9.9", features = ["lua54", "serialize"] }

[build-dependencies]
clap = { version = "4.5.18", features = [ "derive", "cargo" ] }
Expand Down
5 changes: 4 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -37,10 +37,11 @@ $ nix-env -iA notmuch-mailmover

### Building from Source

Otherwise, you have to build from source. You need the following build dependencies:
Otherwise, you have to build from source. You need the following build dependencies (see [install-deps.sh](.ci/install-deps.sh)):

- Rust
- libnotmuch-dev
- liblua5.4-dev

Then run

Expand All @@ -57,6 +58,8 @@ You can also invoke `notmuch-mailmover` directly, but don't forget to run `notmu

Running `notmuch-mailmover` for the first time will create `$XDG_CONFIG_HOME/notmuch-mailmover/config.yaml`.
Then edit the file as you like, see below for an example.
Alternatively, it's possible to write the configuration in Lua 5.4 by creating `config.lua` instead.
See the provided [config.lua](example/config.lua) for an example.

The configuration is largely self-explanatory, except perhaps for the choice of the `rule_match_mode`.
You need to decide whether you want your rules to be pairwise distinct (meaning the queries must not overlap) or ambiguous (where the first or last matching rule wins).
Expand Down
54 changes: 54 additions & 0 deletions example/config.lua
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
-- anything goes here, as long as it returns a table (which can be parsed into the corresponding `config::Config` struct)

--- @enum config.match_mode
--- Match modes for rules.
local match_modes = {
ALL = "all",
FIRST = "first",
UNIQUE = "unique",
}

--- Configuration for notmuch-mailmover.
--
--- @class config
--- @field maildir string Path to the maildir
--- @field notmuch_config string Path to the notmuch configuration
--- @field rename boolean Rename the files when moving
--- @field max_age_days number Maximum age (days) of the messages to be procssed
--- @field rule_match_mode config.match_mode Match mode for rules
--- @field rules rule[] List of rules
---
--- @class rule
--- @field folder string Folder to move the messages to
--- @field query string Notmuch query to match the messages
local config = {
maildir = os.getenv("HOME") .. "/mail",
notmuch_config = "~/.config/notmuch/notmuchrc",
rename = false,
max_age_days = 60,
rule_match_mode = match_modes.FIRST,
rules = {
{
folder = "Trash",
query = "tag:trash",
},
{
folder = "Spam",
query = "tag:spam",
},
{
folder = "Sent",
query = "tag:sent",
},
{
folder = "Archive",
query = "tag:archive",
},
{
folder = "INBOX",
query = "tag:inbox",
},
},
}

return config
Loading

0 comments on commit 0edae3e

Please sign in to comment.