Updating keywords on copy/move

2017-10-14 Thread Daniele Ricci
Hello,
I'm working on my virtual keywords plugin [1] to add an apparently
simple feature: add a keyword to a message when it is moved or copied
into a virtual folder (let's forget about what keyword to add, I'm
starting with a hard-coded one to understand Dovecot plugin
development).

So I've added a mail_copy hook by the notify plugin [2] and did a
simple call to mail_update_keywords [3]. The current source code shows
a call to mail_get_backend_mail, this is me experimenting, I've also
tried calling mail_update_keywords directly on "dst" mail.

The result is an imap crash:

Oct 14 21:22:26 notebook dovecot: imap(daniele): Panic: file
mail-log-plugin.c: line 461 (mail_log_mail_transaction_commit):
assertion failed: (msg->pretext == NULL)
Oct 14 21:22:26 notebook dovecot: imap(daniele): Error: Raw backtrace:
/usr/lib/dovecot/libdovecot.so.0(+0x9f0a2) [0x7f81af52f0a2] ->
/usr/lib/dovecot/libdovecot.so.0(+0x9f19a) [0x7f81af52f19a] ->
/usr/lib/dovecot/libdovecot.so.0(i_fatal+0) [0x7f81af4bfcf8] ->
/usr/lib/dovecot/modules/lib20_mail_log_plugin.so(+0x19e8) [0x7f81aeae89e8] ->
/usr/lib/dovecot/modules/lib15_notify_plugin.so(notify_contexts_mail_transaction_commit+0x58)
[0x7f81aecec548] ->
/usr/lib/dovecot/modules/lib15_notify_plugin.so(+0x2105) [0x7f81aeced105] ->
/usr/lib/dovecot/libdovecot-storage.so.0(mailbox_transaction_commit_get_changes+0x52)
[0x7f81af807ca2] ->
/usr/lib/dovecot/libdovecot-storage.so.0(mailbox_transaction_commit+0x21)
[0x7f81af807d71] ->
/usr/lib/dovecot/modules/lib20_virtual_plugin.so(virtual_transaction_commit+0x78)
[0x7f81ae8e2fb8] ->
/usr/lib/dovecot/modules/lib15_notify_plugin.so(+0x20ec) [0x7f81aeced0ec] ->
/usr/lib/dovecot/libdovecot-storage.so.0(mailbox_transaction_commit_get_changes+0x52)
[0x7f81af807ca2] ->
dovecot/imap(+0x10084) [0x563d0ff2b084] ->
dovecot/imap(command_exec+0x5c) [0x563d0ff37d9c] ->
dovecot/imap(+0x1b322) [0x563d0ff36322] -> dovecot/imap(+0x1b3bc)
[0x563d0ff363bc] ->
dovecot/imap(client_handle_input+0x18d) [0x563d0ff3677d] ->
dovecot/imap(client_input+0xac) [0x563d0ff36ccc] ->
/usr/lib/dovecot/libdovecot.so.0(io_loop_call_io+0x52) [0x7f81af544742] ->
/usr/lib/dovecot/libdovecot.so.0(io_loop_handler_run_internal+0x12e)
[0x7f81af545d8e] ->
/usr/lib/dovecot/libdovecot.so.0(io_loop_handler_run+0x36) [0x7f81af5447d6] ->
/usr/lib/dovecot/libdovecot.so.0(io_loop_run+0x38) [0x7f81af544988] ->
/usr/lib/dovecot/libdovecot.so.0(master_service_run+0x13) [0x7f81af4ca353] ->
dovecot/imap(main+0x329) [0x563d0ff29139] ->
/lib/x86_64-linux-gnu/libc.so.6(__libc_start_main+0xf1)
[0x7f81af1132e1] ->
dovecot/imap(_start+0x2a) [0x563d0ff292ca]

This happens after my hook returns.
Now, before activating core dumps and starting to do some serious
debugging and reverse engineering, I ask: do I have to do something
extra such as opening a transaction or something? Isn't the notify
plugin supposed to do that already?

Thanks for your help!

[1] http://github.com/daniele-athome/dovecot-virtual-keywords-plugin
[2] 
https://github.com/daniele-athome/dovecot-virtual-keywords-plugin/blob/keyword-on-copy/virtual-keywords-plugin.c#L195
[3] 
https://github.com/daniele-athome/dovecot-virtual-keywords-plugin/blob/keyword-on-copy/virtual-keywords-plugin.c#L149

-- 
Daniele


Re: [PLUGIN] Virtual keywords (aka Gmail-like labels)

2017-10-02 Thread Daniele Ricci
That's great news! Feel free to use my code if it may help.

At first I actually thought about patching the virtual plugin itself,
but it's the first time I hack into Dovecot so I thought a separated
(and simpler) plugin would be better.



On Mon, Oct 2, 2017 at 11:29 AM, Aki Tuomi <aki.tu...@dovecot.fi> wrote:
> There is actually some request for ability to users to somehow create
> virtual folders on demand, so it's a thing we are going to work on at
> some point.
>
> Aki
>
>
> On 02.10.2017 12:27, Daniele Ricci wrote:
>> Yes, automation is the main point of the plugin :-)
>>
>> The problem is that creating virtual folders involves writing on the
>> file system directly, which you can't do through IMAP alone. So I had
>> to work within the mail server.
>>
>> What I really wanted to do was to create a storage driver (it seemed
>> more suitable to the plugin scope), but that was much more complex and
>> it will probably come in a future version.
>>
>> I'm also going to extend an existing Roundcube plugin for a more
>> complete keyword handling.
>>
>>
>>
>> On Mon, Oct 2, 2017 at 11:17 AM, Aki Tuomi <aki.tu...@dovecot.fi> wrote:
>>> You can actually create per-user virtual folders too. They don't need to
>>> be global. But I see your plugin does automation, and it could write the
>>> virtual file under user-writable location.
>>>
>>> Aki
>>>
>>>
>>> On 02.10.2017 12:14, Daniele Ricci wrote:
>>>> As a matter of fact I use the virtual plugin to achieve what I want. I
>>>> create dovecot-virtual configuration files.
>>>> But if I understand you correctly, your approach is a system-wide
>>>> configuration. Labels are per-user and dynamic by definition.
>>>>
>>>>
>>>>
>>>> On Mon, Oct 2, 2017 at 8:24 AM, Aki Tuomi <aki.tu...@dovecot.fi> wrote:
>>>>> On 01.10.2017 19:13, Daniele Ricci wrote:
>>>>>> Hello list,
>>>>>> I'm new here and since I've been working on a plugin lately I though
>>>>>> I'd post it here.
>>>>>>
>>>>>> It's GPL licensed, hosted on GitHub:
>>>>>> https://github.com/daniele-athome/dovecot-virtual-keywords-plugin
>>>>>>
>>>>>> I've been trying to find a replacement for Gmail and I already have my
>>>>>> own mailserver. What I'm missing very much is labels. Since folders
>>>>>> don't really match labels, I had to implement something that at least
>>>>>> resembles them.
>>>>>>
>>>>>> I decided to use IMAP keywords since it's probably the closest thing to 
>>>>>> labels.
>>>>>> The README in the repository pretty much describes what this plugin
>>>>>> do, but basically it creates virtual mailboxes with predefined rules
>>>>>> to match for labeled messages.
>>>>>>
>>>>>> E.g. if you set a "Urgent" keyword on any message, the plugin will
>>>>>> create a "Virtual/Urgent" virtual mailbox that will have the message
>>>>>> you just labeled.
>>>>>>
>>>>>> I'm a bit out of practice on C but I believe I managed. I've tested
>>>>>> the plugin locally but I've not deployed it on my production mail
>>>>>> server yet. I'd like to hear your opinions (reviews and comments are
>>>>>> very welcome) and possibly find other people interested in this
>>>>>> approach to discuss about it.
>>>>>>
>>>>>> Thanks!
>>>>> You should be able to do this with virtual plugin itself, like
>>>>>
>>>>> /etc/dovecot/virtual/Urgent:
>>>>> *
>>>>>KEYWORD Urgent
>>>>>
>>>>> Aki
>>>>
>>
>>
>



-- 
Daniele


Re: [PLUGIN] Virtual keywords (aka Gmail-like labels)

2017-10-02 Thread Daniele Ricci
Yes, automation is the main point of the plugin :-)

The problem is that creating virtual folders involves writing on the
file system directly, which you can't do through IMAP alone. So I had
to work within the mail server.

What I really wanted to do was to create a storage driver (it seemed
more suitable to the plugin scope), but that was much more complex and
it will probably come in a future version.

I'm also going to extend an existing Roundcube plugin for a more
complete keyword handling.



On Mon, Oct 2, 2017 at 11:17 AM, Aki Tuomi <aki.tu...@dovecot.fi> wrote:
> You can actually create per-user virtual folders too. They don't need to
> be global. But I see your plugin does automation, and it could write the
> virtual file under user-writable location.
>
> Aki
>
>
> On 02.10.2017 12:14, Daniele Ricci wrote:
>> As a matter of fact I use the virtual plugin to achieve what I want. I
>> create dovecot-virtual configuration files.
>> But if I understand you correctly, your approach is a system-wide
>> configuration. Labels are per-user and dynamic by definition.
>>
>>
>>
>> On Mon, Oct 2, 2017 at 8:24 AM, Aki Tuomi <aki.tu...@dovecot.fi> wrote:
>>>
>>> On 01.10.2017 19:13, Daniele Ricci wrote:
>>>> Hello list,
>>>> I'm new here and since I've been working on a plugin lately I though
>>>> I'd post it here.
>>>>
>>>> It's GPL licensed, hosted on GitHub:
>>>> https://github.com/daniele-athome/dovecot-virtual-keywords-plugin
>>>>
>>>> I've been trying to find a replacement for Gmail and I already have my
>>>> own mailserver. What I'm missing very much is labels. Since folders
>>>> don't really match labels, I had to implement something that at least
>>>> resembles them.
>>>>
>>>> I decided to use IMAP keywords since it's probably the closest thing to 
>>>> labels.
>>>> The README in the repository pretty much describes what this plugin
>>>> do, but basically it creates virtual mailboxes with predefined rules
>>>> to match for labeled messages.
>>>>
>>>> E.g. if you set a "Urgent" keyword on any message, the plugin will
>>>> create a "Virtual/Urgent" virtual mailbox that will have the message
>>>> you just labeled.
>>>>
>>>> I'm a bit out of practice on C but I believe I managed. I've tested
>>>> the plugin locally but I've not deployed it on my production mail
>>>> server yet. I'd like to hear your opinions (reviews and comments are
>>>> very welcome) and possibly find other people interested in this
>>>> approach to discuss about it.
>>>>
>>>> Thanks!
>>> You should be able to do this with virtual plugin itself, like
>>>
>>> /etc/dovecot/virtual/Urgent:
>>> *
>>>KEYWORD Urgent
>>>
>>> Aki
>>
>>
>



-- 
Daniele


Re: [PLUGIN] Virtual keywords (aka Gmail-like labels)

2017-10-02 Thread Daniele Ricci
As a matter of fact I use the virtual plugin to achieve what I want. I
create dovecot-virtual configuration files.
But if I understand you correctly, your approach is a system-wide
configuration. Labels are per-user and dynamic by definition.



On Mon, Oct 2, 2017 at 8:24 AM, Aki Tuomi <aki.tu...@dovecot.fi> wrote:
>
>
> On 01.10.2017 19:13, Daniele Ricci wrote:
>> Hello list,
>> I'm new here and since I've been working on a plugin lately I though
>> I'd post it here.
>>
>> It's GPL licensed, hosted on GitHub:
>> https://github.com/daniele-athome/dovecot-virtual-keywords-plugin
>>
>> I've been trying to find a replacement for Gmail and I already have my
>> own mailserver. What I'm missing very much is labels. Since folders
>> don't really match labels, I had to implement something that at least
>> resembles them.
>>
>> I decided to use IMAP keywords since it's probably the closest thing to 
>> labels.
>> The README in the repository pretty much describes what this plugin
>> do, but basically it creates virtual mailboxes with predefined rules
>> to match for labeled messages.
>>
>> E.g. if you set a "Urgent" keyword on any message, the plugin will
>> create a "Virtual/Urgent" virtual mailbox that will have the message
>> you just labeled.
>>
>> I'm a bit out of practice on C but I believe I managed. I've tested
>> the plugin locally but I've not deployed it on my production mail
>> server yet. I'd like to hear your opinions (reviews and comments are
>> very welcome) and possibly find other people interested in this
>> approach to discuss about it.
>>
>> Thanks!
> You should be able to do this with virtual plugin itself, like
>
> /etc/dovecot/virtual/Urgent:
> *
>KEYWORD Urgent
>
> Aki



-- 
Daniele


[PLUGIN] Virtual keywords (aka Gmail-like labels)

2017-10-01 Thread Daniele Ricci
Hello list,
I'm new here and since I've been working on a plugin lately I though
I'd post it here.

It's GPL licensed, hosted on GitHub:
https://github.com/daniele-athome/dovecot-virtual-keywords-plugin

I've been trying to find a replacement for Gmail and I already have my
own mailserver. What I'm missing very much is labels. Since folders
don't really match labels, I had to implement something that at least
resembles them.

I decided to use IMAP keywords since it's probably the closest thing to labels.
The README in the repository pretty much describes what this plugin
do, but basically it creates virtual mailboxes with predefined rules
to match for labeled messages.

E.g. if you set a "Urgent" keyword on any message, the plugin will
create a "Virtual/Urgent" virtual mailbox that will have the message
you just labeled.

I'm a bit out of practice on C but I believe I managed. I've tested
the plugin locally but I've not deployed it on my production mail
server yet. I'd like to hear your opinions (reviews and comments are
very welcome) and possibly find other people interested in this
approach to discuss about it.

Thanks!
-- 
Daniele