himalaya/tests/test_maildir_backend.rs
Clément DOUIN 158bc86cfa
release v0.5.6 (#301)
* make use of mailparse::MailAddr

* move addr logic to a dedicated file

* update changelog

* add suffix to downoalded attachments with same name (#204)

* implement sort command (#34)

* introduce backends structure (#296)

* implement backend structure poc

* improve config namings

* improve account namings and structure

* rename imap vars to backend

* maildir backend (#299)

* refactor config system, preparing maildir backend

* rename deserializable by deserialized

* wrap backend in a Box

* reword backend trait methods

* merge list envelopes functions

* remove find_raw_msg from backend trait

* remove expunge fn from backend trait

* rename add_msg from backend trait

* init maildir integration tests, start impl maildir backend fns

* implement remaining methods maildir backend, refactor trait

* improve backend trait, add copy and move fns

* remove usage of Mbox in handlers

* reorganize backends folder structure

* move mbox out of domain folder

* rename mbox entities

* improve mbox structure

* remove unused files, move smtp module

* improve envelope, impl get_envelopes for maildir

* link maildir mail entry id to envelope id

* use erased-serde to make backend get_mboxes return a trait object

* remove unused mbox files

* rename Output trait

* make get_envelopes return a trait object

* remove unused impl for imap envelope

* update backend return signature with Box

* replace impl from imap::Fetch to mailparse::ParsedMail

* split flags by backends

* remove unused flags from msg

* remove remaining flags from domain

* impl maildir copy and move, improve maildir e2e tests

* set up imap backend e2e tests

* move domain/msg to msg

* repair broken tests

* fix maildir envelopes encoding issues

* add date column to maildir envelopes

* implement maildir list pagination

* improve maildir subdir path management

* add pgp and maildir features to readme

* update changelog

* bump version v0.5.6
2022-02-22 16:54:39 +01:00

69 lines
2.6 KiB
Rust

use maildir::Maildir;
use std::{env, fs};
use himalaya::{
backends::{Backend, MaildirBackend, MaildirEnvelopes},
config::{AccountConfig, MaildirBackendConfig},
};
#[test]
fn test_maildir_backend() {
// set up maildir folders
let mdir: Maildir = env::temp_dir().join("himalaya-test-mdir").into();
if let Err(_) = fs::remove_dir_all(mdir.path()) {}
mdir.create_dirs().unwrap();
let mdir_sub: Maildir = mdir.path().join(".Subdir").into();
if let Err(_) = fs::remove_dir_all(mdir_sub.path()) {}
mdir_sub.create_dirs().unwrap();
// configure accounts
let account_config = AccountConfig {
inbox_folder: "INBOX".into(),
..AccountConfig::default()
};
let mdir_config = MaildirBackendConfig {
maildir_dir: mdir.path().to_owned(),
};
let mut mdir = MaildirBackend::new(&account_config, &mdir_config);
let mdir_sub_config = MaildirBackendConfig {
maildir_dir: mdir_sub.path().to_owned(),
};
let mut mdir_subdir = MaildirBackend::new(&account_config, &mdir_sub_config);
// check that a message can be added
let msg = include_bytes!("./emails/alice-to-patrick.eml");
let id = mdir.add_msg("INBOX", msg, "seen").unwrap().to_string();
// check that the added message exists
let msg = mdir.get_msg("INBOX", &id).unwrap();
assert_eq!("alice@localhost", msg.from.clone().unwrap().to_string());
assert_eq!("patrick@localhost", msg.to.clone().unwrap().to_string());
assert_eq!("Ceci est un message.", msg.fold_text_plain_parts());
// check that the envelope of the added message exists
let envelopes = mdir.get_envelopes("INBOX", "", "cur", 10, 0).unwrap();
let envelopes: &MaildirEnvelopes = envelopes.as_any().downcast_ref().unwrap();
let envelope = envelopes.first().unwrap();
assert_eq!(1, envelopes.len());
assert_eq!("alice@localhost", envelope.sender);
assert_eq!("Plain message", envelope.subject);
// check that the message can be copied
mdir.copy_msg("INBOX", "Subdir", &envelope.id).unwrap();
assert!(mdir.get_msg("INBOX", &id).is_ok());
assert!(mdir.get_msg("Subdir", &id).is_ok());
assert!(mdir_subdir.get_msg("INBOX", &id).is_ok());
// check that the message can be moved
mdir.move_msg("INBOX", "Subdir", &envelope.id).unwrap();
assert!(mdir.get_msg("INBOX", &id).is_err());
assert!(mdir.get_msg("Subdir", &id).is_ok());
assert!(mdir_subdir.get_msg("INBOX", &id).is_ok());
// check that the message can be deleted
mdir.del_msg("Subdir", &id).unwrap();
assert!(mdir.get_msg("Subdir", &id).is_err());
assert!(mdir_subdir.get_msg("INBOX", &id).is_err());
}