Feng Forum

Other Topics => Feature requests => : chamont April 14, 2010, 06:04:49 PM

: Email filters/rules
: chamont April 14, 2010, 06:04:49 PM
Am I the only one who receives hundreds of emails each day ?

I cannot live without filters/rules able to automatically move my emails to folder/context or apply tags, etc.

Without this, the Feng Office webmail is interesting, but still a toy, not usable in real life.
: Re: Email filters/rules
: cabeza April 20, 2010, 04:04:03 PM
Would love to have them.

If you wish to help let me know.
: Re: Email filters/rules
: chamont April 20, 2010, 05:03:06 PM
Would love to help, for sure. That's rather frustating to suggest only.
But currently my 24/24h 7/7j is not even enough for the job I am paid for.
Next autumn, perhaps...
: Re: Email filters/rules
: cabeza April 23, 2010, 12:29:04 PM
Great! Let us know ...
: Re: Email filters/rules
: newtek October 18, 2010, 02:46:18 PM
Hi

I am starting the filter process but I will have some problem to add the interface view

following the process

adding a classify (or rules) table
adding the corresponding classes
adding the function to cron table

ms,

: Re: Email filters/rules
: cabeza October 18, 2010, 05:14:30 PM
Very interested in your project.
Best
: Re: Email filters/rules
: newtek October 19, 2010, 08:00:06 AM
Ok

I post for reviews, everything is working.

What I have done :

Classify table
:
DROP TABLE IF EXISTS `feng`.`og_classify_objects`;
CREATE TABLE  `feng`.`og_classify_objects` (
  `id` int(10) unsigned NOT NULL auto_increment,
  `workspace_id` int(10) unsigned NOT NULL default '0',
  `account_id` int(10) unsigned NOT NULL default '0',
  `filter` varchar(45) NOT NULL default '', //filter is part of adress mail
  PRIMARY KEY  (`id`)
)  ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci;

Adding the related classes :

./fengoffice/application/models/classify_objects/ClassifyObject.class.php
./fengoffice/application/models/classify_objects/ClassifyObjects.class.php
./fengoffice/application/models/classify_objects/base/BaseClassifyObject.class.php
./fengoffice/application/models/classify_objects/base/BaseClassifyObjects.class.php

Adding the following row to the table 'og_cron_events'
:
INSERT INTO og_cron_events (name, recursive, delay, is_system, enabled)
VALUES('classify_mail', 1, 5, 0, 1)

Adding the following code to ./fengoffice/application/cron_functions.php
:
function classify_mail() {
//Get all classify rules
$classify = ClassifyObjects::findAll();
//Iterate trought classify rules
foreach ($classify as $obj) {
    _log("Classify for filter : " . $obj->getFilter() . " to workspace " . $obj->getWorkspaceId());
//Get workspace by Id
    $myproject = Projects::findById($obj->getWorkspaceId());
//Get mail from account and filter
$mails = MailContents::find(array('conditions' => '`account_id` = ' . $obj->getAccountId() . ' AND `from` like "%' . $obj->getFilter() . '%" ' , 'order' => '`received_date` DESC'));
//Iterate trough found mails
foreach ($mails as $mail) {
    try {
    WorkspaceObjects::addObjectToWorkspace($mail, $myproject);
    } catch (Exception $e) {
//_log("Error : " . $e); I have problem with the function isObjectInWorkspace
    }
}
}

_log("End of Classify email...");


The classes need some function to create the filters and I will need somebody to make the view to setup the filters.

Bye

Waiting for comments

ms
: Re: Email filters/rules
: cabeza October 19, 2010, 08:41:32 AM
Looks promising!
We'll take a deeper look ...
: Re: Email filters/rules
: Murz October 20, 2010, 04:19:34 AM
newtek, thanks for patch! Can you look on my ideas:

http://forums.fengoffice.com/index.php?topic=4857.0
http://forums.fengoffice.com/index.php?topic=4854.0

Maybe you can implement they too in your patch?
: Re: Email filters/rules
: newtek October 20, 2010, 02:07:49 PM
Sure I will do it
: Re: Email filters/rules
: Murz October 21, 2010, 04:10:21 AM
In your module you can add cron function hook without changing the core of FengOffice, it will be easy for install, that manually change FengOffice files and in this variant we can update FengOffice without broke your module.

You must create in folder application/hooks your file, for example "classify_objects_hook.php" and add your function classify_mail() in it, and name of this function in database.
FengOffice include all files from this folder on cron event and will successfully run your function without patching the core.

And in this variant, I think, you can convert your patches to easy-to-install plugin, and post it near others here: http://sourceforge.net/projects/opengoo/files/plugins/

But I don't know how to hook module install process for do the SQL queries on first install of upgrade automatically.

And main question :) Where can I find the interface for configure filters? I install your module, do the database records, after that look in settings, mail accounts, other places and can't find it :(

P.S. and you forgot to write last bracket '}' in your file :)
: Re: Email filters/rules
: brg October 21, 2010, 06:09:12 AM
Hello, newtek!

If you decide to use Murz solution with hook file, you can avoid manual adding row in cron_events.
Instead following code:
Adding the following row to the table 'og_cron_events'
:
INSERT INTO og_cron_events (name, recursive, delay, is_system, enabled)
VALUES('classify_mail', 1, 5, 0, 1)

You may add this code In your hook file, and after first open FO on browser cron event is create.
:
$event = CronEvents::getByName('classify_mail');

if(!$sor){
  $event = new CronEvent;
  $event->setName('classify_mail');
  $event->setDate(DateTimeValueLib::now()->beginningOfDay());
  $event->setIsSystem(false);
  $event->setEnabled(true);
  $event->setDelay(5);
  $event->setRecursive(true);
  $event->save();
}

But this add one SELECT on EVERY page of FO =( I think developers must create algorithm for executing some code only while installing plugin.