3 final class DifferentialCreateMailReceiver
4 extends PhabricatorApplicationMailReceiver
{
6 protected function newApplication() {
7 return new PhabricatorDifferentialApplication();
10 protected function processReceivedMail(
11 PhabricatorMetaMTAReceivedMail
$mail,
12 PhutilEmailAddress
$target) {
14 $author = $this->getAuthor();
16 $attachments = $mail->getAttachments();
20 $files = id(new PhabricatorFileQuery())
22 ->withPHIDs($attachments)
24 foreach ($files as $index => $file) {
25 if ($file->getMimeType() != 'text/plain') {
27 'Could not parse file %s; only files with mimetype text/plain '.
28 'can be parsed via email.',
30 unset($files[$index]);
36 foreach ($files as $file) {
37 $call = new ConduitCall(
38 'differential.createrawdiff',
40 'diff' => $file->loadFileData(),
42 $call->setUser($author);
44 $result = $call->execute();
45 $diffs[$file->getName()] = $result['uri'];
46 } catch (Exception
$e) {
48 'Could not parse attachment %s; only attachments (and mail bodies) '.
49 'generated via "diff" commands can be parsed.',
54 $body = $mail->getCleanTextBody();
56 $call = new ConduitCall(
57 'differential.createrawdiff',
61 $call->setUser($author);
63 $result = $call->execute();
64 $diffs[pht('Mail Body')] = $result['uri'];
65 } catch (Exception
$e) {
67 'Could not parse mail body; only mail bodies (and attachments) '.
68 'generated via "diff" commands can be parsed.');
72 $subject_prefix = pht('[Differential]');
75 'You successfully created %d diff(s).',
79 'Diff creation failed; see body for %s error(s).',
80 phutil_count($errors));
82 $body = new PhabricatorMetaMTAMailBody();
83 $body->addRawSection($subject);
87 $body_label = pht('%s DIFF LINK(S)', phutil_count($diffs));
88 foreach ($diffs as $filename => $diff_uri) {
89 $text_body .= $filename.': '.$diff_uri."\n";
90 $html_body[] = phutil_tag(
96 $html_body[] = phutil_tag('br');
98 $body->addTextSection($body_label, $text_body);
99 $body->addHTMLSection($body_label, $html_body);
102 if (count($errors)) {
103 $body_section = new PhabricatorMetaMTAMailSection();
104 $body_label = pht('%s ERROR(S)', phutil_count($errors));
105 foreach ($errors as $error) {
106 $body_section->addFragment($error);
108 $body->addTextSection($body_label, $body_section);
111 id(new PhabricatorMetaMTAMail())
112 ->addTos(array($author->getPHID()))
113 ->setSubject($subject)
114 ->setSubjectPrefix($subject_prefix)
115 ->setFrom($author->getPHID())
116 ->setBody($body->render())