mirror of
https://github.com/deltachat/deltachat-core.git
synced 2025-10-05 10:39:27 +02:00
new function to cleanup contacts
This commit is contained in:
parent
3c10679094
commit
ea8543ee8d
3 changed files with 40 additions and 6 deletions
|
@ -378,6 +378,7 @@ char* mrmailbox_cmdline(mrmailbox_t* mailbox, const char* cmdline)
|
|||
"addcontact [<name>] <addr>\n"
|
||||
"contactinfo <contact-id>\n"
|
||||
"delcontact <contact-id>\n"
|
||||
"cleanupcontacts\n"
|
||||
"======================================Misc.==\n"
|
||||
"event <event-id to test>\n"
|
||||
"fileinfo <file>\n"
|
||||
|
@ -1022,6 +1023,10 @@ char* mrmailbox_cmdline(mrmailbox_t* mailbox, const char* cmdline)
|
|||
ret = safe_strdup("ERROR: Argument <contact-id> missing.");
|
||||
}
|
||||
}
|
||||
else if( strcmp(cmd, "cleanupcontacts")==0 )
|
||||
{
|
||||
ret = mrmailbox_cleanup_contacts(mailbox)? COMMAND_SUCCEEDED : COMMAND_FAILED;
|
||||
}
|
||||
|
||||
/*******************************************************************************
|
||||
* Misc.
|
||||
|
|
|
@ -90,6 +90,7 @@ void mrmailbox_add_or_lookup_contacts_by_mailbox_list__(mrmailbox_t*
|
|||
void mrmailbox_add_or_lookup_contacts_by_address_list__(mrmailbox_t* ths, struct mailimf_address_list* adr_list, int origin, mrarray_t* ids, int* check_self);
|
||||
int mrmailbox_get_archived_count__ (mrmailbox_t*);
|
||||
int mrmailbox_reset_tables (mrmailbox_t*, int bits); /* reset tables but leaves server configuration, 1=jobs, 2=e2ee, 8=rest but server config */
|
||||
int mrmailbox_cleanup_contacts (mrmailbox_t* ths); /* remove all contacts that are not used (e.g. in a chat, or blocked */
|
||||
size_t mrmailbox_get_real_contact_cnt__ (mrmailbox_t*);
|
||||
uint32_t mrmailbox_add_or_lookup_contact__ (mrmailbox_t*, const char* display_name /*can be NULL*/, const char* addr_spec, int origin, int* sth_modified);
|
||||
int mrmailbox_get_contact_origin__ (mrmailbox_t*, uint32_t id, int* ret_blocked);
|
||||
|
|
|
@ -1459,12 +1459,12 @@ int mrmailbox_get_archived_count__(mrmailbox_t* mailbox)
|
|||
|
||||
|
||||
/**
|
||||
+ * Reset database tables. This function is called from Core cmdline.
|
||||
+ *
|
||||
+ * Argument is a bitmask, executing single or multiple actions in one call.
|
||||
+ *
|
||||
+ * e.g. bitmask 7 triggers actions definded with bits 1, 2 and 4.
|
||||
+ */
|
||||
* Reset database tables. This function is called from Core cmdline.
|
||||
*
|
||||
* Argument is a bitmask, executing single or multiple actions in one call.
|
||||
*
|
||||
* e.g. bitmask 7 triggers actions definded with bits 1, 2 and 4.
|
||||
*/
|
||||
int mrmailbox_reset_tables(mrmailbox_t* ths, int bits)
|
||||
{
|
||||
if( ths == NULL || ths->m_magic != MR_MAILBOX_MAGIC ) {
|
||||
|
@ -1509,6 +1509,34 @@ int mrmailbox_reset_tables(mrmailbox_t* ths, int bits)
|
|||
return 1;
|
||||
}
|
||||
|
||||
/**
|
||||
* Clean up the contacts table. This function is called from Core cmdline.
|
||||
*
|
||||
* All contacts not involved in a chat, not blocked and not being a deaddrop
|
||||
* are removed.
|
||||
*
|
||||
* Deleted contacts from the OS address book normally stay in the contacts
|
||||
* database. With this cleanup, they are also removed, as well as all
|
||||
* auto-added contacts, unless they are used in a chat or for blocking purpose.
|
||||
*
|
||||
*/
|
||||
int mrmailbox_cleanup_contacts(mrmailbox_t* ths)
|
||||
{
|
||||
if( ths == NULL || ths->m_magic != MR_MAILBOX_MAGIC ) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
mrmailbox_log_info(ths, 0, "Cleaning up contacts ...");
|
||||
|
||||
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_unlock(ths->m_sql);
|
||||
|
||||
return 1;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Find out the version of the Delta Chat core library.
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue