maildir updates

This commit is contained in:
Michael Zhang 2021-03-20 03:31:16 -05:00
parent 680c9c9ebc
commit 9379d06450
Signed by: michael
GPG key ID: BDA47A31A3C8EE6B
5 changed files with 25 additions and 13 deletions

View file

@ -1,8 +1,8 @@
use std::path::{Path, PathBuf}; use std::path::{Path, PathBuf};
use tokio::fs::{File, self};
use anyhow::Result; use anyhow::Result;
use tempfile::NamedTempFile; use tempfile::NamedTempFile;
use tokio::fs::{self, File, OpenOptions};
pub struct Maildir { pub struct Maildir {
path: PathBuf, path: PathBuf,
@ -18,16 +18,19 @@ impl Maildir {
/// Stores a new message into the `new` directory /// Stores a new message into the `new` directory
// TODO: maybe have a streaming option? // TODO: maybe have a streaming option?
pub async fn store(&self) -> Result<()> { pub async fn store(&self, opts: StoreOptions) -> Result<PathBuf> {
let unique_name = "hellosu"; let unique_name = opts.create_unique_name();
let tmp_file = self.tmp_dir().join(unique_name); let tmp_file = self.tmp_dir().join(&unique_name);
{ {
let mut file = File::create(&tmp_file).await?; let mut file = OpenOptions::new()
.create_new(true) // fail if the file already exists, this means we aren't unique!
.open(&tmp_file)
.await?;
} }
let new_file = self.new_dir().join(unique_name); let new_file = self.new_dir().join(&unique_name);
fs::rename(tmp_file, new_file).await?; fs::rename(&tmp_file, &new_file).await?;
Ok(()) Ok(new_file)
} }
/// Returns the path to the `tmp` subdirectory /// Returns the path to the `tmp` subdirectory
@ -48,3 +51,12 @@ impl Maildir {
self.path.join("cur") self.path.join("cur")
} }
} }
/// Options that will be used to determine the filename it's stored to
pub struct StoreOptions {}
impl StoreOptions {
pub fn create_unique_name(&self) -> String {
format!("")
}
}

View file

@ -2,8 +2,8 @@
//! //!
//! One of the primary goals of panorama is to be able to always hot-reload configuration files. //! One of the primary goals of panorama is to be able to always hot-reload configuration files.
use std::fs::{self, File};
use std::collections::HashMap; use std::collections::HashMap;
use std::fs::{self, File};
use std::io::Read; use std::io::Read;
use std::path::{Path, PathBuf}; use std::path::{Path, PathBuf};

View file

@ -3,7 +3,7 @@ use std::thread;
use anyhow::Result; use anyhow::Result;
use fern::colors::{Color, ColoredLevelConfig}; use fern::colors::{Color, ColoredLevelConfig};
use futures::future::{TryFutureExt}; use futures::future::TryFutureExt;
use panorama::{ use panorama::{
config::spawn_config_watcher_system, config::spawn_config_watcher_system,
mail::{self, MailEvent}, mail::{self, MailEvent},

View file

@ -7,8 +7,8 @@ use std::sync::{
use anyhow::Result; use anyhow::Result;
use chrono::{DateTime, Datelike, Duration, Local}; use chrono::{DateTime, Datelike, Duration, Local};
use chrono_humanize::HumanTime; use chrono_humanize::HumanTime;
use crossterm::event::{KeyCode, KeyEvent};
use panorama_imap::response::Envelope; use panorama_imap::response::Envelope;
use crossterm::event::{KeyEvent, KeyCode};
use tui::{ use tui::{
buffer::Buffer, buffer::Buffer,
layout::{Constraint, Direction, Layout, Rect}, layout::{Constraint, Direction, Layout, Rect},
@ -19,7 +19,7 @@ use tui::{
use crate::mail::EmailMetadata; use crate::mail::EmailMetadata;
use super::{FrameType, HandlesInput, TermType, InputResult, Window, UI}; use super::{FrameType, HandlesInput, InputResult, TermType, Window, UI};
#[derive(Default, Debug)] #[derive(Default, Debug)]
pub struct MailView { pub struct MailView {

View file

@ -288,7 +288,7 @@ pub async fn run_ui(
let mut should_pop = false; let mut should_pop = false;
if let Some(input_state) = input_states.last_mut() { if let Some(input_state) = input_states.last_mut() {
match input_state.handle_key(&mut term, evt)? { match input_state.handle_key(&mut term, evt)? {
InputResult::Ok => {}, InputResult::Ok => {}
InputResult::Push(state) => { InputResult::Push(state) => {
input_states.push(state); input_states.push(state);
} }