Author Topic: Email filters/rules  (Read 7304 times)

chamont

  • Newbie
  • *
  • Posts: 13
    • View Profile
Email filters/rules
« on: 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.

cabeza

  • Administrator
  • Hero Member
  • *****
  • Posts: 1004
    • View Profile
    • Feng Office
Re: Email filters/rules
« Reply #1 on: April 20, 2010, 04:04:03 pm »
Would love to have them.

If you wish to help let me know.

chamont

  • Newbie
  • *
  • Posts: 13
    • View Profile
Re: Email filters/rules
« Reply #2 on: 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...

cabeza

  • Administrator
  • Hero Member
  • *****
  • Posts: 1004
    • View Profile
    • Feng Office
Re: Email filters/rules
« Reply #3 on: April 23, 2010, 12:29:04 pm »
Great! Let us know ...

newtek

  • Newbie
  • *
  • Posts: 7
    • View Profile
    • Email
Re: Email filters/rules
« Reply #4 on: 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,

« Last Edit: October 18, 2010, 06:54:14 pm by newtek »

cabeza

  • Administrator
  • Hero Member
  • *****
  • Posts: 1004
    • View Profile
    • Feng Office
Re: Email filters/rules
« Reply #5 on: October 18, 2010, 05:14:30 pm »
Very interested in your project.
Best

newtek

  • Newbie
  • *
  • Posts: 7
    • View Profile
    • Email
Re: Email filters/rules
« Reply #6 on: October 19, 2010, 08:00:06 am »
Ok

I post for reviews, everything is working.

What I have done :

Classify table
Code: [Select]
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'
Code: [Select]
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
Code: [Select]
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

cabeza

  • Administrator
  • Hero Member
  • *****
  • Posts: 1004
    • View Profile
    • Feng Office
Re: Email filters/rules
« Reply #7 on: October 19, 2010, 08:41:32 am »
Looks promising!
We'll take a deeper look ...

Murz

  • Full Member
  • ***
  • Posts: 147
    • View Profile
Re: Email filters/rules
« Reply #8 on: 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?

newtek

  • Newbie
  • *
  • Posts: 7
    • View Profile
    • Email
Re: Email filters/rules
« Reply #9 on: October 20, 2010, 02:07:49 pm »
Sure I will do it

Murz

  • Full Member
  • ***
  • Posts: 147
    • View Profile
Re: Email filters/rules
« Reply #10 on: 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 :)
« Last Edit: October 21, 2010, 04:32:29 am by Murz »

brg

  • Freshman
  • *
  • Posts: 22
    • View Profile
Re: Email filters/rules
« Reply #11 on: 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'
Code: [Select]
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.
Code: [Select]
$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.