put back real himalaya sources

This commit is contained in:
Clément DOUIN
2024-11-26 10:46:07 +01:00
parent 69e66b307a
commit 842db08710
7 changed files with 4900 additions and 251 deletions

4714
Cargo.lock generated

File diff suppressed because it is too large Load Diff

View File

@@ -15,67 +15,66 @@ repository = "https://github.com/pimalaya/himalaya/"
features = ["imap", "maildir", "smtp", "sendmail", "oauth2", "wizard", "pgp-commands", "pgp-native"]
rustdoc-args = ["--cfg", "docsrs"]
# [features]
# default = [
# "imap",
# "maildir",
# #"notmuch",
# "smtp",
# #"sendmail",
# #"keyring",
# #"oauth2",
# "wizard",
# #"pgp-commands",
# #"pgp-gpg",
# #"pgp-native",
# ]
[features]
default = [
"imap",
"maildir",
#"notmuch",
"smtp",
#"sendmail",
#"keyring",
#"oauth2",
"wizard",
#"pgp-commands",
#"pgp-gpg",
#"pgp-native",
]
# imap = ["email-lib/imap", "pimalaya-tui/imap"]
# maildir = ["email-lib/maildir", "pimalaya-tui/maildir"]
# notmuch = ["email-lib/notmuch", "pimalaya-tui/notmuch"]
# smtp = ["email-lib/smtp", "pimalaya-tui/smtp"]
# sendmail = ["email-lib/sendmail", "pimalaya-tui/sendmail"]
imap = ["email-lib/imap", "pimalaya-tui/imap"]
maildir = ["email-lib/maildir", "pimalaya-tui/maildir"]
notmuch = ["email-lib/notmuch", "pimalaya-tui/notmuch"]
smtp = ["email-lib/smtp", "pimalaya-tui/smtp"]
sendmail = ["email-lib/sendmail", "pimalaya-tui/sendmail"]
# keyring = ["email-lib/keyring", "pimalaya-tui/keyring", "secret-lib/keyring"]
# oauth2 = ["email-lib/oauth2", "pimalaya-tui/oauth2", "keyring"]
# wizard = ["email-lib/autoconfig", "pimalaya-tui/wizard"]
keyring = ["email-lib/keyring", "pimalaya-tui/keyring", "secret-lib/keyring"]
oauth2 = ["email-lib/oauth2", "pimalaya-tui/oauth2", "keyring"]
wizard = ["email-lib/autoconfig", "pimalaya-tui/wizard"]
# pgp = []
# pgp-commands = ["email-lib/pgp-commands", "mml-lib/pgp-commands", "pimalaya-tui/pgp-commands", "pgp"]
# pgp-gpg = ["email-lib/pgp-gpg", "mml-lib/pgp-gpg", "pimalaya-tui/pgp-gpg", "pgp"]
# pgp-native = ["email-lib/pgp-native", "mml-lib/pgp-native", "pimalaya-tui/pgp-native", "pgp"]
pgp = []
pgp-commands = ["email-lib/pgp-commands", "mml-lib/pgp-commands", "pimalaya-tui/pgp-commands", "pgp"]
pgp-gpg = ["email-lib/pgp-gpg", "mml-lib/pgp-gpg", "pimalaya-tui/pgp-gpg", "pgp"]
pgp-native = ["email-lib/pgp-native", "mml-lib/pgp-native", "pimalaya-tui/pgp-native", "pgp"]
# [build-dependencies]
# git2 = { version = "0.19", default-features = false }
# serde = { version = "1", features = ["derive"] }
# toml = "0.8"
[build-dependencies]
git2 = { version = "0.19", default-features = false }
serde = { version = "1", features = ["derive"] }
toml = "0.8"
[dependencies]
rustls-platform-verifier = "0.4.0"
# ariadne = "0.2"
# clap = { version = "4.4", features = ["derive", "env", "wrap_help"] }
# clap_complete = "4.4"
# clap_mangen = "0.2"
# color-eyre = "0.6"
# email-lib = { version = "=0.26", default-features = false, features = ["tokio-rustls", "derive", "thread"] }
# mail-builder = "0.3"
# mml-lib = { version = "1", default-features = false, features = ["compiler", "interpreter", "derive"] }
# once_cell = "1.16"
# pimalaya-tui = { version = "=0.1", default-features = false, features = ["email", "path", "cli", "himalaya", "tracing", "sled"] }
# secret-lib = { version = "1", default-features = false, features = ["tokio", "rustls", "command", "derive"] }
# serde = { version = "1", features = ["derive"] }
# serde_json = "1"
# shellexpand-utils = "=0.2.1"
# tokio = { version = "1.23", default-features = false, features = ["macros", "rt-multi-thread"] }
# toml = "0.8"
# tracing = "0.1"
# url = "2.2"
# uuid = { version = "0.8", features = ["v4"] }
ariadne = "0.2"
clap = { version = "4.4", features = ["derive", "env", "wrap_help"] }
clap_complete = "4.4"
clap_mangen = "0.2"
color-eyre = "0.6"
email-lib = { version = "=0.26", default-features = false, features = ["tokio-rustls", "derive", "thread"] }
mail-builder = "0.3"
mml-lib = { version = "1", default-features = false, features = ["compiler", "interpreter", "derive"] }
once_cell = "1.16"
pimalaya-tui = { version = "=0.1", default-features = false, features = ["email", "path", "cli", "himalaya", "tracing", "sled"] }
secret-lib = { version = "1", default-features = false, features = ["tokio", "rustls", "command", "derive"] }
serde = { version = "1", features = ["derive"] }
serde_json = "1"
shellexpand-utils = "=0.2.1"
tokio = { version = "1.23", default-features = false, features = ["macros", "rt-multi-thread"] }
toml = "0.8"
tracing = "0.1"
url = "2.2"
uuid = { version = "0.8", features = ["v4"] }
# [patch.crates-io]
# email-lib = { git = "https://github.com/pimalaya/core" }
# mml-lib = { git = "https://github.com/pimalaya/core" }
# oauth-lib = { git = "https://github.com/pimalaya/core" }
# pimalaya-tui = { git = "https://github.com/pimalaya/tui" }
# process-lib = { git = "https://github.com/pimalaya/core" }
# secret-lib = { git = "https://github.com/pimalaya/core" }
[patch.crates-io]
email-lib = { git = "https://github.com/pimalaya/core" }
mml-lib = { git = "https://github.com/pimalaya/core" }
oauth-lib = { git = "https://github.com/pimalaya/core" }
pimalaya-tui = { git = "https://github.com/pimalaya/tui" }
process-lib = { git = "https://github.com/pimalaya/core" }
secret-lib = { git = "https://github.com/pimalaya/core" }

210
build.rs
View File

@@ -1,126 +1,126 @@
// use std::{
// collections::HashMap,
// env::{self, VarError},
// };
use std::{
collections::HashMap,
env::{self, VarError},
};
// use git2::{DescribeOptions, Repository};
// use serde::Deserialize;
use git2::{DescribeOptions, Repository};
use serde::Deserialize;
fn main() {
// features_env();
// target_envs();
// git_envs();
features_env();
target_envs();
git_envs();
}
// /// Builds the `CARGO_FEATURES` environment variable.
// ///
// /// This function turns enabled cargo features into a simple string
// /// `+feature1 +feature2 +featureN`, which then exposes it via the
// /// `CARGO_FEATURES` environment variable.
// ///
// /// It first reads and parses the Cargo.toml in order to extract all
// /// available features (omitting "default"). It then checks for
// /// enabled features via `CARGO_FEATURE_<name>` to finally collect
// /// them into a string.
// fn features_env() {
// #[derive(Deserialize)]
// struct Config {
// features: HashMap<String, Vec<String>>,
// }
/// Builds the `CARGO_FEATURES` environment variable.
///
/// This function turns enabled cargo features into a simple string
/// `+feature1 +feature2 +featureN`, which then exposes it via the
/// `CARGO_FEATURES` environment variable.
///
/// It first reads and parses the Cargo.toml in order to extract all
/// available features (omitting "default"). It then checks for
/// enabled features via `CARGO_FEATURE_<name>` to finally collect
/// them into a string.
fn features_env() {
#[derive(Deserialize)]
struct Config {
features: HashMap<String, Vec<String>>,
}
// impl Config {
// fn enabled_features(self) -> impl Iterator<Item = String> {
// self.features
// .into_keys()
// .filter(|feature| feature != "default")
// .filter(|feature| {
// let feature = feature.replace('-', "_").to_uppercase();
// env::var(format!("CARGO_FEATURE_{feature}")).is_ok()
// })
// }
// }
impl Config {
fn enabled_features(self) -> impl Iterator<Item = String> {
self.features
.into_keys()
.filter(|feature| feature != "default")
.filter(|feature| {
let feature = feature.replace('-', "_").to_uppercase();
env::var(format!("CARGO_FEATURE_{feature}")).is_ok()
})
}
}
// let config: Config =
// toml::from_str(include_str!("./Cargo.toml")).expect("should parse Cargo.toml");
let config: Config =
toml::from_str(include_str!("./Cargo.toml")).expect("should parse Cargo.toml");
// let mut features = String::new();
let mut features = String::new();
// for feature in config.enabled_features() {
// if !features.is_empty() {
// features.push(' ');
// }
// features.push_str(&format!("+{feature}"));
// }
for feature in config.enabled_features() {
if !features.is_empty() {
features.push(' ');
}
features.push_str(&format!("+{feature}"));
}
// println!("cargo::rustc-env=CARGO_FEATURES={features}");
// }
println!("cargo::rustc-env=CARGO_FEATURES={features}");
}
// /// Builds environment variables related to the target platform.
// ///
// /// This function basically forwards existing cargo environments
// /// related to the target platform.
// fn target_envs() {
// forward_env("CARGO_CFG_TARGET_OS");
// forward_env("CARGO_CFG_TARGET_ENV");
// forward_env("CARGO_CFG_TARGET_ARCH");
// }
/// Builds environment variables related to the target platform.
///
/// This function basically forwards existing cargo environments
/// related to the target platform.
fn target_envs() {
forward_env("CARGO_CFG_TARGET_OS");
forward_env("CARGO_CFG_TARGET_ENV");
forward_env("CARGO_CFG_TARGET_ARCH");
}
// /// Builds environment variables related to git.
// ///
// /// This function basically tries to forward existing git environment
// /// variables. In case of failure, it tries to build them using
// /// [`git2`].
// fn git_envs() {
// // skip the process if the current directory is not a git
// // repository (for example, from a nix build root jail)
// let Ok(git) = Repository::open(".") else {
// println!("cargo::rustc-env=GIT_DESCRIBE=unknown");
// println!("cargo::rustc-env=GIT_REV=unknown");
// return;
// };
/// Builds environment variables related to git.
///
/// This function basically tries to forward existing git environment
/// variables. In case of failure, it tries to build them using
/// [`git2`].
fn git_envs() {
// skip the process if the current directory is not a git
// repository (for example, from a nix build root jail)
let Ok(git) = Repository::open(".") else {
println!("cargo::rustc-env=GIT_DESCRIBE=unknown");
println!("cargo::rustc-env=GIT_REV=unknown");
return;
};
// if try_forward_env("GIT_DESCRIBE").is_err() {
// let mut opts = DescribeOptions::new();
// opts.describe_all();
// opts.show_commit_oid_as_fallback(true);
if try_forward_env("GIT_DESCRIBE").is_err() {
let mut opts = DescribeOptions::new();
opts.describe_all();
opts.show_commit_oid_as_fallback(true);
// let description = git
// .describe(&opts)
// .expect("should describe git object")
// .format(None)
// .expect("should format git object description");
let description = git
.describe(&opts)
.expect("should describe git object")
.format(None)
.expect("should format git object description");
// println!("cargo::rustc-env=GIT_DESCRIBE={description}");
// };
println!("cargo::rustc-env=GIT_DESCRIBE={description}");
};
// if try_forward_env("GIT_REV").is_err() {
// let head = git.head().expect("should get git HEAD");
// let commit = head.peel_to_commit().expect("should get git HEAD commit");
// let rev = commit.id().to_string();
if try_forward_env("GIT_REV").is_err() {
let head = git.head().expect("should get git HEAD");
let commit = head.peel_to_commit().expect("should get git HEAD commit");
let rev = commit.id().to_string();
// println!("cargo::rustc-env=GIT_REV={rev}");
// };
// }
println!("cargo::rustc-env=GIT_REV={rev}");
};
}
// /// Tries to forward the given environment variable.
// ///
// /// For a more strict version, see [`forward_env`].
// fn try_forward_env(key: &str) -> Result<String, VarError> {
// let env = env::var(key);
/// Tries to forward the given environment variable.
///
/// For a more strict version, see [`forward_env`].
fn try_forward_env(key: &str) -> Result<String, VarError> {
let env = env::var(key);
// if let Ok(val) = &env {
// println!("cargo::rustc-env={key}={val}");
// }
if let Ok(val) = &env {
println!("cargo::rustc-env={key}={val}");
}
// env
// }
env
}
// /// Forwards the given environment variable.
// ///
// /// This function panics in case the forward fails (when the
// /// environment variable does not exist for example).
// ///
// /// For a less strict version, see [`try_forward_env`].
// fn forward_env(key: &str) {
// try_forward_env(key).expect(&format!("should get env {key}"));
// }
/// Forwards the given environment variable.
///
/// This function panics in case the forward fails (when the
/// environment variable does not exist for example).
///
/// For a less strict version, see [`try_forward_env`].
fn forward_env(key: &str) {
try_forward_env(key).expect(&format!("should get env {key}"));
}

View File

@@ -19,9 +19,9 @@ let
inherit (pkgs) lib hostPlatform;
fenix = import (fetchTarball "https://github.com/soywod/fenix/archive/main.tar.gz") { };
mkToolchain = import ./rust-toolchain.nix fenix;
mkToolchain = import ./rust-toolchain.nix { inherit lib fenix; };
rustTarget = if isNull target then null else hostPlatform.rust.rustcTarget;
rustToolchain = mkToolchain.fromTarget { inherit lib; target = rustTarget; };
rustToolchain = mkToolchain.fromTarget rustTarget;
rustPlatform = pkgs.makeRustPlatform {
rustc = rustToolchain;
cargo = rustToolchain;

View File

@@ -1,4 +1,4 @@
fenix:
{ lib, fenix }:
let
file = ./rust-toolchain.toml;
@@ -6,18 +6,14 @@ let
in
{
# fromFile = { buildSystem }: fenix.packages.${buildSystem}.fromToolchainFile {
# inherit file sha256;
# };
fromTarget = { lib, target ? null }:
fromTarget = target:
let
name = (lib.importTOML file).toolchain.channel;
specs = { inherit name sha256; };
toolchain = fenix.fromToolchainName specs;
crossToolchain = fenix.targets.${target}.fromToolchainName specs;
components = [ toolchain.rustc toolchain.cargo ]
++ lib.optional (!isNull target) crossToolchain;
++ lib.optional (!isNull target) crossToolchain.rust-std;
in
fenix.combine components;

View File

@@ -1,10 +1,10 @@
// pub mod account;
// pub mod cli;
// pub mod completion;
// pub mod config;
// pub mod email;
// pub mod folder;
// pub mod manual;
pub mod account;
pub mod cli;
pub mod completion;
pub mod config;
pub mod email;
pub mod folder;
pub mod manual;
// #[doc(inline)]
// pub use crate::email::{envelope, flag, message};
#[doc(inline)]
pub use crate::email::{envelope, flag, message};

View File

@@ -1,51 +1,47 @@
// use clap::Parser;
// use color_eyre::Result;
// use himalaya::{
// cli::Cli, config::TomlConfig, envelope::command::list::ListEnvelopesCommand,
// message::command::mailto::MessageMailtoCommand,
// };
// use pimalaya_tui::terminal::{
// cli::{printer::StdoutPrinter, tracing},
// config::TomlConfig as _,
// };
use clap::Parser;
use color_eyre::Result;
use himalaya::{
cli::Cli, config::TomlConfig, envelope::command::list::ListEnvelopesCommand,
message::command::mailto::MessageMailtoCommand,
};
use pimalaya_tui::terminal::{
cli::{printer::StdoutPrinter, tracing},
config::TomlConfig as _,
};
// #[tokio::main]
// async fn main() -> Result<()> {
// let tracing = tracing::install()?;
#[tokio::main]
async fn main() -> Result<()> {
let tracing = tracing::install()?;
// #[cfg(feature = "keyring")]
// secret::keyring::set_global_service_name("himalaya-cli");
#[cfg(feature = "keyring")]
secret::keyring::set_global_service_name("himalaya-cli");
// // if the first argument starts by "mailto:", execute straight the
// // mailto message command
// let mailto = std::env::args()
// .nth(1)
// .filter(|arg| arg.starts_with("mailto:"));
// if the first argument starts by "mailto:", execute straight the
// mailto message command
let mailto = std::env::args()
.nth(1)
.filter(|arg| arg.starts_with("mailto:"));
// if let Some(ref url) = mailto {
// let mut printer = StdoutPrinter::default();
// let config = TomlConfig::from_default_paths().await?;
if let Some(ref url) = mailto {
let mut printer = StdoutPrinter::default();
let config = TomlConfig::from_default_paths().await?;
// return MessageMailtoCommand::new(url)?
// .execute(&mut printer, &config)
// .await;
// }
return MessageMailtoCommand::new(url)?
.execute(&mut printer, &config)
.await;
}
// let cli = Cli::parse();
// let mut printer = StdoutPrinter::new(cli.output);
// let res = match cli.command {
// Some(cmd) => cmd.execute(&mut printer, cli.config_paths.as_ref()).await,
// None => {
// let config = TomlConfig::from_paths_or_default(cli.config_paths.as_ref()).await?;
// ListEnvelopesCommand::default()
// .execute(&mut printer, &config)
// .await
// }
// };
// tracing.with_debug_and_trace_notes(res)
// }
fn main() {
println!("Hello, world!");
let cli = Cli::parse();
let mut printer = StdoutPrinter::new(cli.output);
let res = match cli.command {
Some(cmd) => cmd.execute(&mut printer, cli.config_paths.as_ref()).await,
None => {
let config = TomlConfig::from_paths_or_default(cli.config_paths.as_ref()).await?;
ListEnvelopesCommand::default()
.execute(&mut printer, &config)
.await
}
};
tracing.with_debug_and_trace_notes(res)
}