public function processRequest() { $request = $this->getRequest(); if ($request->isFormPost()) { $mail = new PhabricatorMetaMTAMail(); $mail->addTos($request->getArr('to')); $mail->addCCs($request->getArr('cc')); $mail->setSubject($request->getStr('subject')); $mail->setBody($request->getStr('body')); $files = $request->getArr('files'); if ($files) { foreach ($files as $phid) { $file = id(new PhabricatorFile())->loadOneWhere('phid = %s', $phid); $mail->addAttachment(new PhabricatorMetaMTAAttachment($file->loadFileData(), $file->getName(), $file->getMimeType())); } } $mail->setFrom($request->getUser()->getPHID()); $mail->setSimulatedFailureCount($request->getInt('failures')); $mail->setIsHTML($request->getInt('html')); $mail->setIsBulk($request->getInt('bulk')); $mail->setMailTags($request->getStrList('mailtags')); $mail->save(); if ($request->getInt('immediately')) { $mail->sendNow(); } return id(new AphrontRedirectResponse())->setURI($this->getApplicationURI('/view/' . $mail->getID() . '/')); } $failure_caption = "Enter a number to simulate that many consecutive send failures before " . "really attempting to deliver via the underlying MTA."; $doclink_href = PhabricatorEnv::getDoclink('article/Configuring_Outbound_Email.html'); $doclink = phutil_render_tag('a', array('href' => $doclink_href, 'target' => '_blank'), 'Configuring Outbound Email'); $instructions = '<p class="aphront-form-instructions">This form will send a normal ' . 'email using the settings you have configured for Phabricator. For more ' . 'information, see ' . $doclink . '.</p>'; $adapter = PhabricatorEnv::getEnvConfig('metamta.mail-adapter'); $warning = null; if ($adapter == 'PhabricatorMailImplementationTestAdapter') { $warning = new AphrontErrorView(); $warning->setTitle('Email is Disabled'); $warning->setSeverity(AphrontErrorView::SEVERITY_WARNING); $warning->appendChild('<p>This installation of Phabricator is currently set to use ' . '<tt>PhabricatorMailImplementationTestAdapter</tt> to deliver ' . 'outbound email. This completely disables outbound email! All ' . 'outbound email will be thrown in a deep, dark hole until you ' . 'configure a real adapter.</p>'); } $panel_id = celerity_generate_unique_node_id(); $phdlink_href = PhabricatorEnv::getDoclink('article/Managing_Daemons_with_phd.html'); $phdlink = phutil_render_tag('a', array('href' => $phdlink_href, 'target' => '_blank'), '"phd start"'); $form = new AphrontFormView(); $form->setUser($request->getUser()); $form->appendChild($instructions)->appendChild(id(new AphrontFormStaticControl())->setLabel('Adapter')->setValue($adapter))->appendChild(id(new AphrontFormTokenizerControl())->setLabel('To')->setName('to')->setDatasource('/typeahead/common/mailable/'))->appendChild(id(new AphrontFormTokenizerControl())->setLabel('CC')->setName('cc')->setDatasource('/typeahead/common/mailable/'))->appendChild(id(new AphrontFormTextControl())->setLabel('Subject')->setName('subject'))->appendChild(id(new AphrontFormTextAreaControl())->setLabel('Body')->setName('body'))->appendChild(id(new AphrontFormTextControl())->setLabel('Mail Tags')->setName('mailtags')->setCaption('Example: <tt>differential-cc, differential-comment</tt>'))->appendChild(id(new AphrontFormDragAndDropUploadControl())->setLabel('Attach Files')->setName('files')->setDragAndDropTarget($panel_id)->setActivatedClass('aphront-panel-view-drag-and-drop'))->appendChild(id(new AphrontFormTextControl())->setLabel('Simulate Failures')->setName('failures')->setCaption($failure_caption))->appendChild(id(new AphrontFormCheckboxControl())->setLabel('HTML')->addCheckbox('html', '1', 'Send as HTML email.'))->appendChild(id(new AphrontFormCheckboxControl())->setLabel('Bulk')->addCheckbox('bulk', '1', 'Send with bulk email headers.'))->appendChild(id(new AphrontFormCheckboxControl())->setLabel('Send Now')->addCheckbox('immediately', '1', 'Send immediately. (Do not enqueue for daemons.)', PhabricatorEnv::getEnvConfig('metamta.send-immediately'))->setCaption('Daemons can be started with ' . $phdlink . '.'))->appendChild(id(new AphrontFormSubmitControl())->setValue('Send Mail')); $panel = new AphrontPanelView(); $panel->setHeader('Send Email'); $panel->appendChild($form); $panel->setID($panel_id); $panel->setWidth(AphrontPanelView::WIDTH_FORM); $nav = $this->buildSideNavView(); $nav->selectFilter('send'); $nav->appendChild(array($warning, $panel)); return $this->buildApplicationPage($nav, array('title' => 'Send Test')); }
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 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')); }
public function processRequest() { $request = $this->getRequest(); if ($request->isFormPost()) { $mail = new PhabricatorMetaMTAMail(); $mail->addTos($request->getArr('to')); $mail->addCCs($request->getArr('cc')); $mail->setSubject($request->getStr('subject')); $mail->setBody($request->getStr('body')); $mail->setFrom($request->getUser()->getPHID()); $mail->setSimulatedFailureCount($request->getInt('failures')); $mail->setIsHTML($request->getInt('html')); $mail->save(); if ($request->getInt('immediately')) { $mail->sendNow(); } return id(new AphrontRedirectResponse())->setURI('/mail/view/' . $mail->getID() . '/'); } $failure_caption = "Enter a number to simulate that many consecutive send failures before " . "really attempting to deliver via the underlying MTA."; $doclink_href = PhabricatorEnv::getDoclink('article/Configuring_Outbound_Email.html'); $doclink = phutil_render_tag('a', array('href' => $doclink_href, 'target' => '_blank'), 'Configuring Outbound Email'); $instructions = '<p class="aphront-form-instructions">This form will send a normal ' . 'email using the settings you have configured for Phabricator. For more ' . 'information, see ' . $doclink . '.</p>'; $adapter = PhabricatorEnv::getEnvConfig('metamta.mail-adapter'); $warning = null; if ($adapter == 'PhabricatorMailImplementationTestAdapter') { $warning = new AphrontErrorView(); $warning->setTitle('Email is Disabled'); $warning->setSeverity(AphrontErrorView::SEVERITY_WARNING); $warning->appendChild('<p>This installation of Phabricator is currently set to use ' . '<tt>PhabricatorMailImplementationTestAdapter</tt> to deliver ' . 'outbound email. This completely disables outbound email! All ' . 'outbound email will be thrown in a deep, dark hole until you ' . 'configure a real adapter.</p>'); } $form = new AphrontFormView(); $form->setUser($request->getUser()); $form->setAction('/mail/send/'); $form->appendChild($instructions)->appendChild(id(new AphrontFormStaticControl())->setLabel('Configured Adapter')->setValue($adapter))->appendChild(id(new AphrontFormTokenizerControl())->setLabel('To')->setName('to')->setDatasource('/typeahead/common/mailable/'))->appendChild(id(new AphrontFormTokenizerControl())->setLabel('CC')->setName('cc')->setDatasource('/typeahead/common/mailable/'))->appendChild(id(new AphrontFormTextControl())->setLabel('Subject')->setName('subject'))->appendChild(id(new AphrontFormTextAreaControl())->setLabel('Body')->setName('body'))->appendChild(id(new AphrontFormTextControl())->setLabel('Simulate Failures')->setName('failures')->setCaption($failure_caption))->appendChild(id(new AphrontFormCheckboxControl())->setLabel('HTML')->addCheckbox('html', '1', 'Send as HTML email.'))->appendChild(id(new AphrontFormCheckboxControl())->setLabel('Send Now')->addCheckbox('immediately', '1', 'Send immediately, not via MetaMTA background script.'))->appendChild(id(new AphrontFormSubmitControl())->setValue('Send Mail')); $panel = new AphrontPanelView(); $panel->setHeader('Send Email'); $panel->appendChild($form); $panel->setWidth(AphrontPanelView::WIDTH_WIDE); return $this->buildStandardPageResponse(array($warning, $panel), array('title' => 'Send Mail')); }