diff --git a/cmdline/cmdline.c b/cmdline/cmdline.c index 2eb3716e..acd3a2d6 100644 --- a/cmdline/cmdline.c +++ b/cmdline/cmdline.c @@ -451,8 +451,8 @@ char* mrmailbox_cmdline(mrmailbox_t* mailbox, const char* cmdline) "set []\n" "get \n" "configure\n" - "connect\n" - "disconnect\n" + "idle\n" + "interruptidle\n" "poll\n" "help imex (Import/Export)\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; } - else if( strcmp(cmd, "connect")==0 ) + else if( strcmp(cmd, "idle")==0 ) { - mrmailbox_connect(mailbox); - ret = COMMAND_SUCCEEDED; + ret = COMMAND_FAILED; } - else if( strcmp(cmd, "disconnect")==0 ) + else if( strcmp(cmd, "interruptidle")==0 ) { - mrmailbox_disconnect(mailbox); - ret = COMMAND_SUCCEEDED; + ret = COMMAND_FAILED; } else if( strcmp(cmd, "poll")==0 ) { diff --git a/cmdline/main.c b/cmdline/main.c index 2c61811e..cd706181 100644 --- a/cmdline/main.c +++ b/cmdline/main.c @@ -173,7 +173,6 @@ int main(int argc, char ** argv) } else if( strcmp(cmd, "getqr")==0 || strcmp(cmd, "getbadqr")==0 ) { - mrmailbox_connect(mailbox); char* qrstr = mrmailbox_get_securejoin_qr(mailbox, arg1? atoi(arg1) : 0); if( qrstr && qrstr[0] ) { if( strcmp(cmd, "getbadqr")==0 && strlen(qrstr)>40 ) { diff --git a/src/mrjob.c b/src/mrjob.c index b65d2597..749fba49 100644 --- a/src/mrjob.c +++ b/src/mrjob.c @@ -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); job.m_start_again_at = 0; 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_IMAP: mrmailbox_send_msg_to_imap (mailbox, &job); break; case MRJ_DELETE_MSG_ON_IMAP: mrmailbox_delete_msg_on_imap (mailbox, &job); break; diff --git a/src/mrjob.h b/src/mrjob.h index 14cb3ec1..b94cc6e3 100644 --- a/src/mrjob.h +++ b/src/mrjob.h @@ -26,14 +26,13 @@ extern "C" { #endif -#define MRJ_DISCONNECT 50 /* low priority ... */ -#define MRJ_DELETE_MSG_ON_IMAP 100 +#define MRJ_DELETE_MSG_ON_IMAP 100 /* low priority ... */ #define MRJ_MARKSEEN_MDN_ON_IMAP 102 #define MRJ_SEND_MDN 105 #define MRJ_MARKSEEN_MSG_ON_IMAP 110 #define MRJ_SEND_MSG_TO_IMAP 700 -#define MRJ_SEND_MSG_TO_SMTP 800 -#define MRJ_CONNECT_TO_IMAP 900 /* ... high priority*/ +#define MRJ_SEND_MSG_TO_SMTP 800 /* ... high priority*/ + /** * Library-internal. diff --git a/src/mrmailbox.c b/src/mrmailbox.c index 3685cd0e..dd039a05 100644 --- a/src/mrmailbox.c +++ b/src/mrmailbox.c @@ -252,7 +252,7 @@ int mrmailbox_open(mrmailbox_t* mailbox, const char* dbfile, const char* blobdir if( !mrsqlite3_open__(mailbox->m_sql, dbfile, 0) ) { 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 */ mailbox->m_dbfile = safe_strdup(dbfile); diff --git a/src/mrmailbox.h b/src/mrmailbox.h index 8c10b469..4e0713f9 100644 --- a/src/mrmailbox.h +++ b/src/mrmailbox.h @@ -62,11 +62,10 @@ extern "C" { * mrmailbox_set_config(mailbox, "mail_pw", "***"); * * mrmailbox_configure(mailbox); - * mrmailbox_connect(); * ``` * * 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: * @@ -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: * * ``` + * mrmailbox_poll(); + * * mrarray_t* msglist = mrmailbox_get_chat_msgs(mailbox, chat_id, 0, 0); * 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_is_configured (mrmailbox_t*); -void mrmailbox_connect (mrmailbox_t*); -void mrmailbox_disconnect (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*); @@ -328,7 +329,6 @@ int mrchat_set_draft (mrchat_t*, const char* msg); /* d #define mrpoortext_unref mrlot_unref #define mrmailbox_imex_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 diff --git a/src/mrmailbox_configure.c b/src/mrmailbox_configure.c index 6e8baeab..424ac53c 100644 --- a/src/mrmailbox_configure.c +++ b/src/mrmailbox_configure.c @@ -377,12 +377,11 @@ cleanup: * * @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 * * 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 - * and is much faster: + * database and you can call mrmailbox_poll() or mrmailbox_idle() directly: * * ``` * if( !mrmailbox_is_configured(mailbox) ) { @@ -390,7 +389,7 @@ cleanup: * // show an error and/or try over * } * } - * mrmailbox_connect(mailbox); + * mrmailbox_idle(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. 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_kill_actions__(mailbox, MRJ_CONNECT_TO_IMAP, MRJ_DISCONNECT); mrsqlite3_unlock(mailbox->m_sql); 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. * @@ -731,7 +720,7 @@ int mrmailbox_configure_and_connect(mrmailbox_t* mailbox) // deprecated * * @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. */ int mrmailbox_is_configured(mrmailbox_t* mailbox) diff --git a/src/mrmailbox_connect.c b/src/mrmailbox_connect.c index 05272c4a..9af074aa 100644 --- a/src/mrmailbox_connect.c +++ b/src/mrmailbox_connect.c @@ -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 * 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"); mrimap_heartbeat(mailbox->m_imap); } + + +int mrmailbox_idle(mrmailbox_t* mailbox) +{ + return 0; +} + + +int mrmailbox_interrupt_idle(mrmailbox_t* mailbox) +{ + return 0; +}