mirror of
https://github.com/chatmail/core.git
synced 2026-04-24 17:06:28 +03:00
it compiles
This commit is contained in:
@@ -1,7 +1,7 @@
|
||||
extern crate deltachat;
|
||||
|
||||
use std::ffi::{CStr, CString};
|
||||
use std::ptr::NonNull;
|
||||
use std::sync::{Arc, RwLock};
|
||||
use tempfile::tempdir;
|
||||
|
||||
use deltachat::constants::Event;
|
||||
@@ -49,61 +49,70 @@ extern "C" fn cb(_ctx: &dc_context_t, event: Event, data1: usize, data2: usize)
|
||||
}
|
||||
}
|
||||
|
||||
struct Wrapper(NonNull<dc_context_t>);
|
||||
|
||||
unsafe impl std::marker::Send for Wrapper {}
|
||||
unsafe impl std::marker::Sync for Wrapper {}
|
||||
|
||||
fn main() {
|
||||
unsafe {
|
||||
let ctx = dc_context_new(cb, std::ptr::null_mut(), std::ptr::null_mut());
|
||||
let info = dc_get_info(ctx);
|
||||
let info = dc_get_info(&ctx);
|
||||
let info_s = CStr::from_ptr(info);
|
||||
println!("info: {}", info_s.to_str().unwrap());
|
||||
|
||||
let sendable_ctx = Wrapper(NonNull::new(ctx).unwrap());
|
||||
let ctx = Arc::new(RwLock::new(ctx));
|
||||
|
||||
let ctx1 = ctx.clone();
|
||||
let t1 = std::thread::spawn(move || loop {
|
||||
dc_perform_imap_jobs(sendable_ctx.0.as_ptr());
|
||||
dc_perform_imap_fetch(sendable_ctx.0.as_ptr());
|
||||
dc_perform_imap_idle(sendable_ctx.0.as_ptr());
|
||||
dc_perform_imap_jobs(&ctx1.clone().read().unwrap());
|
||||
dc_perform_imap_fetch(&ctx1.clone().read().unwrap());
|
||||
dc_perform_imap_idle(&ctx1.clone().read().unwrap());
|
||||
});
|
||||
|
||||
let sendable_ctx = Wrapper(NonNull::new(ctx).unwrap());
|
||||
let ctx1 = ctx.clone();
|
||||
let t2 = std::thread::spawn(move || loop {
|
||||
dc_perform_smtp_jobs(sendable_ctx.0.as_ptr());
|
||||
dc_perform_smtp_idle(sendable_ctx.0.as_ptr());
|
||||
dc_perform_smtp_jobs(&ctx1.clone().read().unwrap());
|
||||
dc_perform_smtp_idle(&ctx1.clone().read().unwrap());
|
||||
});
|
||||
|
||||
let dir = tempdir().unwrap();
|
||||
let dbfile = CString::new(dir.path().join("db.sqlite").to_str().unwrap()).unwrap();
|
||||
|
||||
println!("opening database {:?}", dbfile);
|
||||
dc_open(ctx, dbfile.as_ptr(), std::ptr::null());
|
||||
|
||||
dc_open(
|
||||
&mut ctx.clone().write().unwrap(),
|
||||
dbfile.as_ptr(),
|
||||
std::ptr::null(),
|
||||
);
|
||||
|
||||
println!("configuring");
|
||||
dc_set_config(
|
||||
ctx,
|
||||
&ctx.clone().read().unwrap(),
|
||||
CString::new("addr").unwrap().as_ptr(),
|
||||
CString::new("d@testrun.org").unwrap().as_ptr(),
|
||||
);
|
||||
dc_set_config(
|
||||
ctx,
|
||||
&ctx.clone().read().unwrap(),
|
||||
CString::new("mail_pw").unwrap().as_ptr(),
|
||||
CString::new("***").unwrap().as_ptr(),
|
||||
);
|
||||
dc_configure(ctx);
|
||||
dc_configure(&ctx.clone().read().unwrap());
|
||||
|
||||
std::thread::sleep_ms(4000);
|
||||
|
||||
let email = CString::new("dignifiedquire@gmail.com").unwrap();
|
||||
println!("sending a message");
|
||||
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 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 msg_text = CString::new("Hi, here is my first message!").unwrap();
|
||||
dc_send_text_msg(ctx, chat_id, msg_text.as_ptr());
|
||||
dc_send_text_msg(&ctx.clone().read().unwrap(), chat_id, msg_text.as_ptr());
|
||||
|
||||
println!("fetching chats..");
|
||||
let chats = dc_get_chatlist(ctx, 0, std::ptr::null(), 0);
|
||||
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) {
|
||||
let summary = dc_chatlist_get_summary(chats, 0, std::ptr::null_mut());
|
||||
@@ -125,7 +134,7 @@ fn main() {
|
||||
}
|
||||
dc_chatlist_unref(chats);
|
||||
|
||||
// let msglist = dc_get_chat_msgs(ctx, chat_id, 0, 0);
|
||||
// let msglist = dc_get_chat_msgs(&ctx.clone().read().unwrap(), 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