use config::MailConfig;
pub struct MailSender<'a> {
config: &'a MailConfig,
account_name_to_send_with: Option<String>,
rescan_maildirs: bool,
}
impl MailSender {
pub fn new(config: &MailConfig) -> Self {
MailSender {
config,
account_name_to_send_with: None,
rescan_maildirs: false
}
}
pub fn send_account(mut self, name: String) -> Self {
self.account_name_to_send_with = Some(name);
self
}
pub fn rescan_maildirs(mut self, b: bool) -> Self {
self.rescan_maildirs = b;
self
}
pub fn run(&self, store: &Store) -> Result<()> {
let sendcommand = match self.account_name_to_send_with {
Some(name) => self.config.sendcommand_for_account(name),
None => self.confnig.sendcommand(),
};
let postsendcommand = match self.account_name_to_send_with {
Some(name) => self.config.postsendcommand_for_account(name),
None => self.confnig.sendcommand(),
};
let account = config
.account(self.account_name_to_send_with)
.ok_or_else(|| format_err!("Account '{}' does not exist", self.account_name_to_send_with))?;
if sendcommand.contains(" ") {
}
if postsendcommand.contains(" ") {
}
let outgoingbox = account
.outgoingbox
.to_str()
.ok_or_else(|| format_err!("Cannot use '{:?}' as outgoingbox", account.outgoingbox))?;
let mut output = Command::new(sendcommand)
.arg(outgoingbox)
.wait_with_output()
.context("Mail sending")?;
write!(rt.stdout(), "{}", output.stdout)?;
write!(rt.stderr(), "{}", output.stderr)?;
let output = Command::new(postsendcommand)
.wait_with_output()
.context("Post 'Mail sending' command")?;
write!(rt.stdout(), "{}", output.stdout)?;
write!(rt.stderr(), "{}", output.stderr)?;
if self.rescan_maildirs {
}
}
}