if ($ann->count() == 0) { $annotation = new Annotation(array('author' => $from, 'source' => Source::EMAIL, 'sourceId' => $mail_id, 'text' => $textPlain, 'textHtml' => $textHtml, 'hashtags' => $hashtags)); $annotation->setConnection($connection_name); $annotation->save(); $result = Parser::parse($titolo); if ($result != false) { $evaluation = new Evaluation(array('annotation_id' => $annotation->id, 'sessione' => $result->sessione, 'evento' => $result->evento, 'punteggio' => $result->punteggio)); $evaluation->setConnection($connection_name); $evaluation->save(); } $attachments = $mail->getAttachments(); foreach ($attachments as $attachment) { $filePath = $attachment->filePath; $data = file_get_contents($filePath); $fileName = $attachment->name; $filesystem->put($mail_id . '/' . $fileName, $data); $attachments = new Attachment(array('annotation_id' => $annotation->id, 'source' => Source::EMAIL, 'fileName' => $fileName, 'filePath' => $mail_id . '/' . $fileName)); $attachments->setConnection($connection_name); $attachments->save(); $filesystem_tmp->delete(basename($filePath)); } $mailbox->moveMail($id, 'Inbox.Elaborated'); } else { $mailbox->markMailAsUnread($id); $mailbox->moveMail($id, 'Inbox.Failure'); } } } } catch (\Exception $e) { $log->addError($e->getFile() . ' on ' . $e->getLine() . ' ' . ' because : ' . $e->getMessage()); }