diff --git a/scripts/mail/mail_handler.php b/scripts/mail/mail_handler.php --- a/scripts/mail/mail_handler.php +++ b/scripts/mail/mail_handler.php @@ -77,6 +77,7 @@ $attachment->getContent(), array( 'name' => $attachment->getFilename(), + 'viewPolicy' => PhabricatorPolicies::POLICY_NOONE, )); $attachments[] = $file->getPHID(); } diff --git a/src/applications/metamta/controller/PhabricatorMetaMTAMailgunReceiveController.php b/src/applications/metamta/controller/PhabricatorMetaMTAMailgunReceiveController.php --- a/src/applications/metamta/controller/PhabricatorMetaMTAMailgunReceiveController.php +++ b/src/applications/metamta/controller/PhabricatorMetaMTAMailgunReceiveController.php @@ -56,7 +56,7 @@ $file = PhabricatorFile::newFromPHPUpload( $file_raw, array( - 'authorPHID' => $user->getPHID(), + 'viewPolicy' => PhabricatorPolicies::POLICY_NOONE, )); $file_phids[] = $file->getPHID(); } catch (Exception $ex) { diff --git a/src/applications/metamta/controller/PhabricatorMetaMTASendGridReceiveController.php b/src/applications/metamta/controller/PhabricatorMetaMTASendGridReceiveController.php --- a/src/applications/metamta/controller/PhabricatorMetaMTASendGridReceiveController.php +++ b/src/applications/metamta/controller/PhabricatorMetaMTASendGridReceiveController.php @@ -42,7 +42,7 @@ $file = PhabricatorFile::newFromPHPUpload( $file_raw, array( - 'authorPHID' => $user->getPHID(), + 'viewPolicy' => PhabricatorPolicies::POLICY_NOONE, )); $file_phids[] = $file->getPHID(); } catch (Exception $ex) { diff --git a/src/applications/metamta/replyhandler/PhabricatorMailReplyHandler.php b/src/applications/metamta/replyhandler/PhabricatorMailReplyHandler.php --- a/src/applications/metamta/replyhandler/PhabricatorMailReplyHandler.php +++ b/src/applications/metamta/replyhandler/PhabricatorMailReplyHandler.php @@ -327,11 +327,8 @@ return $body; } - // NOTE: This is safe, but not entirely correct. Clean it up after - // T7712. These files have the install-default policy right now, which - // may or may not be permissive. $files = id(new PhabricatorFileQuery()) - ->setViewer(PhabricatorUser::getOmnipotentUser()) + ->setViewer($this->getActor()) ->withPHIDs($attachments) ->execute(); diff --git a/src/applications/metamta/storage/PhabricatorMetaMTAReceivedMail.php b/src/applications/metamta/storage/PhabricatorMetaMTAReceivedMail.php --- a/src/applications/metamta/storage/PhabricatorMetaMTAReceivedMail.php +++ b/src/applications/metamta/storage/PhabricatorMetaMTAReceivedMail.php @@ -121,6 +121,19 @@ $this->setAuthorPHID($sender->getPHID()); + // Now that we've identified the sender, mark them as the author of + // any attached files. + $attachments = $this->getAttachments(); + if ($attachments) { + $files = id(new PhabricatorFileQuery()) + ->setViewer(PhabricatorUser::getOmnipotentUser()) + ->withPHIDs($attachments) + ->execute(); + foreach ($files as $file) { + $file->setAuthorPHID($sender->getPHID())->save(); + } + } + $receiver->receiveMail($this, $sender); } catch (PhabricatorMetaMTAReceivedMailProcessingException $ex) { switch ($ex->getStatusCode()) {