Validate contact emails before adding
Also updates the DB to filter out existing invalid contacts. Closes: bgo #713932
This commit is contained in:
parent
3e34b9980a
commit
0f6e76edb3
4 changed files with 38 additions and 0 deletions
|
|
@ -18,3 +18,4 @@ install(FILES version-015.sql DESTINATION ${SQL_DEST})
|
|||
install(FILES version-016.sql DESTINATION ${SQL_DEST})
|
||||
install(FILES version-017.sql DESTINATION ${SQL_DEST})
|
||||
install(FILES version-018.sql DESTINATION ${SQL_DEST})
|
||||
install(FILES version-019.sql DESTINATION ${SQL_DEST})
|
||||
|
|
|
|||
5
sql/version-019.sql
Normal file
5
sql/version-019.sql
Normal file
|
|
@ -0,0 +1,5 @@
|
|||
--
|
||||
-- Dummy database upgrade to validate contact email addresses. See
|
||||
-- src/engine/imap-db/imap-db-database.vala in post_upgrade() for the code
|
||||
-- that runs the upgrade.
|
||||
--
|
||||
|
|
@ -97,6 +97,10 @@ private class Geary.ImapDB.Database : Geary.Db.VersionedDatabase {
|
|||
case 18:
|
||||
post_upgrade_populate_internal_date_time_t();
|
||||
break;
|
||||
|
||||
case 19:
|
||||
post_upgrade_validate_contacts();
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -370,6 +374,31 @@ private class Geary.ImapDB.Database : Geary.Db.VersionedDatabase {
|
|||
}
|
||||
}
|
||||
|
||||
// Version 19.
|
||||
private void post_upgrade_validate_contacts() {
|
||||
try {
|
||||
exec_transaction(Db.TransactionType.RW, (cx) => {
|
||||
Db.Result result = cx.query("SELECT id, email FROM ContactTable");
|
||||
while (!result.finished) {
|
||||
string email = result.string_at(1);
|
||||
if (!RFC822.MailboxAddress.is_valid_address(email)) {
|
||||
int64 id = result.rowid_at(0);
|
||||
|
||||
Db.Statement stmt = cx.prepare("DELETE FROM ContactTable WHERE id = ?");
|
||||
stmt.bind_rowid(0, id);
|
||||
stmt.exec();
|
||||
}
|
||||
|
||||
result.next();
|
||||
}
|
||||
|
||||
return Db.TransactionOutcome.COMMIT;
|
||||
});
|
||||
} catch (Error err) {
|
||||
debug("Error populating autocompletion table during upgrade to database schema 5");
|
||||
}
|
||||
}
|
||||
|
||||
private void on_prepare_database_connection(Db.Connection cx) throws Error {
|
||||
cx.set_busy_timeout_msec(Db.Connection.RECOMMENDED_BUSY_TIMEOUT_MSEC);
|
||||
cx.set_foreign_keys(true);
|
||||
|
|
|
|||
|
|
@ -126,6 +126,9 @@ private class Geary.ImapDB.MessageAddresses : BaseObject {
|
|||
|
||||
private void add_contact(Gee.Map<string, Contact> contacts_map, RFC822.MailboxAddress address,
|
||||
int importance) {
|
||||
if (!address.is_valid())
|
||||
return;
|
||||
|
||||
Contact contact = new Contact.from_rfc822_address(address, importance);
|
||||
Contact? old_contact = contacts_map[contact.normalized_email];
|
||||
if (old_contact == null || old_contact.highest_importance < contact.highest_importance)
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue