@recaptime-dev's working patches + fork for Phorge, a community fork of Phabricator. (Upstream dev and stable branches are at upstream/main and upstream/stable respectively.) hq.recaptime.dev/wiki/Phorge
phorge phabricator
1
fork

Configure Feed

Select the types of activity you want to include in your feed.

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

+38 -16
+1 -5
src/applications/conpherence/mail/ConpherenceReplyHandler.php
··· 58 58 ->setParentMessageID($mail->getMessageID()); 59 59 60 60 $body = $mail->getCleanTextBody(); 61 - $file_phids = $mail->getAttachments(); 62 - $body = $this->enhanceBodyWithAttachments( 63 - $body, 64 - $file_phids, 65 - '{F%d}'); 61 + $body = $this->enhanceBodyWithAttachments($body, $mail->getAttachments()); 66 62 67 63 $xactions = array(); 68 64 if ($this->getMailAddedParticipantPHIDs()) {
+37 -11
src/applications/metamta/replyhandler/PhabricatorMailReplyHandler.php
··· 319 319 return $this->getSingleReplyHandlerPrefix($address); 320 320 } 321 321 322 - final protected function enhanceBodyWithAttachments( 322 + final protected function enhanceBodyWithAttachments( 323 323 $body, 324 - array $attachments, 325 - $format = '- {F%d, layout=link}') { 324 + array $attachments) { 325 + 326 326 if (!$attachments) { 327 327 return $body; 328 328 } 329 329 330 + // NOTE: This is safe, but not entirely correct. Clean it up after 331 + // T7712. These files have the install-default policy right now, which 332 + // may or may not be permissive. 330 333 $files = id(new PhabricatorFileQuery()) 331 - ->setViewer($this->getActor()) 334 + ->setViewer(PhabricatorUser::getOmnipotentUser()) 332 335 ->withPHIDs($attachments) 333 336 ->execute(); 334 337 335 - // if we have some text then double return before adding our file list 336 - if ($body) { 337 - $body .= "\n\n"; 338 - } 338 + $output = array(); 339 + $output[] = $body; 339 340 341 + // We're going to put all the non-images first in a list, then embed 342 + // the images. 343 + $head = array(); 344 + $tail = array(); 340 345 foreach ($files as $file) { 341 - $file_str = sprintf($format, $file->getID()); 342 - $body .= $file_str."\n"; 346 + if ($file->isViewableImage()) { 347 + $tail[] = $file; 348 + } else { 349 + $head[] = $file; 350 + } 343 351 } 344 352 345 - return rtrim($body); 353 + if ($head) { 354 + $list = array(); 355 + foreach ($head as $file) { 356 + $list[] = ' - {'.$file->getMonogram().', layout=link}'; 357 + } 358 + $output[] = implode("\n", $list); 359 + } 360 + 361 + if ($tail) { 362 + $list = array(); 363 + foreach ($tail as $file) { 364 + $list[] = '{'.$file->getMonogram().'}'; 365 + } 366 + $output[] = implode("\n\n", $list); 367 + } 368 + 369 + $output = implode("\n\n", $output); 370 + 371 + return rtrim($output); 346 372 } 347 373 348 374 private function expandRecipientHandles(array $handles) {