function processMails(&$mailServer)
{
    $rez = '';
    $dids = array();
    //array for deleted ids
    $i = 0;
    $newMails = 0;
    //iterate and process each mail
    foreach ($mailServer['mailbox'] as $k => $mail) {
        $i++;
        try {
            if ($mail->hasFlag(\Zend\Mail\Storage::FLAG_SEEN) || empty($mail->subject)) {
                continue;
            }
        } catch (\InvalidArgumentException $e) {
            $rez .= "Cant read this mail, probably empty subject.\n";
            continue;
        }
        $newMails++;
        //Re: [dev #2841] New task: listeners when eupload file on casebox (/1/3-1/3-3/3-assignee/3-au_3)
        $subject = decodeSubject($mail->subject);
        preg_match('/(Re:\\s*)?\\[([^\\s]+)\\s+#(\\d+)\\]/', $subject, $matches);
        // $matches[2] - core name
        // $matches[3] - item id
        //if found core name and core name is registered for this mail server
        //then add email to "mails" per core, to be inserted later all together
        if (!empty($matches[2]) && isset($mailServer['cores'][$matches[2]])) {
            $date = strtotime($mail->date);
            $date = date('Y-m-d H:i:s', $date);
            /* get contents and attachments */
            $parts = getMailContentAndAtachment($mail);
            $content = null;
            $attachments = array();
            foreach ($parts as $p) {
                //content, filename, content-type
                if (!$p['attachment'] && !$content) {
                    $content = $p['content'];
                } else {
                    $attachments[] = $p;
                }
            }
            /* end of get contents and attachments */
            $mailServer['cores'][$matches[2]]['mails'][] = array('id' => $mailServer['mailbox']->getUniqueId($k), 'pid' => $matches[3], 'from' => $mail->from, 'to' => $mail->to, 'date' => $date, 'subject' => $subject, 'content' => $content, 'attachments' => $attachments);
        } else {
            $dids[] = $mailServer['mailbox']->getUniqueId($k);
        }
    }
    $rez .= $newMails > 0 ? "\nnew mails: " . $newMails . "\n" : '';
    $rez .= deleteMails($mailServer['mailbox'], $dids);
    return $rez;
}
Exemplo n.º 2
0
             $delete_ids[] = $mailbox->getUniqueId($k);
             mail($mail->from, 'Error processing your email: ' . $subject, '. We didn\'t find the specified target folder, from the ' . 'subject of your mail, in our database, please correct ' . 'the subject and resend your email. Wrong messages are ' . 'deleted automatically.' . $mail_requirements, 'From: ' . $core['mail_user'] . "\n\r");
             echo "\rcannot find corresponding folder in our database for: {$subject} ... skipping";
             continue;
         } else {
             $pid = $lastPid;
         }
     }
 }
 /* end of locate the corresponding folder in our database */
 /* get email date. Ex: Thu, 24 Feb 2011 22:22:10 +0300 /**/
 $time = strtotime($mail->date);
 $time = date('Y-m-d H:i:s', $time);
 /* end of get email date /**/
 /* get contents and attachments */
 $parts = getMailContentAndAtachment($mail);
 $content = null;
 $attachments = array();
 foreach ($parts as $p) {
     //content, filename, content-type
     if (!$p['attachment'] && !$content) {
         $content = $p['content'];
     } else {
         $attachments[] = $p;
     }
 }
 /* end of get contents and attachments */
 /* creating email object in corresponding case and adding attachments if any */
 $obj = Objects::getCustomClassByType('email');
 $objectId = $obj->create(array('pid' => $pid, 'user_id' => $user_id, 'name' => $subject, 'template_id' => $email_template_id, 'date' => $time, 'cid' => $user_id, 'data' => array('_title' => $subject, '_date_start' => $time, '_content' => $content, 'from' => $mail->from), 'sys_data' => array('old_id' => $mailbox->getUniqueId($k))));
 if (!empty($attachments)) {