3 +--------------------------------------------------------------------+
4 | CiviCRM version 4.5 |
5 +--------------------------------------------------------------------+
6 | Copyright CiviCRM LLC (c) 2004-2014 |
7 +--------------------------------------------------------------------+
8 | This file is a part of CiviCRM. |
10 | CiviCRM is free software; you can copy, modify, and distribute it |
11 | under the terms of the GNU Affero General Public License |
12 | Version 3, 19 November 2007 and the CiviCRM Licensing Exception. |
14 | CiviCRM is distributed in the hope that it will be useful, but |
15 | WITHOUT ANY WARRANTY; without even the implied warranty of |
16 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. |
17 | See the GNU Affero General Public License for more details. |
19 | You should have received a copy of the GNU Affero General Public |
20 | License and the CiviCRM Licensing Exception along |
21 | with this program; if not, contact CiviCRM LLC |
22 | at info[AT]civicrm[DOT]org. If you have questions about the |
23 | GNU Affero General Public License or the licensing of CiviCRM, |
24 | see the CiviCRM license FAQ at http://civicrm.org/licensing |
25 +--------------------------------------------------------------------+
29 * Class to handle encoding and decoding Variable Enveleope Return Path (VERP)
33 * @copyright CiviCRM LLC (c) 2004-2014
37 class CRM_Utils_Verp
{
38 /* Mapping of reserved characters to hex codes */
40 static $encodeMap = array(
51 /* Mapping of hex codes to reserved characters */
53 static $decodeMap = array(
65 * Encode the sender's address with the VERPed recipient.
67 * @param string $sender The address of the sender
68 * @param string $recipient The address of the recipient
70 * @return string The VERP encoded address
74 public static function encode($sender, $recipient) {
75 preg_match('/(.+)\@([^\@]+)$/', $sender, $match);
79 preg_match('/(.+)\@([^\@]+)$/', $recipient, $match);
80 $rlocal = CRM_Utils_Array
::value(1, $match);
81 $rdomain = CRM_Utils_Array
::value(2, $match);
83 foreach (self
::$encodeMap as $char => $code) {
84 $rlocal = preg_replace('/' . preg_quote($char) . '/i', "+$code", $rlocal);
85 $rdomain = preg_replace('/' . preg_quote($char) . '/i', "+$code", $rdomain);
88 return "$slocal-$rlocal=$rdomain@$sdomain";
92 * Decode the address and return the sender and recipient as an array
94 * @param string $address The address to be decoded
96 * @return array The tuple ($sender, $recipient)
100 public static function &verpdecode($address) {
101 preg_match('/^(.+)-([^=]+)=([^\@]+)\@(.+)/', $address, $match);
105 $rdomain = $match[3];
106 $sdomain = $match[4];
108 foreach (self
::$decodeMap as $code => $char) {
109 $rlocal = preg_replace("/+$code/i", $char, $rlocal);
110 $rdomain = preg_replace("/+$code/i", $char, $rdomain);
113 return array("$slocal@$sdomain", "$rlocal@$rdomain");