コード例 #1
0
 protected function buildMailBody(PhabricatorLiskDAO $object, array $xactions)
 {
     $body = new PhabricatorMetaMTAMailBody();
     $body->setViewer($this->requireActor());
     $revision_uri = PhabricatorEnv::getProductionURI('/D' . $object->getID());
     $this->addHeadersAndCommentsToMailBody($body, $xactions, pht('View Revision'), $revision_uri);
     $type_inline = DifferentialTransaction::TYPE_INLINE;
     $inlines = array();
     foreach ($xactions as $xaction) {
         if ($xaction->getTransactionType() == $type_inline) {
             $inlines[] = $xaction;
         }
     }
     if ($inlines) {
         $this->appendInlineCommentsForMail($object, $inlines, $body);
     }
     $changed_uri = $this->getChangedPriorToCommitURI();
     if ($changed_uri) {
         $body->addLinkSection(pht('CHANGED PRIOR TO COMMIT'), $changed_uri);
     }
     $this->addCustomFieldsToMailBody($body, $object, $xactions);
     $body->addLinkSection(pht('REVISION DETAIL'), $revision_uri);
     $update_xaction = null;
     foreach ($xactions as $xaction) {
         switch ($xaction->getTransactionType()) {
             case DifferentialTransaction::TYPE_UPDATE:
                 $update_xaction = $xaction;
                 break;
         }
     }
     if ($update_xaction) {
         $diff = $this->requireDiff($update_xaction->getNewValue(), true);
         $body->addTextSection(pht('AFFECTED FILES'), $this->renderAffectedFilesForMail($diff));
         $config_key_inline = 'metamta.differential.inline-patches';
         $config_inline = PhabricatorEnv::getEnvConfig($config_key_inline);
         $config_key_attach = 'metamta.differential.attach-patches';
         $config_attach = PhabricatorEnv::getEnvConfig($config_key_attach);
         if ($config_inline || $config_attach) {
             $body_limit = PhabricatorEnv::getEnvConfig('metamta.email-body-limit');
             $patch = $this->buildPatchForMail($diff);
             if ($config_inline) {
                 $lines = substr_count($patch, "\n");
                 $bytes = strlen($patch);
                 // Limit the patch size to the smaller of 256 bytes per line or
                 // the mail body limit. This prevents degenerate behavior for patches
                 // with one line that is 10MB long. See T11748.
                 $byte_limits = array();
                 $byte_limits[] = 256 * $config_inline;
                 $byte_limits[] = $body_limit;
                 $byte_limit = min($byte_limits);
                 $lines_ok = $lines <= $config_inline;
                 $bytes_ok = $bytes <= $byte_limit;
                 if ($lines_ok && $bytes_ok) {
                     $this->appendChangeDetailsForMail($object, $diff, $patch, $body);
                 } else {
                     // TODO: Provide a helpful message about the patch being too
                     // large or lengthy here.
                 }
             }
             if ($config_attach) {
                 $name = pht('D%s.%s.patch', $object->getID(), $diff->getID());
                 $mime_type = 'text/x-patch; charset=utf-8';
                 $body->addAttachment(new PhabricatorMetaMTAAttachment($patch, $name, $mime_type));
             }
         }
     }
     return $body;
 }
コード例 #2
0
 protected function buildMailBody(PhabricatorLiskDAO $object, array $xactions)
 {
     $body = new PhabricatorMetaMTAMailBody();
     $body->setViewer($this->requireActor());
     $this->addHeadersAndCommentsToMailBody($body, $xactions);
     $type_inline = DifferentialTransaction::TYPE_INLINE;
     $inlines = array();
     foreach ($xactions as $xaction) {
         if ($xaction->getTransactionType() == $type_inline) {
             $inlines[] = $xaction;
         }
     }
     if ($inlines) {
         $body->addTextSection(pht('INLINE COMMENTS'), $this->renderInlineCommentsForMail($object, $inlines));
     }
     $changed_uri = $this->getChangedPriorToCommitURI();
     if ($changed_uri) {
         $body->addLinkSection(pht('CHANGED PRIOR TO COMMIT'), $changed_uri);
     }
     $this->addCustomFieldsToMailBody($body, $object, $xactions);
     $body->addLinkSection(pht('REVISION DETAIL'), PhabricatorEnv::getProductionURI('/D' . $object->getID()));
     $update_xaction = null;
     foreach ($xactions as $xaction) {
         switch ($xaction->getTransactionType()) {
             case DifferentialTransaction::TYPE_UPDATE:
                 $update_xaction = $xaction;
                 break;
         }
     }
     if ($update_xaction) {
         $diff = $this->requireDiff($update_xaction->getNewValue(), true);
         $body->addTextSection(pht('AFFECTED FILES'), $this->renderAffectedFilesForMail($diff));
         $config_key_inline = 'metamta.differential.inline-patches';
         $config_inline = PhabricatorEnv::getEnvConfig($config_key_inline);
         $config_key_attach = 'metamta.differential.attach-patches';
         $config_attach = PhabricatorEnv::getEnvConfig($config_key_attach);
         if ($config_inline || $config_attach) {
             $patch_section = $this->renderPatchForMail($diff);
             $lines = count(phutil_split_lines($patch_section->getPlaintext()));
             if ($config_inline && $lines <= $config_inline) {
                 $body->addTextSection(pht('CHANGE DETAILS'), $patch_section);
             }
             if ($config_attach) {
                 $name = pht('D%s.%s.patch', $object->getID(), $diff->getID());
                 $mime_type = 'text/x-patch; charset=utf-8';
                 $body->addAttachment(new PhabricatorMetaMTAAttachment($patch_section->getPlaintext(), $name, $mime_type));
             }
         }
     }
     return $body;
 }
 /**
  * @task mail
  */
 protected function buildMailBody(PhabricatorLiskDAO $object, array $xactions)
 {
     $body = new PhabricatorMetaMTAMailBody();
     $body->setViewer($this->requireActor());
     $this->addHeadersAndCommentsToMailBody($body, $xactions);
     $this->addCustomFieldsToMailBody($body, $object, $xactions);
     return $body;
 }