Problem/Motivation
Multipart (MIME entities) messages can have mail attachments. As a part of #2804543: [META] Provide a complex Inmail element issue, we want to be able to display mail attachments as well.
Proposed resolution
Similarly to #2804545: Display email's inline images using new element, we should create a new element (and a twig template) that handles "attachment" case. We would need to check "attachment" in content disposition header and act in these cases. See: https://tools.ietf.org/html/rfc2183
Regarding the display, we could just display the file name and it's extension. Also, the great UX would be to have this clickable. In that case the attachment would open/download.
Remaining tasks
User interface changes
API changes
Data model changes
Comment | File | Size | Author |
---|---|---|---|
#13 | display_mail_attachments-2804551-13-interdiff.txt | 98.89 KB | mbovan |
#13 | display_mail_attachments-2804551-13.patch | 14.91 KB | mbovan |
| |||
#11 | display_mail_attachments-2804551-11-interdiff.txt | 104.54 KB | mbovan |
#11 | display_mail_attachments-2804551-11.patch | 106.88 KB | mbovan |
| |||
#11 | Screen Shot 2016-10-17 at 14.03.53.png | 39.21 KB | mbovan |
Comments
Comment #2
miro_dietikerWithout this, mails might be huge, eating large amount of space in DB or filesystem, without any value at all.
One of the key points with this code is, we should check the resource / memory usage and try to be very friendly.
Inmail could introduce the idea to offload attachments to temporary files when parsing, or skip them at all until they are really accessed.
See the API / Parser level issue: #2805533: META Special treatment for attachment / image parts in parser
Comment #3
miro_dietikerSee mockup discussion at #2804587-6: Create mail display mock-ups
Comment #4
miro_dietikerComment #5
mbovan CreditAttribution: mbovan at MD Systems GmbH commentedCreated a patch based on inputs above and discussions in #2804587: Create mail display mock-ups, #2807719: Readd the body for multipart messages.
Also, providing simple tests based on #2807733: Write mail display tests per example.
I think there is space to improve parsing logic, but my concern is whether should we do it in prerendering or during the core Inmail parsing phase?
That said, we could think about introducing "Attachment" (Inmail) entity as there are many things describing it: filename, content type, attachment type (image, video, document), encoding, raw content, offloaded temporary file (entity)? etc... That would certainly help us to avoid complex prerendering logic and to parse an email much better.
Comment #6
miro_dietikerIt would not be the parser that is extended. The parser just identifies the mail standard elements and does this correct following the standard. The missing piece there is adress parsing.
We could introduce a new helper that converts / filters / accesses these elements to be more prepared for display.
But for now i would recommend put this into preprocess and move the logic into a helper with follow-ups. I highly recommend to make the features just work as simple as possible with the first iteration (incl test coverage).
Comment #7
mbovan CreditAttribution: mbovan at MD Systems GmbH commentedMoved build-attachments logic into preprocess hook.
Created a follow-up for attachment identifier/helper method.
Comment #8
miro_dietikerWould be really nice to get a status screenshot if you implement some feature like this with visual elements. It takes quite some steps to setup an environment to test drive it and "see" it to understand if it works for the user or not.
Comment #9
miro_dietikerWhy an image without source and figcaption?
What we semantically deliver is more a bullet item than an image with metadata.
I'm missing a basic file size indication.
Please test with longer filenames and also special chars.
And also add other examples such as Content-Disposition: inline.
Comment #10
mbovan CreditAttribution: mbovan at MD Systems GmbH commentedRe #8:
Ah, sorry, here is the screenshot. I thought there is not too much to see except the list of items:
Re #9:
No source as we don't have mockups/images yet. There is a comment in Twig to add it when it's ready.
Yes, then we can remove figure/figcaption and just use
<img>
in<li>
.Skipped this part as I thought we'll use the correct file size when we have attachments offloading to temporary files.
I'll provide some rough estimation based on an encoded string.
Inline (images) are currently not supported. I am going to extend the logic to support them in this issue as well.
Comment #11
mbovan CreditAttribution: mbovan at MD Systems GmbH commentedAddressed #9.
Added a file size indicator, added support for inline images (as attachments) and removed
<figcaption>
.Improved tests with several attachments of images, text files, special characters in file names, long file names etc.
Because of this, the patch is going to be ~100KB big. Also, had some issues to assert the special characters in the file name, so the patch is currently asserting "non-special" part and the file size only.
Here is the current screenshot:
We can probably make all the helper methods cleaner in #2817007: Introduce attachment identifier helper...
Edit: Related issue update.
Comment #12
miro_dietikerCool.
But we don't commit large files just to verify file size asserts. In that case, i trust the code works.
If you really need to pass in large data into the mail, you can pick any file or create dummy data and do base64 encode.
Follow-Up: The special characters will be important and need to be asserted.. Note though that the mail body is in different encoding than the browser, so you need to think properly about both collation and encoding. You might need to inline-base64-encode the filename header...
You should start to track which parts (numeric keys) are used so later code knows about it. Don't drop the numbers because it will no more be possible to return a reference to it. For instance (follow-up), a download filename will need to link to the part for download, which will need the part key.
Comment #13
mbovan CreditAttribution: mbovan at MD Systems GmbH commentedYeah, removed the big files and replaced them smaller ones (~1KB).
Created followups. Also, index reference path seems much more complicated than I thought at first, so I created a followup for it.
In this patch, I added
$index
which is (the first level) message part index. That works fine for attachments since they are always "attached" to the main Multipart message, while there are issues with sub-elements (related/alternative which is not supported for display yet) and inline images. When we start with #2817007: Introduce attachment identifier helper these issues might be fixed by themselves though...Comment #15
miro_dietikerCommitted. More stuff, display adjustment in follow-ups.
Follow-Up: This would be the perfect example for a unit test.
Comment #16
miro_dietikerOops, PHPStorm also warns about this piece:
$suffixes[floor($base)]
floor() still returns float and is not save as array key. You need to cast it to (int).
Comment #17
miro_dietikerTested a bit more, did some longer review, testing multipart worked most easily with this:
cat tests/modules/inmail_test/eml/attachments/complex.eml | drush --uri=http://d8.dev/ inmail-process drush
Follow-Up: The headers still don't look like the mockup.
This also applies to the attachment list. That list should also have a semantical title "Attachments".
We should start with some wrappers and reduce the header area. It really needs to start look nice.
Follow-Up: If i accidentally forget to provide the deliverer, i get these error messages:
There is no feedback on the terminal about processing.
Follow-Up:
\Drupal\inmail\MessageProcessor::process should return the ProcessorResult... and later processMultiple should return an array of these by preserving the keys.
Then, drush_inmail_process() can check for verbose flag and output feedback.
Also from the Paste email tab, the response is just "The message has been processed.". It should additionally display a link to the log record if logging is enabled.
Follow-Up: Improve logging
The log record created displays two valueless arguments:
DRUPAL\INMAIL\DEFAULTANALYZERRESULT
[contexts] (object):
MODERATORFORWARDHANDLER
[0] (object):
[string] (string): Moderator email address not set
This seems pretty useless to me. There is an issue to build a meaningful context summary for logging.
Funnily, the ForwardHandler doesn't report anything if it forwards the mail. Instead it logs if it is unconfigured... Do we need log severities?
Follow-Up: Download attachments on click
This will need a passthrough route. The element doesn't know where an element is stored. So the element should get an attachment route key from the caller. If not provided, the attachments are not linked.
Follow-Up: Deliver images
First simply deliver them so that they are displayed in a browser. Later also support inline images.
Back to needs-work to create the follow-up issues. Please close when created.
Comment #18
mbovan CreditAttribution: mbovan at MD Systems GmbH commentedCreated a bunch of issues for #17:
Here is the list:
Marking this one as fixed.