<?php
/*
+--------------------------------------------------------------------+
- | CiviCRM version 4.5 |
+ | CiviCRM version 4.6 |
+--------------------------------------------------------------------+
- | Copyright CiviCRM LLC (c) 2004-2014 |
+ | Copyright CiviCRM LLC (c) 2004-2015 |
+--------------------------------------------------------------------+
| This file is a part of CiviCRM. |
| |
| GNU Affero General Public License or the licensing of CiviCRM, |
| see the CiviCRM license FAQ at http://civicrm.org/licensing |
+--------------------------------------------------------------------+
-*/
+ */
/**
*
* @package CRM
- * @copyright CiviCRM LLC (c) 2004-2014
+ * @copyright CiviCRM LLC (c) 2004-2015
* $Id$
*
*/
class CRM_Utils_Mail_Incoming {
- CONST
+ const
EMAILPROCESSOR_CREATE_INDIVIDUAL = 1,
EMAILPROCESSOR_OVERRIDE = 2,
EMAILPROCESSOR_IGNORE = 3;
*
* @return string
*/
- function formatMail($mail, &$attachments) {
+ public function formatMail($mail, &$attachments) {
$t = '';
$t .= "From: " . self::formatAddress($mail->from) . "\n";
$t .= "To: " . self::formatAddresses($mail->to) . "\n";
*
* @throws Exception
*/
- function formatMailMultipart($part, &$attachments) {
+ public function formatMailMultipart($part, &$attachments) {
if ($part instanceof ezcMailMultiPartAlternative) {
return self::formatMailMultipartAlternative($part, $attachments);
}
*
* @return string
*/
- function formatMailMultipartMixed($part, &$attachments) {
+ public function formatMailMultipartMixed($part, &$attachments) {
$t = '';
foreach ($part->getParts() as $key => $alternativePart) {
$t .= self::formatMailPart($alternativePart, $attachments);
*
* @return string
*/
- function formatMailMultipartRelated($part, &$attachments) {
+ public function formatMailMultipartRelated($part, &$attachments) {
$t = '';
$t .= "-RELATED MAIN PART-\n";
$t .= self::formatMailPart($part->getMainPart(), $attachments);
*
* @return string
*/
- function formatMailMultipartDigest($part, &$attachments) {
+ public function formatMailMultipartDigest($part, &$attachments) {
$t = '';
foreach ($part->getParts() as $key => $alternativePart) {
$t .= "-DIGEST-$key-\n";
*
* @return string
*/
- function formatMailRfc822Digest($part, &$attachments) {
+ public function formatMailRfc822Digest($part, &$attachments) {
$t = '';
$t .= "-DIGEST-ITEM-\n";
$t .= "Item:\n\n";
*
* @return string
*/
- function formatMailMultipartAlternative($part, &$attachments) {
+ public function formatMailMultipartAlternative($part, &$attachments) {
$t = '';
foreach ($part->getParts() as $key => $alternativePart) {
$t .= "-ALTERNATIVE ITEM $key-\n";
*
* @return string
*/
- function formatMailMultipartReport($part, &$attachments) {
+ public function formatMailMultipartReport($part, &$attachments) {
$t = '';
foreach ($part->getParts() as $key => $reportPart) {
$t .= "-REPORT-$key-\n";
*
* @return null
*/
- function formatMailFile($part, &$attachments) {
+ public function formatMailFile($part, &$attachments) {
$attachments[] = array(
'dispositionType' => $part->dispositionType,
'contentType' => $part->contentType,
*
* @return string
*/
- function formatAddresses($addresses) {
+ public function formatAddresses($addresses) {
$fa = array();
foreach ($addresses as $address) {
$fa[] = self::formatAddress($address);
*
* @return string
*/
- function formatAddress($address) {
+ public function formatAddress($address) {
$name = '';
if (!empty($address->name)) {
$name = "{$address->name} ";
* @return array
* @throws Exception
*/
- function &parse(&$file) {
+ public function &parse(&$file) {
// check that the file exists and has some content
if (!file_exists($file) ||
!trim(file_get_contents($file))
) {
return CRM_Core_Error::createAPIError(ts('%1 does not exists or is empty',
- array(1 => $file)
- ));
+ array(1 => $file)
+ ));
}
require_once 'ezc/Base/src/ezc_bootstrap.php';
require_once 'ezc/autoload/mail_autoload.php';
// explode email to digestable format
- $set = new ezcMailFileSet(array($file));
+ $set = new ezcMailFileSet(array($file));
$parser = new ezcMailParser();
- $mail = $parser->parseMail($set);
+ $mail = $parser->parseMail($set);
if (!$mail) {
return CRM_Core_Error::createAPIError(ts('%1 could not be parsed',
- array(1 => $file)
- ));
+ array(1 => $file)
+ ));
}
// since we only have one fileset
// we definitely need a contact id for the from address
// if we dont have one, skip this email
if (empty($params['from']['id'])) {
- return;
+ return NULL;
}
$emailFields = array('to', 'cc', 'bcc');
$config = CRM_Core_Config::singleton();
for ($i = 0; $i < count($attachments); $i++) {
$attachNum = $i + 1;
- $fileName = basename($attachments[$i]['fullName']);
- $newName = CRM_Utils_File::makeFileName($fileName);
- $location = $config->uploadDir . $newName;
+ $fileName = basename($attachments[$i]['fullName']);
+ $newName = CRM_Utils_File::makeFileName($fileName);
+ $location = $config->uploadDir . $newName;
// move file to the civicrm upload directory
rename($attachments[$i]['fullName'], $location);
$subParam['email'] = $address->email;
$subParam['name'] = $address->name;
-
$contactID = self::getContactID($subParam['email'],
$subParam['name'],
TRUE,
}
/**
- * Retrieve a contact ID and if not present
+ * Retrieve a contact ID and if not present.
* create one with this email
*/
public static function getContactID($email, $name = NULL, $create = TRUE, &$mail) {
CRM_Core_DAO::$_nullArray
);
}
-}
+}