-
Notifications
You must be signed in to change notification settings - Fork 525
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Basic eml/mbox import with ImportMailService instead of DraftService
Co-authored-by: jomapp <[email protected]>
- Loading branch information
1 parent
3e3c04a
commit a625b54
Showing
42 changed files
with
915 additions
and
2,215 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,4 @@ | ||
/// How to: Import Imap mail from greenmail to tutanota | ||
/// How to: Import IMAP mail from Greenmail to TutaMail | ||
/// | ||
/// | ||
/// 1. Start GreenMail server | ||
|
@@ -33,8 +33,8 @@ async fn main() { | |
import_client::ImapImport, ImapCredentials, ImapImportConfig, LoginMechanism, | ||
}; | ||
use tutao_node_mimimi::importer::{ImportSource, ImportState, Importer}; | ||
use tutasdk::folder_system::MailSetKind; | ||
use tutasdk::net::native_rest_client::NativeRestClient; | ||
use tutasdk::IdTuple; | ||
use tutasdk::Sdk; | ||
|
||
let sdk = Sdk::new( | ||
|
@@ -61,15 +61,21 @@ async fn main() { | |
imap_import_client: ImapImport::new(imap_import_config), | ||
}; | ||
|
||
let mail_facade = logged_in_sdk.mail_facade(); | ||
let mailbox = mail_facade.load_user_mailbox().await.unwrap(); | ||
let folders = mail_facade | ||
.load_folders_for_mailbox(&mailbox) | ||
.await | ||
.unwrap(); | ||
let inbox_folder = folders | ||
.system_folder_by_type(MailSetKind::Inbox) | ||
.expect("inbox should exist"); | ||
|
||
let mut importer = Importer::new( | ||
logged_in_sdk, | ||
import_source, | ||
"[email protected]".to_string(), | ||
// todo!("How to get target mail folder id") | ||
IdTuple { | ||
list_id: Default::default(), | ||
element_id: Default::default(), | ||
}, | ||
inbox_folder._id.clone(), | ||
); | ||
|
||
let import_status = importer | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -2,7 +2,6 @@ use crate::importer::file_reader::import_client::{FileImport, FileIterationError | |
use crate::importer::imap_reader::import_client::{ImapImport, ImapIterationError}; | ||
use crate::importer::imap_reader::ImapImportConfig; | ||
use crate::importer::importable_mail::ImportableMail; | ||
use std::future::Future; | ||
use std::sync::Arc; | ||
use tutasdk::crypto::aes::Iv; | ||
use tutasdk::crypto::key::{GenericAesKey, VersionedAesKey}; | ||
|
@@ -13,13 +12,6 @@ use tutasdk::services::ExtraServiceParams; | |
use tutasdk::{ApiCallError, IdTuple, LoggedInSdk}; | ||
|
||
pub type NapiTokioMutex<T> = napi::tokio::sync::Mutex<T>; | ||
pub type NapiResult<T> = napi::Result<T>; | ||
|
||
/// A handle, once imap/file reader get the importable mail, | ||
/// this handle is responsible to do the import to server, | ||
/// Returns a boolean, indicating if this import was successful or not. | ||
// todo: return more verbose status | ||
pub type ImporterHandle = Box<dyn Fn(ImportableMail) -> Box<dyn Future<Output = bool>>>; | ||
|
||
pub mod file_reader; | ||
pub mod imap_reader; | ||
|
@@ -196,7 +188,7 @@ impl ImporterInner { | |
.get_service_executor() | ||
.post::<ImportMailService>(import_mail_post_in, service_params) | ||
.await | ||
.expect("Cannot execute DraftService"); | ||
.expect("Cannot execute ImportMailService"); | ||
|
||
Ok(import_mail_post_out) | ||
} | ||
|
@@ -283,15 +275,36 @@ mod tests { | |
use crate::importer::imap_reader::{ImapCredentials, LoginMechanism}; | ||
use crate::tuta_imap::testing::GreenMailTestServer; | ||
use mail_builder::MessageBuilder; | ||
use tutasdk::entities::tutanota::MailFolder; | ||
use tutasdk::folder_system::MailSetKind; | ||
use tutasdk::net::native_rest_client::NativeRestClient; | ||
use tutasdk::Sdk; | ||
|
||
// todo: implement a way to get any folder id ( or create a new one for every test? ) | ||
async fn get_test_import_folder_id() -> IdTuple { | ||
IdTuple { | ||
list_id: Default::default(), | ||
element_id: Default::default(), | ||
} | ||
fn sample_email(subject: String) -> String { | ||
let email = MessageBuilder::new() | ||
.from(("Matthias", "[email protected]")) | ||
.to(("Johannes", "[email protected]")) | ||
.subject(subject) | ||
.text_body("Hello tutao! this is the first step to have email import.Want to see html 😀?<p style='color:red'>red</p>") | ||
.write_to_string() | ||
.unwrap(); | ||
} | ||
|
||
async fn get_test_import_folder_id( | ||
logged_in_sdk: &Arc<LoggedInSdk>, | ||
kind: MailSetKind, | ||
) -> MailFolder { | ||
let mail_facade = logged_in_sdk.mail_facade(); | ||
let mailbox = mail_facade.load_user_mailbox().await.unwrap(); | ||
let folders = mail_facade | ||
.load_folders_for_mailbox(&mailbox) | ||
.await | ||
.unwrap(); | ||
folders | ||
.system_folder_by_type(kind) | ||
.expect("inbox should exist") | ||
.clone() | ||
} | ||
|
||
async fn init_imap_importer() -> (ImporterInner, GreenMailTestServer) { | ||
|
@@ -320,11 +333,13 @@ mod tests { | |
imap_import_client: ImapImport::new(imap_import_config), | ||
}; | ||
let randomizer_facade = RandomizerFacade::from_core(rand::rngs::OsRng); | ||
let target_mail_folder_id = get_test_import_folder_id(&logged_in_sdk, MailSetKind::Archive) | ||
.await | ||
._id; | ||
|
||
let importer = ImporterInner { | ||
importer_mail_address, | ||
// todo: find a way to get inbox folder id? | ||
target_mail_folder_id: get_test_import_folder_id().await, | ||
target_mail_folder_id, | ||
logged_in_sdk, | ||
import_source, | ||
randomizer_facade, | ||
|
@@ -347,15 +362,18 @@ mod tests { | |
fs_email_client: FileImport::new(file_path, is_mbox), | ||
}; | ||
let randomizer_facade = RandomizerFacade::from_core(rand::rngs::OsRng); | ||
let import_inner = ImporterInner { | ||
let target_mail_folder_id = get_test_import_folder_id(&logged_in_sdk, MailSetKind::Archive) | ||
.await | ||
._id; | ||
|
||
ImporterInner { | ||
status: ImportStatus::default(), | ||
importer_mail_address: "[email protected]".to_string(), | ||
target_mail_folder_id: get_test_import_folder_id().await, | ||
target_mail_folder_id, | ||
logged_in_sdk, | ||
import_source, | ||
randomizer_facade, | ||
}; | ||
import_inner | ||
} | ||
} | ||
|
||
#[tokio::test] | ||
|
@@ -377,17 +395,6 @@ mod tests { | |
); | ||
} | ||
|
||
fn sample_email(subject: String) -> String { | ||
let email = MessageBuilder::new() | ||
.from(("Matthias", "[email protected]")) | ||
.to(("Johannes", "[email protected]")) | ||
.subject(subject) | ||
.text_body("Hello tutao! this is the first step to have email import.Want to see html 😀?<p style='color:red'>red</p>") | ||
.write_to_string() | ||
.unwrap(); | ||
} | ||
|
||
#[tokio::test] | ||
pub async fn import_single_from_imap_default_folder() { | ||
let (mut importer, greenmail) = init_imap_importer().await; | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.