public function processRequest()
 {
     // Get a page of mails together with pager.
     $request = $this->getRequest();
     $user = $request->getUser();
     $offset = $request->getInt('offset', 0);
     $related_phid = $request->getStr('phid');
     $status = $request->getStr('status');
     $pager = new AphrontPagerView();
     $pager->setOffset($offset);
     $pager->setURI($request->getRequestURI(), 'offset');
     $mail = new PhabricatorMetaMTAMail();
     $conn_r = $mail->establishConnection('r');
     $wheres = array();
     if ($status) {
         $wheres[] = qsprintf($conn_r, 'status = %s', $status);
     }
     if ($related_phid) {
         $wheres[] = qsprintf($conn_r, 'relatedPHID = %s', $related_phid);
     }
     if (count($wheres)) {
         $where_clause = 'WHERE ' . implode($wheres, ' AND ');
     } else {
         $where_clause = 'WHERE 1 = 1';
     }
     $data = queryfx_all($conn_r, 'SELECT * FROM %T
     %Q
     ORDER BY id DESC
     LIMIT %d, %d', $mail->getTableName(), $where_clause, $pager->getOffset(), $pager->getPageSize() + 1);
     $data = $pager->sliceResults($data);
     $mails = $mail->loadAllFromArray($data);
     // Render the details table.
     $rows = array();
     foreach ($mails as $mail) {
         $next_retry = $mail->getNextRetry() - time();
         if ($next_retry <= 0) {
             $next_retry = "None";
         } else {
             $next_retry = phabricator_format_relative_time_detailed($next_retry);
         }
         $rows[] = array(PhabricatorMetaMTAMail::getReadableStatus($mail->getStatus()), $mail->getRetryCount(), $next_retry, phabricator_datetime($mail->getDateCreated(), $user), phabricator_format_relative_time_detailed(time() - $mail->getDateModified()), phutil_escape_html($mail->getSubject()), phutil_render_tag('a', array('class' => 'button small grey', 'href' => $this->getApplicationURI('/view/' . $mail->getID() . '/')), 'View'));
     }
     $table = new AphrontTableView($rows);
     $table->setHeaders(array('Status', 'Retry', 'Next', 'Created', 'Updated', 'Subject', ''));
     $table->setColumnClasses(array(null, null, null, null, null, 'wide', 'action'));
     // Render the whole page.
     $panel = new AphrontPanelView();
     $panel->appendChild($table);
     $panel->setHeader('MetaMTA Messages');
     $panel->appendChild($pager);
     $nav = $this->buildSideNavView();
     $nav->selectFilter('sent');
     $nav->appendChild($panel);
     return $this->buildApplicationPage($nav, array('title' => 'Sent Mail'));
 }
 public function execute(PhutilArgumentParser $args)
 {
     $console = PhutilConsole::getConsole();
     $viewer = $this->getViewer();
     $mails = id(new PhabricatorMetaMTAMail())->loadAllWhere('1 = 1 ORDER BY id DESC LIMIT %d', $args->getArg('limit'));
     if (!$mails) {
         $console->writeErr("%s\n", pht('No sent mail.'));
         return 0;
     }
     $table = id(new PhutilConsoleTable())->setShowHeader(false)->addColumn('id', array('title' => 'ID'))->addColumn('status', array('title' => 'Status'))->addColumn('subject', array('title' => 'Subject'));
     foreach (array_reverse($mails) as $mail) {
         $status = $mail->getStatus();
         $table->addRow(array('id' => $mail->getID(), 'status' => PhabricatorMetaMTAMail::getReadableStatus($status), 'subject' => $mail->getSubject()));
     }
     $table->draw();
     return 0;
 }
 public function processRequest()
 {
     $request = $this->getRequest();
     $user = $request->getUser();
     $mail = id(new PhabricatorMetaMTAMail())->load($this->id);
     if (!$mail) {
         return new Aphront404Response();
     }
     $status = PhabricatorMetaMTAMail::getReadableStatus($mail->getStatus());
     $form = new AphrontFormView();
     $form->setUser($request->getUser());
     $form->appendChild(id(new AphrontFormStaticControl())->setLabel('Subject')->setValue($mail->getSubject()))->appendChild(id(new AphrontFormStaticControl())->setLabel('Created')->setValue(phabricator_datetime($mail->getDateCreated(), $user)))->appendChild(id(new AphrontFormStaticControl())->setLabel('Status')->setValue($status))->appendChild(id(new AphrontFormStaticControl())->setLabel('Retry Count')->setValue($mail->getRetryCount()))->appendChild(id(new AphrontFormStaticControl())->setLabel('Message')->setValue($mail->getMessage()))->appendChild(id(new AphrontFormStaticControl())->setLabel('Related PHID')->setValue($mail->getRelatedPHID()))->appendChild(id(new AphrontFormSubmitControl())->addCancelButton($this->getApplicationURI(), 'Done'));
     $panel = new AphrontPanelView();
     $panel->setHeader('View Email');
     $panel->appendChild($form);
     $panel->setWidth(AphrontPanelView::WIDTH_WIDE);
     return $this->buildApplicationPage($panel, array('title' => 'View Mail'));
 }
 public function processRequest()
 {
     // Get a page of mails together with pager.
     $request = $this->getRequest();
     $user = $request->getUser();
     $offset = $request->getInt('offset', 0);
     $related_phid = $request->getStr('phid');
     $pager = new AphrontPagerView();
     $pager->setOffset($offset);
     $pager->setURI($request->getRequestURI(), 'offset');
     $mail = new PhabricatorMetaMTAMail();
     $conn_r = $mail->establishConnection('r');
     if ($related_phid) {
         $where_clause = qsprintf($conn_r, 'WHERE relatedPHID = %s', $related_phid);
     } else {
         $where_clause = 'WHERE 1 = 1';
     }
     $data = queryfx_all($conn_r, 'SELECT * FROM %T
     %Q
     ORDER BY id DESC
     LIMIT %d, %d', $mail->getTableName(), $where_clause, $pager->getOffset(), $pager->getPageSize() + 1);
     $data = $pager->sliceResults($data);
     $mails = $mail->loadAllFromArray($data);
     // Render the details table.
     $rows = array();
     foreach ($mails as $mail) {
         $rows[] = array(PhabricatorMetaMTAMail::getReadableStatus($mail->getStatus()), $mail->getRetryCount(), $mail->getNextRetry() - time() . ' s', phabricator_datetime($mail->getDateCreated(), $user), time() - $mail->getDateModified() . ' s', phutil_escape_html($mail->getSubject()), phutil_render_tag('a', array('class' => 'button small grey', 'href' => '/mail/view/' . $mail->getID() . '/'), 'View'));
     }
     $table = new AphrontTableView($rows);
     $table->setHeaders(array('Status', 'Retry', 'Next', 'Created', 'Updated', 'Subject', ''));
     $table->setColumnClasses(array(null, null, null, null, null, 'wide', 'action'));
     // Render the whole page.
     $panel = new AphrontPanelView();
     $panel->appendChild($table);
     $panel->setHeader('MetaMTA Messages');
     if ($user->getIsAdmin()) {
         $panel->setCreateButton('Send New Test Message', '/mail/send/');
     }
     $panel->appendChild($pager);
     return $this->buildStandardPageResponse($panel, array('title' => 'MetaMTA', 'tab' => 'queue'));
 }