C12.4: mail credentials and OAuth sign-in

Passwords and refresh tokens go only to the system keychain; a refused
keychain keeps them in memory until exit and says why. Gmail and
Microsoft sign in by authorization code with S256 PKCE on a loopback
redirect; refresh tokens are kept, and revoked grants ask to sign in
again. Client IDs come from the build (env or oauth.env). ureq trace
records never reach the log.

Co-Authored-By: Claude <noreply@anthropic.com>
This commit is contained in:
ZacharyZhang-NYandClaude committed 2026-10-19 18:59:56 -04:00
1 parent 7c5bf48589
commit bd68382921
19 files changed
+1065 -6

No files matched your search

+32 -4
View File
@@ -7,7 +7,8 @@ use std::{
};
use anyhow::{Context, Result};
use env_logger::{Builder, Env, Target};
use env_logger::{Builder, Env, Logger, Target};
use log::{Level, Log, Metadata, Record};
use crate::{AppId, data_dir};
@@ -28,6 +29,31 @@ impl Write for Tee {
}
}
/// The HTTP library logs raw bytes, tokens too.
struct Private(Logger);
fn wire(meta: &Metadata) -> bool {
let target = meta.target();
let http = target == "ureq" || target.starts_with("ureq::") || target.starts_with("ureq_proto");
http && meta.level() > Level::Info
}
impl Log for Private {
fn enabled(&self, meta: &Metadata) -> bool {
!wire(meta) && self.0.enabled(meta)
}
fn log(&self, record: &Record) {
if self.enabled(record.metadata()) {
self.0.log(record);
}
}
fn flush(&self) {
self.0.flush();
}
}
/// The file logging writes to; none until `init` succeeds.
pub fn path() -> Option<&'static Path> {
LOG_PATH.get().map(PathBuf::as_path)
@@ -66,10 +92,12 @@ pub fn init_in(app: AppId, dir: &Path) -> Result<()> {
.append(true)
.open(&path)
.with_context(|| format!("cannot open {}", path.display()))?;
Builder::from_env(Env::new().filter_or("ELY_LOG", "info"))
let logger = Builder::from_env(Env::new().filter_or("ELY_LOG", "info"))
.target(Target::Pipe(Box::new(Tee(file))))
.try_init()
.context("a logger is already set")?;
.build();
let level = logger.filter();
log::set_boxed_logger(Box::new(Private(logger))).context("a logger is already set")?;
log::set_max_level(level);
LOG_PATH.set(path).expect("the logger was set once");
let previous = panic::take_hook();