summaryrefslogtreecommitdiff
path: root/it_mail.class
diff options
context:
space:
mode:
Diffstat (limited to 'it_mail.class')
-rw-r--r--it_mail.class40
1 files changed, 25 insertions, 15 deletions
diff --git a/it_mail.class b/it_mail.class
index 94801a5..2342778 100644
--- a/it_mail.class
+++ b/it_mail.class
@@ -82,7 +82,7 @@ function add_header($header, $value)
{
case 'To':
foreach ((array)$value as $val)
- $this->to[] = $this->addrlist_escape($val);
+ $this->to[] = $this->addrlist_encode($val);
break;
case 'Subject':
@@ -91,12 +91,12 @@ function add_header($header, $value)
case 'Cc':
foreach ((array)$value as $val)
- $this->cc[] = $this->addrlist_escape($val);
+ $this->cc[] = $this->addrlist_encode($val);
break;
case 'Bcc':
foreach ((array)$value as $val)
- $this->bcc[] = $this->addrlist_escape($val);
+ $this->bcc[] = $this->addrlist_encode($val);
break;
case 'charset':
@@ -108,7 +108,7 @@ function add_header($header, $value)
/* FALLTHROUGH */
default:
$this->header_names[] = $header;
- $this->header_values[] = $header == 'From' || $header =='Reply-To' ? $this->addrlist_escape($value) : $this->header_escape($value);
+ $this->header_values[] = $header == 'From' || $header =='Reply-To' ? $this->addrlist_encode($value) : $this->header_encode($value);
break;
}
}
@@ -278,7 +278,7 @@ function send($p = array())
foreach ($this->attachments as $attachment)
{
- $name = $this->header_escape($attachment['name']);
+ $name = $this->header_encode($attachment['name']);
$text .= "\n--$boundary\nContent-Type: {$attachment['mimetype']}; name=\"$name\"\nContent-Transfer-Encoding: base64\nContent-ID: <{$attachment['cid']}>\nContent-Disposition: {$attachment['disposition']}; filename=\"$name\"\n\n";
$text .= chunk_split(base64_encode($attachment['data']));
}
@@ -291,12 +291,12 @@ function send($p = array())
if (it::is_live() || EDC('forcemail') || $p['forcemail'])
{
- if (($result = mail($to, $this->header_escape($this->subject), $text, implode("\n", $headers), $this->flags)) === false)
+ if (($result = mail($to, $this->header_encode($this->subject), $text, implode("\n", $headers), $this->flags)) === false)
it::error(['title' => "failed sending mail to $to subject $this->subject", 'body' => ['text' => $text, 'headers' => $headers, 'flags' => $this->flags]]);
return $result;
}
else
- return ED($to, $this->header_escape($this->subject), $text, $headers, $this->flags);
+ return ED($to, $this->header_encode($this->subject), $text, $headers, $this->flags);
}
@@ -369,7 +369,7 @@ static function addrlist_split($string)
* @param $string String to be escaped
* @return String escape suitable for sending in header line
*/
-function header_escape($string)
+function header_encode($string)
{
return preg_match('/[\x00-\x1f\x7f-\xff]/', $string)
? ltrim(
@@ -388,15 +388,15 @@ function header_escape($string)
* @param $string String containing address list
* @return String suitable for sending in address list headers
*/
-function addrlist_escape($string)
+function addrlist_encode($string)
{
# Exclude e-mail addresses from being encoded as
# e.g. GMail or Exchange have problems with that
foreach (self::addrlist_split($string) as list($name, $email))
{
- $email = self::email_escape($email);
+ $email = self::email_encode($email);
if ($name && $email)
- $result[] = $this->header_escape(trim($name)) . " <$email>";
+ $result[] = $this->header_encode(trim($name)) . " <$email>";
else if (!$name && $email)
$result[] = $email;
}
@@ -411,12 +411,22 @@ function addrlist_escape($string)
* @param $string Fulle name to be escaped
* @return String to be safely used in "$fullname <$email>" for To: etc.
*/
-static function fullname_escape($string)
+static function fullname_encode($string)
{
return '"' . preg_replace('/["\x00-\x1f]/', '', $string) . '"';
}
+
+/**
+ * Legacy function
+ */
+static function fullname_escape($string)
+{
+ return fullname_encode($string);
+}
+
+
/**
* INTERNAL: Split email-address into local part and doomain
* @return Array with to elements: local part and domain
@@ -451,7 +461,7 @@ static function email_split($email)
* INTERNAL: Convert domain part of email address into ascii idn form
* @return String with converted email address
*/
-static function email_escape($email)
+static function email_encode($email)
{
list($local, $domain) = self::email_split($email);
@@ -506,7 +516,7 @@ static function address_error($addresslist)
{
foreach (self::addrlist_split($addresslist) as list($dummy, $email))
{
- $email = self::email_escape($email);
+ $email = self::email_encode($email);
if (filter_var($email, FILTER_VALIDATE_EMAIL) === false && !it::match('^\s*[a-z][-a-z0-9]*\s*$', $email))
return "invalid format on $email";
}
@@ -526,7 +536,7 @@ static function check_email($email, $checkmailbox = false)
{
$result = IT_MAIL_CHECKEMAIL_INVALID;
- $email = self::email_escape($email);
+ $email = self::email_encode($email);
list($dummy, $domain) = self::email_split($email);
/* Check if username starts with www. or not well-formed => reject */
if (!preg_match('/^www\./', $email) && filter_var($email, FILTER_VALIDATE_EMAIL) !== false && $domain)