mirror of
https://github.com/deltachat/deltachat-core.git
synced 2025-10-06 03:50:08 +02:00
cleanup
This commit is contained in:
parent
e6f8fd4608
commit
942da81f39
7 changed files with 102 additions and 144 deletions
|
@ -102,7 +102,7 @@ static int mrmailbox_cleanup_contacts(mrmailbox_t* ths)
|
||||||
|
|
||||||
mrsqlite3_lock(ths->m_sql);
|
mrsqlite3_lock(ths->m_sql);
|
||||||
|
|
||||||
mrsqlite3_execute__(ths->m_sql, "DELETE FROM contacts WHERE id>" MR_STRINGIFY(MR_CONTACT_ID_LAST_SPECIAL) " AND blocked=0 AND NOT EXISTS (SELECT contact_id FROM chats_contacts where contacts.id = chats_contacts.contact_id) AND NOT EXISTS (select from_id from msgs WHERE msgs.from_id = contacts.id);");
|
mrsqlite3_execute__(ths->m_sql, "DELETE FROM contacts WHERE id>" MR_STRINGIFY(MR_CONTACT_ID_LAST_SPECIAL) " AND blocked=0 AND NOT EXISTS (SELECT contact_id FROM chats_contacts where contacts.id = chats_contacts.contact_id) AND NOT EXISTS (select from_id from msgs WHERE msgs.from_id = contacts.id);");
|
||||||
|
|
||||||
mrsqlite3_unlock(ths->m_sql);
|
mrsqlite3_unlock(ths->m_sql);
|
||||||
|
|
||||||
|
@ -273,14 +273,10 @@ static int poke_spec(mrmailbox_t* mailbox, const char* spec)
|
||||||
mailbox->m_cb(mailbox, MR_EVENT_MSGS_CHANGED, 0, 0); /* even if read_cnt>0, the number of messages added to the database may be 0. While we regard this issue using IMAP, we ignore it here. */
|
mailbox->m_cb(mailbox, MR_EVENT_MSGS_CHANGED, 0, 0); /* even if read_cnt>0, the number of messages added to the database may be 0. While we regard this issue using IMAP, we ignore it here. */
|
||||||
}
|
}
|
||||||
|
|
||||||
/* success */
|
|
||||||
success = 1;
|
success = 1;
|
||||||
|
|
||||||
/* cleanup */
|
|
||||||
cleanup:
|
cleanup:
|
||||||
if( dir ) {
|
if( dir ) { closedir(dir); }
|
||||||
closedir(dir);
|
|
||||||
}
|
|
||||||
free(real_spec);
|
free(real_spec);
|
||||||
free(suffix);
|
free(suffix);
|
||||||
return success;
|
return success;
|
||||||
|
|
|
@ -404,10 +404,8 @@ int mrcontact_load_from_db__(mrcontact_t* ths, mrsqlite3_t* sql, uint32_t contac
|
||||||
ths->m_authname = safe_strdup((char*)sqlite3_column_text (stmt, 4));
|
ths->m_authname = safe_strdup((char*)sqlite3_column_text (stmt, 4));
|
||||||
}
|
}
|
||||||
|
|
||||||
/* success */
|
|
||||||
success = 1;
|
success = 1;
|
||||||
|
|
||||||
/* cleanup */
|
|
||||||
cleanup:
|
cleanup:
|
||||||
return success;
|
return success;
|
||||||
}
|
}
|
||||||
|
|
|
@ -269,7 +269,7 @@ extern "C" {
|
||||||
* Acquire or release a wakelock.
|
* Acquire or release a wakelock.
|
||||||
*
|
*
|
||||||
* The core surrounds critical functions that should not be killed by the operating system with wakelocks.
|
* The core surrounds critical functions that should not be killed by the operating system with wakelocks.
|
||||||
* Before a critical function _MR_EVENT_WAKE_LOCK with data1=1_ is called, it it finishes, _MR_EVENT_WAKE_LOCK with data1=0_ is called.
|
* Before a critical function _MR_EVENT_WAKE_LOCK with data1=1_ is called, when it finishes, _MR_EVENT_WAKE_LOCK with data1=0_ is called.
|
||||||
* If you do not need this functionality, just ignore this event.
|
* If you do not need this functionality, just ignore this event.
|
||||||
*
|
*
|
||||||
* @param data1 1=acquire wakelock, 0=release wakelock, the core does not make nested or unsynchronized calls
|
* @param data1 1=acquire wakelock, 0=release wakelock, the core does not make nested or unsynchronized calls
|
||||||
|
|
172
src/mrmailbox.c
172
src/mrmailbox.c
|
@ -247,45 +247,40 @@ int mrmailbox_open(mrmailbox_t* mailbox, const char* dbfile, const char* blobdir
|
||||||
mrsqlite3_lock(mailbox->m_sql);
|
mrsqlite3_lock(mailbox->m_sql);
|
||||||
db_locked = 1;
|
db_locked = 1;
|
||||||
|
|
||||||
/* Open() sets up the object and connects to the given database
|
/* Open() sets up the object and connects to the given database
|
||||||
from which all configuration is read/written to. */
|
from which all configuration is read/written to. */
|
||||||
|
|
||||||
/* Create/open sqlite database */
|
/* Create/open sqlite database */
|
||||||
if( !mrsqlite3_open__(mailbox->m_sql, dbfile, 0) ) {
|
if( !mrsqlite3_open__(mailbox->m_sql, dbfile, 0) ) {
|
||||||
goto cleanup;
|
goto cleanup;
|
||||||
}
|
|
||||||
mrjob_kill_action__(mailbox, MRJ_CONNECT_TO_IMAP);
|
|
||||||
|
|
||||||
/* backup dbfile name */
|
|
||||||
mailbox->m_dbfile = safe_strdup(dbfile);
|
|
||||||
|
|
||||||
/* set blob-directory
|
|
||||||
(to avoid double slashed, the given directory should not end with an slash) */
|
|
||||||
if( blobdir && blobdir[0] ) {
|
|
||||||
mailbox->m_blobdir = safe_strdup(blobdir);
|
|
||||||
}
|
|
||||||
else {
|
|
||||||
mailbox->m_blobdir = mr_mprintf("%s-blobs", dbfile);
|
|
||||||
mr_create_folder(mailbox->m_blobdir, mailbox);
|
|
||||||
}
|
|
||||||
|
|
||||||
/* cache some settings */
|
|
||||||
update_config_cache__(mailbox, NULL);
|
|
||||||
|
|
||||||
/* success */
|
|
||||||
success = 1;
|
|
||||||
|
|
||||||
/* cleanup */
|
|
||||||
cleanup:
|
|
||||||
if( !success ) {
|
|
||||||
if( mrsqlite3_is_open(mailbox->m_sql) ) {
|
|
||||||
mrsqlite3_close__(mailbox->m_sql);
|
|
||||||
}
|
}
|
||||||
}
|
mrjob_kill_action__(mailbox, MRJ_CONNECT_TO_IMAP);
|
||||||
|
|
||||||
if( db_locked ) {
|
/* backup dbfile name */
|
||||||
mrsqlite3_unlock(mailbox->m_sql);
|
mailbox->m_dbfile = safe_strdup(dbfile);
|
||||||
}
|
|
||||||
|
/* set blob-directory
|
||||||
|
(to avoid double slashed, the given directory should not end with an slash) */
|
||||||
|
if( blobdir && blobdir[0] ) {
|
||||||
|
mailbox->m_blobdir = safe_strdup(blobdir);
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
mailbox->m_blobdir = mr_mprintf("%s-blobs", dbfile);
|
||||||
|
mr_create_folder(mailbox->m_blobdir, mailbox);
|
||||||
|
}
|
||||||
|
|
||||||
|
update_config_cache__(mailbox, NULL);
|
||||||
|
|
||||||
|
success = 1;
|
||||||
|
|
||||||
|
cleanup:
|
||||||
|
if( !success ) {
|
||||||
|
if( mrsqlite3_is_open(mailbox->m_sql) ) {
|
||||||
|
mrsqlite3_close__(mailbox->m_sql);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if( db_locked ) { mrsqlite3_unlock(mailbox->m_sql); }
|
||||||
|
|
||||||
return success;
|
return success;
|
||||||
}
|
}
|
||||||
|
@ -404,8 +399,10 @@ int mrmailbox_set_config(mrmailbox_t* ths, const char* key, const char* value)
|
||||||
}
|
}
|
||||||
|
|
||||||
mrsqlite3_lock(ths->m_sql);
|
mrsqlite3_lock(ths->m_sql);
|
||||||
|
|
||||||
ret = mrsqlite3_set_config__(ths->m_sql, key, value);
|
ret = mrsqlite3_set_config__(ths->m_sql, key, value);
|
||||||
update_config_cache__(ths, key);
|
update_config_cache__(ths, key);
|
||||||
|
|
||||||
mrsqlite3_unlock(ths->m_sql);
|
mrsqlite3_unlock(ths->m_sql);
|
||||||
|
|
||||||
return ret;
|
return ret;
|
||||||
|
@ -435,7 +432,9 @@ char* mrmailbox_get_config(mrmailbox_t* ths, const char* key, const char* def)
|
||||||
}
|
}
|
||||||
|
|
||||||
mrsqlite3_lock(ths->m_sql);
|
mrsqlite3_lock(ths->m_sql);
|
||||||
|
|
||||||
ret = mrsqlite3_get_config__(ths->m_sql, key, def);
|
ret = mrsqlite3_get_config__(ths->m_sql, key, def);
|
||||||
|
|
||||||
mrsqlite3_unlock(ths->m_sql);
|
mrsqlite3_unlock(ths->m_sql);
|
||||||
|
|
||||||
return ret; /* the returned string must be free()'d, returns NULL only if "def" is NULL and "key" is unset */
|
return ret; /* the returned string must be free()'d, returns NULL only if "def" is NULL and "key" is unset */
|
||||||
|
@ -457,8 +456,10 @@ int mrmailbox_set_config_int(mrmailbox_t* ths, const char* key, int32_t value)
|
||||||
}
|
}
|
||||||
|
|
||||||
mrsqlite3_lock(ths->m_sql);
|
mrsqlite3_lock(ths->m_sql);
|
||||||
|
|
||||||
ret = mrsqlite3_set_config_int__(ths->m_sql, key, value);
|
ret = mrsqlite3_set_config_int__(ths->m_sql, key, value);
|
||||||
update_config_cache__(ths, key);
|
update_config_cache__(ths, key);
|
||||||
|
|
||||||
mrsqlite3_unlock(ths->m_sql);
|
mrsqlite3_unlock(ths->m_sql);
|
||||||
|
|
||||||
return ret;
|
return ret;
|
||||||
|
@ -479,7 +480,9 @@ int32_t mrmailbox_get_config_int(mrmailbox_t* ths, const char* key, int32_t def)
|
||||||
}
|
}
|
||||||
|
|
||||||
mrsqlite3_lock(ths->m_sql);
|
mrsqlite3_lock(ths->m_sql);
|
||||||
|
|
||||||
ret = mrsqlite3_get_config_int__(ths->m_sql, key, def);
|
ret = mrsqlite3_get_config_int__(ths->m_sql, key, def);
|
||||||
|
|
||||||
mrsqlite3_unlock(ths->m_sql);
|
mrsqlite3_unlock(ths->m_sql);
|
||||||
|
|
||||||
return ret;
|
return ret;
|
||||||
|
@ -728,13 +731,8 @@ void mrmailbox_connect_to_imap(mrmailbox_t* ths, mrjob_t* job /*may be NULL if t
|
||||||
}
|
}
|
||||||
|
|
||||||
cleanup:
|
cleanup:
|
||||||
if( param ) {
|
if( is_locked ) { mrsqlite3_unlock(ths->m_sql); }
|
||||||
mrloginparam_unref(param);
|
mrloginparam_unref(param);
|
||||||
}
|
|
||||||
|
|
||||||
if( is_locked ) {
|
|
||||||
mrsqlite3_unlock(ths->m_sql);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@ -782,7 +780,9 @@ void mrmailbox_disconnect(mrmailbox_t* mailbox)
|
||||||
}
|
}
|
||||||
|
|
||||||
mrsqlite3_lock(mailbox->m_sql);
|
mrsqlite3_lock(mailbox->m_sql);
|
||||||
|
|
||||||
mrjob_kill_action__(mailbox, MRJ_CONNECT_TO_IMAP);
|
mrjob_kill_action__(mailbox, MRJ_CONNECT_TO_IMAP);
|
||||||
|
|
||||||
mrsqlite3_unlock(mailbox->m_sql);
|
mrsqlite3_unlock(mailbox->m_sql);
|
||||||
|
|
||||||
mrimap_disconnect(mailbox->m_imap);
|
mrimap_disconnect(mailbox->m_imap);
|
||||||
|
@ -845,19 +845,14 @@ mrchatlist_t* mrmailbox_get_chatlist(mrmailbox_t* mailbox, int listflags, const
|
||||||
mrsqlite3_lock(mailbox->m_sql);
|
mrsqlite3_lock(mailbox->m_sql);
|
||||||
db_locked = 1;
|
db_locked = 1;
|
||||||
|
|
||||||
if( !mrchatlist_load_from_db__(obj, listflags, query) ) {
|
if( !mrchatlist_load_from_db__(obj, listflags, query) ) {
|
||||||
goto cleanup;
|
goto cleanup;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* success */
|
success = 1;
|
||||||
|
|
||||||
success = 1;
|
|
||||||
|
|
||||||
/* cleanup */
|
|
||||||
cleanup:
|
cleanup:
|
||||||
if( db_locked ) {
|
if( db_locked ) { mrsqlite3_unlock(mailbox->m_sql); }
|
||||||
mrsqlite3_unlock(mailbox->m_sql);
|
|
||||||
}
|
|
||||||
|
|
||||||
if( success ) {
|
if( success ) {
|
||||||
return obj;
|
return obj;
|
||||||
|
@ -893,18 +888,14 @@ mrchat_t* mrmailbox_get_chat(mrmailbox_t* mailbox, uint32_t chat_id)
|
||||||
mrsqlite3_lock(mailbox->m_sql);
|
mrsqlite3_lock(mailbox->m_sql);
|
||||||
db_locked = 1;
|
db_locked = 1;
|
||||||
|
|
||||||
if( !mrchat_load_from_db__(obj, chat_id) ) {
|
if( !mrchat_load_from_db__(obj, chat_id) ) {
|
||||||
goto cleanup;
|
goto cleanup;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* success */
|
success = 1;
|
||||||
success = 1;
|
|
||||||
|
|
||||||
/* cleanup */
|
|
||||||
cleanup:
|
cleanup:
|
||||||
if( db_locked ) {
|
if( db_locked ) { mrsqlite3_unlock(mailbox->m_sql); }
|
||||||
mrsqlite3_unlock(mailbox->m_sql);
|
|
||||||
}
|
|
||||||
|
|
||||||
if( success ) {
|
if( success ) {
|
||||||
return obj;
|
return obj;
|
||||||
|
@ -1159,7 +1150,9 @@ mrarray_t* mrmailbox_get_chat_media(mrmailbox_t* mailbox, uint32_t chat_id, int
|
||||||
}
|
}
|
||||||
|
|
||||||
mrsqlite3_lock(mailbox->m_sql);
|
mrsqlite3_lock(mailbox->m_sql);
|
||||||
|
|
||||||
ret = mrmailbox_get_chat_media__(mailbox, chat_id, msg_type, or_msg_type);
|
ret = mrmailbox_get_chat_media__(mailbox, chat_id, msg_type, or_msg_type);
|
||||||
|
|
||||||
mrsqlite3_unlock(mailbox->m_sql);
|
mrsqlite3_unlock(mailbox->m_sql);
|
||||||
|
|
||||||
return ret;
|
return ret;
|
||||||
|
@ -1233,7 +1226,7 @@ uint32_t mrmailbox_get_next_media(mrmailbox_t* mailbox, uint32_t curr_msg_id, in
|
||||||
|
|
||||||
cleanup:
|
cleanup:
|
||||||
if( locked ) { mrsqlite3_unlock(mailbox->m_sql); }
|
if( locked ) { mrsqlite3_unlock(mailbox->m_sql); }
|
||||||
if( list ) { mrarray_unref(list); }
|
mrarray_unref(list);
|
||||||
mrmsg_unref(msg);
|
mrmsg_unref(msg);
|
||||||
return ret_msg_id;
|
return ret_msg_id;
|
||||||
}
|
}
|
||||||
|
@ -1338,9 +1331,7 @@ mrarray_t* mrmailbox_get_fresh_msgs(mrmailbox_t* mailbox)
|
||||||
success = 1;
|
success = 1;
|
||||||
|
|
||||||
cleanup:
|
cleanup:
|
||||||
if( locked ) {
|
if( locked ) { mrsqlite3_unlock(mailbox->m_sql); }
|
||||||
mrsqlite3_unlock(mailbox->m_sql);
|
|
||||||
}
|
|
||||||
|
|
||||||
if( success ) {
|
if( success ) {
|
||||||
return ret;
|
return ret;
|
||||||
|
@ -1452,9 +1443,7 @@ mrarray_t* mrmailbox_get_chat_msgs(mrmailbox_t* mailbox, uint32_t chat_id, uint3
|
||||||
success = 1;
|
success = 1;
|
||||||
|
|
||||||
cleanup:
|
cleanup:
|
||||||
if( locked ) {
|
if( locked ) { mrsqlite3_unlock(mailbox->m_sql); }
|
||||||
mrsqlite3_unlock(mailbox->m_sql);
|
|
||||||
}
|
|
||||||
|
|
||||||
if( success ) {
|
if( success ) {
|
||||||
return ret;
|
return ret;
|
||||||
|
@ -1555,9 +1544,7 @@ mrarray_t* mrmailbox_search_msgs(mrmailbox_t* mailbox, uint32_t chat_id, const c
|
||||||
success = 1;
|
success = 1;
|
||||||
|
|
||||||
cleanup:
|
cleanup:
|
||||||
if( locked ) {
|
if( locked ) { mrsqlite3_unlock(mailbox->m_sql); }
|
||||||
mrsqlite3_unlock(mailbox->m_sql);
|
|
||||||
}
|
|
||||||
free(strLikeInText);
|
free(strLikeInText);
|
||||||
free(strLikeBeg);
|
free(strLikeBeg);
|
||||||
free(real_query);
|
free(real_query);
|
||||||
|
@ -3133,7 +3120,9 @@ int mrmailbox_is_contact_in_chat(mrmailbox_t* mailbox, uint32_t chat_id, uint32_
|
||||||
}
|
}
|
||||||
|
|
||||||
mrsqlite3_lock(mailbox->m_sql);
|
mrsqlite3_lock(mailbox->m_sql);
|
||||||
|
|
||||||
ret = mrmailbox_is_contact_in_chat__(mailbox, chat_id, contact_id);
|
ret = mrmailbox_is_contact_in_chat__(mailbox, chat_id, contact_id);
|
||||||
|
|
||||||
mrsqlite3_unlock(mailbox->m_sql);
|
mrsqlite3_unlock(mailbox->m_sql);
|
||||||
|
|
||||||
return ret;
|
return ret;
|
||||||
|
@ -3720,12 +3709,8 @@ mrarray_t* mrmailbox_get_known_contacts(mrmailbox_t* mailbox, const char* query)
|
||||||
}
|
}
|
||||||
|
|
||||||
cleanup:
|
cleanup:
|
||||||
if( locked ) {
|
if( locked ) { mrsqlite3_unlock(mailbox->m_sql); }
|
||||||
mrsqlite3_unlock(mailbox->m_sql);
|
if( s3strLikeCmd ) { sqlite3_free(s3strLikeCmd); }
|
||||||
}
|
|
||||||
if( s3strLikeCmd ) {
|
|
||||||
sqlite3_free(s3strLikeCmd);
|
|
||||||
}
|
|
||||||
free(self_addr);
|
free(self_addr);
|
||||||
free(self_name);
|
free(self_name);
|
||||||
free(self_name2);
|
free(self_name2);
|
||||||
|
@ -3868,7 +3853,9 @@ void mrmailbox_marknoticed_contact(mrmailbox_t* mailbox, uint32_t contact_id)
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
mrsqlite3_lock(mailbox->m_sql);
|
mrsqlite3_lock(mailbox->m_sql);
|
||||||
|
|
||||||
marknoticed_contact__(mailbox, contact_id);
|
marknoticed_contact__(mailbox, contact_id);
|
||||||
|
|
||||||
mrsqlite3_unlock(mailbox->m_sql);
|
mrsqlite3_unlock(mailbox->m_sql);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -3967,14 +3954,8 @@ void mrmailbox_block_contact(mrmailbox_t* mailbox, uint32_t contact_id, int new_
|
||||||
}
|
}
|
||||||
|
|
||||||
cleanup:
|
cleanup:
|
||||||
if( transaction_pending ) {
|
if( transaction_pending ) { mrsqlite3_rollback__(mailbox->m_sql); }
|
||||||
mrsqlite3_rollback__(mailbox->m_sql);
|
if( locked ) { mrsqlite3_unlock(mailbox->m_sql); }
|
||||||
}
|
|
||||||
|
|
||||||
if( locked ) {
|
|
||||||
mrsqlite3_unlock(mailbox->m_sql);
|
|
||||||
}
|
|
||||||
|
|
||||||
mrcontact_unref(contact);
|
mrcontact_unref(contact);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -4179,9 +4160,7 @@ int mrmailbox_delete_contact(mrmailbox_t* mailbox, uint32_t contact_id)
|
||||||
success = 1;
|
success = 1;
|
||||||
|
|
||||||
cleanup:
|
cleanup:
|
||||||
if( locked ) {
|
if( locked ) { mrsqlite3_unlock(mailbox->m_sql); }
|
||||||
mrsqlite3_unlock(mailbox->m_sql);
|
|
||||||
}
|
|
||||||
return success;
|
return success;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -4349,9 +4328,7 @@ mrmsg_t* mrmailbox_get_msg(mrmailbox_t* mailbox, uint32_t msg_id)
|
||||||
success = 1;
|
success = 1;
|
||||||
|
|
||||||
cleanup:
|
cleanup:
|
||||||
if( db_locked ) {
|
if( db_locked ) { mrsqlite3_unlock(mailbox->m_sql); }
|
||||||
mrsqlite3_unlock(mailbox->m_sql);
|
|
||||||
}
|
|
||||||
|
|
||||||
if( success ) {
|
if( success ) {
|
||||||
return obj;
|
return obj;
|
||||||
|
@ -4708,9 +4685,7 @@ void mrmailbox_delete_msg_on_imap(mrmailbox_t* mailbox, mrjob_t* job)
|
||||||
locked = 0;
|
locked = 0;
|
||||||
|
|
||||||
cleanup:
|
cleanup:
|
||||||
if( locked ) {
|
if( locked ) { mrsqlite3_unlock(mailbox->m_sql); }
|
||||||
mrsqlite3_unlock(mailbox->m_sql);
|
|
||||||
}
|
|
||||||
mrmsg_unref(msg);
|
mrmsg_unref(msg);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -4820,9 +4795,7 @@ void mrmailbox_markseen_msg_on_imap(mrmailbox_t* mailbox, mrjob_t* job)
|
||||||
}
|
}
|
||||||
|
|
||||||
cleanup:
|
cleanup:
|
||||||
if( locked ) {
|
if( locked ) { mrsqlite3_unlock(mailbox->m_sql); }
|
||||||
mrsqlite3_unlock(mailbox->m_sql);
|
|
||||||
}
|
|
||||||
mrmsg_unref(msg);
|
mrmsg_unref(msg);
|
||||||
free(new_server_folder);
|
free(new_server_folder);
|
||||||
}
|
}
|
||||||
|
@ -5023,7 +4996,8 @@ void mrmailbox_send_mdn(mrmailbox_t* mailbox, mrjob_t* job)
|
||||||
}
|
}
|
||||||
|
|
||||||
/* connect to SMTP server, if not yet done */
|
/* connect to SMTP server, if not yet done */
|
||||||
if( !mrsmtp_is_connected(mailbox->m_smtp) ) {
|
if( !mrsmtp_is_connected(mailbox->m_smtp) )
|
||||||
|
{
|
||||||
mrloginparam_t* loginparam = mrloginparam_new();
|
mrloginparam_t* loginparam = mrloginparam_new();
|
||||||
mrsqlite3_lock(mailbox->m_sql);
|
mrsqlite3_lock(mailbox->m_sql);
|
||||||
mrloginparam_read__(loginparam, mailbox->m_sql, "configured_");
|
mrloginparam_read__(loginparam, mailbox->m_sql, "configured_");
|
||||||
|
|
|
@ -863,27 +863,26 @@ void mrmailbox_receive_imf(mrmailbox_t* mailbox, const char* imf_raw_not_termina
|
||||||
goto cleanup; /* Error - even adding an empty record won't help as we do not know the message ID */
|
goto cleanup; /* Error - even adding an empty record won't help as we do not know the message ID */
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/* Check, if the mail comes from extern, resp. is not sent by us. This is a _really_ important step
|
||||||
|
as messages sent by us are used to validate other mail senders and receivers.
|
||||||
|
For this purpose, we assume, the `Return-Path:`-header is never present if the message is sent by us.
|
||||||
|
The `Received:`-header may be another idea, however, this is also set if mails are transfered from other accounts via IMAP.
|
||||||
|
Using `From:` alone is no good idea, as mailboxes may use different sending-addresses - moreover, they may change over the years.
|
||||||
|
However, we use `From:` as an additional hint below. */
|
||||||
|
if( mrmimeparser_lookup_field(mime_parser, "Return-Path") ) {
|
||||||
|
has_return_path = 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
if( has_return_path ) {
|
||||||
|
incoming = 1;
|
||||||
|
}
|
||||||
|
|
||||||
mrsqlite3_lock(mailbox->m_sql);
|
mrsqlite3_lock(mailbox->m_sql);
|
||||||
db_locked = 1;
|
db_locked = 1;
|
||||||
|
|
||||||
mrsqlite3_begin_transaction__(mailbox->m_sql);
|
mrsqlite3_begin_transaction__(mailbox->m_sql);
|
||||||
transaction_pending = 1;
|
transaction_pending = 1;
|
||||||
|
|
||||||
|
|
||||||
/* Check, if the mail comes from extern, resp. is not sent by us. This is a _really_ important step
|
|
||||||
as messages sent by us are used to validate other mail senders and receivers.
|
|
||||||
For this purpose, we assume, the `Return-Path:`-header is never present if the message is sent by us.
|
|
||||||
The `Received:`-header may be another idea, however, this is also set if mails are transfered from other accounts via IMAP.
|
|
||||||
Using `From:` alone is no good idea, as mailboxes may use different sending-addresses - moreover, they may change over the years.
|
|
||||||
However, we use `From:` as an additional hint below. */
|
|
||||||
if( mrmimeparser_lookup_field(mime_parser, "Return-Path") ) {
|
|
||||||
has_return_path = 1;
|
|
||||||
}
|
|
||||||
|
|
||||||
if( has_return_path ) {
|
|
||||||
incoming = 1;
|
|
||||||
}
|
|
||||||
|
|
||||||
/* for incoming messages, get From: and check if it is known (for known From:'s we add the other To:/Cc:/Bcc: in the 3rd pass) */
|
/* for incoming messages, get From: and check if it is known (for known From:'s we add the other To:/Cc:/Bcc: in the 3rd pass) */
|
||||||
if( incoming
|
if( incoming
|
||||||
&& (field=mrmimeparser_lookup_field(mime_parser, "From"))!=NULL
|
&& (field=mrmimeparser_lookup_field(mime_parser, "From"))!=NULL
|
||||||
|
@ -1322,31 +1321,17 @@ void mrmailbox_receive_imf(mrmailbox_t* mailbox, const char* imf_raw_not_termina
|
||||||
free(emlname);
|
free(emlname);
|
||||||
}
|
}
|
||||||
|
|
||||||
/* end sql-transaction */
|
|
||||||
mrsqlite3_commit__(mailbox->m_sql);
|
mrsqlite3_commit__(mailbox->m_sql);
|
||||||
transaction_pending = 0;
|
transaction_pending = 0;
|
||||||
|
|
||||||
/* done */
|
|
||||||
cleanup:
|
cleanup:
|
||||||
if( transaction_pending ) {
|
if( transaction_pending ) { mrsqlite3_rollback__(mailbox->m_sql); }
|
||||||
mrsqlite3_rollback__(mailbox->m_sql);
|
if( db_locked ) { mrsqlite3_unlock(mailbox->m_sql); }
|
||||||
}
|
|
||||||
|
|
||||||
if( db_locked ) {
|
mrmimeparser_unref(mime_parser);
|
||||||
mrsqlite3_unlock(mailbox->m_sql);
|
free(rfc724_mid);
|
||||||
}
|
mrarray_unref(to_ids);
|
||||||
|
|
||||||
if( mime_parser ) {
|
|
||||||
mrmimeparser_unref(mime_parser);
|
|
||||||
}
|
|
||||||
|
|
||||||
if( rfc724_mid ) {
|
|
||||||
free(rfc724_mid);
|
|
||||||
}
|
|
||||||
|
|
||||||
if( to_ids ) {
|
|
||||||
mrarray_unref(to_ids);
|
|
||||||
}
|
|
||||||
|
|
||||||
if( created_db_entries ) {
|
if( created_db_entries ) {
|
||||||
if( create_event_to_send ) {
|
if( create_event_to_send ) {
|
||||||
|
|
|
@ -223,6 +223,7 @@ int mrmimefactory_load_msg(mrmimefactory_t* factory, uint32_t msg_id)
|
||||||
if( success ) {
|
if( success ) {
|
||||||
factory->m_increation = mrmsg_is_increation__(factory->m_msg);
|
factory->m_increation = mrmsg_is_increation__(factory->m_msg);
|
||||||
}
|
}
|
||||||
|
|
||||||
mrsqlite3_unlock(mailbox->m_sql);
|
mrsqlite3_unlock(mailbox->m_sql);
|
||||||
locked = 0;
|
locked = 0;
|
||||||
|
|
||||||
|
|
|
@ -1090,17 +1090,21 @@ int mrmsg_is_increation__(const mrmsg_t* msg)
|
||||||
int mrmsg_is_increation(mrmsg_t* msg)
|
int mrmsg_is_increation(mrmsg_t* msg)
|
||||||
{
|
{
|
||||||
/* surrounds mrmsg_is_increation__() with locking and error checking */
|
/* surrounds mrmsg_is_increation__() with locking and error checking */
|
||||||
|
int is_increation = 0;
|
||||||
|
|
||||||
if( msg == NULL || msg->m_magic != MR_MSG_MAGIC ) {
|
if( msg == NULL || msg->m_magic != MR_MSG_MAGIC ) {
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
int is_increation = 0;
|
|
||||||
if( msg->m_mailbox && MR_MSG_NEEDS_ATTACHMENT(msg->m_type) /*additional check for speed reasons*/ )
|
if( msg->m_mailbox && MR_MSG_NEEDS_ATTACHMENT(msg->m_type) /*additional check for speed reasons*/ )
|
||||||
{
|
{
|
||||||
mrsqlite3_lock(msg->m_mailbox->m_sql);
|
mrsqlite3_lock(msg->m_mailbox->m_sql);
|
||||||
|
|
||||||
is_increation = mrmsg_is_increation__(msg);
|
is_increation = mrmsg_is_increation__(msg);
|
||||||
|
|
||||||
mrsqlite3_unlock(msg->m_mailbox->m_sql);
|
mrsqlite3_unlock(msg->m_mailbox->m_sql);
|
||||||
}
|
}
|
||||||
|
|
||||||
return is_increation;
|
return is_increation;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue