diff --git a/Cargo.lock b/Cargo.lock index 871f4b7..f72f998 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -211,7 +211,7 @@ dependencies = [ "futures-lite 2.3.0", "parking", "polling 3.7.3", - "rustix 0.38.36", + "rustix 0.38.37", "slab", "tracing", "windows-sys 0.59.0", @@ -250,7 +250,7 @@ dependencies = [ "cfg-if", "event-listener 3.1.0", "futures-lite 1.13.0", - "rustix 0.38.36", + "rustix 0.38.37", "windows-sys 0.48.0", ] @@ -262,7 +262,7 @@ checksum = "3b43422f69d8ff38f95f1b2bb76517c91589a924d1559a0e935d7c8ce0274c11" dependencies = [ "proc-macro2", "quote", - "syn 2.0.77", + "syn 2.0.79", ] [[package]] @@ -277,7 +277,7 @@ dependencies = [ "cfg-if", "futures-core", "futures-io", - "rustix 0.38.36", + "rustix 0.38.37", "signal-hook-registry", "slab", "windows-sys 0.59.0", @@ -291,13 +291,13 @@ checksum = "8b75356056920673b02621b35afd0f7dda9306d03c79a30f5c56c44cf256e3de" [[package]] name = "async-trait" -version = "0.1.82" +version = "0.1.83" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a27b8a3a6e1a44fa4c8baf1f653e4172e81486d4941f2237e20dc2d0cf4ddff1" +checksum = "721cae7de5c34fbb2acd27e21e6d2cf7b886dce0c27388d46c4e6c47ea4318dd" dependencies = [ "proc-macro2", "quote", - "syn 2.0.77", + "syn 2.0.79", ] [[package]] @@ -308,9 +308,9 @@ checksum = "1505bd5d3d116872e7271a6d4e16d81d0c8570876c8de68093a09ac269d8aac0" [[package]] name = "autocfg" -version = "1.3.0" +version = "1.4.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "0c4b4d0bd25bd0b74681c0ad21497610ce1b7c91b1022cd21c80c6fbdd9476b0" +checksum = "ace50bade8e6234aa140d9a2f552bbee1db4d353f69b8217bc503490fc1a9f26" [[package]] name = "backtrace" @@ -433,7 +433,7 @@ checksum = "e0af050e27e5d57aa14975f97fe47a134c46a390f91819f23a625319a7111bfa" dependencies = [ "proc-macro2", "quote", - "syn 2.0.77", + "syn 2.0.79", ] [[package]] @@ -443,7 +443,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "40723b8fb387abc38f4f4a37c09073622e41dd12327033091ef8950659e6dc0c" dependencies = [ "memchr", - "regex-automata 0.4.7", + "regex-automata 0.4.8", "serde", ] @@ -476,9 +476,9 @@ checksum = "1fd0f2584146f6f2ef48085050886acf353beff7305ebd1ae69500e27c67f64b" [[package]] name = "bytes" -version = "1.7.1" +version = "1.7.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "8318a53db07bb3f8dca91a600466bdb3f2eaadeedfdbcf02e1accbad9271ba50" +checksum = "428d9aa8fbc0670b7b8d6030a7fadd0f86151cae55e4dbbece15f3780a3dfaf3" [[package]] name = "camellia" @@ -490,12 +490,6 @@ dependencies = [ "cipher", ] -[[package]] -name = "cassowary" -version = "0.3.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "df8670b8c7b9dae1793364eafadf7239c40d669904660c5960d74cfd80b46a53" - [[package]] name = "cast5" version = "0.11.1" @@ -505,15 +499,6 @@ dependencies = [ "cipher", ] -[[package]] -name = "castaway" -version = "0.2.3" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "0abae9be0aaf9ea96a3b1b8b1b55c602ca751eba1b1500220cea4ecbafe7c0d5" -dependencies = [ - "rustversion", -] - [[package]] name = "cbc" version = "0.1.2" @@ -525,9 +510,9 @@ dependencies = [ [[package]] name = "cc" -version = "1.1.18" +version = "1.1.22" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "b62ac837cdb5cb22e10a256099b4fc502b1dfe560cb282963a974d7abd80e476" +checksum = "9540e661f81799159abee814118cc139a2004b3a3aa3ea37724a1b66530b90e0" dependencies = [ "shlex", ] @@ -596,9 +581,9 @@ dependencies = [ [[package]] name = "clap" -version = "4.5.17" +version = "4.5.18" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "3e5a21b8495e732f1b3c364c9949b201ca7bae518c502c80256c96ad79eaf6ac" +checksum = "b0956a43b323ac1afaffc053ed5c4b7c1f1800bacd1683c353aabbb752515dd3" dependencies = [ "clap_builder", "clap_derive", @@ -606,26 +591,27 @@ dependencies = [ [[package]] name = "clap_builder" -version = "4.5.17" +version = "4.5.18" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "8cf2dd12af7a047ad9d6da2b6b249759a22a7abc0f474c1dae1777afa4b21a73" +checksum = "4d72166dd41634086d5803a47eb71ae740e61d84709c36f3c34110173db3961b" dependencies = [ "anstream", "anstyle", "clap_lex", "strsim 0.11.1", + "terminal_size", ] [[package]] name = "clap_derive" -version = "4.5.13" +version = "4.5.18" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "501d359d5f3dcaf6ecdeee48833ae73ec6e42723a1e52419c79abf9507eec0a0" +checksum = "4ac6a0c7b1a9e9a5186361f67dfa1b88213572f427fb9ab038efb2bd8c582dab" dependencies = [ - "heck 0.5.0", + "heck", "proc-macro2", "quote", - "syn 2.0.77", + "syn 2.0.79", ] [[package]] @@ -673,25 +659,12 @@ version = "7.1.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "b34115915337defe99b2aff5c2ce6771e5fbc4079f4b506301f5cf394c8452f7" dependencies = [ + "crossterm 0.27.0", "strum", "strum_macros", "unicode-width", ] -[[package]] -name = "compact_str" -version = "0.8.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "6050c3a16ddab2e412160b31f2c871015704239bca62f72f6e5f0be631d3f644" -dependencies = [ - "castaway", - "cfg-if", - "itoa", - "rustversion", - "ryu", - "static_assertions", -] - [[package]] name = "concurrent-queue" version = "2.5.0" @@ -824,7 +797,8 @@ dependencies = [ "crossterm_winapi", "mio 1.0.2", "parking_lot 0.12.3", - "rustix 0.38.36", + "rustix 0.38.37", + "serde", "signal-hook", "signal-hook-mio", "winapi", @@ -895,7 +869,7 @@ checksum = "f46882e17999c6cc590af592290432be3bce0428cb0d5f8b6715e4dc7b383eb3" dependencies = [ "proc-macro2", "quote", - "syn 2.0.77", + "syn 2.0.79", ] [[package]] @@ -1169,7 +1143,7 @@ dependencies = [ [[package]] name = "email-lib" version = "0.25.0" -source = "git+https://github.com/pimalaya/core#3fd4fd27e6c803d2248a845726a2b9331f27e7d7" +source = "git+https://github.com/pimalaya/core#119975060c78b7632d1760a823428bf6ca07bb03" dependencies = [ "async-trait", "chrono", @@ -1221,7 +1195,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "0f24a09fd651027f8764f8a12c12358715cb9bab622ab3125ede3dd6ae047c95" dependencies = [ "quote", - "syn 2.0.77", + "syn 2.0.79", ] [[package]] @@ -1244,14 +1218,14 @@ dependencies = [ [[package]] name = "enum-as-inner" -version = "0.6.0" +version = "0.6.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "5ffccbb6966c05b32ef8fbac435df276c4ae4d3dc55a8cd0eb9745e6c12f546a" +checksum = "a1e6a265c649f3f5979b601d26f1d05ada116434c87741c9493cb56218f76cbc" dependencies = [ - "heck 0.4.1", + "heck", "proc-macro2", "quote", - "syn 2.0.77", + "syn 2.0.79", ] [[package]] @@ -1272,7 +1246,7 @@ checksum = "de0d48a183585823424a4ce1aa132d174a6a81bd540895822eb4c8373a8e49e8" dependencies = [ "proc-macro2", "quote", - "syn 2.0.77", + "syn 2.0.79", ] [[package]] @@ -1354,6 +1328,17 @@ version = "2.1.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "e8c02a5121d4ea3eb16a80748c74f5549a5665e4c21333c6098f283870fbdea6" +[[package]] +name = "fd-lock" +version = "4.0.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "7e5768da2206272c81ef0b5e951a41862938a6070da63bcea197899942d3b947" +dependencies = [ + "cfg-if", + "rustix 0.38.37", + "windows-sys 0.52.0", +] + [[package]] name = "ff" version = "0.13.0" @@ -1390,9 +1375,9 @@ checksum = "0ce7134b9999ecaf8bcd65542e436736ef32ddca1b3e06094cb6ec5755203b80" [[package]] name = "flate2" -version = "1.0.33" +version = "1.0.34" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "324a1be68054ef05ad64b861cc9eaf1d623d2d8cb25b4bf2cb9cdd902b4bf253" +checksum = "a1b589b4dc103969ad3cf85c950899926ec64300a1a46d76c03a6072957036f0" dependencies = [ "crc32fast", "miniz_oxide 0.8.0", @@ -1525,7 +1510,7 @@ checksum = "87750cf4b7a4c0625b1529e4c543c2182106e4dedc60a2a6455e00d212c489ac" dependencies = [ "proc-macro2", "quote", - "syn 2.0.77", + "syn 2.0.79", ] [[package]] @@ -1716,12 +1701,6 @@ dependencies = [ "allocator-api2", ] -[[package]] -name = "heck" -version = "0.4.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "95505c38b4572b2d910cecb0281560f54b440a19336cbbcb27bf6ce6adc6f5a8" - [[package]] name = "heck" version = "0.5.0" @@ -1802,13 +1781,13 @@ version = "0.1.0" dependencies = [ "ariadne", "async-trait", + "clap", "color-eyre", "comfy-table", "crossterm 0.27.0", "dirs 4.0.0", "email-lib", "email_address", - "fuzzy-matcher", "mail-builder", "md5", "mml-lib", @@ -1817,7 +1796,7 @@ dependencies = [ "petgraph", "pimalaya-tui", "process-lib", - "ratatui", + "reedline", "secret-lib", "serde", "serde_json", @@ -2007,7 +1986,7 @@ dependencies = [ "hyper 1.4.1", "hyper-util", "log", - "rustls 0.23.12", + "rustls 0.23.13", "rustls-native-certs 0.8.0", "rustls-pki-types", "tokio", @@ -2017,9 +1996,9 @@ dependencies = [ [[package]] name = "hyper-util" -version = "0.1.7" +version = "0.1.9" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "cde7055719c54e36e95e8719f95883f22072a48ede39db7fc17a4e1d5281e9b9" +checksum = "41296eb09f183ac68eec06e03cdbea2e759633d4067b2f6552fc2e009bcad08b" dependencies = [ "bytes", "futures-channel", @@ -2030,16 +2009,15 @@ dependencies = [ "pin-project-lite", "socket2 0.5.7", "tokio", - "tower", "tower-service", "tracing", ] [[package]] name = "iana-time-zone" -version = "0.1.60" +version = "0.1.61" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "e7ffbb5a1b541ea2561f8c41c087286cc091e21e556a4f09a8f6cbf17b69b141" +checksum = "235e081f3925a06703c2d0117ea8b91f042756fd6e7a6e5d901e8ca1a996b220" dependencies = [ "android_system_properties", "core-foundation-sys", @@ -2096,7 +2074,7 @@ dependencies = [ [[package]] name = "imap-client" version = "0.1.4" -source = "git+https://github.com/pimalaya/imap-client#a36badd488e5ab9703e00e9cc8fc71e37d97856f" +source = "git+https://github.com/pimalaya/imap-client#c1f0dfcfb3e5f22763324d6d2497e195d44c9ec8" dependencies = [ "imap-next", "once_cell", @@ -2211,16 +2189,6 @@ dependencies = [ "unicode-width", ] -[[package]] -name = "instability" -version = "0.3.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "b23a0c8dfe501baac4adf6ebbfa6eddf8f0c07f56b058cc1288017e32397846c" -dependencies = [ - "quote", - "syn 2.0.77", -] - [[package]] name = "instant" version = "0.1.13" @@ -2267,9 +2235,9 @@ checksum = "7943c866cc5cd64cbc25b2e01621d07fa8eb2a1a23160ee81ce38704e97b8ecf" [[package]] name = "itertools" -version = "0.13.0" +version = "0.12.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "413ee7dfc52ee1a4949ceeb7dbc8a33f2d6c088194d9f922fb8318faf1f01186" +checksum = "ba291022dbbd398a455acf126c1e341954079855bc60dfdda641363bd6922569" dependencies = [ "either", ] @@ -2354,9 +2322,9 @@ dependencies = [ [[package]] name = "libc" -version = "0.2.158" +version = "0.2.159" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d8adc4bb1803a324070e64a98ae98f38934d91957a99cfb3a43dcbc01bc56439" +checksum = "561d97a539a36e26a9a5fad1ea11a3039a67714694aaa379433e580854bc3dc5" [[package]] name = "libgpg-error-sys" @@ -2383,7 +2351,7 @@ checksum = "c0ff37bd590ca25063e35af745c343cb7a0271906fb7b37e4813e8f79f00268d" dependencies = [ "bitflags 2.6.0", "libc", - "redox_syscall 0.5.3", + "redox_syscall 0.5.7", ] [[package]] @@ -2430,15 +2398,6 @@ version = "0.4.22" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "a7a70ba024b9dc04c27ea2f0c0548feb474ec5c54bba33a7f72f873a39d07b24" -[[package]] -name = "lru" -version = "0.12.4" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "37ee39891760e7d94734f6f63fedc29a2e4a152f836120753a72503f09fcf904" -dependencies = [ - "hashbrown", -] - [[package]] name = "lru-cache" version = "0.1.2" @@ -2474,12 +2433,12 @@ checksum = "7a575d25cf00ed68e5790b473b29242a47e991c6187785d47b45e31fc5816554" dependencies = [ "base64 0.22.1", "gethostname", - "rustls 0.23.12", + "rustls 0.23.13", "rustls-pki-types", "smtp-proto", "tokio", "tokio-rustls 0.26.0", - "webpki-roots 0.26.5", + "webpki-roots 0.26.6", ] [[package]] @@ -2627,9 +2586,9 @@ dependencies = [ [[package]] name = "nanohtml2text" -version = "0.1.4" +version = "0.1.5" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "999681fe3c0524336e98ece1c25ee4278607f25cc1e361ad0f9201c8bf56dc2c" +checksum = "9d4bdc3645754d2da280343bd8f1eaa9acf56c4ed75b540c98c898b171a3d867" [[package]] name = "newline-converter" @@ -2699,6 +2658,15 @@ dependencies = [ "winapi", ] +[[package]] +name = "nu-ansi-term" +version = "0.50.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d4a28e057d01f97e61255210fcff094d74ed0466038633e95017f5beb68e4399" +dependencies = [ + "windows-sys 0.52.0", +] + [[package]] name = "num" version = "0.4.3" @@ -2758,7 +2726,7 @@ checksum = "ed3955f1a9c7c0c15e092f9c887db08b1fc683305fdf6eb6684f22555355e202" dependencies = [ "proc-macro2", "quote", - "syn 2.0.77", + "syn 2.0.79", ] [[package]] @@ -2805,7 +2773,7 @@ dependencies = [ [[package]] name = "oauth-lib" version = "0.1.1" -source = "git+https://github.com/pimalaya/core#3fd4fd27e6c803d2248a845726a2b9331f27e7d7" +source = "git+https://github.com/pimalaya/core#119975060c78b7632d1760a823428bf6ca07bb03" dependencies = [ "log", "oauth2", @@ -2846,9 +2814,12 @@ dependencies = [ [[package]] name = "once_cell" -version = "1.19.0" +version = "1.20.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "3fdb12b2476b595f9358c5161aa467c2438859caa136dec86c26fdd2efe17b92" +checksum = "82881c4be219ab5faaf2ad5e5e5ecdff8c66bd7402ca3160975c93b24961afd1" +dependencies = [ + "portable-atomic", +] [[package]] name = "openssl-probe" @@ -2989,7 +2960,7 @@ checksum = "1e401f977ab385c9e4e3ab30627d6f26d00e2c73eef317493c4ec6d468726cf8" dependencies = [ "cfg-if", "libc", - "redox_syscall 0.5.3", + "redox_syscall 0.5.7", "smallvec", "windows-targets 0.52.6", ] @@ -3101,7 +3072,7 @@ dependencies = [ [[package]] name = "pimalaya-tui" version = "0.1.0" -source = "git+https://github.com/pimalaya/tui#fba8c1284dbaaa4433c7cb6b242e68864d8d5b44" +source = "git+https://github.com/pimalaya/tui#b40ca9d9e161b91e9efcb762fa05f06e3fe46f63" dependencies = [ "clap", "color-eyre", @@ -3118,32 +3089,12 @@ dependencies = [ "shellexpand-utils", "thiserror", "toml", - "toml_edit 0.22.20", + "toml_edit 0.22.22", "tracing", "tracing-error", "tracing-subscriber", ] -[[package]] -name = "pin-project" -version = "1.1.5" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "b6bf43b791c5b9e34c3d182969b4abb522f9343702850a2e57f460d00d09b4b3" -dependencies = [ - "pin-project-internal", -] - -[[package]] -name = "pin-project-internal" -version = "1.1.5" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "2f38a4412a78282e09a2cf38d195ea5420d15ba0602cb375210efbc877243965" -dependencies = [ - "proc-macro2", - "quote", - "syn 2.0.77", -] - [[package]] name = "pin-project-lite" version = "0.2.14" @@ -3190,9 +3141,9 @@ dependencies = [ [[package]] name = "pkg-config" -version = "0.3.30" +version = "0.3.31" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d231b230927b5e4ad203db57bbcbee2802f6bce620b1e4a9024a07d94e2907ec" +checksum = "953ec861398dccce10c670dfeaf3ec4911ca479e9c02154b3a215178c5f566f2" [[package]] name = "polling" @@ -3220,11 +3171,17 @@ dependencies = [ "concurrent-queue", "hermit-abi 0.4.0", "pin-project-lite", - "rustix 0.38.36", + "rustix 0.38.37", "tracing", "windows-sys 0.59.0", ] +[[package]] +name = "portable-atomic" +version = "1.9.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "cc9c68a3f6da06753e9335d63e27f6b9754dd1920d941135b7ea8224f141adb2" + [[package]] name = "ppv-lite86" version = "0.2.20" @@ -3289,7 +3246,7 @@ dependencies = [ [[package]] name = "process-lib" version = "0.4.2" -source = "git+https://github.com/pimalaya/core#3fd4fd27e6c803d2248a845726a2b9331f27e7d7" +source = "git+https://github.com/pimalaya/core#119975060c78b7632d1760a823428bf6ca07bb03" dependencies = [ "log", "serde", @@ -3342,27 +3299,6 @@ dependencies = [ "getrandom", ] -[[package]] -name = "ratatui" -version = "0.28.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "fdef7f9be5c0122f890d58bdf4d964349ba6a6161f705907526d891efabba57d" -dependencies = [ - "bitflags 2.6.0", - "cassowary", - "compact_str", - "crossterm 0.28.1", - "instability", - "itertools", - "lru", - "paste", - "strum", - "strum_macros", - "unicode-segmentation", - "unicode-truncate", - "unicode-width", -] - [[package]] name = "rayon" version = "1.10.0" @@ -3394,9 +3330,9 @@ dependencies = [ [[package]] name = "redox_syscall" -version = "0.5.3" +version = "0.5.7" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "2a908a6e00f1fdd0dfd9c0eb08ce85126f6d8bbda50017e74bc4a4b7d4a926a4" +checksum = "9b6dfecf2c74bce2466cabf93f6664d6998a69eb21e39f4207930065b27b771f" dependencies = [ "bitflags 2.6.0", ] @@ -3412,16 +3348,36 @@ dependencies = [ "thiserror", ] +[[package]] +name = "reedline" +version = "0.35.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c5289de810296f8f2ff58d35544d92ae98d0a631453388bc3e608086be0fa596" +dependencies = [ + "chrono", + "crossterm 0.28.1", + "fd-lock", + "itertools", + "nu-ansi-term 0.50.1", + "serde", + "strip-ansi-escapes", + "strum", + "strum_macros", + "thiserror", + "unicode-segmentation", + "unicode-width", +] + [[package]] name = "regex" -version = "1.10.6" +version = "1.11.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "4219d74c6b67a3654a9fbebc4b419e22126d13d2f3c4a07ee0cb61ff79a79619" +checksum = "38200e5ee88914975b69f657f0801b6f6dccafd44fd9326302a4aaeecfacb1d8" dependencies = [ "aho-corasick", "memchr", - "regex-automata 0.4.7", - "regex-syntax 0.8.4", + "regex-automata 0.4.8", + "regex-syntax 0.8.5", ] [[package]] @@ -3446,13 +3402,13 @@ dependencies = [ [[package]] name = "regex-automata" -version = "0.4.7" +version = "0.4.8" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "38caf58cc5ef2fed281f89292ef23f6365465ed9a41b7a7754eb4e26496c92df" +checksum = "368758f23274712b504848e9d5a6f010445cc8b87a7cdb4d7cbee666c1288da3" dependencies = [ "aho-corasick", "memchr", - "regex-syntax 0.8.4", + "regex-syntax 0.8.5", ] [[package]] @@ -3469,9 +3425,9 @@ checksum = "dbb5fb1acd8a1a18b3dd5be62d25485eb770e05afb408a9627d14d451bae12da" [[package]] name = "regex-syntax" -version = "0.8.4" +version = "0.8.5" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "7a66a03ae7c801facd77a29370b4faec201768915ac14a721ba36f20bc9c209b" +checksum = "2b15c43186be67a4fd63bee50d0303afffcef381492ebe2c5d87f324e1b8815c" [[package]] name = "reqwest" @@ -3609,9 +3565,9 @@ dependencies = [ [[package]] name = "rustix" -version = "0.38.36" +version = "0.38.37" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "3f55e80d50763938498dd5ebb18647174e0c76dc38c5505294bb224624f30f36" +checksum = "8acb788b847c24f28525660c4d7758620a7210875711f79e7f663cc152726811" dependencies = [ "bitflags 2.6.0", "errno", @@ -3634,15 +3590,15 @@ dependencies = [ [[package]] name = "rustls" -version = "0.23.12" +version = "0.23.13" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "c58f8c84392efc0a126acce10fa59ff7b3d2ac06ab451a33f2741989b806b044" +checksum = "f2dabaac7466917e566adb06783a81ca48944c6898a1b08b9374106dd671f4c8" dependencies = [ "log", "once_cell", "ring", "rustls-pki-types", - "rustls-webpki 0.102.7", + "rustls-webpki 0.102.8", "subtle", "zeroize", ] @@ -3693,9 +3649,9 @@ dependencies = [ [[package]] name = "rustls-pki-types" -version = "1.8.0" +version = "1.9.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "fc0a2ce646f8655401bb81e7927b812614bd5d91dbc968696be50603510fcaf0" +checksum = "0e696e35370c65c9c541198af4543ccd580cf17fc25d8e05c5a242b202488c55" [[package]] name = "rustls-webpki" @@ -3709,9 +3665,9 @@ dependencies = [ [[package]] name = "rustls-webpki" -version = "0.102.7" +version = "0.102.8" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "84678086bd54edf2b415183ed7a94d0efb049f1b646a33e22a36f3794be6ae56" +checksum = "64ca1bc8749bd4cf37b5ce386cc146580777b4e8572c7b97baf22c83f444bee9" dependencies = [ "ring", "rustls-pki-types", @@ -3825,9 +3781,9 @@ dependencies = [ [[package]] name = "security-framework-sys" -version = "2.11.1" +version = "2.12.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "75da29fe9b9b08fe9d6b22b5b4bcbc75d8db3aa31e639aa56bb62e9d46bfceaf" +checksum = "ea4a292869320c0272d7bc55a5a6aafaff59b4f63404a003887b679a2e05b4b6" dependencies = [ "core-foundation-sys", "libc", @@ -3877,7 +3833,7 @@ checksum = "243902eda00fad750862fc144cea25caca5e20d615af0a81bee94ca738f1df1f" dependencies = [ "proc-macro2", "quote", - "syn 2.0.77", + "syn 2.0.79", ] [[package]] @@ -3910,14 +3866,14 @@ checksum = "6c64451ba24fc7a6a2d60fc75dd9c83c90903b19028d4eff35e88fc1e86564e9" dependencies = [ "proc-macro2", "quote", - "syn 2.0.77", + "syn 2.0.79", ] [[package]] name = "serde_spanned" -version = "0.6.7" +version = "0.6.8" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "eb5b1b31579f3811bf615c144393417496f152e12ac8b7663bf664f4a815306d" +checksum = "87607cb1398ed59d48732e575a4c28a7a8ebf2454b964fe3f224f2afc07909e1" dependencies = [ "serde", ] @@ -4123,6 +4079,15 @@ version = "1.1.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "a2eb9349b6444b326872e140eb1cf5e7c522154d69e7a0ffb0fb81c06b37543f" +[[package]] +name = "strip-ansi-escapes" +version = "0.2.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "55ff8ef943b384c414f54aefa961dd2bd853add74ec75e7ac74cf91dba62bcfa" +dependencies = [ + "vte", +] + [[package]] name = "strsim" version = "0.9.3" @@ -4146,9 +4111,6 @@ name = "strum" version = "0.26.3" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "8fec0f0aef304996cf250b31b5a10dee7980c85da9d759361292b8bca5a18f06" -dependencies = [ - "strum_macros", -] [[package]] name = "strum_macros" @@ -4156,11 +4118,11 @@ version = "0.26.4" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "4c6bee85a5a24955dc440386795aa378cd9cf82acd5f764469152d2270e581be" dependencies = [ - "heck 0.5.0", + "heck", "proc-macro2", "quote", "rustversion", - "syn 2.0.77", + "syn 2.0.79", ] [[package]] @@ -4182,9 +4144,9 @@ dependencies = [ [[package]] name = "syn" -version = "2.0.77" +version = "2.0.79" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "9f35bcdf61fd8e7be6caf75f429fdca8beb3ed76584befb503b1569faee373ed" +checksum = "89132cd0bf050864e1d38dc3bbc07a0eb8e7530af26344d3d2bbbef83499f590" dependencies = [ "proc-macro2", "quote", @@ -4225,7 +4187,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "a3e535eb8dded36d55ec13eddacd30dec501792ff23a0b1682c38601b8cf2349" dependencies = [ "cfg-expr", - "heck 0.5.0", + "heck", "pkg-config", "toml", "version-compare", @@ -4239,35 +4201,45 @@ checksum = "61c41af27dd6d1e27b1b16b489db798443478cef1f06a660c96db617ba5de3b1" [[package]] name = "tempfile" -version = "3.12.0" +version = "3.13.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "04cbcdd0c794ebb0d4cf35e88edd2f7d2c4c3e9a5a6dab322839b321c6a87a64" +checksum = "f0f2c9fc62d0beef6951ccffd757e241266a2c833136efbe35af6cd2567dca5b" dependencies = [ "cfg-if", "fastrand 2.1.1", "once_cell", - "rustix 0.38.36", + "rustix 0.38.37", "windows-sys 0.59.0", ] +[[package]] +name = "terminal_size" +version = "0.3.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "21bebf2b7c9e0a515f6e0f8c51dc0f8e4696391e6f1ff30379559f8365fb0df7" +dependencies = [ + "rustix 0.38.37", + "windows-sys 0.48.0", +] + [[package]] name = "thiserror" -version = "1.0.63" +version = "1.0.64" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "c0342370b38b6a11b6cc11d6a805569958d54cfa061a29969c3b5ce2ea405724" +checksum = "d50af8abc119fb8bb6dbabcfa89656f46f84aa0ac7688088608076ad2b459a84" dependencies = [ "thiserror-impl", ] [[package]] name = "thiserror-impl" -version = "1.0.63" +version = "1.0.64" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a4558b58466b9ad7ca0f102865eccc95938dca1a74a856f2b57b6629050da261" +checksum = "08904e7672f5eb876eaaf87e0ce17857500934f4981c4a0ab2b4aa98baac7fc3" dependencies = [ "proc-macro2", "quote", - "syn 2.0.77", + "syn 2.0.79", ] [[package]] @@ -4321,7 +4293,7 @@ checksum = "693d596312e88961bc67d7f1f97af8a70227d9f90c31bba5806eec004978d752" dependencies = [ "proc-macro2", "quote", - "syn 2.0.77", + "syn 2.0.79", ] [[package]] @@ -4340,7 +4312,7 @@ version = "0.26.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "0c7bc40d0e5a97695bb96e27995cd3a08538541b0a846f65bba7a359f36700d4" dependencies = [ - "rustls 0.23.12", + "rustls 0.23.13", "rustls-pki-types", "tokio", ] @@ -4367,7 +4339,7 @@ dependencies = [ "serde", "serde_spanned", "toml_datetime", - "toml_edit 0.22.20", + "toml_edit 0.22.22", ] [[package]] @@ -4392,38 +4364,17 @@ dependencies = [ [[package]] name = "toml_edit" -version = "0.22.20" +version = "0.22.22" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "583c44c02ad26b0c3f3066fe629275e50627026c51ac2e595cca4c230ce1ce1d" +checksum = "4ae48d6208a266e853d946088ed816055e556cc6028c5e8e2b84d9fa5dd7c7f5" dependencies = [ "indexmap", "serde", "serde_spanned", "toml_datetime", - "winnow 0.6.18", -] - -[[package]] -name = "tower" -version = "0.4.13" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "b8fa9be0de6cf49e536ce1851f987bd21a43b771b09473c3549a6c853db37c1c" -dependencies = [ - "futures-core", - "futures-util", - "pin-project", - "pin-project-lite", - "tokio", - "tower-layer", - "tower-service", + "winnow 0.6.20", ] -[[package]] -name = "tower-layer" -version = "0.3.3" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "121c2a6cda46980bb0fcd1647ffaf6cd3fc79a013de288782836f6df9c48780e" - [[package]] name = "tower-service" version = "0.3.3" @@ -4449,7 +4400,7 @@ checksum = "34704c8d6ebcbc939824180af020566b01a7c01f80641264eba0999f6c2b6be7" dependencies = [ "proc-macro2", "quote", - "syn 2.0.77", + "syn 2.0.79", ] [[package]] @@ -4490,7 +4441,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "ad0f048c97dbd9faa9b7df56362b8ebcaa52adb06b498c050d2f4e32f90a7a8b" dependencies = [ "matchers", - "nu-ansi-term", + "nu-ansi-term 0.46.0", "once_cell", "regex", "sharded-slab", @@ -4555,41 +4506,30 @@ checksum = "08f95100a766bf4f8f28f90d77e0a5461bbdb219042e7679bebe79004fed8d75" [[package]] name = "unicode-ident" -version = "1.0.12" +version = "1.0.13" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "3354b9ac3fae1ff6755cb6db53683adb661634f67557942dea4facebec0fee4b" +checksum = "e91b56cd4cadaeb79bbf1a5645f6b4f8dc5bde8834ad5894a8db35fda9efa1fe" [[package]] name = "unicode-normalization" -version = "0.1.23" +version = "0.1.24" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a56d1686db2308d901306f92a263857ef59ea39678a5458e7cb17f01415101f5" +checksum = "5033c97c4262335cded6d6fc3e5c18ab755e1a3dc96376350f3d8e9f009ad956" dependencies = [ "tinyvec", ] [[package]] name = "unicode-segmentation" -version = "1.11.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d4c87d22b6e3f4a18d4d40ef354e97c90fcb14dd91d7dc0aa9d8a1172ebf7202" - -[[package]] -name = "unicode-truncate" -version = "1.1.0" +version = "1.12.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "b3644627a5af5fa321c95b9b235a72fd24cd29c648c2c379431e6628655627bf" -dependencies = [ - "itertools", - "unicode-segmentation", - "unicode-width", -] +checksum = "f6ccf251212114b54433ec949fd6a7841275f9ada20dddd2f29e9ceea4501493" [[package]] name = "unicode-width" -version = "0.1.13" +version = "0.1.14" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "0336d538f7abc86d282a4189614dfaa90810dfc2c6f6427eaf88e16311dd225d" +checksum = "7dd6e30e90baa6f72411720665d41d89b9a3d039dc45b8faea1ddd07f617f6af" [[package]] name = "untrusted" @@ -4659,6 +4599,26 @@ version = "0.9.5" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "0b928f33d975fc6ad9f86c8f283853ad26bdd5b10b7f1542aa2fa15e2289105a" +[[package]] +name = "vte" +version = "0.11.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f5022b5fbf9407086c180e9557be968742d839e68346af7792b8592489732197" +dependencies = [ + "utf8parse", + "vte_generate_state_changes", +] + +[[package]] +name = "vte_generate_state_changes" +version = "0.1.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "2e369bee1b05d510a7b4ed645f5faa90619e05437111783ea5848f28d97d3c2e" +dependencies = [ + "proc-macro2", + "quote", +] + [[package]] name = "waker-fn" version = "1.2.0" @@ -4712,7 +4672,7 @@ dependencies = [ "once_cell", "proc-macro2", "quote", - "syn 2.0.77", + "syn 2.0.79", "wasm-bindgen-shared", ] @@ -4746,7 +4706,7 @@ checksum = "afc340c74d9005395cf9dd098506f7f44e38f2b4a21c6aaacf9a105ea5e1e836" dependencies = [ "proc-macro2", "quote", - "syn 2.0.77", + "syn 2.0.79", "wasm-bindgen-backend", "wasm-bindgen-shared", ] @@ -4775,9 +4735,9 @@ checksum = "5f20c57d8d7db6d3b86154206ae5d8fba62dd39573114de97c2cb0578251f8e1" [[package]] name = "webpki-roots" -version = "0.26.5" +version = "0.26.6" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "0bd24728e5af82c6c4ec1b66ac4844bdf8156257fccda846ec58b42cd0cdbe6a" +checksum = "841c67bff177718f1d4dfefde8d8f0e78f9b6589319ba88312f567fc5841a958" dependencies = [ "rustls-pki-types", ] @@ -4987,9 +4947,9 @@ dependencies = [ [[package]] name = "winnow" -version = "0.6.18" +version = "0.6.20" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "68a9bda4691f099d435ad181000724da8e5899daa10713c2d432552b9ccd3a6f" +checksum = "36c1fec1a2bb5866f07c25f68c26e565c4c200aebb96d7e55710c19d3e8ac49b" dependencies = [ "memchr", ] @@ -5047,9 +5007,9 @@ dependencies = [ [[package]] name = "xml-rs" -version = "0.8.21" +version = "0.8.22" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "539a77ee7c0de333dcc6da69b177380a0b81e0dacfa4f7344c465a36871ee601" +checksum = "af4e2e2f7cba5a093896c1e150fbfe177d1883e7448200efb81d40b9d339ef26" [[package]] name = "yansi" @@ -5142,7 +5102,7 @@ checksum = "fa4f8080344d4671fb4e831a13ad1e68092748387dfc4f55e356242fae12ce3e" dependencies = [ "proc-macro2", "quote", - "syn 2.0.77", + "syn 2.0.79", ] [[package]] @@ -5162,7 +5122,7 @@ checksum = "ce36e65b0d2999d2aafac989fb249189a141aee1f53c612c1f37d72631959f69" dependencies = [ "proc-macro2", "quote", - "syn 2.0.77", + "syn 2.0.79", ] [[package]] diff --git a/Cargo.toml b/Cargo.toml index 46509b5..4965c6b 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -50,13 +50,13 @@ pgp-native = ["email-lib/pgp-native", "mml-lib/pgp-native", "pgp"] [dependencies] ariadne = "0.2" async-trait = "0.1" +clap = { version = "4.4", features = ["derive", "env", "wrap_help"] } color-eyre = "0.6.3" -comfy-table = { version = "7.1", default-features = false } +comfy-table = { version = "7.1" } crossterm = { version = "0.27", features = ["serde"] } dirs = "4" email-lib = { version = "=0.25.0", default-features = false, features = ["derive", "thread", "tracing"] } email_address = { version = "0.2", optional = true } -fuzzy-matcher = "0.3" mail-builder = "0.3" md5 = "0.7" mml-lib = { version = "=1.0.14", default-features = false, features = ["derive"] } @@ -65,7 +65,7 @@ once_cell = "1.16" petgraph = "0.6" pimalaya-tui = { version = "=0.1.0", default-features = false, features = ["email", "path", "cli", "config", "tracing"] } process-lib = { version = "=0.4.2", features = ["derive"] } -ratatui = "=0.28.1" +reedline = "0.35.0" secret-lib = { version = "=0.4.6", default-features = false, features = ["command", "derive"], optional = true } serde = { version = "1", features = ["derive"] } serde_json = "1" diff --git a/src/account/config.rs b/src/account/config.rs new file mode 100644 index 0000000..d79eff2 --- /dev/null +++ b/src/account/config.rs @@ -0,0 +1,100 @@ +//! Deserialized account config module. +//! +//! This module contains the raw deserialized representation of an +//! account in the accounts section of the user configuration file. + +use std::path::PathBuf; + +use crossterm::style::Color; +#[cfg(feature = "pgp")] +use email::account::config::pgp::PgpConfig; +#[cfg(feature = "imap")] +use email::imap::config::ImapConfig; +#[cfg(feature = "maildir")] +use email::maildir::config::MaildirConfig; +#[cfg(feature = "notmuch")] +use email::notmuch::config::NotmuchConfig; +#[cfg(feature = "sendmail")] +use email::sendmail::config::SendmailConfig; +#[cfg(feature = "smtp")] +use email::smtp::config::SmtpConfig; +use process::Command; +use serde::{Deserialize, Serialize}; + +use crate::backend::BackendKind; + +// use crate::{ +// backend::BackendKind, envelope::config::EnvelopeConfig, flag::config::FlagConfig, +// folder::config::FolderConfig, message::config::MessageConfig, +// }; + +/// Represents all existing kind of account config. +#[derive(Clone, Debug, Default, Eq, PartialEq, Deserialize, Serialize)] +#[serde(rename_all = "kebab-case", deny_unknown_fields)] +pub struct TomlAccountConfig { + pub default: Option, + pub email: String, + pub display_name: Option, + pub signature: Option, + pub signature_delim: Option, + pub downloads_dir: Option, + pub backend: Option, + + #[cfg(feature = "pgp")] + pub pgp: Option, + + // pub folder: Option, + // pub envelope: Option, + // pub flag: Option, + pub message: Option, + // pub template: Option, + #[cfg(feature = "imap")] + pub imap: Option, + #[cfg(feature = "maildir")] + pub maildir: Option, + #[cfg(feature = "notmuch")] + pub notmuch: Option, + #[cfg(feature = "smtp")] + pub smtp: Option, + #[cfg(feature = "sendmail")] + pub sendmail: Option, +} + +#[derive(Clone, Debug, Default, Eq, PartialEq, Deserialize, Serialize)] +pub struct MessageConfig { + pub send: Option, +} + +#[derive(Clone, Debug, Default, Eq, PartialEq, Deserialize, Serialize)] +pub struct MessageSendConfig { + pub backend: Option, + pub save_copy: Option, + pub pre_hook: Option, +} + +#[derive(Clone, Debug, Default, Eq, PartialEq, Deserialize, Serialize)] +#[serde(rename_all = "kebab-case")] +pub struct ListAccountsTableConfig { + pub preset: Option, + pub name_color: Option, + pub backends_color: Option, + pub default_color: Option, +} + +// impl ListAccountsTableConfig { +// pub fn preset(&self) -> &str { +// self.preset.as_deref().unwrap_or(presets::ASCII_MARKDOWN) +// } + +// pub fn name_color(&self) -> comfy_table::Color { +// map_color(self.name_color.unwrap_or(Color::Green)) +// } + +// pub fn backends_color(&self) -> comfy_table::Color { +// map_color(self.backends_color.unwrap_or(Color::Blue)) +// } + +// pub fn default_color(&self) -> comfy_table::Color { +// map_color(self.default_color.unwrap_or(Color::Reset)) +// } +// } diff --git a/src/account/mod.rs b/src/account/mod.rs new file mode 100644 index 0000000..ef68c36 --- /dev/null +++ b/src/account/mod.rs @@ -0,0 +1 @@ +pub mod config; diff --git a/src/backend.rs b/src/backend.rs new file mode 100644 index 0000000..ea62c1b --- /dev/null +++ b/src/backend.rs @@ -0,0 +1,178 @@ +use async_trait::async_trait; +#[cfg(feature = "imap")] +use email::imap::{config::ImapConfig, ImapContext, ImapContextBuilder}; +#[cfg(feature = "maildir")] +use email::maildir::{config::MaildirConfig, MaildirContextBuilder, MaildirContextSync}; +#[cfg(feature = "notmuch")] +use email::notmuch::{config::NotmuchConfig, NotmuchContextBuilder, NotmuchContextSync}; +#[cfg(feature = "sendmail")] +use email::sendmail::{config::SendmailConfig, SendmailContextBuilder, SendmailContextSync}; +#[cfg(feature = "smtp")] +use email::smtp::{config::SmtpConfig, SmtpContextBuilder, SmtpContextSync}; +use email::{ + backend::{ + context::BackendContextBuilder, feature::BackendFeature, macros::BackendContext, + mapper::SomeBackendContextBuilderMapper, + }, + folder::list::ListFolders, + AnyResult, +}; +use serde::{Deserialize, Serialize}; + +#[derive(Clone, Debug, Eq, PartialEq)] +pub enum BackendConfig { + #[cfg(feature = "imap")] + Imap(ImapConfig), + #[cfg(feature = "maildir")] + Maildir(MaildirConfig), + #[cfg(feature = "notmuch")] + Notmuch(NotmuchConfig), + #[cfg(feature = "smtp")] + Smtp(SmtpConfig), + #[cfg(feature = "sendmail")] + Sendmail(SendmailConfig), +} + +#[derive(Clone, Debug, Eq, Hash, PartialEq, Serialize, Deserialize)] +#[serde(rename_all = "kebab-case")] +pub enum BackendKind { + None, + #[cfg(feature = "imap")] + Imap, + #[cfg(feature = "maildir")] + Maildir, + #[cfg(feature = "notmuch")] + Notmuch, + #[cfg(feature = "smtp")] + Smtp, + #[cfg(feature = "sendmail")] + Sendmail, +} + +#[derive(BackendContext)] +pub struct Context { + #[cfg(feature = "imap")] + imap: Option, + #[cfg(feature = "maildir")] + maildir: Option, + #[cfg(feature = "notmuch")] + notmuch: Option, + #[cfg(feature = "smtp")] + smtp: Option, + #[cfg(feature = "sendmail")] + sendmail: Option, +} + +#[cfg(feature = "imap")] +impl AsRef> for Context { + fn as_ref(&self) -> &Option { + &self.imap + } +} + +#[cfg(feature = "maildir")] +impl AsRef> for Context { + fn as_ref(&self) -> &Option { + &self.maildir + } +} + +#[cfg(feature = "notmuch")] +impl AsRef> for Context { + fn as_ref(&self) -> &Option { + &self.notmuch + } +} + +#[cfg(feature = "smtp")] +impl AsRef> for Context { + fn as_ref(&self) -> &Option { + &self.smtp + } +} + +#[cfg(feature = "sendmail")] +impl AsRef> for Context { + fn as_ref(&self) -> &Option { + &self.sendmail + } +} + +#[derive(Clone)] +pub struct ContextBuilder { + pub backend: BackendKind, + pub sending_backend: BackendKind, + + #[cfg(feature = "imap")] + pub imap: Option, + #[cfg(feature = "maildir")] + pub maildir: Option, + #[cfg(feature = "notmuch")] + pub notmuch: Option, + #[cfg(feature = "sendmail")] + pub sendmail: Option, + #[cfg(feature = "smtp")] + pub smtp: Option, +} + +#[async_trait] +impl BackendContextBuilder for ContextBuilder { + type Context = Context; + + fn list_folders(&self) -> Option> { + match self.backend { + #[cfg(feature = "imap")] + BackendKind::Imap => self.list_folders_with_some(&self.imap), + #[cfg(feature = "maildir")] + BackendKind::Maildir => self.list_folders_with_some(&self.maildir), + #[cfg(feature = "notmuch")] + BackendKind::Notmuch => self.list_folders_with_some(&self.notmuch), + _ => None, + } + } + + async fn build(self) -> AnyResult { + #[cfg(feature = "imap")] + let imap = match self.imap { + Some(imap) => Some(imap.build().await?), + None => None, + }; + + #[cfg(feature = "maildir")] + let maildir = match self.maildir { + Some(maildir) => Some(maildir.build().await?), + None => None, + }; + + #[cfg(feature = "notmuch")] + let notmuch = match self.notmuch { + Some(notmuch) => Some(notmuch.build().await?), + None => None, + }; + + #[cfg(feature = "smtp")] + let smtp = match self.smtp { + Some(smtp) => Some(smtp.build().await?), + None => None, + }; + + #[cfg(feature = "sendmail")] + let sendmail = match self.sendmail { + Some(sendmail) => Some(sendmail.build().await?), + None => None, + }; + + Ok(Context { + #[cfg(feature = "imap")] + imap, + #[cfg(feature = "maildir")] + maildir, + #[cfg(feature = "notmuch")] + notmuch, + #[cfg(feature = "smtp")] + smtp, + #[cfg(feature = "sendmail")] + sendmail, + }) + } +} diff --git a/src/cli.rs b/src/cli.rs new file mode 100644 index 0000000..cc47e74 --- /dev/null +++ b/src/cli.rs @@ -0,0 +1,35 @@ +use std::path::PathBuf; + +use clap::Parser; +use pimalaya_tui::cli::arg::path_parser; + +#[derive(Parser, Debug)] +#[command(name = "himalaya", author, version, about)] +#[command(propagate_version = true, infer_subcommands = true)] +pub struct Cli { + /// Override the default configuration file path. + /// + /// The given paths are shell-expanded then canonicalized (if + /// applicable). If the first path does not point to a valid file, + /// the wizard will propose to assist you in the creation of the + /// configuration file. Other paths are merged with the first one, + /// which allows you to separate your public config from your + /// private(s) one(s). + #[arg(short, long = "config", global = true, env = "HIMALAYA_CONFIG")] + #[arg(value_name = "PATH", value_parser = path_parser)] + pub config_paths: Vec, + + /// Enable logs with spantrace. + /// + /// This is the same as running the command with `RUST_LOG=debug` + /// environment variable. + #[arg(long, global = true, conflicts_with = "trace")] + pub debug: bool, + + /// Enable verbose logs with backtrace. + /// + /// This is the same as running the command with `RUST_LOG=trace` + /// and `RUST_BACKTRACE=1` environment variables. + #[arg(long, global = true, conflicts_with = "debug")] + pub trace: bool, +} diff --git a/src/config.rs b/src/config.rs new file mode 100644 index 0000000..fb322b7 --- /dev/null +++ b/src/config.rs @@ -0,0 +1,216 @@ +use std::{collections::HashMap, path::PathBuf}; + +use color_eyre::{ + eyre::{bail, eyre}, + Result, +}; +use crossterm::style::Color; +use email::{ + account::config::AccountConfig, + message::{config::MessageConfig, send::config::MessageSendConfig}, +}; +use pimalaya_tui::config::TomlConfig; +use serde::{Deserialize, Serialize}; +use shellexpand_utils::{canonicalize, expand}; + +use crate::account::config::{ListAccountsTableConfig, TomlAccountConfig}; + +/// Represents the user config file. +#[derive(Clone, Debug, Default, Eq, PartialEq, Deserialize, Serialize)] +#[serde(rename_all = "kebab-case", deny_unknown_fields)] +pub struct Config { + #[serde(alias = "name")] + pub display_name: Option, + pub signature: Option, + pub signature_delim: Option, + pub downloads_dir: Option, + pub accounts: HashMap, + pub account: Option, +} + +impl TomlConfig for Config { + fn project_name() -> &'static str { + "himalaya" + } +} + +impl Config { + /// Read and parse the TOML configuration from default paths. + pub async fn from_default_paths() -> Result { + match Self::first_valid_default_path() { + Some(path) => Self::from_paths(&[path]), + None => bail!("cannot find config file from default paths"), + } + } + + /// Read and parse the TOML configuration at the optional given + /// path. + /// + /// If the given path exists, then read and parse the TOML + /// configuration from it. + /// + /// If the given path does not exist, then create it using the + /// wizard. + /// + /// If no path is given, then either read and parse the TOML + /// configuration at the first valid default path, otherwise + /// create it using the wizard. wizard. + pub async fn from_paths_or_default(paths: &[PathBuf]) -> Result { + match paths.len() { + 0 => Self::from_default_paths().await, + _ if paths[0].exists() => Self::from_paths(paths), + _ => bail!("cannot find config file from default paths"), + } + } + + pub fn into_toml_account_config( + &self, + account_name: Option<&str>, + ) -> Result<(String, TomlAccountConfig)> { + #[allow(unused_mut)] + let (account_name, mut toml_account_config) = match account_name { + Some("default") | Some("") | None => self + .accounts + .iter() + .find_map(|(name, account)| { + account + .default + .filter(|default| *default) + .map(|_| (name.to_owned(), account.clone())) + }) + .ok_or_else(|| eyre!("cannot find default account")), + Some(name) => self + .accounts + .get(name) + .map(|account| (name.to_owned(), account.clone())) + .ok_or_else(|| eyre!("cannot find account {name}")), + }?; + + #[cfg(all(feature = "imap", feature = "keyring"))] + if let Some(imap_config) = toml_account_config.imap.as_mut() { + imap_config + .auth + .replace_undefined_keyring_entries(&account_name)?; + } + + #[cfg(all(feature = "smtp", feature = "keyring"))] + if let Some(smtp_config) = toml_account_config.smtp.as_mut() { + smtp_config + .auth + .replace_undefined_keyring_entries(&account_name)?; + } + + Ok((account_name, toml_account_config)) + } + + /// Build account configurations from a given account name. + pub fn into_account_configs( + self, + account_name: Option<&str>, + ) -> Result<(TomlAccountConfig, AccountConfig)> { + let (account_name, toml_account_config) = self.into_toml_account_config(account_name)?; + + let config = email::config::Config { + display_name: self.display_name, + signature: self.signature, + signature_delim: self.signature_delim, + downloads_dir: self.downloads_dir, + + accounts: HashMap::from_iter(self.accounts.clone().into_iter().map( + |(name, config)| { + ( + name.clone(), + AccountConfig { + name, + email: config.email, + display_name: config.display_name, + signature: config.signature, + signature_delim: config.signature_delim, + downloads_dir: config.downloads_dir, + // folder: config.folder.map(|c| FolderConfig { + // aliases: c.alias, + // list: c.list.map(|c| c.remote), + // }), + folder: None, + // envelope: config.envelope.map(|c| EnvelopeConfig { + // list: c.list.map(|c| c.remote), + // thread: c.thread.map(|c| c.remote), + // }), + envelope: None, + // flag: None, + flag: None, + message: config.message.map(|c| MessageConfig { + send: c.send.map(|c| MessageSendConfig { + pre_hook: c.pre_hook, + save_copy: c.save_copy, + }), + ..Default::default() + }), + // template: config.template, + template: None, + #[cfg(feature = "pgp")] + pgp: config.pgp, + }, + ) + }, + )), + }; + + let account_config = config.account(account_name)?; + + Ok((toml_account_config, account_config)) + } + + pub fn account_list_table_preset(&self) -> Option { + self.account + .as_ref() + .and_then(|account| account.list.as_ref()) + .and_then(|list| list.table.as_ref()) + .and_then(|table| table.preset.clone()) + } + + pub fn account_list_table_name_color(&self) -> Option { + self.account + .as_ref() + .and_then(|account| account.list.as_ref()) + .and_then(|list| list.table.as_ref()) + .and_then(|table| table.name_color) + } + + pub fn account_list_table_backends_color(&self) -> Option { + self.account + .as_ref() + .and_then(|account| account.list.as_ref()) + .and_then(|list| list.table.as_ref()) + .and_then(|table| table.backends_color) + } + + pub fn account_list_table_default_color(&self) -> Option { + self.account + .as_ref() + .and_then(|account| account.list.as_ref()) + .and_then(|list| list.table.as_ref()) + .and_then(|table| table.default_color) + } +} + +/// Parse a configuration file path as [`PathBuf`]. +/// +/// The path is shell-expanded then canonicalized (if applicable). +pub fn path_parser(path: &str) -> Result { + expand::try_path(path) + .map(canonicalize::path) + .map_err(|err| err.to_string()) +} + +#[derive(Clone, Debug, Default, Eq, PartialEq, Deserialize, Serialize)] +#[serde(rename_all = "kebab-case")] +pub struct AccountsConfig { + pub list: Option, +} + +#[derive(Clone, Debug, Default, Eq, PartialEq, Deserialize, Serialize)] +#[serde(rename_all = "kebab-case")] +pub struct ListAccountsConfig { + pub table: Option, +} diff --git a/src/envelope.rs b/src/envelope.rs new file mode 100644 index 0000000..65fa291 --- /dev/null +++ b/src/envelope.rs @@ -0,0 +1,372 @@ +use std::{collections::HashSet, fmt, ops::Deref, sync::Arc}; + +use color_eyre::Result; +use comfy_table::{presets, Attribute, Cell, ContentArrangement, Row, Table}; +use crossterm::style::Color; +use email::account::config::AccountConfig; +use serde::{Deserialize, Serialize}; + +use crate::id_mapper::IdMapper; + +#[derive(Clone, Debug, Default, Serialize)] +pub struct Mailbox { + pub name: Option, + pub addr: String, +} + +#[derive(Clone, Debug, Default, Serialize)] +pub struct Envelope { + pub id: String, + pub flags: Flags, + pub subject: String, + pub from: Mailbox, + pub to: Mailbox, + pub date: String, + pub has_attachment: bool, +} + +impl Envelope { + fn to_row(&self, config: &ListEnvelopesTableConfig) -> Row { + let mut all_attributes = vec![]; + + let unseen = !self.flags.contains(&Flag::Seen); + if unseen { + all_attributes.push(Attribute::Bold) + } + + let flags = { + let mut flags = String::new(); + + flags.push(config.flagged_char(self.flags.contains(&Flag::Flagged))); + flags.push(config.unseen_char(unseen)); + flags.push(config.attachment_char(self.has_attachment)); + flags.push(config.replied_char(self.flags.contains(&Flag::Answered))); + + flags + }; + + let mut row = Row::new(); + row.max_height(1); + + row.add_cell( + Cell::new(&self.id) + .add_attributes(all_attributes.clone()) + .fg(config.id_color()), + ) + .add_cell( + Cell::new(flags) + .add_attributes(all_attributes.clone()) + .fg(config.flags_color()), + ) + .add_cell( + Cell::new(&self.subject) + .add_attributes(all_attributes.clone()) + .fg(config.subject_color()), + ) + .add_cell( + Cell::new(if let Some(name) = &self.from.name { + name + } else { + &self.from.addr + }) + .add_attributes(all_attributes.clone()) + .fg(config.sender_color()), + ) + .add_cell( + Cell::new(&self.date) + .add_attributes(all_attributes) + .fg(config.date_color()), + ); + + row + } +} + +#[derive(Clone, Debug, Default, Serialize)] +pub struct Envelopes(Vec); + +impl Envelopes { + pub fn try_from_lib( + config: Arc, + id_mapper: &IdMapper, + envelopes: email::envelope::Envelopes, + ) -> Result { + let envelopes = envelopes + .iter() + .map(|envelope| { + Ok(Envelope { + id: id_mapper.get_or_create_alias(&envelope.id)?, + flags: envelope.flags.clone().into(), + subject: envelope.subject.clone(), + from: Mailbox { + name: envelope.from.name.clone(), + addr: envelope.from.addr.clone(), + }, + to: Mailbox { + name: envelope.to.name.clone(), + addr: envelope.to.addr.clone(), + }, + date: envelope.format_date(&config), + has_attachment: envelope.has_attachment, + }) + }) + .collect::>>()?; + + Ok(Envelopes(envelopes)) + } +} + +impl Deref for Envelopes { + type Target = Vec; + + fn deref(&self) -> &Self::Target { + &self.0 + } +} + +impl Envelopes { + pub fn new(envelopes: Vec) -> Self { + Self(envelopes) + } +} + +pub struct EnvelopesTable { + envelopes: Envelopes, + width: Option, + config: ListEnvelopesTableConfig, +} + +impl EnvelopesTable { + pub fn with_some_width(mut self, width: Option) -> Self { + self.width = width; + self + } + + pub fn with_some_preset(mut self, preset: Option) -> Self { + self.config.preset = preset; + self + } + + pub fn with_some_unseen_char(mut self, char: Option) -> Self { + self.config.unseen_char = char; + self + } + + pub fn with_some_replied_char(mut self, char: Option) -> Self { + self.config.replied_char = char; + self + } + + pub fn with_some_flagged_char(mut self, char: Option) -> Self { + self.config.flagged_char = char; + self + } + + pub fn with_some_attachment_char(mut self, char: Option) -> Self { + self.config.attachment_char = char; + self + } + + pub fn with_some_id_color(mut self, color: Option) -> Self { + self.config.id_color = color; + self + } + + pub fn with_some_flags_color(mut self, color: Option) -> Self { + self.config.flags_color = color; + self + } + + pub fn with_some_subject_color(mut self, color: Option) -> Self { + self.config.subject_color = color; + self + } + + pub fn with_some_sender_color(mut self, color: Option) -> Self { + self.config.sender_color = color; + self + } + + pub fn with_some_date_color(mut self, color: Option) -> Self { + self.config.date_color = color; + self + } +} + +impl From for EnvelopesTable { + fn from(envelopes: Envelopes) -> Self { + Self { + envelopes, + width: None, + config: Default::default(), + } + } +} + +impl fmt::Display for EnvelopesTable { + fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { + let mut table = Table::new(); + + table + .load_preset(self.config.preset()) + .set_content_arrangement(ContentArrangement::DynamicFullWidth) + .set_header(Row::from([ + Cell::new("ID"), + Cell::new("FLAGS"), + Cell::new("SUBJECT"), + Cell::new("FROM"), + Cell::new("DATE"), + ])) + .add_rows(self.envelopes.iter().map(|env| env.to_row(&self.config))); + + if let Some(width) = self.width { + table.set_width(width); + } + + writeln!(f)?; + write!(f, "{table}")?; + writeln!(f)?; + Ok(()) + } +} + +#[derive(Clone, Debug, Default, Eq, PartialEq, Deserialize, Serialize)] +#[serde(rename_all = "kebab-case")] +pub struct ListEnvelopesTableConfig { + pub preset: Option, + + pub unseen_char: Option, + pub replied_char: Option, + pub flagged_char: Option, + pub attachment_char: Option, + + pub id_color: Option, + pub flags_color: Option, + pub subject_color: Option, + pub sender_color: Option, + pub date_color: Option, +} + +impl ListEnvelopesTableConfig { + pub fn preset(&self) -> &str { + self.preset.as_deref().unwrap_or(presets::ASCII_MARKDOWN) + } + + pub fn replied_char(&self, replied: bool) -> char { + if replied { + self.replied_char.unwrap_or('R') + } else { + ' ' + } + } + + pub fn flagged_char(&self, flagged: bool) -> char { + if flagged { + self.flagged_char.unwrap_or('!') + } else { + ' ' + } + } + + pub fn attachment_char(&self, attachment: bool) -> char { + if attachment { + self.attachment_char.unwrap_or('@') + } else { + ' ' + } + } + + pub fn unseen_char(&self, unseen: bool) -> char { + if unseen { + self.unseen_char.unwrap_or('*') + } else { + ' ' + } + } + + pub fn id_color(&self) -> comfy_table::Color { + map_color(self.id_color.unwrap_or(Color::Red)) + } + + pub fn flags_color(&self) -> comfy_table::Color { + map_color(self.flags_color.unwrap_or(Color::Reset)) + } + + pub fn subject_color(&self) -> comfy_table::Color { + map_color(self.subject_color.unwrap_or(Color::Green)) + } + + pub fn sender_color(&self) -> comfy_table::Color { + map_color(self.sender_color.unwrap_or(Color::Blue)) + } + + pub fn date_color(&self) -> comfy_table::Color { + map_color(self.date_color.unwrap_or(Color::DarkYellow)) + } +} + +fn map_color(color: Color) -> comfy_table::Color { + match color { + Color::Reset => comfy_table::Color::Reset, + Color::Black => comfy_table::Color::Black, + Color::DarkGrey => comfy_table::Color::DarkGrey, + Color::Red => comfy_table::Color::Red, + Color::DarkRed => comfy_table::Color::DarkRed, + Color::Green => comfy_table::Color::Green, + Color::DarkGreen => comfy_table::Color::DarkGreen, + Color::Yellow => comfy_table::Color::Yellow, + Color::DarkYellow => comfy_table::Color::DarkYellow, + Color::Blue => comfy_table::Color::Blue, + Color::DarkBlue => comfy_table::Color::DarkBlue, + Color::Magenta => comfy_table::Color::Magenta, + Color::DarkMagenta => comfy_table::Color::DarkMagenta, + Color::Cyan => comfy_table::Color::Cyan, + Color::DarkCyan => comfy_table::Color::DarkCyan, + Color::White => comfy_table::Color::White, + Color::Grey => comfy_table::Color::Grey, + Color::Rgb { r, g, b } => comfy_table::Color::Rgb { r, g, b }, + Color::AnsiValue(n) => comfy_table::Color::AnsiValue(n), + } +} + +/// Represents the flag variants. +#[derive(Clone, Debug, Eq, Hash, PartialEq, Ord, PartialOrd, Serialize)] +pub enum Flag { + Seen, + Answered, + Flagged, + Deleted, + Draft, + Custom(String), +} + +impl From<&email::flag::Flag> for Flag { + fn from(flag: &email::flag::Flag) -> Self { + use email::flag::Flag::*; + match flag { + Seen => Flag::Seen, + Answered => Flag::Answered, + Flagged => Flag::Flagged, + Deleted => Flag::Deleted, + Draft => Flag::Draft, + Custom(flag) => Flag::Custom(flag.clone()), + } + } +} + +#[derive(Clone, Debug, Default, Eq, PartialEq, Serialize)] +pub struct Flags(pub HashSet); + +impl Deref for Flags { + type Target = HashSet; + + fn deref(&self) -> &Self::Target { + &self.0 + } +} + +impl From for Flags { + fn from(flags: email::flag::Flags) -> Self { + Flags(flags.iter().map(Flag::from).collect()) + } +} diff --git a/src/id_mapper.rs b/src/id_mapper.rs new file mode 100644 index 0000000..06c2d74 --- /dev/null +++ b/src/id_mapper.rs @@ -0,0 +1,142 @@ +use color_eyre::{eyre::eyre, eyre::Context, Result}; +use dirs::data_dir; +use email::account::config::AccountConfig; +use sled::{Config, Db}; +use std::collections::HashSet; +use tracing::debug; + +#[derive(Debug)] +pub enum IdMapper { + Dummy, + Mapper(Db), +} + +impl IdMapper { + pub fn new(account_config: &AccountConfig, folder: &str) -> Result { + let digest = md5::compute(account_config.name.clone() + folder); + let db_path = data_dir() + .ok_or(eyre!("cannot get XDG data directory"))? + .join("himalaya") + .join(".id-mappers") + .join(format!("{digest:x}")); + + let conn = Config::new() + .path(&db_path) + .idgen_persist_interval(1) + .open() + .with_context(|| format!("cannot open id mapper database at {db_path:?}"))?; + + Ok(Self::Mapper(conn)) + } + + pub fn create_alias(&self, id: I) -> Result + where + I: AsRef, + { + let id = id.as_ref(); + match self { + Self::Dummy => Ok(id.to_owned()), + Self::Mapper(conn) => { + debug!("creating alias for id {id}…"); + + let alias = conn + .generate_id() + .with_context(|| format!("cannot create alias for id {id}"))? + .to_string(); + debug!("created alias {alias} for id {id}"); + + conn.insert(&id, alias.as_bytes()) + .with_context(|| format!("cannot insert alias {alias} for id {id}"))?; + + Ok(alias) + } + } + } + + pub fn get_or_create_alias(&self, id: I) -> Result + where + I: AsRef, + { + let id = id.as_ref(); + match self { + Self::Dummy => Ok(id.to_owned()), + Self::Mapper(conn) => { + debug!("getting alias for id {id}…"); + + let alias = conn + .get(id) + .with_context(|| format!("cannot get alias for id {id}"))?; + + let alias = match alias { + Some(alias) => { + let alias = String::from_utf8_lossy(alias.as_ref()); + debug!("found alias {alias} for id {id}"); + alias.to_string() + } + None => { + debug!("alias not found, creating it…"); + self.create_alias(id)? + } + }; + + Ok(alias) + } + } + } + + pub fn get_id(&self, alias: A) -> Result + where + A: ToString, + { + let alias = alias.to_string(); + + match self { + Self::Dummy => Ok(alias.to_string()), + Self::Mapper(conn) => { + debug!("getting id from alias {alias}…"); + + let id = conn + .iter() + .flat_map(|entry| entry) + .find_map(|(entry_id, entry_alias)| { + if entry_alias.as_ref() == alias.as_bytes() { + let entry_id = String::from_utf8_lossy(entry_id.as_ref()); + Some(entry_id.to_string()) + } else { + None + } + }) + .ok_or_else(|| eyre!("cannot get id from alias {alias}"))?; + debug!("found id {id} from alias {alias}"); + + Ok(id) + } + } + } + + pub fn get_ids(&self, aliases: impl IntoIterator) -> Result> { + let aliases: Vec = aliases.into_iter().map(|alias| alias.to_string()).collect(); + + match self { + Self::Dummy => Ok(aliases), + Self::Mapper(conn) => { + let aliases: HashSet<&str> = aliases.iter().map(|alias| alias.as_str()).collect(); + let ids: Vec = conn + .iter() + .flat_map(|entry| entry) + .filter_map(|(entry_id, entry_alias)| { + let alias = String::from_utf8_lossy(entry_alias.as_ref()); + if aliases.contains(alias.as_ref()) { + let entry_id = String::from_utf8_lossy(entry_id.as_ref()); + Some(entry_id.to_string()) + } else { + None + } + }) + .collect(); + + Ok(ids) + } + } + } +} diff --git a/src/main.rs b/src/main.rs index 64720ca..af5af82 100644 --- a/src/main.rs +++ b/src/main.rs @@ -1,285 +1,183 @@ +pub mod account; +pub mod backend; +pub mod cli; +pub mod config; +pub mod envelope; +pub mod id_mapper; + use std::{ - collections::{HashSet, VecDeque}, - hash::{Hash, Hasher}, + ops::{Deref, DerefMut}, + sync::Arc, }; +use backend::BackendKind; +use clap::Parser; +use cli::Cli; use color_eyre::Result; -use comfy_table::{presets::UTF8_FULL, Cell, ContentArrangement, Table}; -use fuzzy_matcher::{skim::SkimMatcherV2, FuzzyMatcher}; -use once_cell::sync::Lazy; -use ratatui::{ - crossterm::event::{self, Event, KeyCode, KeyModifiers}, - layout::{Constraint, Layout, Position}, - style::Stylize, - text::{Line, Text}, - widgets::{List, ListItem, Paragraph}, - DefaultTerminal, Frame, +#[cfg(feature = "imap")] +use email::imap::ImapContextBuilder; +#[cfg(feature = "maildir")] +use email::maildir::MaildirContextBuilder; +#[cfg(feature = "notmuch")] +use email::notmuch::NotmuchContextBuilder; +#[cfg(feature = "sendmail")] +use email::sendmail::SendmailContextBuilder; +#[cfg(feature = "smtp")] +use email::smtp::SmtpContextBuilder; +use email::{backend::BackendBuilder, folder::list::ListFolders}; + +use pimalaya_tui::cli::tracing; +use reedline::{ + default_emacs_keybindings, ColumnarMenu, DefaultCompleter, DefaultPrompt, DefaultPromptSegment, + Emacs, KeyCode, KeyModifiers, MenuBuilder, Reedline, ReedlineEvent, ReedlineMenu, Signal, }; -static COMMANDS: Lazy> = Lazy::new(|| { - HashSet::from_iter([ - Command::new("account").with_children([Command::new("list"), Command::new("doctor")]), - Command::new("folder").with_children([ - Command::new("add"), - Command::new("list"), - Command::new("expunge"), - Command::new("purge"), - Command::new("delete"), - ]), - Command::new("envelope").with_children([Command::new("list"), Command::new("thread")]), - Command::new("flag").with_children([ - Command::new("add"), - Command::new("set"), - Command::new("remove"), - ]), - Command::new("message").with_children([ - Command::new("read"), - Command::new("thread"), - Command::new("write"), - Command::new("reply"), - Command::new("forward"), - Command::new("copy"), - Command::new("move"), - Command::new("delete"), - ]), - ]) -}); - -struct App { - input: String, - character_index: usize, - choices: Vec, - log: String, - table: bool, -} - -impl App { - fn new() -> Self { - Self { - input: String::new(), - character_index: 0, - choices: Vec::new(), - log: String::new(), - table: false, - } - } - - fn move_cursor_left(&mut self) { - let cursor_moved_left = self.character_index.saturating_sub(1); - self.character_index = self.clamp_cursor(cursor_moved_left); - } - - fn move_cursor_right(&mut self) { - let cursor_moved_right = self.character_index.saturating_add(1); - self.character_index = self.clamp_cursor(cursor_moved_right); - } - - fn enter_char(&mut self, new_char: char) { - let index = self.byte_index(); - self.input.insert(index, new_char); - self.move_cursor_right(); - } - - fn byte_index(&self) -> usize { - self.input - .char_indices() - .map(|(i, _)| i) - .nth(self.character_index) - .unwrap_or(self.input.len()) - } - - fn delete_char(&mut self) { - let is_not_cursor_leftmost = self.character_index != 0; - if is_not_cursor_leftmost { - let current_index = self.character_index; - let from_left_to_current_index = current_index - 1; - - let before_char_to_delete = self.input.chars().take(from_left_to_current_index); - let after_char_to_delete = self.input.chars().skip(current_index); - self.input = before_char_to_delete.chain(after_char_to_delete).collect(); - self.move_cursor_left(); - } - } - - fn clamp_cursor(&self, new_cursor_pos: usize) -> usize { - new_cursor_pos.clamp(0, self.input.chars().count()) - } - - fn reset_cursor(&mut self) { - self.character_index = 0; - } - - fn submit(&mut self) { - self.input.clear(); - self.reset_cursor(); - self.table = true; - } - - fn complete(&mut self) { - self.choices.clear(); - - let mut cmds = COMMANDS.clone(); - let mut names = VecDeque::new(); - - for name in self.input.split_whitespace() { - let cmd = Command::new(name); - names.push_back(name); - - if let Some(cmd) = cmds.get(&cmd) { - cmds = cmd.children.clone(); - } - } - - let matcher = SkimMatcherV2::default(); - let mut matches = HashSet::new(); - - let input = names.pop_back().unwrap_or(&self.input); - - for (i, cmd) in cmds.into_iter().enumerate() { - if input.is_empty() || self.input.ends_with(' ') { - matches.insert((i as i64, cmd)); - } else if let Some(score) = matcher.fuzzy_match(&cmd.name, input) { - matches.insert((score, cmd)); - } - } - - match matches.len() { - 0 => { - return; - } - 1 => { - names.push_back(&matches.iter().next().unwrap().1.name); - self.input = names.iter().map(|name| name.to_string() + " ").collect(); - self.character_index = self.input.chars().count(); - } - _ => { - let mut scores: Vec<_> = matches.iter().cloned().collect(); - scores.sort_by(|(a, _), (b, _)| a.cmp(b)); - - for (_, cmd) in scores { - self.choices.push(cmd.name) +use crate::{backend::ContextBuilder, config::Config}; + +#[tokio::main] +async fn main() -> Result<()> { + tracing::install()?; + + let cli = Cli::parse(); + + println!("Welcome to Himalaya REPL!"); + println!("Connecting…"); + + let config = Config::from_paths_or_default(&cli.config_paths).await?; + let (toml_account_config, account_config) = config.into_account_configs(None)?; + let account_config = Arc::new(account_config); + + let backend = BackendBuilder::new( + account_config.clone(), + ContextBuilder { + backend: toml_account_config.backend.unwrap_or(BackendKind::None), + sending_backend: toml_account_config + .message + .and_then(|c| c.send) + .and_then(|c| c.backend) + .unwrap_or(BackendKind::None), + + #[cfg(feature = "imap")] + imap: toml_account_config + .imap + .map(|imap| ImapContextBuilder::new(account_config.clone(), Arc::new(imap))), + #[cfg(feature = "maildir")] + maildir: toml_account_config.maildir.map(|maildir| { + MaildirContextBuilder::new(account_config.clone(), Arc::new(maildir)) + }), + #[cfg(feature = "notmuch")] + notmuch: toml_account_config.notmuch.map(|notmuch| { + NotmuchContextBuilder::new(account_config.clone(), Arc::new(notmuch)) + }), + #[cfg(feature = "smtp")] + smtp: toml_account_config + .smtp + .map(|smtp| SmtpContextBuilder::new(account_config.clone(), Arc::new(smtp))), + #[cfg(feature = "sendmail")] + sendmail: toml_account_config.sendmail.map(|sendmail| { + SendmailContextBuilder::new(account_config.clone(), Arc::new(sendmail)) + }), + }, + ) + .build() + .await?; + + println!(); + + let mut mode_kind = Mode::Unselected; + let mut mode = UnselectedMode::new(); + + let prompt = DefaultPrompt::new( + DefaultPromptSegment::Basic(String::from("himalaya-repl")), + DefaultPromptSegment::Empty, + ); + + let mut folder = Option::<&str>::None; + + loop { + match mode.read_line(&prompt)? { + Signal::Success(cmd) => match cmd.as_str() { + "list" => { + let folders = backend.list_folders().await?; + println!("folders: {folders:?}"); } - } - } - } - - fn run(mut self, mut terminal: DefaultTerminal) -> Result<()> { - loop { - terminal.draw(|frame| self.draw(frame))?; - - if let Event::Key(key) = event::read()? { - match key.code { - KeyCode::Tab => self.complete(), - KeyCode::Enter => self.submit(), - KeyCode::Char('c') if key.modifiers.contains(KeyModifiers::CONTROL) => { - return Ok(()); - } - KeyCode::Char(c) => self.enter_char(c), - KeyCode::Backspace => self.delete_char(), - KeyCode::Left => self.move_cursor_left(), - KeyCode::Right => self.move_cursor_right(), - _ => {} + "select" => { + // TODO: select folder + let folders = backend.list_folders().await?; + println!("folders: {folders:?}"); + } + // "envelope list" => { + // let id_mapper = IdMapper::Dummy; + // let envelopes = backend + // .list_envelopes( + // "INBOX", + // ListEnvelopesOptions { + // page_size: 10, + // ..Default::default() + // }, + // ) + // .await?; + // let envelopes = + // Envelopes::try_from_lib(account_config.clone(), &id_mapper, envelopes)?; + // let table = EnvelopesTable::from(envelopes); + // println!("{table}"); + // } + cmd => { + eprintln!("{cmd}: command not found"); } + }, + Signal::CtrlD | Signal::CtrlC => { + println!("Bye!"); + break; } } } - fn draw(&self, frame: &mut Frame) { - let prompt = "himalaya $ "; - - let layout = Layout::vertical([ - Constraint::Fill(1), - Constraint::Length(self.choices.len() as u16), - Constraint::Length(1), - ]); - - let [output_area, completion_area, input_area] = layout.areas(frame.area()); - - if self.table { - let mut table = Table::new(); - - table - .load_preset(UTF8_FULL) - .set_content_arrangement(ContentArrangement::DynamicFullWidth) - .set_width(80) - .set_header(vec![ - Cell::new("Header1"), - Cell::new("Header2"), - Cell::new("Header3"), - ]) - .add_row(vec![ - Cell::new("This is a bold text"), - Cell::new("This is a green text"), - Cell::new("This one has black background"), - ]) - .add_row(vec![ - Cell::new("Blinky boi"), - Cell::new("Blinky boi"), - Cell::new("COMBINE ALL THE THINGS"), - ]) - .set_width(output_area.width); - - frame.render_widget(Paragraph::new(table.to_string()), output_area); - } + Ok(()) +} - let items = self - .choices - .iter() - .map(|choice| ListItem::new(Text::raw(choice).cyan())); +enum Mode { + Unselected, + Selected, +} - frame.render_widget(List::new(items), completion_area); +struct UnselectedMode(Reedline); - let prompt_layout = - Layout::horizontal([Constraint::Length(prompt.len() as u16), Constraint::Fill(1)]); +impl UnselectedMode { + pub fn new() -> impl DerefMut { + let commands = vec!["create".into(), "list".into(), "select".into()]; + let completer = Box::new(DefaultCompleter::new_with_wordlen(commands.clone(), 2)); + let completion_menu = Box::new(ColumnarMenu::default().with_name("completion")); - let [prompt_area, input_area] = prompt_layout.areas(input_area); + let mut keybinds = default_emacs_keybindings(); + keybinds.add_binding( + KeyModifiers::NONE, + KeyCode::Tab, + ReedlineEvent::UntilFound(vec![ + ReedlineEvent::Menu("completion".to_string()), + ReedlineEvent::MenuNext, + ]), + ); - frame.render_widget(Text::raw(prompt).blue(), prompt_area); - frame.render_widget(&self.input, input_area); + let reedline = Reedline::create() + .with_completer(completer) + .with_menu(ReedlineMenu::EngineCompleter(completion_menu)) + .with_edit_mode(Box::new(Emacs::new(keybinds))); - frame.set_cursor_position(Position::new( - input_area.x + self.character_index as u16, - input_area.y, - )) + Self(reedline) } } -#[derive(Clone, Debug, Eq)] -struct Command { - name: String, - children: HashSet, -} +impl Deref for UnselectedMode { + type Target = Reedline; -impl PartialEq for Command { - fn eq(&self, other: &Self) -> bool { - self.name == other.name + fn deref(&self) -> &Self::Target { + &self.0 } } -impl Hash for Command { - fn hash(&self, state: &mut H) { - self.name.hash(state); +impl DerefMut for UnselectedMode { + fn deref_mut(&mut self) -> &mut Self::Target { + &mut self.0 } } - -impl Command { - pub fn new(name: impl ToString) -> Self { - Self { - name: name.to_string(), - children: HashSet::new(), - } - } - - fn with_children(mut self, children: impl IntoIterator) -> Self { - self.children = children.into_iter().collect(); - self - } -} - -fn main() -> Result<()> { - color_eyre::install()?; - let terminal = ratatui::init(); - let app_result = App::new().run(terminal); - ratatui::restore(); - app_result -}