mirror of
https://github.com/chatmail/core.git
synced 2026-04-26 18:06:35 +03:00
fix some locking issues, start rust-imap impl
This commit is contained in:
committed by
Lars-Magnus Skog
parent
0b3a4b4c13
commit
e7d72dfdd4
@@ -1,7 +1,7 @@
|
||||
extern crate deltachat;
|
||||
|
||||
use std::ffi::{CStr, CString};
|
||||
use std::sync::{Arc, RwLock};
|
||||
use std::sync::Arc;
|
||||
use tempfile::tempdir;
|
||||
|
||||
use deltachat::constants::Event;
|
||||
@@ -20,6 +20,10 @@ extern "C" fn cb(_ctx: &dc_context_t, event: Event, data1: usize, data2: usize)
|
||||
println!("[{:?}]", event);
|
||||
|
||||
match event {
|
||||
Event::CONFIGURE_PROGRESS => {
|
||||
println!(" progress: {}", data1);
|
||||
0
|
||||
}
|
||||
Event::HTTP_GET => {
|
||||
let url = unsafe { CStr::from_ptr(data1 as *const _).to_str().unwrap() };
|
||||
|
||||
@@ -56,19 +60,20 @@ fn main() {
|
||||
let info_s = CStr::from_ptr(info);
|
||||
println!("info: {}", info_s.to_str().unwrap());
|
||||
|
||||
let ctx = Arc::new(RwLock::new(ctx));
|
||||
|
||||
let ctx = Arc::new(ctx);
|
||||
let ctx1 = ctx.clone();
|
||||
let t1 = std::thread::spawn(move || loop {
|
||||
dc_perform_imap_jobs(&ctx1.clone().read().unwrap());
|
||||
dc_perform_imap_fetch(&ctx1.clone().read().unwrap());
|
||||
dc_perform_imap_idle(&ctx1.clone().read().unwrap());
|
||||
dc_perform_imap_jobs(&ctx1);
|
||||
dc_perform_imap_fetch(&ctx1);
|
||||
std::thread::sleep_ms(1000);
|
||||
|
||||
// dc_perform_imap_idle(&ctx1);
|
||||
});
|
||||
|
||||
let ctx1 = ctx.clone();
|
||||
let t2 = std::thread::spawn(move || loop {
|
||||
dc_perform_smtp_jobs(&ctx1.clone().read().unwrap());
|
||||
dc_perform_smtp_idle(&ctx1.clone().read().unwrap());
|
||||
// dc_perform_smtp_jobs(&ctx1);
|
||||
// dc_perform_smtp_idle(&ctx1);
|
||||
});
|
||||
|
||||
let dir = tempdir().unwrap();
|
||||
@@ -76,42 +81,31 @@ fn main() {
|
||||
|
||||
println!("opening database {:?}", dbfile);
|
||||
|
||||
dc_open(
|
||||
&mut ctx.clone().write().unwrap(),
|
||||
dbfile.as_ptr(),
|
||||
std::ptr::null(),
|
||||
);
|
||||
dc_open(&ctx, dbfile.as_ptr(), std::ptr::null());
|
||||
|
||||
println!("configuring");
|
||||
dc_set_config(
|
||||
&ctx.clone().read().unwrap(),
|
||||
&ctx,
|
||||
CString::new("addr").unwrap().as_ptr(),
|
||||
CString::new("d@testrun.org").unwrap().as_ptr(),
|
||||
);
|
||||
dc_set_config(
|
||||
&ctx.clone().read().unwrap(),
|
||||
&ctx,
|
||||
CString::new("mail_pw").unwrap().as_ptr(),
|
||||
CString::new("***").unwrap().as_ptr(),
|
||||
);
|
||||
dc_configure(&ctx.clone().read().unwrap());
|
||||
dc_configure(&ctx);
|
||||
|
||||
std::thread::sleep_ms(4000);
|
||||
|
||||
let email = CString::new("dignifiedquire@gmail.com").unwrap();
|
||||
println!("sending a message");
|
||||
let contact_id = dc_create_contact(
|
||||
&ctx.clone().read().unwrap(),
|
||||
std::ptr::null(),
|
||||
email.as_ptr(),
|
||||
);
|
||||
let chat_id = dc_create_chat_by_contact_id(&ctx.clone().read().unwrap(), contact_id);
|
||||
let contact_id = dc_create_contact(&ctx, std::ptr::null(), email.as_ptr());
|
||||
let chat_id = dc_create_chat_by_contact_id(&ctx, contact_id);
|
||||
let msg_text = CString::new("Hi, here is my first message!").unwrap();
|
||||
dc_send_text_msg(&ctx.clone().read().unwrap(), chat_id, msg_text.as_ptr());
|
||||
dc_send_text_msg(&ctx, chat_id, msg_text.as_ptr());
|
||||
|
||||
println!("fetching chats..");
|
||||
let ctx1 = ctx.clone();
|
||||
let ctx = ctx1.read().unwrap();
|
||||
|
||||
let chats = dc_get_chatlist(&ctx, 0, std::ptr::null(), 0);
|
||||
|
||||
for i in 0..dc_chatlist_get_cnt(chats) {
|
||||
@@ -134,7 +128,7 @@ fn main() {
|
||||
}
|
||||
dc_chatlist_unref(chats);
|
||||
|
||||
// let msglist = dc_get_chat_msgs(&ctx.clone().read().unwrap(), chat_id, 0, 0);
|
||||
// let msglist = dc_get_chat_msgs(&ctx, chat_id, 0, 0);
|
||||
// for i in 0..dc_array_get_cnt(msglist) {
|
||||
// let msg_id = dc_array_get_id(msglist, i);
|
||||
// let msg = dc_get_msg(context, msg_id);
|
||||
|
||||
Reference in New Issue
Block a user