Example #1
0
 public function getMailListAction($request)
 {
     $repo = $this->repo('Account');
     $box = $this->openBoxFromRequest($request);
     $data = $box->fetch($request->request->get('page', 1), $request->request->get('perpage', 20), $request->request->get('query', null), $request->request->get('search-in', 'SUBJECT'));
     $total = $data->total;
     $result = $data->list;
     foreach ($result as $message) {
         if (property_exists($message, 'size')) {
             $message->size = $repo->formatBytes($message->size);
         } else {
             $message->size = $repo->formatBytes(0);
         }
         if (property_exists($message, 'date')) {
             /**
              * I don't know why this os addet, but with this,
              * DateTime::__construct() doesn't work.
              */
             $message->date = trim(str_replace('(CET)', '', $message->date));
             if (Mailbox::datetimeValid($message->date)) {
                 $message->date = (new DateTime($message->date))->format('Y.m.d H:i');
             }
         } else {
             $message->date = '---';
         }
     }
     return $this->responseAJAX(['status' => 'success', 'data' => ['list' => $result, 'total' => $total]]);
 }
Example #2
0
 public function fetchMessages($sequence)
 {
     $result = imap_fetch_overview($this->connection, $sequence, FT_UID);
     foreach ($result as &$mail) {
         if (property_exists($mail, 'subject')) {
             $mail->subject = static::decode($mail->subject, $this->imap->serverEncoding);
         }
         if (property_exists($mail, 'from')) {
             $mail->from = static::decode($mail->from, $this->imap->serverEncoding);
         }
         if (property_exists($mail, 'to')) {
             $mail->to = static::decode($mail->to, $this->imap->serverEncoding);
         }
         if (property_exists($mail, 'date')) {
             if (Mailbox::datetimeValid($mail->date)) {
                 $mail->date_timestamp = (new DateTime($mail->date))->getTimestamp();
             } else {
                 $mail->date_timestamp = 0;
             }
         }
     }
     return array_reverse($result);
 }