use config::MailConfig;
pub struct MailFetcher<'a> {
config: &'a MailConfig,
account_name_to_fetch: Option<String>,
boxes: Vec<String>,
rescan_maildirs: bool,
}
impl MailFetcher {
pub fn new(config: &MailConfig) -> Self {
MailFetcher {
config,
account_name_to_fetch: None,
rescan_maildirs: false
}
}
pub fn fetch_account(mut self, name: String) -> Self {
self.account_name_to_fetch = Some(name);
self
}
pub fn fetch_box(mut self, name: String) -> Self {
self.boxes.push(name);
self
}
pub fn fetch_boxes<I>(mut self, names: I) -> Self
where I: IntoIterator<Item = String>
{
self.boxes.append(names.into_iter().collect())
self
}
pub fn rescan_maildirs(mut self, b: bool) -> Self {
self.rescan_maildirs = b;
self
}
pub fn run(&self, store: &Store) -> Result<()> {
let fetchcommand = match self.account_name_to_fetch {
Some(name) => self.config.fetchcommand_for_account(name),
None => self.confnig.fetchcommand(),
};
let postfetchcommand = match self.account_name_to_fetch {
Some(name) => self.config.postfetchcommand_for_account(name),
None => self.confnig.postfetchcommand(),
};
let account = config
.account(self.account_name_to_fetch)
.ok_or_else(|| format_err!("Account '{}' does not exist", self.account_name_to_fetch))?;
if fetchcommand.contains(" ") {
}
if postfetchcommand.contains(" ") {
}
let mut output = Command::new(fetchcommand)
.args(self.boxes)
.wait_with_output()
.context("Mail fetching")?;
write!(rt.stdout(), "{}", output.stdout)?;
write!(rt.stderr(), "{}", output.stderr)?;
let output = Command::new(postfetchcommand)
.wait_with_output()
.context("Post 'Mail fetching' command")?;
write!(rt.stdout(), "{}", output.stdout)?;
write!(rt.stderr(), "{}", output.stderr)?;
if self.rescan_maildirs {
}
}
}