Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
/target
/debug
Cargo.lock

config.cfg
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ If it fails parsing a report, I would be happy if you could make it available to
## Installation

1. Clone this repository
2. Adapt the `config.cfg` file to point to your IMAP account that has the DMARC reports.
2. Adapt copy `config.example.cfg` to `config.cfg` and adapt it to point to your IMAP account that has the DMARC reports.
3. run `cargo run`
4. Fetch reports either via the GUI or by running `curl http://localhost:8000/fetch`

Expand Down
3 changes: 3 additions & 0 deletions config.cfg → config.example.cfg
Original file line number Diff line number Diff line change
Expand Up @@ -7,3 +7,6 @@ port = 993
user = dmarc
password = pass
store_folder = processed

# delete this line to use the root INBOX folder as input
input_folder = dmarc_reports
4 changes: 4 additions & 0 deletions src/config/arguments.rs
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,10 @@ pub struct Opt {
/// Imap server port. Defaults to '993'
pub port: Option<u16>,

#[structopt(long)]
/// The IMAP folder where to read report mails from, if not INBOX.
pub input_folder: Option<String>,

#[structopt(long)]
/// The IMAP folder where to place report mails once processed.
pub store_folder: Option<String>,
Expand Down
17 changes: 17 additions & 0 deletions src/config/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ pub struct Config {
pub user: String,
pub password: String,
pub store_folder: String,
pub input_folder: Option<String>,
}

impl Config {
Expand Down Expand Up @@ -57,6 +58,11 @@ impl Config {
.get("account", "password")
.expect("No password specified")
});
let input_folder = args
.input_folder
.clone()
.map(|v| Some(v))
.unwrap_or_else(|| config_file.get("account", "input_folder"));
let store_folder = args.store_folder.clone().unwrap_or_else(|| {
config_file
.get("account", "store_folder")
Expand All @@ -69,6 +75,7 @@ impl Config {
port,
user,
password,
input_folder,
store_folder,
}
}
Expand Down Expand Up @@ -99,6 +106,7 @@ mod tests {
user: None,
password: None,
store_folder: None,
input_folder: None,
};
assert_eq!(
Config {
Expand All @@ -108,6 +116,7 @@ mod tests {
user: String::from("foo"),
password: String::from("bar"),
store_folder: String::from("processed"),
input_folder: None,
},
Config::merge_config_options(&cf_file, &args)
);
Expand All @@ -116,6 +125,11 @@ mod tests {
cf_file.set("global", "db_path", Some(String::from("mydata.db")));
cf_file.set("account", "store_folder", Some(String::from("finished")));
cf_file.set("account", "port", Some(String::from("123")));
cf_file.set(
"account",
"input_folder",
Some(String::from("my/dmarc-reports")),
);
assert_eq!(
Config {
db_path: PathBuf::from("mydata.db"),
Expand All @@ -124,6 +138,7 @@ mod tests {
user: String::from("foo"),
password: String::from("bar"),
store_folder: String::from("finished"),
input_folder: Some(String::from("my/dmarc-reports")),
},
Config::merge_config_options(&cf_file, &args)
);
Expand All @@ -137,6 +152,7 @@ mod tests {
user: Some(String::from("newuser")),
password: Some(String::from("newpassword")),
store_folder: Some(String::from("newstorefolder")),
input_folder: Some(String::from("your/dmarc-reports")),
};
assert_eq!(
Config {
Expand All @@ -146,6 +162,7 @@ mod tests {
user: String::from("newuser"),
password: String::from("newpassword"),
store_folder: String::from("newstorefolder"),
input_folder: Some(String::from("your/dmarc-reports")),
},
Config::merge_config_options(&cf_file, &allargs)
);
Expand Down
11 changes: 9 additions & 2 deletions src/imap_extract/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ pub struct ImapExtract {
user: String,
password: String,
store_folder: String,
input_folder: Option<String>,
}

impl ImapExtract {
Expand All @@ -44,6 +45,7 @@ impl ImapExtract {
port: config.port,
user: config.user.clone(),
password: config.password.clone(),
input_folder: config.input_folder.clone(),
store_folder: config.store_folder.clone(),
}
}
Expand All @@ -69,9 +71,14 @@ impl ImapExtract {
}
};

let input_folder = if let Some(input_folder) = self.input_folder {
format!("INBOX/{}", input_folder)
} else {
"INBOX".to_string()
};
let inbox = imap_session
.select("INBOX")
.context("Failed to select INBOX")?;
.select(&input_folder)
.context(format!("Failed to select {}", &input_folder))?;
let message_count = inbox.exists;

if message_count == 0 {
Expand Down