? email_substituting.patch
Index: bbcode-filter.inc
===================================================================
RCS file: /cvs/drupal/contributions/modules/bbcode/bbcode-filter.inc,v
retrieving revision 1.63
diff -u -p -r1.63 bbcode-filter.inc
--- bbcode-filter.inc	13 Jan 2008 06:17:31 -0000	1.63
+++ bbcode-filter.inc	17 Apr 2009 13:40:46 -0000
@@ -250,11 +250,12 @@ function _bbcode_filter_process(&$body, 
     // comma, double quote or <.
      $ret = preg_replace('#([\t\r\n >\(\[\|])(www|ftp)\.(([\w\-]+\.)*[\w]+(:[0-9]+)?(/[^ \"\'\(\n\r\t<\)\[\]\|]*)?)#i', '\1<a href="http://\2.\3">\2.\3</a>', $ret);
 
-    // matches an email@domain type address at the start of a line, or after a space.
+    // matches an email@domain type address at the start of a line, or after a space, or after a <p> tag.
     // Note: Only the followed chars are valid; alphanums, "-", "_" and or ".".
-    if (variable_get("bbcode_encode_mailto_$format", 1))
-      $ret = preg_replace_callback("#([\t\r\n ])([a-z0-9\-_.]+?)@([\w\-]+\.([\w\-\.]+\.)*[\w]+)#i", '_bbcode_encode_mailto', $ret);
-    else 
+    if (variable_get("bbcode_encode_mailto_$format", 1)) {
+      $ret = preg_replace_callback("#([\t\r\n ]|(<p>))([a-z0-9\-_.]+?)@([\w\-]+\.([\w\-\.]+\.)*[\w]+)#i", '_bbcode_encode_mailto', $ret);
+    }
+    else
       $ret = preg_replace('#([\t\r\n ])([a-z0-9\-_.]+?)@([\w\-]+\.([\w\-\.]+\.)*[\w]+)#i', '\\1<a href="mailto:\\2@\\3">\\2@\\3</a>', $ret);
 
     // Remove our padding
@@ -312,10 +313,10 @@ function _bbcode_generate_index($body, $
 }
 
 function _bbcode_encode_mailto($matches) {
-  if (isset($matches[3])) 
-    $link = 'document.write(\'<a href="mailto:' . $matches[2].'@'.$matches[3] . '">' . $matches[2].'@'.$matches[3] . '</a>\');';
-  else 
-    $link = 'document.write(\'<a href="mailto:' . $matches[1] . '" class="bb-email">' . (isset($matches[2]) ? $matches[2] : $matches[1]) . '</a>\');';
+  if (isset($matches[4]))
+    $link = 'document.write(\'<a href="mailto:' . $matches[3].'@'.$matches[4] . '">' . $matches[3].'@'.$matches[4] . '</a>\');';
+  else
+    $link = 'document.write(\'<a href="mailto:' . $matches[1] . '" class="bb-email">' . (isset($matches[3]) ? $matches[3] : $matches[1]) . '</a>\');';
 
   $js_encode = '';
   for ($x = 0; $x < strlen($link); $x++) 
