Bug 2267 - Perl filter needs a few more functions
Summary: Perl filter needs a few more functions
Status: NEW
Alias: None
Product: Claws Mail (GTK 2)
Classification: Unclassified
Component: Plugins/Perl (show other bugs)
Version: 3.7.6
Hardware: PC Linux
: P3 enhancement
Assignee: users
URL:
Depends on:
Blocks:
 
Reported: 2010-09-15 09:52 UTC by P Fudd
Modified: 2012-12-21 08:56 UTC (History)
0 users

See Also:


Attachments
A perl filter that moves messages into archive folders by month (901 bytes, text/plain)
2010-09-15 09:52 UTC, P Fudd
no flags Details

Description P Fudd 2010-09-15 09:52:20 UTC
Created attachment 898 [details]
A perl filter that moves messages into archive folders by month

I'm switch to claws from evolution.  I had archived 8 years of sent and received mail by month.  Trying to import this into claws was hard.  My solution:

Create a folder named Archive, create a subfolder named received-2002-02, edit folderlist.xml to create the other 191 subfolders, make those subfolders by creating directories and copying the .claws_cache, .claws_mark and .mh_sequences to them.  Then concatenate the received and sent mbox files into a single received and a single sent mbox file.  Then import those two mbox files into a temporary folder in claws.  Then create a perl script that parses the Date: line, and moving messages to their respective folders.  Worked like a charm, but took forever.

Suggestions: 
1. Add a perl function that lets you create a folder.  
2. Another function could return the age of a message, rather than the existing less than or greater than functions.
3. This process is slow (~12 messages per second); is there some low-hanging optimization that could be done, such as delaying cache updates during a massive manual filtering?
4. Could you add an option to import multiple mbox files easily?
5. Maybe another feature to add would be a way to cancel a filtering operation, short of kill -9.

I'm attaching my perlfilter.

Thanks!
Comment 1 P Fudd 2010-09-15 09:57:13 UTC
Oh, and when the perlfilter tried to move a message to a folder that didn't exist, no error was generated except to the standard error of the claws-mail process, which is usually put into ~/.xsession-errors.

Also, the perlfilter logfilter output goes into the network log, named claws.log, not the filter.log.  I was beating my head against a wall trying to make the perl filter show up in the filter log, but in reality it was working all along.
Comment 2 Holger Berndt 2010-09-15 10:44:57 UTC
> 1. Add a perl function that lets you create a folder.  

There is a "make_sure_folder_exists" function which will create the folder if it doesn't exist yet (but may fail).

> 2. Another function could return the age of a message

That may be a nice enhancement.

> 3. [...] delaying cache updates during a massive manual filtering

The plugin currently works on individual messages, so it doesn't know whether the filtering is massive or not.

> 4. Could you add an option to import multiple mbox files easily?

Why would a filter script deal with importing? That sounds more like UI automation, and would be a request for the Python plugin.

5. Maybe another feature to add would be a way to cancel a filtering operation,

You can stop filter processing for individual messages, but not for successive messages. See 3.

> no error was generated except to the standard error
> of the claws-mail process

Yes, that should probably go into the log file, too. You can check for errors in your script by looking at the return value (true on success, undef on error).

> Also, the perlfilter logfilter output goes into
> the network log, named claws.log, not the filter.log

True, that should be moved. (That is historic. The Perl plugin introduced logging capability before the builtin filtering engine did, so at that time there was no filter log yet.)
Comment 3 P Fudd 2010-09-15 19:21:48 UTC
>> 1. Add a perl function that lets you create a folder.  

> There is a "make_sure_folder_exists" function which will create the folder if
> it doesn't exist yet (but may fail).

The only documentation I could find was at http://www.linuxcertif.com/man/1/claws-mail-perl-filter/ , and it doesn't mention it.  It must be out of date.

>> 3. [...] delaying cache updates during a massive manual filtering

>The plugin currently works on individual messages, so it doesn't know whether
>the filtering is massive or not.

I guess this needs to be directed to someone else; this is a situation where the cache is slowing things down, not speeding things up.

At some point, the program knows that it's processing more than a few messages.  That information is not given to the perl filter, because the perl filter can't do anything about it.  However, the code that runs the perl filter could temporarily turn off the cache, and rebuild it after filtering.  I didn't know if that was something you handled, or someone else.

>> 4. Could you add an option to import multiple mbox files easily?

> Why would a filter script deal with importing? That sounds more like UI
> automation, and would be a request for the Python plugin.

Ah, yes, this should have been directed to another person.  Do I have to submit a new feature request, or can (or should) this request be redirected?

>> no error was generated except to the standard error
>> of the claws-mail process
>
>Yes, that should probably go into the log file, too. You can check for errors
>in your script by looking at the return value (true on success, undef on
>error).

I thought the 'move' command never returned?
Comment 4 Holger Berndt 2010-09-15 19:56:28 UTC
> http://www.linuxcertif.com/man/1/claws-mail-perl-filter/

That's indeed an older version of the documentation. The latest version ships with the source in the file cm_perl.pod, and can be viewed with 'perldoc cm_perl.pod' (which is documented in the README file). If you got the plugin from a distribution package, it may or may not have installed the documentation as a man-page or the like.

> Ah, yes, this should have been directed to another
> person.  Do I have to submit a new feature request,
> or can (or should) this request be redirected?

If you file a separate enhancement request, chances that I forget about it get a tiny bit smaller. :-)

> I thought the 'move' command never returned?

Oh, yes, you're of course right.

Note You need to log in before you can comment on or make changes to this bug.