Author Topic: Sieverules (managesieve) plugin  (Read 212923 times)

Offline RonG

  • Newbie
  • *
  • Posts: 3
Sieverules plugin
« Reply #315 on: August 12, 2011, 04:55:37 PM »
Quote from: kase;18990
Hello,

I'm very impressed about the script but I have a problem.


I have a global sieve rule to move spam into the Junk folder. Not very impressing. But when I add a custom sieve rule in roundcube the global rule has no effect anymore.


Maybe someone can help me?

Dovecot deliver, amavis, sieve (of couse :D )

If you need further informations, ask :)

thanks,
kase

 
Problem is you're using a global sieve rules file.  It's not supposed to be executed if the user has their own sieve rules.  What you want to do is rename the rules file from global.sieve, which is executed only in the absence of user rules, to before.sieve, which is executed for all users.

Offline RonG

  • Newbie
  • *
  • Posts: 3
Wrap Vacation rule
« Reply #316 on: August 12, 2011, 05:07:12 PM »
Hi, I just discovered that the vacation rule created by Sieverules replies to all incoming mail.  Replying to mailing list mail is what's called being a bad neighbor, and tends to get the person using the autoresponder disabled from their mailing lists along with angry notes from other subscribers.

I'd like to alter my Sieverules plugin to generate out-of-office rules as noted here Correct sieve vacation filtering (with the exception that Precedence: Junk should also be included, as well as null senders, MAILER-DAEMON, and DSNs (delivery status notifications)), and I was wondering if someone could point me in the right direction.

Offline JohnDoh

  • Global Moderator
  • Hero Member
  • *****
  • Posts: 2,845
Sieverules plugin
« Reply #317 on: August 13, 2011, 04:24:12 AM »
what exactly do you want to know? you can use the top half of the form, the "filter rules" section to put tests in which have to be passed before the vacation message is sent. the example you linked they have the line
Code: [Select]
if not header :contains "Precedence" ["bulk","list"] { so on the form you select "other header" in the first box, type "Precedence" (without the quotes) in the text box which appears next to it. then select "does not contain" and finally "bulk" (without the quotes). and then press the add button and make another row but with "list" in the final box.
Roundcube Plugins: Contextmenu, SpamAssassin Prefs, and more…

Offline RonG

  • Newbie
  • *
  • Posts: 3
Sieverules plugin
« Reply #318 on: August 15, 2011, 12:13:18 AM »
Quote from: JohnDoh;36148
what exactly do you want to know? you can use the top half of the form, the "filter rules" section to put tests in which have to be passed before the vacation message is sent. the example you linked they have the line
Code: [Select]
if not header :contains "Precedence" ["bulk","list"] { so on the form you select "other header" in the first box, type "Precedence" (without the quotes) in the text box which appears next to it. then select "does not contain" and finally "bulk" (without the quotes). and then press the add button and make another row but with "list" in the final box.

 
If I have to try and explain the need to do this to users, it's never going to happen, at least not until they've inconvenienced a lot of people including themselves.  I want to generate out of office rules that comply with community standards without having to explain things like Precedence: Bulk to users.  They shouldn't have to remember that autoresponders should *never* respond to mailing lists or automatic notices and how not to, they expect that to be taken care of by the software, and it was pretty surprising to me to learn that Sieve vacation doesn't try to handle this on its own.  Since it doesn't, it falls to me to take care of this for my users by having Sieverules do it by generating a proper autoresponder rule for them instead.

Offline JohnDoh

  • Global Moderator
  • Hero Member
  • *****
  • Posts: 2,845
Sieverules plugin
« Reply #319 on: August 15, 2011, 03:03:10 AM »
The simple answer is that everyone has different mail server setups and different times when they want their vacation messages sent out so doing it out of the box is impossible. I think you have 4 options:
1) Use a simple predefined rule and just select that every time.
2) Create a more complex rule in an example rule file and use that ever time.
3) Mod the plugin code to do what you want.
4) Use a different plugin.
Roundcube Plugins: Contextmenu, SpamAssassin Prefs, and more…

Offline osterhase

  • Jr. Member
  • **
  • Posts: 19
Sieverules plugin
« Reply #320 on: August 16, 2011, 05:19:20 AM »
Hi there!

I'm using roundcube & sieverules on our mailservers for about half a year now and we are really convinced! Because the server-landscape expanded we had to move to ISPConfig3 to administrate our servers. This software also provides the possibility to edit filterrules but the mechanism of ISPConfig3 and sieverules do not like each other and both keep overwritting each others files.

So I want to customize sieverules and wanted to ask for a feedback if my line of thought is generally possible or completly of the track and would appreciate a couple of starting-points:

1. I want that sieverules writes the rules that are installed by the users into the file roundcube.sieve but it should leave the file dovecot.sieve alone (due this is the file in that the rules are actually written by ispconfig). Where (e.g. in which file) can I disable the linkage of roundecube.sieve to dovecot.sieve?

2. I would like to have a custom php-script/code run each time a user edits / saves a filter rule. This piece of code establishes a connection to ISPConfig (API) and writes the roundcube.sieve file as a ruleset into the database of ISPConfig which than applies this into the actual dovecot.sieve-filter-file. Where do I have to add this code-snippet (in which file(s))?

3. I would like to use the $user-variable in the script - is this possible and is the output the format "somename@somedomain.net"?

I'm thankful for any help and suggestions.

Best regards.

Offline JohnDoh

  • Global Moderator
  • Hero Member
  • *****
  • Posts: 2,845
Sieverules plugin
« Reply #321 on: August 16, 2011, 07:58:37 AM »
Quote
1. I want that sieverules writes the rules that are installed by the users into the file roundcube.sieve but it should leave the file dovecot.sieve alone (due this is the file in that the rules are actually written by ispconfig). Where (e.g. in which file) can I disable the linkage of roundecube.sieve to dovecot.sieve?
2. I would like to have a custom php-script/code run each time a user edits / saves a filter rule. This piece of code establishes a connection to ISPConfig (API) and writes the roundcube.sieve file as a ruleset into the database of ISPConfig which than applies this into the actual dovecot.sieve-filter-file. Where do I have to add this code-snippet (in which file(s))?

it might be possible to solve both of these in the same (possibly slightly ineligant) solution. the roundcube ruleset is activated each time save is pressed unless there the multiple ruleset feature is enabled. when the save is completed a hook could be executed to allow any one to do anything they want, in this case, set the active one back to the ispconfig one and copy the rules into ispconfig. what do you think?

if not you just need to modify the save function, somewhere around line 920 in the repo version of sieverules.php

Quote
3. I would like to use the $user-variable in the script - is this possible and is the output the format "somename@somedomain.net"?

do you mean the sieve variables extension? there is limited support for that when doing fileinto and for setting the the from address on vacation messages but thats about it.
Roundcube Plugins: Contextmenu, SpamAssassin Prefs, and more…

Offline osterhase

  • Jr. Member
  • **
  • Posts: 19
Sieverules plugin
« Reply #322 on: August 18, 2011, 04:45:17 AM »
Quote from: JohnDoh;36190
it might be possible to solve both of these in the same (possibly slightly ineligant) solution. the roundcube ruleset is activated each time save is pressed unless there the multiple ruleset feature is enabled. when the save is completed a hook could be executed to allow any one to do anything they want, in this case, set the active one back to the ispconfig one and copy the rules into ispconfig. what do you think?


I'm not quite sure if I understood what you meant. But I rather think it's the right way to modify the save function. (What do you mean with multiple ruleset feature? That more than one condition / rule is applied to one filter?)

Quote
if not you just need to modify the save function, somewhere around line 920 in the repo version of sieverules.php

Yeah - we found that line and tried to modify it by inserting a function. A set of problems arised (to be honest: we are not php-godlords):

We defined our script as function at the beginning of sieverules.php:

and then called the function:

Code: [Select]
if ($save && $result === true) {
$this->api->output->command('display_message', $this->gettext('filtersaved1'), 'confirmation');
//osterhase inserted:
$user = 'testen@domain.net';
api_ispconfig($user);
// end of insert
if ($script['disabled'] == 1)
$filter_name = $script['name'] . ' (' . $this->gettext('disabled') . ')';
else
$filter_name = $script['name'];


The function was actually executed but we stumbled over the security concept of our servers:

Code: [Select]
Aug 18 10:23:01 flux01 roundcube: PHP Warning:  file(/var/vmail/domain.net/testen/sieve/roundcube.sieve): failed to open stream: Die Operation ist nicht erlaubt in /var/www/clients/client7/web45/web/plugins/sieverules/sieverules.php on line 56

The problem there is that the user which executes the script is not allowed to leave his web-directory and so we cannot read in the roundcube.sieve-file. This lead us to the general question how the sieverule-plugin is doing that (I assumed that it would do that via connecting to the managesieve-server and let this one do the changes in the maildir) - is that correct?

This is the first and major problem we have in customizing the sieverule-plugin - how to bypass our own security concept. Actually sounds weird... :D

My only idea at the moment is to get sieverules.php to save the roundcube.sieve file temporarlly in the tmp directory of roundcube until it is read in by the api_ispconfig function. Any other suggestions?

Edit: Is it possible to catch the content of roundcube.sieve before it is actually written? If yes, with which variable can it be called? So it would be possible to replace $spamfilter with that.


Quote from: JohnDoh;36190
do you mean the sieve variables extension? there is limited support for that when doing fileinto and for setting the the from address on vacation messages but thats about it.


As you can see in the inserted lines we actually need the email-address of the current email-user to determine the correct database entry - my question was rather directed into this direction.

I've attached the modified sieverules.php (the "prints" are for debugging - obviously) and would be really thankful if you would have further suggestions.

Offline JohnDoh

  • Global Moderator
  • Hero Member
  • *****
  • Posts: 2,845
Sieverules plugin
« Reply #323 on: August 20, 2011, 03:22:52 AM »
Quote
The problem there is that the user which executes the script is not allowed to leave his web-directory and so we cannot read in the roundcube.sieve-file. This lead us to the general question how the sieverule-plugin is doing that (I assumed that it would do that via connecting to the managesieve-server and let this one do the changes in the maildir) - is that correct?

Yes, the plugin connects to the managesieve server. It uses the Pear Net_Sieve lib for all the communication stuff.

In the repo version of the plugin I have just added the hook `sieverules_saved` so now you don’t need to modify the sieverules code directly. You can make a new plugin which uses hook and then do whatever you want. I have attached an example of how to use it.

UPDATE 20110824: The sieverules_saved has been updated to make it more reliable. the attached example has been updated to reflect the changes, more information is available in the readme.

UPDATE 20110828: The hook is run BEFORE the save process completes (it can be used to abort a save) so the hook has been changed to sieverules_save to reflect this.
« Last Edit: August 28, 2011, 07:32:41 AM by JohnDoh »
Roundcube Plugins: Contextmenu, SpamAssassin Prefs, and more…

Offline osterhase

  • Jr. Member
  • **
  • Posts: 19
Sieverules plugin
« Reply #324 on: August 20, 2011, 10:30:14 AM »
F*** YEAH! Thanks! Gonna check it out...

Offline osterhase

  • Jr. Member
  • **
  • Posts: 19
Sieverules plugin
« Reply #325 on: August 22, 2011, 05:35:12 AM »
Hey John,

thanks again for your work! Your file really helped us to understand (really small scale though) how it's actually possible to write a plugin. A couple of questions arised because we also tried to implement the log functionality. The function reads:

Code: [Select]
write_log('errors', 'sieverules_saved login failed');

We figured that we could exchange 'errors' with 'log' - so it actually logs things even it is not an error:

Code: [Select]
write_log('log', "ispconfig: login successful. Session-ID: $session_id");

But we would not like to spam the logfiles everytime a user changes his spamfilter-settings with things like that. Is there an option like "debug" so it's just written in the log if a high log level is defined in the main-configuration file? (We tried 'debug' but it obviously did not work out.)

The second problem arised when the user is deleting a spamfilter. Because there's no hook in the sieverules.php sieverules_saved does not react on that. Do you think it's possible to add another hook there?

Attached is the current code of the plugin (we even set up an config.inc.php) :cool:

Thanks mate for your great work!

Offline lolomin

  • Newbie
  • *
  • Posts: 2
Sieverules plugin
« Reply #326 on: August 23, 2011, 03:36:30 AM »
Hi,

just installed latest sieverules plugin : 1.14 but got an error reported in error_log when trying to access Settings menu in RoundCube :
PHP Fatal error:  Call to undefined method rcube_plugin_api::load_plugin() in /var/www/html/roundcubemail-0.6-beta/program/include/rcube_plugin.php on line 96, referer:

Do I forgot something ? I can't figure why I'm having this error, all is working properly with version 1.9 of the plugin ...

If anyone is having a clue about the cause, thks by advance for your help.

Laurent

Offline JohnDoh

  • Global Moderator
  • Hero Member
  • *****
  • Posts: 2,845
Sieverules plugin
« Reply #327 on: August 23, 2011, 07:51:19 AM »
thats an error from the rc core, not the plugin. which version of rc are you running? v1.14 of sieverules requires 0.6b
Roundcube Plugins: Contextmenu, SpamAssassin Prefs, and more…

Offline lolomin

  • Newbie
  • *
  • Posts: 2
Sieverules plugin
« Reply #328 on: August 23, 2011, 08:30:52 AM »
Hi JohnDoh,

Thks for your reply.

Using RoundCube 0.6beta here, just upgraded it from 0.5.2 to 0.6beta with the help of bin/installto.sh script.
Is there any information I can provide you that can be useful ?

Laurent

Offline JohnDoh

  • Global Moderator
  • Hero Member
  • *****
  • Posts: 2,845
Sieverules plugin
« Reply #329 on: August 24, 2011, 02:47:41 AM »
Quote
But we would not like to spam the logfiles everytime a user changes his spamfilter-settings with things like that. Is there an option like "debug" so it's just written in the log if a high log level is defined in the main-configuration file? (We tried 'debug' but it obviously did not work out.)

easiest way is just to put the write_log call inside an if statement which checks the log level from the config. there are lots of examples in my code and others of how to read values from the config.

Quote
The second problem arised when the user is deleting a spamfilter. Because there's no hook in the sieverules.php sieverules_saved does not react on that. Do you think it's possible to add another hook there?

you are correct, the new improved version in the repo does a much better job and ensures the hook is called every time something is saved to the server. there is also a new example of how to use it in my earlier post.
Roundcube Plugins: Contextmenu, SpamAssassin Prefs, and more…