Author Topic: Roundcube 0.7.2 full mail headers caching possible?  (Read 5753 times)

Offline Lonwolf892005

  • Newbie
  • *
  • Posts: 4
Roundcube 0.7.2 full mail headers caching possible?
« on: July 11, 2012, 03:34:46 PM »
Hello!

After installing roundcube, configuring it to run with multiple mail servers (yahoo, gmail, etc..) i have run into a somewhat serious issue:

The e-mails are not cached entirely by default in the database.

I have caching enabled, i can see the data serialized in the table but it's missing part of the headers.
One of the e-mail campaign software we use sends an ID in the header (let's say param-id=345). It is inserted around content-type and timestamp lines in the message header. However this information is not stored in the database.

I have already devised an API to extract this ID from mail body, but not all e-mail bodies will have this ID incorporated into them and it will be available only in the header.

I noticed when you hit viewsource from roundcube, i can see the custom ID in the headers there.

Is there any (easy) way to force roundcube to parse and store ALL headers into the database when caching messages? Or, can someone hint me how can i force the message viewsource to cache in the same table or another table ??

I have looked into the source code and couldn't find a solution to my problem.

TL;DR:

How can you force roundcube to cache full e-mails just like "View source" button in the interface?

-Lonwolf

Offline JohnDoh

  • Global Moderator
  • Hero Member
  • *****
  • Posts: 2,856
Re: Roundcube 0.7.2 full mail headers caching possible?
« Reply #1 on: July 12, 2012, 02:29:14 AM »
Hi, Roundcube only caches the information it needs for the message list. That is some of the headers and the message structure. The idea is to speed up the process of listing messages for web servers with slow connections to the IMAP server. It does not cache the entire contents of the message. To get Roundcube to cache more headers then what you have to do is make a plugin on the imap_init hook. From there you can tell Roundcube which headers it should retrieve and store in the cache. AFAIK you can’t just tell it to get them all, you have to know the name of the header. If you want to see an example of how to set the headers check out Cor Bosman’s Listcommands plugin.
Roundcube Plugins: Contextmenu, SpamAssassin Prefs, and more…

Offline Lonwolf892005

  • Newbie
  • *
  • Posts: 4
Re: Roundcube 0.7.2 full mail headers caching possible?
« Reply #2 on: July 12, 2012, 11:53:41 AM »
Hello John and thank you for your reply.

I have looked into the plugin you hinted and also the default installed plugins but not activated. I noticed there is a plugin there called 'show_additional_headers' that theoretically should do what i need. I added these 2 lines in the roundcube config file:

Code: [Select]
//main.inc.php config file entries
$rcmail_config['plugins'] = array('show_additional_headers');
$rcmail_config['show_additional_headers'] = array('x-job');

Here is a sample output of viewsource of a mail with custom headers:

Code: [Select]
MIME-Version: 1.0
x-job: 447
X-Mailer-LID: 70
X-Mailer-RecptId: 4026507
X: 8

After i activated the plugin, i logged in with the user that received this email, did a refresh, but the cache didn't receive the new parameter( cannot find any x-job or 447 reference in any rows of the mysql table cache).

Is it normal? I cannot figure it out right now if it should affect database cache or not with this plugin.

My other chance is to download, activate the plugin you mentioned, remove the processing part of URLS and tell the plugin to add my custom header(s)? If i login with the users, will the old e-mails be recached and will I find the header info in the database?

I am really stuck here :(

-Lonwolf

Offline JohnDoh

  • Global Moderator
  • Hero Member
  • *****
  • Posts: 2,856
Re: Roundcube 0.7.2 full mail headers caching possible?
« Reply #3 on: July 13, 2012, 01:33:40 AM »
ahh I forgot all about that plugin, yes that is perfect. iirc you'll need to clear the cache and let it rebuild once you have setup all the extra headers you want. only messages recieved after the new settings are in place will get the extra info in the cache.
Roundcube Plugins: Contextmenu, SpamAssassin Prefs, and more…

Offline Lonwolf892005

  • Newbie
  • *
  • Posts: 4
Re: Roundcube 0.7.2 full mail headers caching possible?
« Reply #4 on: July 13, 2012, 09:55:10 AM »
Well i deleted all the information in cache tables from phpmyadmin. Still no luck, the job header didn't process  :-\
I can't seem to make this work.. Is there anything obvious i missed?  - or  -Is there another way to force cache rebuild?

-Lonwolf

Offline Lonwolf892005

  • Newbie
  • *
  • Posts: 4
Re: Roundcube 0.7.2 full mail headers caching possible?
« Reply #5 on: July 15, 2012, 07:56:16 AM »
Hey!

After a few days I managed to make it work. Apparently "Show additional message headers" plugin does absolutely nothing for me, so i took the code from the mentioned plugin above and replaced it:

Code: [Select]
class show_additional_headers extends rcube_plugin
{

public $task = 'mail';

  function init()
  {
    $rcmail = rcmail::get_instance();
    if (!$rcmail->action || in_array($rcmail->action, array('list', 'show', 'preview'))) {
      $this->add_hook('imap_init', array($this, 'imap_init'));
    }
  }

  function imap_init($p)
  {
    $rcmail = rcmail::get_instance();
    $mailinglist_headers = array_keys($this->get_list_headers());
    $p['fetch_headers'] .= trim($p['fetch_headers']. ' ' . strtoupper(join(' ', $mailinglist_headers)));
    return($p);
  }


  private function get_list_headers()
  {
    $mailinglist_headers = array(
      'x-job'        => 'job'
      );
    return($mailinglist_headers);
  }
}


I removed the whole class definition with what i needed, and adding headers is done in the array from get. The value of each array key is irrelevant :) . If you want to cache all headers that you know, simply add them in the array.
Hoping this post will help some other lost souls in the future.

Thank you JohnDoh for your help!

-Lonwolf