[kmail2] [Bug 283020] Store Kmail Tags in IMAP flags, like Thunderbird

Erik Quaeghebeur bugzilla_noreply at kde.org
Sun Mar 20 22:21:31 GMT 2022


https://bugs.kde.org/show_bug.cgi?id=283020

--- Comment #30 from Erik Quaeghebeur <bugs.kde.org at e3q.eu> ---
I've been looking at this issue again. The KMail/Akonadi codebase is still to
scary for me in most places, so I tried to circumvent it and add this
functionality using SQL triggers directly in Akonadi's database. I'm using the
SQLite backend, but this should be similar for MySQL and Postgresql.

*TLDR: Using only SQL triggers, a flag added by another client can be synced
via IMAP to an Akonadi tag, but deleting it from another client does not work.
Adding and deleting from KMail does not sync to the IMAP server.*

For my experiments, I used DB browser for SQLite <https://sqlitebrowser.org/>
to add triggers and look at the database; it is a bit more convenient than the
functionality in Akonadiconsole. To test, I created two tags in Akonadi (via
KMail's config) and these have ids 3 and 5 in the TagTable. I used one flag,
with id 57 in the FlagTable. Flag 57 should be synced to tag 3. Tag 5 was used
for deeper investigations. (Obviously, the trigger would need to be made
flag/tag-agnostic, but this would require adding a FlagTagRelation table, which
would go to far for an initial test. It would also have been a waste of time.)

Then, I created the following triggers:

1. Adding tag 3 when flag 57 arrives in the database:
---
create trigger "insert_tag_from_flag" after insert on "PimItemFlagRelation"
when NEW.Flag_Id is 57
begin
        insert or ignore into "PimItemTagRelation" values (NEW.PimItem_id, 3);
end
---
This works. The tag is added to the mail in KMail if in another client
(Trojita, Thunderbird) the tag is added to the mail.

2. Adding flag 57 when tag 3 arrives in the database:
---
create trigger "insert_flag_from_tag" after insert on "PimItemTagRelation"
when NEW.Tag_Id is 3
begin
        insert or ignore into "PimItemFlagRelation" values (NEW.PimItem_id,
57);
end
---
This does not sync. The flag is added to the database, alright, but Akonadi
isn't aware of it and does not propagate it to the server. ⇒ This needs to be
coded in Akonadi/KMail.

3. Deleting tag 3 when flag 57 is removed in the database:
---
create trigger "delete_tag_from_flag" after delete on "PimItemFlagRelation"
when OLD.Flag_Id is 57
begin
        delete from "PimItemTagRelation" where "PimItem_id" == "OLD.PimItem_id"
and "Tag_id" == 3;
        insert into "PimItemTagRelation" values (OLD.PimItem_id, 5);
end
---
This does not persist. For a moment, the tag is removed, but then it is added
again, likely from another in-memory data structure. (I was keeping the mail
folder containing the mail with removed flag open in KMail.) To verify that
indeed the database commit works, the additional insert was added, which
confirms it does. ⇒ This needs to be coded in Akonadi/KMail.

4. Removing flag 57 when tag 3 is deleted in the database:
---
create trigger "delete_flag_from_tag" after delete on "PimItemTagRelation"
when OLD.Tag_Id is 3
begin
        delete from "PimItemFlagRelation" where "PimItem_id" ==
"OLD.PimItem_id" and "Flag_id" == 57;
end
---
This does not sync. The flag is removed from the database, alright, but Akonadi
isn't aware of it and does not propagate it to the server. ⇒ This needs to be
coded in Akonadi/KMail.

So, while insightful to me, this idea doesn't really bring us closer. Into the
code we must go.

-- 
You are receiving this mail because:
You are the assignee for the bug.


More information about the Kdepim-bugs mailing list