Online Editor : add a mailto

Author Message

Anthony M.

Wednesday 21 March 2007 8:12:57 am

Hi,

i want to add a mailto in the online editor (version 4.2.1) like this :

mailto:email1@domaine.com;email2@domaine.com?subject=my subject

but EZPublish show the error :

Invalid e-mail address: 'email1@domaine.com;email2@domaine.com?subject=my%20subject'

Why ?? Is it a bug ??

Thanks a lot

Anthony

Luke Barton

Wednesday 31 October 2007 8:00:49 am

Anthony,

I just encountered the same problem in EZP 3.10.0 and OE 4.2.4.

Here's what I did to solve the problem:

1. I searched all the files in my EZP installation for the string "Invalid e-mail address." This returned 2 results:

a. /extension/ezdhtml/ezxmltext/handlers/input/ezdhtmlinputparser.php
b. /kernel/classes/datatypes/ezxmltext/handlers/input/ezsimplifiedxmlinputparser.php

2. This error is generated if this validation step fails:

include_once( 'lib/ezutils/classes/ezmail.php' );
if ( !eZMail::validateMail( $mailAddr[1] ) )
{
...
}

3. In the file "/lib/ezutils/classes/ezmail.php," there is a regular expression for email address validation (I've broken it out of serveral lines for readability):

define( 'EZ_MAIL_REGEXP', 
'(
[0-9a-zA-Z]
([-.\w]*
[0-9a-zA-Z_])*
@
(((
([0-9a-zA-Z])+
([-\w]*
[0-9a-zA-Z])*
\.
)
+
[a-zA-Z]{2,9})|
(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\.
(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\.
(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\.
(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)))
' );

4. That expression does not accommodate a query string on the end because it is used to validate email addresses, not mailto: links. I created another regular expression and function for mailto: validation.

5. The new regular expression is in "/lib/ezutils/classes/ezmail.php" is:

define( 'EZ_MAILTO_REGEXP', 
'(
[0-9a-zA-Z]
([-.\w]*
[0-9a-zA-Z_])*
@
(((
([0-9a-zA-Z])+
([-\w]*
[0-9a-zA-Z])*
\.
)
+
[a-zA-Z]{2,9})|
(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\.
(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\.
(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\.
(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?))
(\?[a-zA-Z0-9=]*)?((&[a-zA-Z0-9=]*))*))
' );

The last part...

(\?[a-zA-Z0-9=]*)?((&[a-zA-Z0-9=]*))*)

...seems to accommodate for strings <i>starting with a question mark, followed by 0..n occurences of alphanumeric characters and an equal sign, followed by 0..n occurrences of a pattern that starts with an ampersand, followed by 0..n occurrences of an alphanumeric pattern and an equal sign</i>. I stress the word seems, because I don't write regular expressions very often. It's not perfect, but it works for simple cases. And it gives false positives, but I can live with that for now.

6. I also created a function in '/lib/ezutils/classes/ezmail.php" called validateMailto:

function validateMailto( $address )
{
//$pos = ( ereg( '^' . EZ_MAILTO_REGEXP . '$', $address) );
$pos = ereg(EZ_MAILTO_REGEXP, $address);
return $pos;
}

Again, probably not perfect, but it's working so far.

7. In the other two files mentioned in step 1 above, I changed the call to read as such:

include_once( 'lib/ezutils/classes/ezmail.php' );
if ( !eZMail::validateMailto( $mailAddr[1] ) )
{
...
}

So far this is working, but I'm sure it will fail on same cases and should be reviewed and improved.

Anyway, I hope people find this hack useful...

-Luke

PS: I've also reported a bug:
http://issues.ez.no/IssueView.php?Id=11798

Powered by eZ Publish™ CMS Open Source Web Content Management. Copyright © 1999-2014 eZ Systems AS (except where otherwise noted). All rights reserved.

eZ debug

Timing: Jan 31 2025 01:32:15
Script start
Timing: Jan 31 2025 01:32:15
Module start 'layout'
Timing: Jan 31 2025 01:32:15
Module start 'content'
Timing: Jan 31 2025 01:32:15
Module end 'content'
Timing: Jan 31 2025 01:32:15
Script end

Main resources:

Total runtime0.0293 sec
Peak memory usage4,096.0000 KB
Database Queries3

Timing points:

CheckpointStart (sec)Duration (sec)Memory at start (KB)Memory used (KB)
Script start 0.00000.0055 588.1328151.2109
Module start 'layout' 0.00550.0047 739.3438220.6875
Module start 'content' 0.01020.0172 960.0313997.8047
Module end 'content' 0.02740.0018 1,957.835933.9922
Script end 0.0292  1,991.8281 

Time accumulators:

 Accumulator Duration (sec) Duration (%) Count Average (sec)
Ini load
Load cache0.003010.4092140.0002
Check MTime0.00134.5975140.0001
Mysql Total
Database connection0.00072.561010.0007
Mysqli_queries0.00289.480130.0009
Looping result0.00000.044810.0000
Template Total0.00134.610.0013
Template load0.00113.759610.0011
Template processing0.00020.812710.0002
Override
Cache load0.00082.698610.0008
General
dbfile0.00123.938080.0001
String conversion0.00000.030940.0000
Note: percentages do not add up to 100% because some accumulators overlap

Templates used to render the page:

UsageRequested templateTemplateTemplate loadedEditOverride
1print_pagelayout.tpl<No override>extension/community/design/community/templates/print_pagelayout.tplEdit templateOverride template
 Number of times templates used: 1
 Number of unique templates used: 1

Time used to render debug report: 0.0001 secs