Kayako Logo
Modifications & Addon Releases Modification guides and addons are posted here to share with the community. Do not post requests in here!

Reply
 
LinkBack (1) Thread Tools Search this Thread Rate Thread Display Modes
  1 links from elsewhere to this Post. Click to view. (#1) Old
atDev Offline
Member
 
Posts: 81
Join Date: Jan 2007

Regular expressions for breaklines (regex) - 25-12-2007, 11:43 PM

Where in the files/code are the breaklines checked? I'll code it in.
   
Reply With Quote
  (#2) Old
atDev Offline
Member
 
Posts: 81
Join Date: Jan 2007

26-12-2007, 06:31 PM

Nevermind... for anyone interested here yah go.

When entering the breakline make sure it begins with / as this triggers it to do a regex compare.

/modules/parser/functions_parsercore.php

Replace:
Code:
function processBreakLines($content)
{
    global $_SWIFT;
    parserDebug("NOTICE: Processing Breaklines");

    $breakline = &$_SWIFT["breaklinecache"];

    parserDebug("NOTICE: Breakline Total: ".count($breakline));
    if (!is_array($breakline))
    {
        parserDebug("NOTICE: No Breaklines found!");
        return $content;
    }

    foreach ($breakline as $key=>$val)
    {
        parserDebug("NOTICE: Processing Breakline: ".$val);
        
        $breakcontent = reversestrchr($content, $val);

        if ($breakcontent)
        {
            parserDebug("NOTICE: Breakline Triggered!");
            // Eureaka! Eureaka! Eureaka!
            return $breakcontent;
        }
    }

    return $content;
}
With:
Code:
function processBreakLines($content)
{
    global $_SWIFT;
    parserDebug("NOTICE: Processing Breaklines");

    $breakline = &$_SWIFT["breaklinecache"];

    parserDebug("NOTICE: Breakline Total: ".count($breakline));
    if (!is_array($breakline))
    {
        parserDebug("NOTICE: No Breaklines found!");
        return $content;
    }

    foreach ($breakline as $key=>$val)
    {
        parserDebug("NOTICE: Processing Breakline: ".$val);
        if(substr($val,0,1) == '/') {
            $splits = preg_split($val,$content);
            $breakcontent = count($splits) ? $splits[0] : false;   
        } else {
            $breakcontent = reversestrchr($content, $val);
        }
        if ($breakcontent)
        {
            parserDebug("NOTICE: Breakline Triggered!");
            // Eureaka! Eureaka! Eureaka!
            return $breakcontent;
        }
    }

    return $content;
}
Note: see bug fix in post Regular expressions for breaklines (regex)

Last edited by Jamie Edwards : 28-12-2007 at 11:17 AM.
   
Reply With Quote
  (#3) Old
Jamie Edwards Offline
Operations Manager
 
Jamie Edwards's Avatar
 
Posts: 4,313
Join Date: Jan 2006
Location: UK

SupportSuite
Owned License

26-12-2007, 06:38 PM

Hi atDev,

So this modification will work with and without regular expressions entered as breaklines?


Jamie Edwards (jamie.edwards ]at[ kayako.com)
----------------------------------------------------------------
---
  • New to the forum? New user's guide here.
  • Submit bug reports here.
  • Submit support tickets via the members area.
  • Submit sales queries either via live chat or via e-mail.
  • There is no official ETA on Version 4.
   
Reply With Quote
  (#4) Old
atDev Offline
Member
 
Posts: 81
Join Date: Jan 2007

26-12-2007, 07:04 PM

Quote:
So this modification will work with and without regular expressions entered as breaklines?
Yes. The main issue to look at is how to determine if the breakline entered in the kayako admin area should be treated as regex or not.

There are two ways to do this in my opinion.

1. Check some character in the breakline that signifies it as regex, like I did above. We check the first character, if its a /, we know this is a regex string.

2. Do a regex no matter what. Since all the kayako code is doing right now is finding the breakline and selecting all text before it, we can do this all at once with regex.

I have tested #1, as seen in the code above.

For #2 it would be like:
Code:
function processBreakLines($content)
{
    global $_SWIFT;
    parserDebug("NOTICE: Processing Breaklines");

    $breakline = &$_SWIFT["breaklinecache"];

    parserDebug("NOTICE: Breakline Total: ".count($breakline));
    if (!is_array($breakline))
    {
        parserDebug("NOTICE: No Breaklines found!");
        return $content;
    }

    foreach ($breakline as $key=>$val)
    {
        parserDebug("NOTICE: Processing Breakline: ".$val);
        $splits = preg_split('/'.$val.'/',$content);
        $breakcontent = count($splits) ? $splits[0] : false;   

        if ($breakcontent)
        {
            parserDebug("NOTICE: Breakline Triggered!");
            // Eureaka! Eureaka! Eureaka!
            return $breakcontent;
        }
    }

    return $content;
}
Keep in mind with this code, you no longer need to enter / and / before and after the regex string as we add this anyway in the above code.

A common reply line is something like:
On 12/17/07, Some Name <test@test.com> wrote:

The regex code below will work for this (has been tested):
/On [0-9]{1,2}\/[0-9]{1,2}\/[0-9]{1,2},(.)+ <(.)+@(.)+> wrote:/

Keep in mind again, the above works for the first solution given, if you use the code in this post (which is untested) you would remove the / and / like:
On [0-9]{1,2}\/[0-9]{1,2}\/[0-9]{1,2},(.)+ <(.)+@(.)+> wrote:
   
Reply With Quote
  (#5) Old
atDev Offline
Member
 
Posts: 81
Join Date: Jan 2007

26-12-2007, 07:07 PM

As far as implementing this in the core kayako code, I would tell your developers to use solution #2 as you are going to be comparing a string versus the email content no matter what.

preg_split will work even if its given a static string (no regex) but it may be a bit slower.

It is either that or do an if/else statement like I did in #1 solution above.
   
Reply With Quote
  (#6) Old
Jamie Edwards Offline
Operations Manager
 
Jamie Edwards's Avatar
 
Posts: 4,313
Join Date: Jan 2006
Location: UK

SupportSuite
Owned License

26-12-2007, 07:10 PM

Hi atDev,

Thanks a lot for sharing this - we will be implementing a regex solution soon. I have split your posts to a new thread here.


Jamie Edwards (jamie.edwards ]at[ kayako.com)
----------------------------------------------------------------
---
  • New to the forum? New user's guide here.
  • Submit bug reports here.
  • Submit support tickets via the members area.
  • Submit sales queries either via live chat or via e-mail.
  • There is no official ETA on Version 4.
   
Reply With Quote
  (#7) Old
atDev Offline
Member
 
Posts: 81
Join Date: Jan 2007

26-12-2007, 07:12 PM

I did some basic tests on my own and everything parsed smoothly, I will update this thread if any noticeable problems pop up but its a pretty basic change so no side effects should be seen.
   
Reply With Quote
  (#8) Old
atDev Offline
Member
 
Posts: 81
Join Date: Jan 2007

27-12-2007, 11:06 PM

For anyone needing them. After reviewing some more emails not getting parsed we have added these three regex lines to catch variations of the breakline:

/On [0-9]{1,2}\/[0-9]{1,2}\/[0-9]{1,2},(.)+ <(.)+@(.)+> wrote:/

/On [A-Za-z]{3} [0-9]{1,2}, at [0-9]{1,2}:[0-9]{2} (PM|AM), (.)+ wrote:/

/On [A-Za-z]{3} [0-9]{1,2}, [0-9]{4} [0-9]{1,2}:[0-9]{2} (PM|AM), (.)+ <(.)+@(.)+> wrote:/
   
Reply With Quote
  (#9) Old
atDev Offline
Member
 
Posts: 81
Join Date: Jan 2007

28-12-2007, 04:05 AM

A bugfix. It appears preg_split returns the entire string if no splits are done, which in theory it should. This causes it to no parse/run through the rest of the breaklines. I switched to using this:
Code:
    foreach ($breakline as $key=>$val)
    {
        parserDebug("NOTICE: Processing Breakline: ".$val);
        if(substr($val,0,1) == '/') {
            $breakcontent = preg_match($val, $content, $matches, PREG_OFFSET_CAPTURE) ? substr($content,0,$matches[0][1]) : false;   
        } else {
            $breakcontent = reversestrchr($content, $val);
        }
        if ($breakcontent)
        {
            parserDebug("NOTICE: Breakline Triggered!");
            // Eureaka! Eureaka! Eureaka!
            return $breakcontent;
        }
    }
This uses preg_match instead which is a surefire way of true/false match/no match instead of splitting it. Then we just do a substr using the offset of the first match, much like the script already does but it uses static string matching.
   
Reply With Quote
  (#10) Old
maykelrr Offline
New Member
 
Posts: 2
Join Date: Feb 2008

eSupport
Yearly Leased License
24-02-2008, 03:14 PM

Hi, I would like to implement this in my support site, but I have a leased eSupport and the source is zend-encoded, is there any way to obtain the same zend-encoded file with this change on it?

Thanks!
Maykel Rodriguez
SpeedyRails - Celebrating our First Anniversary!
   
Reply With Quote
  (#11) Old
craigbrass Offline
Senior Member
 
Posts: 4,951
Join Date: Jun 2005
Location: Cumbria, UK

SupportSuite
Owned License
24-02-2008, 03:22 PM

You need to contact Jamie (jamie.edwards<!at!>kayako<!dot!>com) listing the files you need and he will be able to provide.


Craig Brass - Kayako Forum Squatter (Note: I am NOT a staff member)

Icon Headquarters - Its Elixir - Web2Messenger
   
Reply With Quote
  (#12) Old
Jamie Edwards Offline
Operations Manager
 
Jamie Edwards's Avatar
 
Posts: 4,313
Join Date: Jan 2006
Location: UK

SupportSuite
Owned License

24-02-2008, 06:43 PM

Hi Maykel,

Unfortunatly the open files are unable on your leased license; in order to have near-unrestricted access to the source code (except for the licensing functions), you need to have an owned license.


Jamie Edwards (jamie.edwards ]at[ kayako.com)
----------------------------------------------------------------
---
  • New to the forum? New user's guide here.
  • Submit bug reports here.
  • Submit support tickets via the members area.
  • Submit sales queries either via live chat or via e-mail.
  • There is no official ETA on Version 4.
   
Reply With Quote
  (#13) Old
craigbrass Offline
Senior Member
 
Posts: 4,951
Join Date: Jun 2005
Location: Cumbria, UK

SupportSuite
Owned License
24-02-2008, 08:04 PM

I thought you were able to request individual files and get them unencoded?


Craig Brass - Kayako Forum Squatter (Note: I am NOT a staff member)

Icon Headquarters - Its Elixir - Web2Messenger
   
Reply With Quote
  (#14) Old
Ryan Lederman Offline
Chief Operating Officer
 
Ryan Lederman's Avatar
 
Posts: 789
Join Date: May 2005
Location: Boise, Idaho

17-04-2008, 06:43 PM

I've committed this feature to CVS as of today. Breaklines that are to be treated as a regular expression start with "regex:" and must contain the start/stop symbols of a normal regex; (e.g. "regex:@[abcd]@")


Ryan Lederman (ryan.lederman ]at[ kayako.com)
----------------------------------------------------------------
---
   
Reply With Quote
Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On

LinkBacks (?)
LinkBack to this Thread: http://forums.kayako.com/f52/regular-expressions-breaklines-regex-14950/
Posted By For Type Date
Kayako Bug Tracker - Viewing Bug #418 - Regular expressions for breaklines (regex) This thread Refback 26-12-2007 07:13 PM

Similar Threads
Thread Thread Starter Forum Replies Last Post
Mail parser -> Rules and regular expressions for headers AllanMar Will Implement (V4) 4 11-04-2008 03:30 PM
Regex validation and custom fields (how to make it work?) richm SupportSuite, eSupport and LiveResponse 8 24-12-2007 11:19 PM
Mail parser post-parse regex to find word in subject? richm SupportSuite, eSupport and LiveResponse 1 22-08-2007 03:53 PM
Built in regex tester richm Will Implement (V4) 2 15-08-2007 05:57 PM



Powered by vBulletin® Version 3.6.8
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
LinkBacks Enabled by vBSEO 3.1.0

Kayako provides online help desk software and support solutions; enabling companies to improve their support and reduce costs.

Our three main products include: SupportSuite, eSupport and LiveResponse



1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46