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 tokio::fs::{File, self};
use anyhow::Result;
use tempfile::NamedTempFile;
use tokio::fs::{self, File, OpenOptions};
pub struct Maildir {
path: PathBuf,
@ -18,16 +18,19 @@ impl Maildir {
/// Stores a new message into the `new` directory
// TODO: maybe have a streaming option?
pub async fn store(&self) -> Result<()> {
let unique_name = "hellosu";
let tmp_file = self.tmp_dir().join(unique_name);
pub async fn store(&self, opts: StoreOptions) -> Result<PathBuf> {
let unique_name = opts.create_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);
fs::rename(tmp_file, new_file).await?;
Ok(())
let new_file = self.new_dir().join(&unique_name);
fs::rename(&tmp_file, &new_file).await?;
Ok(new_file)
}
/// Returns the path to the `tmp` subdirectory
@ -48,3 +51,12 @@ impl Maildir {
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.
use std::fs::{self, File};
use std::collections::HashMap;
use std::fs::{self, File};
use std::io::Read;
use std::path::{Path, PathBuf};

View file

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

View file

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

View file

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