From 474fae06eea02c17c706c33d401db519753d8498 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Cl=C3=A9ment=20DOUIN?= Date: Sun, 19 Sep 2021 10:14:25 +0200 Subject: [PATCH] move attachment, body and header to dedicated folders --- src/domain/mbox/mod.rs | 2 +- src/domain/msg/arg.rs | 21 ++++------------ src/domain/msg/attachment/arg.rs | 24 +++++++++++++++++++ .../{attachment.rs => attachment/entity.rs} | 0 src/domain/msg/attachment/mod.rs | 4 ++++ src/domain/msg/{body.rs => body/entity.rs} | 0 src/domain/msg/body/mod.rs | 1 + src/domain/msg/entity.rs | 6 +++-- src/domain/msg/handler.rs | 8 +++---- .../msg/{headers.rs => header/entity.rs} | 0 src/domain/msg/header/mod.rs | 1 + src/domain/msg/mod.rs | 2 +- src/domain/msg/tpl/handler.rs | 4 ++-- 13 files changed, 46 insertions(+), 27 deletions(-) create mode 100644 src/domain/msg/attachment/arg.rs rename src/domain/msg/{attachment.rs => attachment/entity.rs} (100%) create mode 100644 src/domain/msg/attachment/mod.rs rename src/domain/msg/{body.rs => body/entity.rs} (100%) create mode 100644 src/domain/msg/body/mod.rs rename src/domain/msg/{headers.rs => header/entity.rs} (100%) create mode 100644 src/domain/msg/header/mod.rs diff --git a/src/domain/mbox/mod.rs b/src/domain/mbox/mod.rs index bb656c4..93e2889 100644 --- a/src/domain/mbox/mod.rs +++ b/src/domain/mbox/mod.rs @@ -1,4 +1,4 @@ -//! Module related to mailboxes. +//! Module related to mailbox. pub mod arg; pub mod entity; diff --git a/src/domain/msg/arg.rs b/src/domain/msg/arg.rs index 8d31678..40da564 100644 --- a/src/domain/msg/arg.rs +++ b/src/domain/msg/arg.rs @@ -226,22 +226,12 @@ fn page_arg<'a>() -> Arg<'a, 'a> { .default_value("0") } -/// Message attachment argument. -/// TODO: move to attachment folder -fn attachment_arg<'a>() -> Arg<'a, 'a> { - Arg::with_name("attachments") - .help("Adds attachment to the message") - .short("a") - .long("attachment") - .value_name("PATH") - .multiple(true) -} - /// Message subcommands. pub fn subcmds<'a>() -> Vec> { vec![ msg::flag::arg::subcmds(), msg::tpl::arg::subcmds(), + msg::attachment::arg::subcmds(), vec![ SubCommand::with_name("list") .aliases(&["lst", "l"]) @@ -262,7 +252,7 @@ pub fn subcmds<'a>() -> Vec> { ), SubCommand::with_name("write") .about("Writes a new message") - .arg(attachment_arg()), + .arg(msg::attachment::arg::path_arg()), SubCommand::with_name("send") .about("Sends a raw message") .arg(Arg::with_name("message").raw(true).last(true)), @@ -287,19 +277,16 @@ pub fn subcmds<'a>() -> Vec> { .long("raw") .short("r"), ), - SubCommand::with_name("attachments") - .about("Downloads all message attachments") - .arg(uid_arg()), SubCommand::with_name("reply") .about("Answers to a message") .arg(uid_arg()) .arg(reply_all_arg()) - .arg(attachment_arg()), + .arg(msg::attachment::arg::path_arg()), SubCommand::with_name("forward") .aliases(&["fwd"]) .about("Forwards a message") .arg(uid_arg()) - .arg(attachment_arg()), + .arg(msg::attachment::arg::path_arg()), SubCommand::with_name("copy") .aliases(&["cp"]) .about("Copies a message to the targetted mailbox") diff --git a/src/domain/msg/attachment/arg.rs b/src/domain/msg/attachment/arg.rs new file mode 100644 index 0000000..b36daf2 --- /dev/null +++ b/src/domain/msg/attachment/arg.rs @@ -0,0 +1,24 @@ +//! Module related to message attachment CLI. +//! +//! This module provides arguments related to message attachment. + +use clap::{App, Arg, SubCommand}; + +use crate::domain::msg; + +/// Message attachment subcommands. +pub(crate) fn subcmds<'a>() -> Vec> { + vec![SubCommand::with_name("attachments") + .about("Downloads all message attachments") + .arg(msg::arg::uid_arg())] +} + +/// Message attachment path argument. +pub(crate) fn path_arg<'a>() -> Arg<'a, 'a> { + Arg::with_name("attachments") + .help("Adds attachment to the message") + .short("a") + .long("attachment") + .value_name("PATH") + .multiple(true) +} diff --git a/src/domain/msg/attachment.rs b/src/domain/msg/attachment/entity.rs similarity index 100% rename from src/domain/msg/attachment.rs rename to src/domain/msg/attachment/entity.rs diff --git a/src/domain/msg/attachment/mod.rs b/src/domain/msg/attachment/mod.rs new file mode 100644 index 0000000..809996c --- /dev/null +++ b/src/domain/msg/attachment/mod.rs @@ -0,0 +1,4 @@ +//! Module related to message attachment. + +pub mod arg; +pub mod entity; diff --git a/src/domain/msg/body.rs b/src/domain/msg/body/entity.rs similarity index 100% rename from src/domain/msg/body.rs rename to src/domain/msg/body/entity.rs diff --git a/src/domain/msg/body/mod.rs b/src/domain/msg/body/mod.rs new file mode 100644 index 0000000..e8c3d6a --- /dev/null +++ b/src/domain/msg/body/mod.rs @@ -0,0 +1 @@ +pub mod entity; diff --git a/src/domain/msg/entity.rs b/src/domain/msg/entity.rs index 672d3d2..cc167f3 100644 --- a/src/domain/msg/entity.rs +++ b/src/domain/msg/entity.rs @@ -3,10 +3,12 @@ use imap::types::{Fetch, Flag, ZeroCopy}; use log::debug; use mailparse; -use super::{attachment::Attachment, body::Body, headers::Headers}; use crate::{ config::entity::Account, - domain::msg::flag::entity::Flags, + domain::msg::{ + attachment::entity::Attachment, body::entity::Body, flag::entity::Flags, + header::entity::Headers, + }, ui::table::{Cell, Row, Table}, }; diff --git a/src/domain/msg/handler.rs b/src/domain/msg/handler.rs index be6bddd..bcbf6d9 100644 --- a/src/domain/msg/handler.rs +++ b/src/domain/msg/handler.rs @@ -18,8 +18,10 @@ use crate::{ mbox::entity::Mbox, msg::{ self, - body::Body, - entity::{Msg, Msgs}, + body::entity::Body, + entity::{Msg, MsgSerialized, Msgs}, + flag::entity::Flags, + header::entity::Headers, }, smtp::service::SmtpServiceInterface, }, @@ -27,8 +29,6 @@ use crate::{ ui::choice::{self, PostEditChoice}, }; -use super::{entity::MsgSerialized, flag::entity::Flags, headers::Headers}; - // TODO: move this function to the right folder fn msg_interaction( output: &OutputService, diff --git a/src/domain/msg/headers.rs b/src/domain/msg/header/entity.rs similarity index 100% rename from src/domain/msg/headers.rs rename to src/domain/msg/header/entity.rs diff --git a/src/domain/msg/header/mod.rs b/src/domain/msg/header/mod.rs new file mode 100644 index 0000000..e8c3d6a --- /dev/null +++ b/src/domain/msg/header/mod.rs @@ -0,0 +1 @@ +pub mod entity; diff --git a/src/domain/msg/mod.rs b/src/domain/msg/mod.rs index 57ef7f7..9d809c3 100644 --- a/src/domain/msg/mod.rs +++ b/src/domain/msg/mod.rs @@ -30,7 +30,7 @@ pub mod attachment; /// This module is used in the `Msg` struct, which should represent the headers /// fields like `To:` and `From:`. -pub mod headers; +pub mod header; /// This module is used in the `Msg` struct, which should represent the body of /// a msg; The part where you're writing some text like `Dear Mr. LMAO`. diff --git a/src/domain/msg/tpl/handler.rs b/src/domain/msg/tpl/handler.rs index 5666402..108ea93 100644 --- a/src/domain/msg/tpl/handler.rs +++ b/src/domain/msg/tpl/handler.rs @@ -13,9 +13,9 @@ use crate::{ domain::{ imap::service::ImapServiceInterface, msg::{ - body::Body, + body::entity::Body, entity::{Msg, MsgSerialized}, - headers::Headers, + header::entity::Headers, tpl::arg::Tpl, }, },