From 7a43bdd46e18726e353ef98505cb395c7f377ec7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Cl=C3=A9ment=20DOUIN?= Date: Sun, 19 Sep 2021 16:58:10 +0200 Subject: [PATCH] review read command --- src/domain/msg/handler.rs | 45 ++++++++++++++++++++++++++++++--------- src/output/service.rs | 13 ++++++----- 2 files changed, 41 insertions(+), 17 deletions(-) diff --git a/src/domain/msg/handler.rs b/src/domain/msg/handler.rs index 7becbe7..518b593 100644 --- a/src/domain/msg/handler.rs +++ b/src/domain/msg/handler.rs @@ -29,7 +29,7 @@ use crate::{ }, smtp::service::SmtpServiceInterface, }, - output::service::{OutputService, OutputServiceInterface}, + output::service::OutputServiceInterface, ui::{ choice::{self, PostEditChoice}, editor, @@ -37,7 +37,11 @@ use crate::{ }; // TODO: move this function to the right folder -fn msg_interaction( +fn msg_interaction< + OutputService: OutputServiceInterface, + ImapService: ImapServiceInterface, + SmtpService: SmtpServiceInterface, +>( output: &OutputService, msg: &mut Msg, imap: &mut ImapService, @@ -180,7 +184,11 @@ pub fn delete( +pub fn forward< + OutputService: OutputServiceInterface, + ImapService: ImapServiceInterface, + SmtpService: SmtpServiceInterface, +>( uid: &str, attachments_paths: Vec<&str>, account: &Account, @@ -201,7 +209,7 @@ pub fn forward( +pub fn list( page_size: Option, page: usize, account: &Account, @@ -224,7 +232,11 @@ pub fn list( /// Parse and edit a message from a [mailto] URL string. /// /// [mailto]: https://en.wikipedia.org/wiki/Mailto -pub fn mailto( +pub fn mailto< + OutputService: OutputServiceInterface, + ImapService: ImapServiceInterface, + SmtpService: SmtpServiceInterface, +>( url: &Url, account: &Account, output: &OutputService, @@ -295,7 +307,8 @@ pub fn move_( +/// Read a message from the given UID. +pub fn read( uid: &str, // TODO: use the mime to select the right body _mime: String, @@ -313,7 +326,11 @@ pub fn read( Ok(()) } -pub fn reply( +pub fn reply< + OutputService: OutputServiceInterface, + ImapService: ImapServiceInterface, + SmtpService: SmtpServiceInterface, +>( uid: &str, all: bool, attachments_paths: Vec<&str>, @@ -349,7 +366,7 @@ pub fn save( Ok(()) } -pub fn search( +pub fn search( page_size: Option, page: usize, query: String, @@ -370,7 +387,11 @@ pub fn search( Ok(()) } -pub fn send( +pub fn send< + OutputService: OutputServiceInterface, + ImapService: ImapServiceInterface, + SmtpService: SmtpServiceInterface, +>( msg: &str, output: &OutputService, imap: &mut ImapService, @@ -400,7 +421,11 @@ pub fn send( +pub fn write< + OutputService: OutputServiceInterface, + ImapService: ImapServiceInterface, + SmtpService: SmtpServiceInterface, +>( attachments_paths: Vec<&str>, account: &Account, output: &OutputService, diff --git a/src/output/service.rs b/src/output/service.rs index 509dc34..27229ea 100644 --- a/src/output/service.rs +++ b/src/output/service.rs @@ -59,6 +59,7 @@ impl OutputJson { pub trait OutputServiceInterface { fn print(&self, data: T) -> Result<()>; + fn is_json(&self) -> bool; } #[derive(Debug)] @@ -66,13 +67,6 @@ pub struct OutputService { fmt: OutputFmt, } -impl OutputService { - /// Returns true, if the formatting should be json. - pub fn is_json(&self) -> bool { - self.fmt == OutputFmt::Json - } -} - impl OutputServiceInterface for OutputService { /// Print the provided item out according to the formatting setting when you created this /// struct. @@ -87,6 +81,11 @@ impl OutputServiceInterface for OutputService { }; Ok(()) } + + /// Returns true, if the formatting should be json. + fn is_json(&self) -> bool { + self.fmt == OutputFmt::Json + } } impl Default for OutputService {