Add public function to iterate over maildir

This commit is contained in:
Payas Relekar 2024-07-20 20:44:50 +05:30
parent 7f8ba1337b
commit 24427f6f65

View file

@ -110,6 +110,13 @@ pub fn maildir_iterator(mbox_path: String) -> Iterator(String) {
|> iterator.map(read_file)
}
// TODO: better error
pub fn maildir_iterate(maildir_path: String) -> Iterator(#(String, String)) {
case simplifile.get_files(maildir_path) {
Ok(maillist) -> iterator.from_list(maillist) |> iterator.map(fn(path) { #(path, read_file(path)) })
Error(_) -> #("", "") |> list.wrap |> iterator.from_list
}
}
fn read_file(file_path: String) -> String {
file_path
|> simplifile.read