protected function processReceivedMail(PhabricatorMetaMTAReceivedMail $mail, PhabricatorUser $sender)
 {
     $title = $mail->getSubject();
     if (!$title) {
         $title = pht('Email Paste');
     }
     $file = PhabricatorPasteEditor::initializeFileForPaste($sender, $title, $mail->getCleanTextBody());
     $xactions = array();
     $xactions[] = id(new PhabricatorPasteTransaction())->setTransactionType(PhabricatorPasteTransaction::TYPE_CONTENT)->setNewValue($file->getPHID());
     $xactions[] = id(new PhabricatorPasteTransaction())->setTransactionType(PhabricatorPasteTransaction::TYPE_TITLE)->setNewValue($title);
     $xactions[] = id(new PhabricatorPasteTransaction())->setTransactionType(PhabricatorPasteTransaction::TYPE_LANGUAGE)->setNewValue('');
     // auto-detect
     $paste = PhabricatorPaste::initializeNewPaste($sender);
     $content_source = PhabricatorContentSource::newForSource(PhabricatorContentSource::SOURCE_EMAIL, array('id' => $mail->getID()));
     $editor = id(new PhabricatorPasteEditor())->setActor($sender)->setContentSource($content_source)->setContinueOnNoEffect(true);
     $xactions = $editor->applyTransactions($paste, $xactions);
     $mail->setRelatedPHID($paste->getPHID());
     $subject_prefix = PhabricatorEnv::getEnvConfig('metamta.paste.subject-prefix');
     $subject = pht('You successfully created a paste.');
     $paste_uri = PhabricatorEnv::getProductionURI($paste->getURI());
     $body = new PhabricatorMetaMTAMailBody();
     $body->addRawSection($subject);
     $body->addTextSection(pht('PASTE LINK'), $paste_uri);
     id(new PhabricatorMetaMTAMail())->addTos(array($sender->getPHID()))->setSubject($subject)->setSubjectPrefix($subject_prefix)->setFrom($sender->getPHID())->setRelatedPHID($paste->getPHID())->setBody($body->render())->saveAndSend();
 }
 private function assertEmail($expect, $herald_hints)
 {
     $env = PhabricatorEnv::beginScopedEnv();
     $env->overrideEnvConfig('phabricator.production-uri', 'http://test.com/');
     $env->overrideEnvConfig('metamta.herald.show-hints', $herald_hints);
     $body = new PhabricatorMetaMTAMailBody();
     $body->addRawSection('salmon');
     $body->addTextSection('HEADER', "bass\ntrout\n");
     $body->addHeraldSection('/xscript/');
     $this->assertEqual($expect, $body->render());
 }
 private function sendMail(PhabricatorMailTarget $target, PhabricatorRepository $repository, PhabricatorRepositoryPushEvent $event)
 {
     $task_data = $this->getTaskData();
     $viewer = $target->getViewer();
     $locale = PhabricatorEnv::beginScopedLocale($viewer->getTranslation());
     $logs = $event->getLogs();
     list($ref_lines, $ref_list) = $this->renderRefs($logs);
     list($commit_lines, $subject_line) = $this->renderCommits($repository, $logs, idx($task_data, 'info', array()));
     $ref_count = count($ref_lines);
     $commit_count = count($commit_lines);
     $handles = id(new PhabricatorHandleQuery())->setViewer($viewer)->withPHIDs(array($event->getPusherPHID()))->execute();
     $pusher_name = $handles[$event->getPusherPHID()]->getName();
     $repo_name = $repository->getMonogram();
     if ($commit_count) {
         $overview = pht('%s pushed %d commit(s) to %s.', $pusher_name, $commit_count, $repo_name);
     } else {
         $overview = pht('%s pushed to %s.', $pusher_name, $repo_name);
     }
     $details_uri = PhabricatorEnv::getProductionURI('/diffusion/pushlog/view/' . $event->getID() . '/');
     $body = new PhabricatorMetaMTAMailBody();
     $body->addRawSection($overview);
     $body->addLinkSection(pht('DETAILS'), $details_uri);
     if ($commit_lines) {
         $body->addTextSection(pht('COMMITS'), implode("\n", $commit_lines));
     }
     if ($ref_lines) {
         $body->addTextSection(pht('REFERENCES'), implode("\n", $ref_lines));
     }
     $prefix = PhabricatorEnv::getEnvConfig('metamta.diffusion.subject-prefix');
     $parts = array();
     if ($commit_count) {
         $parts[] = pht('%s commit(s)', $commit_count);
     }
     if ($ref_count) {
         $parts[] = implode(', ', $ref_list);
     }
     $parts = implode(', ', $parts);
     if ($subject_line) {
         $subject = pht('(%s) %s', $parts, $subject_line);
     } else {
         $subject = pht('(%s)', $parts);
     }
     $mail = id(new PhabricatorMetaMTAMail())->setRelatedPHID($event->getPHID())->setSubjectPrefix($prefix)->setVarySubjectPrefix(pht('[Push]'))->setSubject($subject)->setFrom($event->getPusherPHID())->setBody($body->render())->setThreadID($event->getPHID(), $is_new = true)->addHeader('Thread-Topic', $subject)->setIsBulk(true);
     $target->sendMail($mail);
 }
예제 #4
0
 protected function processReceivedMail(PhabricatorMetaMTAReceivedMail $mail, PhabricatorUser $sender)
 {
     $attachment_phids = $mail->getAttachments();
     if (empty($attachment_phids)) {
         throw new PhabricatorMetaMTAReceivedMailProcessingException(MetaMTAReceivedMailStatus::STATUS_UNHANDLED_EXCEPTION, pht('Ignoring email to create files that did not include attachments.'));
     }
     $first_phid = head($attachment_phids);
     $mail->setRelatedPHID($first_phid);
     $attachment_count = count($attachment_phids);
     if ($attachment_count > 1) {
         $subject = pht('You successfully uploaded %d files.', $attachment_count);
     } else {
         $subject = pht('You successfully uploaded a file.');
     }
     $subject_prefix = PhabricatorEnv::getEnvConfig('metamta.files.subject-prefix');
     $file_uris = array();
     foreach ($attachment_phids as $phid) {
         $file_uris[] = PhabricatorEnv::getProductionURI('/file/info/' . $phid . '/');
     }
     $body = new PhabricatorMetaMTAMailBody();
     $body->addRawSection($subject);
     $body->addTextSection(pht('FILE LINKS'), implode("\n", $file_uris));
     id(new PhabricatorMetaMTAMail())->addTos(array($sender->getPHID()))->setSubject($subject)->setSubjectPrefix($subject_prefix)->setFrom($sender->getPHID())->setRelatedPHID($first_phid)->setBody($body->render())->saveAndSend();
 }
예제 #5
0
 public function send()
 {
     $email_to = array_filter(array_unique($this->to));
     $question = $this->getQuestion();
     $target = $this->getTarget();
     $uri = PhabricatorEnv::getURI('/Q' . $question->getID());
     $thread_id = $this->getThreadID();
     $handles = id(new PhabricatorObjectHandleData($email_to))->loadHandles();
     $reply_handler = new PonderReplyHandler();
     $reply_handler->setMailReceiver($question);
     $body = new PhabricatorMetaMTAMailBody();
     $body->addRawSection($this->renderBody());
     $body->addTextSection(pht('QUESTION DETAIL'), $uri);
     $template = id(new PhabricatorMetaMTAMail())->setSubject($this->getThreadTopic())->setSubjectPrefix($this->getSubjectPrefix())->setVarySubjectPrefix($this->renderVaryPrefix())->setFrom($target->getAuthorPHID())->setParentMessageID($this->parentMessageID)->addHeader('Thread-Topic', $this->getThreadTopic())->setThreadID($this->getThreadID(), false)->setRelatedPHID($question->getPHID())->setIsBulk(true)->setBody($body->render());
     $mails = $reply_handler->multiplexMail($template, array_select_keys($handles, $email_to), array());
     foreach ($mails as $mail) {
         $mail->saveAndSend();
     }
 }
 private function sendWaitingForApprovalEmail(PhabricatorUser $user)
 {
     $title = '[Phabricator] ' . pht('New User "%s" Awaiting Approval', $user->getUsername());
     $body = new PhabricatorMetaMTAMailBody();
     $body->addRawSection(pht('Newly registered user "%s" is awaiting account approval by an ' . 'administrator.', $user->getUsername()));
     $body->addLinkSection(pht('APPROVAL QUEUE'), PhabricatorEnv::getProductionURI('/people/query/approval/'));
     $body->addLinkSection(pht('DISABLE APPROVAL QUEUE'), PhabricatorEnv::getProductionURI('/config/edit/auth.require-approval/'));
     $admins = id(new PhabricatorPeopleQuery())->setViewer(PhabricatorUser::getOmnipotentUser())->withIsAdmin(true)->execute();
     if (!$admins) {
         return;
     }
     $mail = id(new PhabricatorMetaMTAMail())->addTos(mpull($admins, 'getPHID'))->setSubject($title)->setBody($body->render())->saveAndSend();
 }
 private function newMailMessage(PhabricatorUser $viewer, array $events)
 {
     $events = msort($events, 'getEpoch');
     $next_event = head($events);
     $body = new PhabricatorMetaMTAMailBody();
     foreach ($events as $event) {
         $body->addTextSection(null, pht('%s is starting in %s minute(s), at %s.', $event->getEvent()->getName(), $event->getDisplayMinutes(), $event->getDisplayTime()));
         $body->addLinkSection(pht('EVENT DETAIL'), PhabricatorEnv::getProductionURI($event->getEvent()->getURI()));
     }
     $next_event = head($events)->getEvent();
     $subject = $next_event->getName();
     if (count($events) > 1) {
         $more = pht('(+%s more...)', new PhutilNumber(count($events) - 1));
         $subject = "{$subject} {$more}";
     }
     $calendar_phid = id(new PhabricatorCalendarApplication())->getPHID();
     return id(new PhabricatorMetaMTAMail())->setSubject($subject)->addTos(array($viewer->getPHID()))->setSensitiveContent(false)->setFrom($calendar_phid)->setIsBulk(true)->setSubjectPrefix(pht('[Calendar]'))->setVarySubjectPrefix(pht('[Reminder]'))->setThreadID($next_event->getPHID(), false)->setRelatedPHID($next_event->getPHID())->setBody($body->render())->setHTMLBody($body->renderHTML());
 }
 protected function processReceivedMail(PhabricatorMetaMTAReceivedMail $mail, PhabricatorUser $sender)
 {
     $attachments = $mail->getAttachments();
     $files = array();
     $errors = array();
     if ($attachments) {
         $files = id(new PhabricatorFileQuery())->setViewer($sender)->withPHIDs($attachments)->execute();
         foreach ($files as $index => $file) {
             if ($file->getMimeType() != 'text/plain') {
                 $errors[] = pht('Could not parse file %s; only files with mimetype text/plain ' . 'can be parsed via email.', $file->getName());
                 unset($files[$index]);
             }
         }
     }
     $diffs = array();
     foreach ($files as $file) {
         $call = new ConduitCall('differential.createrawdiff', array('diff' => $file->loadFileData()));
         $call->setUser($sender);
         try {
             $result = $call->execute();
             $diffs[$file->getName()] = $result['uri'];
         } catch (Exception $e) {
             $errors[] = pht('Could not parse attachment %s; only attachments (and mail bodies) ' . 'generated via "diff" commands can be parsed.', $file->getName());
         }
     }
     $body = $mail->getCleanTextBody();
     if ($body) {
         $call = new ConduitCall('differential.createrawdiff', array('diff' => $body));
         $call->setUser($sender);
         try {
             $result = $call->execute();
             $diffs[pht('Mail Body')] = $result['uri'];
         } catch (Exception $e) {
             $errors[] = pht('Could not parse mail body; only mail bodies (and attachments) ' . 'generated via "diff" commands can be parsed.');
         }
     }
     $subject_prefix = PhabricatorEnv::getEnvConfig('metamta.differential.subject-prefix');
     if (count($diffs)) {
         $subject = pht('You successfully created %d diff(s).', count($diffs));
     } else {
         $subject = pht('Diff creation failed; see body for %s error(s).', new PhutilNumber(count($errors)));
     }
     $body = new PhabricatorMetaMTAMailBody();
     $body->addRawSection($subject);
     if (count($diffs)) {
         $text_body = '';
         $html_body = array();
         $body_label = pht('%s DIFF LINK(S)', new PhutilNumber(count($diffs)));
         foreach ($diffs as $filename => $diff_uri) {
             $text_body .= $filename . ': ' . $diff_uri . "\n";
             $html_body[] = phutil_tag('a', array('href' => $diff_uri), $filename);
             $html_body[] = phutil_tag('br');
         }
         $body->addTextSection($body_label, $text_body);
         $body->addHTMLSection($body_label, $html_body);
     }
     if (count($errors)) {
         $body_section = new PhabricatorMetaMTAMailSection();
         $body_label = pht('%s ERROR(S)', new PhutilNumber(count($errors)));
         foreach ($errors as $error) {
             $body_section->addFragment($error);
         }
         $body->addTextSection($body_label, $body_section);
     }
     id(new PhabricatorMetaMTAMail())->addTos(array($sender->getPHID()))->setSubject($subject)->setSubjectPrefix($subject_prefix)->setFrom($sender->getPHID())->setBody($body->render())->saveAndSend();
 }
    private function buildErrorMailBody($error, PhabricatorMetaMTAReceivedMail $mail)
    {
        $original_body = $mail->getRawTextBody();
        $main_body = <<<EOBODY
Your request failed because an error was encoutered while processing it:

  ERROR: {$error}

  -- Original Body -------------------------------------------------------------

  {$original_body}

EOBODY;
        $body = new PhabricatorMetaMTAMailBody();
        $body->addRawSection($main_body);
        $body->addReplySection($this->getReplyHandlerInstructions());
        return $body->render();
    }
 private function renderMailBody(PhabricatorAuditComment $comment, $cname, PhabricatorObjectHandle $handle, PhabricatorMailReplyHandler $reply_handler, array $inline_comments)
 {
     assert_instances_of($inline_comments, 'PhabricatorInlineCommentInterface');
     $commit = $this->commit;
     $user = $this->user;
     $name = $user->getUsername();
     $verb = PhabricatorAuditActionConstants::getActionPastTenseVerb($comment->getAction());
     $body = new PhabricatorMetaMTAMailBody();
     $body->addRawSection("{$name} {$verb} commit {$cname}.");
     $body->addRawSection($comment->getContent());
     if ($inline_comments) {
         $block = array();
         $path_map = id(new DiffusionPathQuery())->withPathIDs(mpull($inline_comments, 'getPathID'))->execute();
         $path_map = ipull($path_map, 'path', 'id');
         foreach ($inline_comments as $inline) {
             $path = idx($path_map, $inline->getPathID());
             if ($path === null) {
                 continue;
             }
             $start = $inline->getLineNumber();
             $len = $inline->getLineLength();
             if ($len) {
                 $range = $start . '-' . ($start + $len);
             } else {
                 $range = $start;
             }
             $content = $inline->getContent();
             $block[] = "{$path}:{$range} {$content}";
         }
         $body->addTextSection(pht('INLINE COMMENTS'), implode("\n", $block));
     }
     $body->addTextSection(pht('COMMIT'), PhabricatorEnv::getProductionURI($handle->getURI()));
     $body->addReplySection($reply_handler->getReplyHandlerInstructions());
     return $body->render();
 }
 private function sendEmail($task, $transactions, $email_to, $email_cc)
 {
     $email_to = array_filter(array_unique($email_to));
     $email_cc = array_filter(array_unique($email_cc));
     $phids = array();
     foreach ($transactions as $transaction) {
         foreach ($transaction->extractPHIDs() as $phid) {
             $phids[$phid] = true;
         }
     }
     foreach ($email_to as $phid) {
         $phids[$phid] = true;
     }
     foreach ($email_cc as $phid) {
         $phids[$phid] = true;
     }
     $phids = array_keys($phids);
     $handles = id(new PhabricatorObjectHandleData($phids))->loadHandles();
     $view = new ManiphestTransactionDetailView();
     $view->setTransactionGroup($transactions);
     $view->setHandles($handles);
     $view->setAuxiliaryFields($this->auxiliaryFields);
     list($action, $main_body) = $view->renderForEmail($with_date = false);
     $is_create = $this->isCreate($transactions);
     $task_uri = PhabricatorEnv::getURI('/T' . $task->getID());
     $reply_handler = $this->buildReplyHandler($task);
     $body = new PhabricatorMetaMTAMailBody();
     $body->addRawSection($main_body);
     if ($is_create) {
         $body->addTextSection(pht('TASK DESCRIPTION'), $task->getDescription());
     }
     $body->addTextSection(pht('TASK DETAIL'), $task_uri);
     $body->addReplySection($reply_handler->getReplyHandlerInstructions());
     $thread_id = 'maniphest-task-' . $task->getPHID();
     $task_id = $task->getID();
     $title = $task->getTitle();
     $mailtags = $this->getMailTags($transactions);
     $template = id(new PhabricatorMetaMTAMail())->setSubject("T{$task_id}: {$title}")->setSubjectPrefix($this->getSubjectPrefix())->setVarySubjectPrefix("[{$action}]")->setFrom($transaction->getAuthorPHID())->setParentMessageID($this->parentMessageID)->addHeader('Thread-Topic', "T{$task_id}: " . $task->getOriginalTitle())->setThreadID($thread_id, $is_create)->setRelatedPHID($task->getPHID())->setIsBulk(true)->setMailTags($mailtags)->setBody($body->render());
     $mails = $reply_handler->multiplexMail($template, array_select_keys($handles, $email_to), array_select_keys($handles, $email_cc));
     foreach ($mails as $mail) {
         $mail->saveAndSend();
     }
 }
 public function doWork()
 {
     $viewer = PhabricatorUser::getOmnipotentUser();
     $task_data = $this->getTaskData();
     $email_phids = idx($task_data, 'emailPHIDs');
     if (!$email_phids) {
         // If we don't have any email targets, don't send any email.
         return;
     }
     $event_phid = idx($task_data, 'eventPHID');
     $event = id(new PhabricatorRepositoryPushEventQuery())->setViewer($viewer)->withPHIDs(array($event_phid))->needLogs(true)->executeOne();
     $repository = $event->getRepository();
     if ($repository->isImporting()) {
         // If the repository is still importing, don't send email.
         return;
     }
     if ($repository->getDetail('herald-disabled')) {
         // If publishing is disabled, don't send email.
         return;
     }
     $logs = $event->getLogs();
     list($ref_lines, $ref_list) = $this->renderRefs($logs);
     list($commit_lines, $subject_line) = $this->renderCommits($repository, $logs, idx($task_data, 'info', array()));
     $ref_count = count($ref_lines);
     $commit_count = count($commit_lines);
     $handles = id(new PhabricatorHandleQuery())->setViewer($viewer)->withPHIDs(array($event->getPusherPHID()))->execute();
     $pusher_name = $handles[$event->getPusherPHID()]->getName();
     $repo_name = $repository->getMonogram();
     if ($commit_count) {
         $overview = pht('%s pushed %d commit(s) to %s.', $pusher_name, $commit_count, $repo_name);
     } else {
         $overview = pht('%s pushed to %s.', $pusher_name, $repo_name);
     }
     $details_uri = PhabricatorEnv::getProductionURI('/diffusion/pushlog/view/' . $event->getID() . '/');
     $body = new PhabricatorMetaMTAMailBody();
     $body->addRawSection($overview);
     $body->addTextSection(pht('DETAILS'), $details_uri);
     if ($commit_lines) {
         $body->addTextSection(pht('COMMITS'), implode("\n", $commit_lines));
     }
     if ($ref_lines) {
         $body->addTextSection(pht('REFERENCES'), implode("\n", $ref_lines));
     }
     $prefix = PhabricatorEnv::getEnvConfig('metamta.diffusion.subject-prefix');
     $parts = array();
     if ($commit_count) {
         $parts[] = pht('%s commit(s)', $commit_count);
     }
     if ($ref_count) {
         $parts[] = implode(', ', $ref_list);
     }
     $parts = implode(', ', $parts);
     if ($subject_line) {
         $subject = pht('(%s) %s', $parts, $subject_line);
     } else {
         $subject = pht('(%s)', $parts);
     }
     $mail = id(new PhabricatorMetaMTAMail())->setRelatedPHID($event->getPHID())->setSubjectPrefix($prefix)->setVarySubjectPrefix(pht('[Push]'))->setSubject($subject)->setFrom($event->getPusherPHID())->setBody($body->render())->setThreadID($event->getPHID(), $is_new = true)->addHeader('Thread-Topic', $subject)->setIsBulk(true);
     $to_handles = id(new PhabricatorHandleQuery())->setViewer($viewer)->withPHIDs($email_phids)->execute();
     $reply_handler = new PhabricatorRepositoryPushReplyHandler();
     $mails = $reply_handler->multiplexMail($mail, $to_handles, array());
     foreach ($mails as $mail) {
         $mail->saveAndSend();
     }
 }
예제 #13
0
 protected function buildBody()
 {
     $main_body = $this->renderBody();
     $body = new PhabricatorMetaMTAMailBody();
     $body->addRawSection($main_body);
     $reply_handler = $this->getReplyHandler();
     $body->addReplySection($reply_handler->getReplyHandlerInstructions());
     if ($this->getHeraldTranscriptURI() && $this->isFirstMailToRecipients()) {
         $manage_uri = '/herald/view/differential/';
         $xscript_uri = $this->getHeraldTranscriptURI();
         $body->addHeraldSection($manage_uri, $xscript_uri);
     }
     return $body->render();
 }