mirror of
https://github.com/deltachat/deltachat-core.git
synced 2025-10-04 18:29:19 +02:00
prepare idle
This commit is contained in:
parent
2f9e9f278c
commit
031bcafa47
8 changed files with 32 additions and 92 deletions
|
@ -451,8 +451,8 @@ char* mrmailbox_cmdline(mrmailbox_t* mailbox, const char* cmdline)
|
||||||
"set <configuration-key> [<value>]\n"
|
"set <configuration-key> [<value>]\n"
|
||||||
"get <configuration-key>\n"
|
"get <configuration-key>\n"
|
||||||
"configure\n"
|
"configure\n"
|
||||||
"connect\n"
|
"idle\n"
|
||||||
"disconnect\n"
|
"interruptidle\n"
|
||||||
"poll\n"
|
"poll\n"
|
||||||
"help imex (Import/Export)\n"
|
"help imex (Import/Export)\n"
|
||||||
"==============================Chat commands==\n"
|
"==============================Chat commands==\n"
|
||||||
|
@ -680,15 +680,13 @@ char* mrmailbox_cmdline(mrmailbox_t* mailbox, const char* cmdline)
|
||||||
{
|
{
|
||||||
ret = mrmailbox_configure(mailbox)? COMMAND_SUCCEEDED : COMMAND_FAILED;
|
ret = mrmailbox_configure(mailbox)? COMMAND_SUCCEEDED : COMMAND_FAILED;
|
||||||
}
|
}
|
||||||
else if( strcmp(cmd, "connect")==0 )
|
else if( strcmp(cmd, "idle")==0 )
|
||||||
{
|
{
|
||||||
mrmailbox_connect(mailbox);
|
ret = COMMAND_FAILED;
|
||||||
ret = COMMAND_SUCCEEDED;
|
|
||||||
}
|
}
|
||||||
else if( strcmp(cmd, "disconnect")==0 )
|
else if( strcmp(cmd, "interruptidle")==0 )
|
||||||
{
|
{
|
||||||
mrmailbox_disconnect(mailbox);
|
ret = COMMAND_FAILED;
|
||||||
ret = COMMAND_SUCCEEDED;
|
|
||||||
}
|
}
|
||||||
else if( strcmp(cmd, "poll")==0 )
|
else if( strcmp(cmd, "poll")==0 )
|
||||||
{
|
{
|
||||||
|
|
|
@ -173,7 +173,6 @@ int main(int argc, char ** argv)
|
||||||
}
|
}
|
||||||
else if( strcmp(cmd, "getqr")==0 || strcmp(cmd, "getbadqr")==0 )
|
else if( strcmp(cmd, "getqr")==0 || strcmp(cmd, "getbadqr")==0 )
|
||||||
{
|
{
|
||||||
mrmailbox_connect(mailbox);
|
|
||||||
char* qrstr = mrmailbox_get_securejoin_qr(mailbox, arg1? atoi(arg1) : 0);
|
char* qrstr = mrmailbox_get_securejoin_qr(mailbox, arg1? atoi(arg1) : 0);
|
||||||
if( qrstr && qrstr[0] ) {
|
if( qrstr && qrstr[0] ) {
|
||||||
if( strcmp(cmd, "getbadqr")==0 && strlen(qrstr)>40 ) {
|
if( strcmp(cmd, "getbadqr")==0 && strlen(qrstr)>40 ) {
|
||||||
|
|
|
@ -131,8 +131,6 @@ static void* job_thread_entry_point(void* entry_arg)
|
||||||
mrmailbox_log_info(mailbox, 0, "Executing job #%i, action %i...", (int)job.m_job_id, (int)job.m_action);
|
mrmailbox_log_info(mailbox, 0, "Executing job #%i, action %i...", (int)job.m_job_id, (int)job.m_action);
|
||||||
job.m_start_again_at = 0;
|
job.m_start_again_at = 0;
|
||||||
switch( job.m_action ) {
|
switch( job.m_action ) {
|
||||||
case MRJ_CONNECT_TO_IMAP: mrmailbox_ll_connect_to_imap (mailbox, &job); break;
|
|
||||||
case MRJ_DISCONNECT: mrmailbox_ll_disconnect (mailbox, &job); break;
|
|
||||||
case MRJ_SEND_MSG_TO_SMTP: mrmailbox_send_msg_to_smtp (mailbox, &job); break;
|
case MRJ_SEND_MSG_TO_SMTP: mrmailbox_send_msg_to_smtp (mailbox, &job); break;
|
||||||
case MRJ_SEND_MSG_TO_IMAP: mrmailbox_send_msg_to_imap (mailbox, &job); break;
|
case MRJ_SEND_MSG_TO_IMAP: mrmailbox_send_msg_to_imap (mailbox, &job); break;
|
||||||
case MRJ_DELETE_MSG_ON_IMAP: mrmailbox_delete_msg_on_imap (mailbox, &job); break;
|
case MRJ_DELETE_MSG_ON_IMAP: mrmailbox_delete_msg_on_imap (mailbox, &job); break;
|
||||||
|
|
|
@ -26,14 +26,13 @@ extern "C" {
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
|
||||||
#define MRJ_DISCONNECT 50 /* low priority ... */
|
#define MRJ_DELETE_MSG_ON_IMAP 100 /* low priority ... */
|
||||||
#define MRJ_DELETE_MSG_ON_IMAP 100
|
|
||||||
#define MRJ_MARKSEEN_MDN_ON_IMAP 102
|
#define MRJ_MARKSEEN_MDN_ON_IMAP 102
|
||||||
#define MRJ_SEND_MDN 105
|
#define MRJ_SEND_MDN 105
|
||||||
#define MRJ_MARKSEEN_MSG_ON_IMAP 110
|
#define MRJ_MARKSEEN_MSG_ON_IMAP 110
|
||||||
#define MRJ_SEND_MSG_TO_IMAP 700
|
#define MRJ_SEND_MSG_TO_IMAP 700
|
||||||
#define MRJ_SEND_MSG_TO_SMTP 800
|
#define MRJ_SEND_MSG_TO_SMTP 800 /* ... high priority*/
|
||||||
#define MRJ_CONNECT_TO_IMAP 900 /* ... high priority*/
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Library-internal.
|
* Library-internal.
|
||||||
|
|
|
@ -252,7 +252,7 @@ int mrmailbox_open(mrmailbox_t* mailbox, const char* dbfile, const char* blobdir
|
||||||
if( !mrsqlite3_open__(mailbox->m_sql, dbfile, 0) ) {
|
if( !mrsqlite3_open__(mailbox->m_sql, dbfile, 0) ) {
|
||||||
goto cleanup;
|
goto cleanup;
|
||||||
}
|
}
|
||||||
mrjob_kill_actions__(mailbox, MRJ_CONNECT_TO_IMAP, MRJ_DISCONNECT);
|
//mrjob_kill_actions__(mailbox, MRJ_CONNECT_TO_IMAP, MRJ_DISCONNECT);
|
||||||
|
|
||||||
/* backup dbfile name */
|
/* backup dbfile name */
|
||||||
mailbox->m_dbfile = safe_strdup(dbfile);
|
mailbox->m_dbfile = safe_strdup(dbfile);
|
||||||
|
|
|
@ -62,11 +62,10 @@ extern "C" {
|
||||||
* mrmailbox_set_config(mailbox, "mail_pw", "***");
|
* mrmailbox_set_config(mailbox, "mail_pw", "***");
|
||||||
*
|
*
|
||||||
* mrmailbox_configure(mailbox);
|
* mrmailbox_configure(mailbox);
|
||||||
* mrmailbox_connect();
|
|
||||||
* ```
|
* ```
|
||||||
*
|
*
|
||||||
* mrmailbox_configure() may take a while and saves the result in
|
* mrmailbox_configure() may take a while and saves the result in
|
||||||
* the database. On subsequent starts, you can call mrmailbox_connect() directly.
|
* the database. On subsequent starts, calling this function is not needed.
|
||||||
*
|
*
|
||||||
* However, now you can send your first message:
|
* However, now you can send your first message:
|
||||||
*
|
*
|
||||||
|
@ -81,6 +80,8 @@ extern "C" {
|
||||||
* Answer this email in any email program with "Got it!" and you will get the message from delta as follows:
|
* Answer this email in any email program with "Got it!" and you will get the message from delta as follows:
|
||||||
*
|
*
|
||||||
* ```
|
* ```
|
||||||
|
* mrmailbox_poll();
|
||||||
|
*
|
||||||
* mrarray_t* msglist = mrmailbox_get_chat_msgs(mailbox, chat_id, 0, 0);
|
* mrarray_t* msglist = mrmailbox_get_chat_msgs(mailbox, chat_id, 0, 0);
|
||||||
* for( size_t i = 0; i < mrarray_get_cnt(msglist); i++ )
|
* for( size_t i = 0; i < mrarray_get_cnt(msglist); i++ )
|
||||||
* {
|
* {
|
||||||
|
@ -212,9 +213,9 @@ char* mrmailbox_get_info (mrmailbox_t*);
|
||||||
int mrmailbox_configure (mrmailbox_t*);
|
int mrmailbox_configure (mrmailbox_t*);
|
||||||
int mrmailbox_is_configured (mrmailbox_t*);
|
int mrmailbox_is_configured (mrmailbox_t*);
|
||||||
|
|
||||||
void mrmailbox_connect (mrmailbox_t*);
|
|
||||||
void mrmailbox_disconnect (mrmailbox_t*);
|
|
||||||
int mrmailbox_poll (mrmailbox_t*);
|
int mrmailbox_poll (mrmailbox_t*);
|
||||||
|
int mrmailbox_idle (mrmailbox_t*);
|
||||||
|
int mrmailbox_interrupt_idle (mrmailbox_t*);
|
||||||
|
|
||||||
void mrmailbox_stop_ongoing_process(mrmailbox_t*);
|
void mrmailbox_stop_ongoing_process(mrmailbox_t*);
|
||||||
|
|
||||||
|
@ -328,7 +329,6 @@ int mrchat_set_draft (mrchat_t*, const char* msg); /* d
|
||||||
#define mrpoortext_unref mrlot_unref
|
#define mrpoortext_unref mrlot_unref
|
||||||
#define mrmailbox_imex_cancel mrmailbox_stop_ongoing_process
|
#define mrmailbox_imex_cancel mrmailbox_stop_ongoing_process
|
||||||
#define mrmailbox_configure_cancel mrmailbox_stop_ongoing_process
|
#define mrmailbox_configure_cancel mrmailbox_stop_ongoing_process
|
||||||
int mrmailbox_configure_and_connect(mrmailbox_t*); // deprecated - use mrmailbox_configure() and mrmailbox_connect() instead
|
|
||||||
|
|
||||||
|
|
||||||
#ifdef __cplusplus
|
#ifdef __cplusplus
|
||||||
|
|
|
@ -377,12 +377,11 @@ cleanup:
|
||||||
*
|
*
|
||||||
* @param mailbox the mailbox object as created by mrmailbox_new().
|
* @param mailbox the mailbox object as created by mrmailbox_new().
|
||||||
*
|
*
|
||||||
* @return 1=configured successfully can connect with mrmailbox_connect()
|
* @return 1=configured successfully,
|
||||||
* 0=configuration failed
|
* 0=configuration failed
|
||||||
*
|
*
|
||||||
* There is no need to call this every program start, the result is saved in the
|
* There is no need to call this every program start, the result is saved in the
|
||||||
* database. Instead, you can use mrmailbox_connect() which reuses the configuration
|
* database and you can call mrmailbox_poll() or mrmailbox_idle() directly:
|
||||||
* and is much faster:
|
|
||||||
*
|
*
|
||||||
* ```
|
* ```
|
||||||
* if( !mrmailbox_is_configured(mailbox) ) {
|
* if( !mrmailbox_is_configured(mailbox) ) {
|
||||||
|
@ -390,7 +389,7 @@ cleanup:
|
||||||
* // show an error and/or try over
|
* // show an error and/or try over
|
||||||
* }
|
* }
|
||||||
* }
|
* }
|
||||||
* mrmailbox_connect(mailbox);
|
* mrmailbox_idle(mailbox);
|
||||||
* ```
|
* ```
|
||||||
*/
|
*/
|
||||||
int mrmailbox_configure(mrmailbox_t* mailbox)
|
int mrmailbox_configure(mrmailbox_t* mailbox)
|
||||||
|
@ -432,7 +431,7 @@ int mrmailbox_configure(mrmailbox_t* mailbox)
|
||||||
//mrsqlite3_set_config_int__(mailbox->m_sql, "configured", 0); -- NO: we do _not_ reset this flag if it was set once; otherwise the user won't get back to his chats (as an alternative, we could change the UI). Moreover, and not changeable in the UI, we use this flag to check if we shall search for backups.
|
//mrsqlite3_set_config_int__(mailbox->m_sql, "configured", 0); -- NO: we do _not_ reset this flag if it was set once; otherwise the user won't get back to his chats (as an alternative, we could change the UI). Moreover, and not changeable in the UI, we use this flag to check if we shall search for backups.
|
||||||
mailbox->m_smtp->m_log_connect_errors = 1;
|
mailbox->m_smtp->m_log_connect_errors = 1;
|
||||||
mailbox->m_imap->m_log_connect_errors = 1;
|
mailbox->m_imap->m_log_connect_errors = 1;
|
||||||
mrjob_kill_actions__(mailbox, MRJ_CONNECT_TO_IMAP, MRJ_DISCONNECT);
|
//mrjob_kill_actions__(mailbox, MRJ_CONNECT_TO_IMAP, MRJ_DISCONNECT);
|
||||||
|
|
||||||
mrsqlite3_unlock(mailbox->m_sql);
|
mrsqlite3_unlock(mailbox->m_sql);
|
||||||
locked = 0;
|
locked = 0;
|
||||||
|
@ -711,16 +710,6 @@ cleanup:
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
int mrmailbox_configure_and_connect(mrmailbox_t* mailbox) // deprecated
|
|
||||||
{
|
|
||||||
int success = mrmailbox_configure(mailbox);
|
|
||||||
if( success ) {
|
|
||||||
mrmailbox_connect(mailbox);
|
|
||||||
}
|
|
||||||
return success;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Check if the mailbox is already configured.
|
* Check if the mailbox is already configured.
|
||||||
*
|
*
|
||||||
|
@ -731,7 +720,7 @@ int mrmailbox_configure_and_connect(mrmailbox_t* mailbox) // deprecated
|
||||||
*
|
*
|
||||||
* @param mailbox The mailbox object as created by mrmailbox_new().
|
* @param mailbox The mailbox object as created by mrmailbox_new().
|
||||||
*
|
*
|
||||||
* @return 1=mailbox is configured and mrmailbox_connect() can be called directly as needed,
|
* @return 1=mailbox is configured and mrmailbox_poll() or mrmailbox_idle() will work as expected;
|
||||||
* 0=mailbox is not configured and a configuration by mrmailbox_configure() is required.
|
* 0=mailbox is not configured and a configuration by mrmailbox_configure() is required.
|
||||||
*/
|
*/
|
||||||
int mrmailbox_is_configured(mrmailbox_t* mailbox)
|
int mrmailbox_is_configured(mrmailbox_t* mailbox)
|
||||||
|
|
|
@ -78,61 +78,6 @@ void mrmailbox_ll_disconnect(mrmailbox_t* mailbox, mrjob_t* job /*may be NULL if
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Connect to the mailbox using the configured settings. We connect using IMAP-IDLE or, if this is not possible,
|
|
||||||
* a using poll algorithm.
|
|
||||||
*
|
|
||||||
* @memberof mrmailbox_t
|
|
||||||
*
|
|
||||||
* @param mailbox The mailbox object as created by mrmailbox_new()
|
|
||||||
*
|
|
||||||
* @return None
|
|
||||||
*/
|
|
||||||
void mrmailbox_connect(mrmailbox_t* mailbox)
|
|
||||||
{
|
|
||||||
if( mailbox == NULL || mailbox->m_magic != MR_MAILBOX_MAGIC ) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
mrsqlite3_lock(mailbox->m_sql);
|
|
||||||
|
|
||||||
mailbox->m_smtp->m_log_connect_errors = 1;
|
|
||||||
mailbox->m_imap->m_log_connect_errors = 1;
|
|
||||||
|
|
||||||
mrjob_kill_actions__(mailbox, MRJ_CONNECT_TO_IMAP, MRJ_DISCONNECT);
|
|
||||||
mrjob_add__(mailbox, MRJ_CONNECT_TO_IMAP, 0, NULL, 0);
|
|
||||||
|
|
||||||
mrsqlite3_unlock(mailbox->m_sql);
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Disonnect the mailbox from the server.
|
|
||||||
* This function adds a job to disconnect the mailbox from the server.
|
|
||||||
* The disconnect job has a lower priority, so that pending sending etc. are
|
|
||||||
* executed before. During this time calls to mrmailbox_pull() will return 0.
|
|
||||||
*
|
|
||||||
* @memberof mrmailbox_t
|
|
||||||
*
|
|
||||||
* @param mailbox The mailbox object as created by mrmailbox_new()
|
|
||||||
*
|
|
||||||
* @return None
|
|
||||||
*/
|
|
||||||
void mrmailbox_disconnect(mrmailbox_t* mailbox)
|
|
||||||
{
|
|
||||||
if( mailbox == NULL || mailbox->m_magic != MR_MAILBOX_MAGIC ) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
mrsqlite3_lock(mailbox->m_sql);
|
|
||||||
|
|
||||||
mrjob_kill_actions__(mailbox, MRJ_CONNECT_TO_IMAP, MRJ_DISCONNECT);
|
|
||||||
mrjob_add__(mailbox, MRJ_DISCONNECT, 0, NULL, 0);
|
|
||||||
|
|
||||||
mrsqlite3_unlock(mailbox->m_sql);
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Check for changes in the mailbox. mrmailbox_poll() connects, checks and disconnects
|
* Check for changes in the mailbox. mrmailbox_poll() connects, checks and disconnects
|
||||||
* as fast as possible for this purpose. If there are new messages, you get them
|
* as fast as possible for this purpose. If there are new messages, you get them
|
||||||
|
@ -232,3 +177,15 @@ void mrmailbox_heartbeat(mrmailbox_t* mailbox)
|
||||||
//mrmailbox_log_info(mailbox, 0, "<3 Mailbox");
|
//mrmailbox_log_info(mailbox, 0, "<3 Mailbox");
|
||||||
mrimap_heartbeat(mailbox->m_imap);
|
mrimap_heartbeat(mailbox->m_imap);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
int mrmailbox_idle(mrmailbox_t* mailbox)
|
||||||
|
{
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
int mrmailbox_interrupt_idle(mrmailbox_t* mailbox)
|
||||||
|
{
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue