Merge pull request #5605 from sfe-ev/fix-upgrade-option_value
[civicrm-core.git] / CRM / Utils / Mail / Incoming.php
index 5567541539a604d5d28ed38c3e16a72af39755a1..a8fa85b9dc3647dc88d479af876f2676ae711058 100644 (file)
@@ -1,9 +1,9 @@
 <?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;
@@ -44,7 +44,7 @@ class CRM_Utils_Mail_Incoming {
    *
    * @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";
@@ -94,7 +94,7 @@ class CRM_Utils_Mail_Incoming {
    *
    * @throws Exception
    */
-  function formatMailMultipart($part, &$attachments) {
+  public function formatMailMultipart($part, &$attachments) {
     if ($part instanceof ezcMailMultiPartAlternative) {
       return self::formatMailMultipartAlternative($part, $attachments);
     }
@@ -124,7 +124,7 @@ class CRM_Utils_Mail_Incoming {
    *
    * @return string
    */
-  function formatMailMultipartMixed($part, &$attachments) {
+  public function formatMailMultipartMixed($part, &$attachments) {
     $t = '';
     foreach ($part->getParts() as $key => $alternativePart) {
       $t .= self::formatMailPart($alternativePart, $attachments);
@@ -138,7 +138,7 @@ class CRM_Utils_Mail_Incoming {
    *
    * @return string
    */
-  function formatMailMultipartRelated($part, &$attachments) {
+  public function formatMailMultipartRelated($part, &$attachments) {
     $t = '';
     $t .= "-RELATED MAIN PART-\n";
     $t .= self::formatMailPart($part->getMainPart(), $attachments);
@@ -156,7 +156,7 @@ class CRM_Utils_Mail_Incoming {
    *
    * @return string
    */
-  function formatMailMultipartDigest($part, &$attachments) {
+  public function formatMailMultipartDigest($part, &$attachments) {
     $t = '';
     foreach ($part->getParts() as $key => $alternativePart) {
       $t .= "-DIGEST-$key-\n";
@@ -172,7 +172,7 @@ class CRM_Utils_Mail_Incoming {
    *
    * @return string
    */
-  function formatMailRfc822Digest($part, &$attachments) {
+  public function formatMailRfc822Digest($part, &$attachments) {
     $t = '';
     $t .= "-DIGEST-ITEM-\n";
     $t .= "Item:\n\n";
@@ -187,7 +187,7 @@ class CRM_Utils_Mail_Incoming {
    *
    * @return string
    */
-  function formatMailMultipartAlternative($part, &$attachments) {
+  public function formatMailMultipartAlternative($part, &$attachments) {
     $t = '';
     foreach ($part->getParts() as $key => $alternativePart) {
       $t .= "-ALTERNATIVE ITEM $key-\n";
@@ -214,7 +214,7 @@ class CRM_Utils_Mail_Incoming {
    *
    * @return string
    */
-  function formatMailMultipartReport($part, &$attachments) {
+  public function formatMailMultipartReport($part, &$attachments) {
     $t = '';
     foreach ($part->getParts() as $key => $reportPart) {
       $t .= "-REPORT-$key-\n";
@@ -230,7 +230,7 @@ class CRM_Utils_Mail_Incoming {
    *
    * @return null
    */
-  function formatMailFile($part, &$attachments) {
+  public function formatMailFile($part, &$attachments) {
     $attachments[] = array(
       'dispositionType' => $part->dispositionType,
       'contentType' => $part->contentType,
@@ -246,7 +246,7 @@ class CRM_Utils_Mail_Incoming {
    *
    * @return string
    */
-  function formatAddresses($addresses) {
+  public function formatAddresses($addresses) {
     $fa = array();
     foreach ($addresses as $address) {
       $fa[] = self::formatAddress($address);
@@ -259,7 +259,7 @@ class CRM_Utils_Mail_Incoming {
    *
    * @return string
    */
-  function formatAddress($address) {
+  public function formatAddress($address) {
     $name = '';
     if (!empty($address->name)) {
       $name = "{$address->name} ";
@@ -273,29 +273,29 @@ class CRM_Utils_Mail_Incoming {
    * @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
@@ -324,7 +324,7 @@ class CRM_Utils_Mail_Incoming {
     // 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');
@@ -347,9 +347,9 @@ class CRM_Utils_Mail_Incoming {
       $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);
@@ -383,7 +383,6 @@ class CRM_Utils_Mail_Incoming {
     $subParam['email'] = $address->email;
     $subParam['name'] = $address->name;
 
-
     $contactID = self::getContactID($subParam['email'],
       $subParam['name'],
       TRUE,
@@ -409,7 +408,7 @@ class CRM_Utils_Mail_Incoming {
   }
 
   /**
-   * 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) {
@@ -455,5 +454,5 @@ class CRM_Utils_Mail_Incoming {
       CRM_Core_DAO::$_nullArray
     );
   }
-}
 
+}