mirror of
https://we.phorge.it/source/phorge.git
synced 2024-11-19 21:32:43 +01:00
Improve rules for embedding files received via email
Summary: Ref T7199. Ref T7712. This improves the file rules for email: - Embed visible images as thumbnails. - Put all other file types in a nice list. This "fixes" an issue caused by the opposite of the problem described in T7712 -- files being dropped if the default ruleset is too restrictive. T7712 is the real solution here, but use a half-measure for now. Test Plan: - Sent mail with two non-images and two images. - Got a nice list of non-images and embeds of images. Reviewers: btrahan Reviewed By: btrahan Subscribers: epriestley Maniphest Tasks: T7712, T7199 Differential Revision: https://secure.phabricator.com/D12235
This commit is contained in:
parent
6f028e16e8
commit
afd86a0420
2 changed files with 38 additions and 16 deletions
|
@ -58,11 +58,7 @@ final class ConpherenceReplyHandler extends PhabricatorMailReplyHandler {
|
||||||
->setParentMessageID($mail->getMessageID());
|
->setParentMessageID($mail->getMessageID());
|
||||||
|
|
||||||
$body = $mail->getCleanTextBody();
|
$body = $mail->getCleanTextBody();
|
||||||
$file_phids = $mail->getAttachments();
|
$body = $this->enhanceBodyWithAttachments($body, $mail->getAttachments());
|
||||||
$body = $this->enhanceBodyWithAttachments(
|
|
||||||
$body,
|
|
||||||
$file_phids,
|
|
||||||
'{F%d}');
|
|
||||||
|
|
||||||
$xactions = array();
|
$xactions = array();
|
||||||
if ($this->getMailAddedParticipantPHIDs()) {
|
if ($this->getMailAddedParticipantPHIDs()) {
|
||||||
|
|
|
@ -321,28 +321,54 @@ abstract class PhabricatorMailReplyHandler {
|
||||||
|
|
||||||
final protected function enhanceBodyWithAttachments(
|
final protected function enhanceBodyWithAttachments(
|
||||||
$body,
|
$body,
|
||||||
array $attachments,
|
array $attachments) {
|
||||||
$format = '- {F%d, layout=link}') {
|
|
||||||
if (!$attachments) {
|
if (!$attachments) {
|
||||||
return $body;
|
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())
|
$files = id(new PhabricatorFileQuery())
|
||||||
->setViewer($this->getActor())
|
->setViewer(PhabricatorUser::getOmnipotentUser())
|
||||||
->withPHIDs($attachments)
|
->withPHIDs($attachments)
|
||||||
->execute();
|
->execute();
|
||||||
|
|
||||||
// if we have some text then double return before adding our file list
|
$output = array();
|
||||||
if ($body) {
|
$output[] = $body;
|
||||||
$body .= "\n\n";
|
|
||||||
}
|
|
||||||
|
|
||||||
|
// We're going to put all the non-images first in a list, then embed
|
||||||
|
// the images.
|
||||||
|
$head = array();
|
||||||
|
$tail = array();
|
||||||
foreach ($files as $file) {
|
foreach ($files as $file) {
|
||||||
$file_str = sprintf($format, $file->getID());
|
if ($file->isViewableImage()) {
|
||||||
$body .= $file_str."\n";
|
$tail[] = $file;
|
||||||
|
} else {
|
||||||
|
$head[] = $file;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return rtrim($body);
|
if ($head) {
|
||||||
|
$list = array();
|
||||||
|
foreach ($head as $file) {
|
||||||
|
$list[] = ' - {'.$file->getMonogram().', layout=link}';
|
||||||
|
}
|
||||||
|
$output[] = implode("\n", $list);
|
||||||
|
}
|
||||||
|
|
||||||
|
if ($tail) {
|
||||||
|
$list = array();
|
||||||
|
foreach ($tail as $file) {
|
||||||
|
$list[] = '{'.$file->getMonogram().'}';
|
||||||
|
}
|
||||||
|
$output[] = implode("\n\n", $list);
|
||||||
|
}
|
||||||
|
|
||||||
|
$output = implode("\n\n", $output);
|
||||||
|
|
||||||
|
return rtrim($output);
|
||||||
}
|
}
|
||||||
|
|
||||||
private function expandRecipientHandles(array $handles) {
|
private function expandRecipientHandles(array $handles) {
|
||||||
|
|
Loading…
Reference in a new issue