Often it is desirable to have full control about the text part of a text/html multipart email. A clean solution would be to let the user choose a CCK field to use for the text part. (it would still be possible to have no text part, or an auto-generated one)
Thx a lot,
Donquixote
| Comment | File | Size | Author |
|---|---|---|---|
| #34 | plaintextfield_rerolled.patch | 19.29 KB | berdir |
| #32 | plaintextfield-437456-29.patch | 20.3 KB | berdir |
| #31 | plaintextfield-437456-#29.patch.tar_.gz | 5.92 KB | s_leu |
| #25 | plain_text_per_type.patch | 9.27 KB | liquidcms |
| #23 | plain_text_per_type.patch | 9.08 KB | liquidcms |
Comments
Comment #1
sutharsan commentedLook at the display settings of your newsletter content type. You can show/hide CCK field in HTML and plain text messages. This should work for plain text alternatives.
Comment #2
donquixote commentedThanks, this makes perfect sense!
I created one field for the HTML Mail version, another for the plaintext version, and yet another for the online version. This also solves the problem with relative links for attached images, see http://drupal.org/node/319229#comment-1487828
What I still need to figure out is how to remove all the CSS. Ideally, I want something as simple and stone-age as this:
I'm not sure about the wrapping
<font>tag, maybe this has to be moved down into the child DOM nodes.Another problem I found was that I can't use HTML comments (I disabled all filters except the pathfilter). But I guess this problem is a general one for Drupal, not just for emails.
Comment #3
donquixote commentedFor those who found this forum topic after a google search, some answers I found myself:
- A simple way to remove CSS is to create a file "mail.css" in your theme, and leave it empty (or put some no-effect rules inside). The mail.css does not add to the usual site CSS, it replaces it completely. Still, this does not completely remove the
<style>tag.- HTML comments can be re-enabled by disabling the core html sanitizer input filter. If you still want sanitized html, you can try htmltidy module or htmLawed module instead. I'm not sure which side effects these have, but maybe they can even do something useful.
- If you are using an admin theme that is different from the public site theme (and check "use admin theme for content editing"), then you have to put your newsletter templates into the admin theme.
Comment #4
donquixote commentedBack on topic.
Problem:
I applied all the settings in node display, enabling only the "Plaintext Email Version" CCK field for the simplenews plaintext display context. (and filled it with some dummy text, in my test newsletter). The other fields are on "hidden" (checkbox) and "exclude" (dropdown). I flushed all caches.
Unfortunately it still sends the auto-generated text, and my dummy text does not appear anywhere.
Comment #5
donquixote commentedFor clarification:
- If I send the email as plaintext, everything works as it should.
- If I send the email as html, and then tell my email client to show the text version, only then do I get the auto-generated text version. Which I don't want!
Looking into the simplenews code, I can see that the programmer did not intend to allow an independent text part in a multipart message.
I make this a feature request.
Comment #6
sutharsan commentedIf you could write the code too, the feature has the best cards to get implemented. Talking is silver, code is gold ;)
Comment #7
donquixote commentedYup, just finished a patch :)
I'm sorry I am not yet used to the patch format used in these forums, so for now I just attach the modified code (all modifications are commented as such, search for "MODIFI" to find these spots)
What it does:
- I found that simplenews_mail_mail() calls drupal_mail(), which again calls simplenews_mail().
- With the modifications applied, drupal_mail() (and thus simplenews_mail()) is now called twice: One time for the text version, one time for the html version.
- To make this possible, the buffer array $messages used in simplenews_mail() needs an additional dimension, the $build_mode. This is necessary, because otherwise the plaintext run will load from the buffer that was filled in the html run.
Issues:
- I am not sure about the effects of this modifications on people who actually want the automatically generated text version.
- I found that simplenews_html_to_text() is called both in simplenews_mail(), and in simplenews_mail_mail(). So, I assume that after the modification it will still be called. I don't know if this is necessary if the mail content is built from a CCK field that is meant as plaintext.
I'm sure some of this can be refactored or done better, but for me it does the job.
Thanks for your attention so far,
donquixote
Comment #8
donquixote commentedIf you want to ensure backwards compatibility, you could create additional sending options next to "plain" and "html", so we would have
- plain: rendered with build mode "email_plain", then simplenews_html_to_text().
- html, as before: build mode "html", then a plaintext version using simplenews_html_to_text()
- both (new): build mode "html" for the html version, then build mode "plain" + simplenews_html_to_text() for the text version.
- html only: no plaintext part (just for completeness)
All this assuming that simplenews_html_to_text() should be applied to any plaintext version.
I didn't implement this, because I thought it's better to begin with a simple patch.
Comment #9
sutharsan commentedComment #10
broonWhile using simplenews 6.x-1.x there had been no such choice, so all newsletter issues were written in the main body field. By using the patch from #709234: Simplenews custom plain text version I could create one (!) additional CCK field for the plain text version.
Now, when upgrading to 6.x-2.x I can choose which custom fields to show/hide on plain/html view but I can't set any options for the body field (which contains the HTML part and shouldn't be send when sending as plain text).
Is there possibly an option I missed to disable node->body on plain emails?
Regards,
Paul
Comment #11
miro_dietikerCould someone please convert this to a clean patch for 6.x-2.x?
This functionality was requested a few times.
I'm not sure if we should use a CCK field for this...
Instead i think it should be a simple optional text field (in case of specific user permissions).
We also should still have the permission to autocreate the text and provide it as a template (js callback?)
So conversion would be a great start but there's still some work left and decisions to take to include this in simplenews.
Comment #12
simon georges commentedI can work on the patch next week-end, but if you think there should be another solution, maybe we'd be better off discussing it first ;)
Comment #13
broonI tried to combine both this patch as well as #709234: Simplenews custom plain text version. Patch is against current 6.x-2.x (as of 2010-11-22) and still needs work. The solution is still about adding a new CCK field.
Cheers,
Paul
Comment #14
miro_dietikerThanks for the patch. Lot easier to read for me .-) Here's a few thoughts from my first sight.
There are tabs in the patch..
It doesn't make sense to me to choose the plaintext field per newsletter. Much more it is per content type (note there are multiple possible!).
If we add a body field, we really should provide a way (such as js button/callback) to build the plaintext from the node.
Note that you'r making the plaintext simplenews build mode obsolete. We should document this in the UI.
Additionally it seems to me you're ignoring input filters completely for the field. This seems wrong to me. If a filter is chosen it should be applied.
We need cck module to be optional. Make the patch hide the new options in the UI if cck is inactive and also make the processes work cleanly in this case with enough checks.
Other opinions?
(Seems still a lot of work to do.)
Comment #15
broonYou're absolutely right, there's still much work. My patch was just a first draft of a conversion to 2.x and works just fine within a test environment for a client.
I'll just throw in my thoughts:
In addition, I am working on including the language chooser in the newsletter block, which already works quite well but is still missing an admin UI for choosing to disable this feature because the simplenews forms are meant to be very slim. But that's actually another issue and maybe shouldn't be discussed here.
Cheers,
Paul
Comment #16
miro_dietikerYou can't hide the plaintext field based on newsletter vocabulary term.
The field will show up in any case. Providing per-newsletter settings will lead to confusion. The node form is per content type so i strongly recommend to define a plaintext body field per nodetype.
We might introduce a permission such as "manually edit plaintext" to prevent non-knowing users from the plaintext topic confusion.
Comment #17
miro_dietikerIs someone still working on this?
Comment #18
liquidcms commentedsubscribing.
and asking where this is at... the UI for this for our client is simple:
add a "Body - Plain Text" field to node and send all newsletters as multipart mimemail and let client's mail reader sort it out.
this post sounded promising when i found it but now not so sure what the module is doing. Display settings don't seem to support this. I would guess that we could disable the html field (which is Body; so can't actually do that but could disable Body and make a cck Body field) from going in the plain text email; but we have no need to ever send as plain text... we only will ever send as multipart. So, closest to that i guess is send as html (is this just labeled wrong? is it really JUST html or is it multipart?)
also, don't really care about the ahah convert to text and fill plain text field.. kind of a cool feature; but not a must have by a long shot - whereas not being able to have users read text or html makes snews unusable for us.
I'll do some testing to see if i can sort out what is there - which despite display setting options; i dont think there is any support at the moment for handling the real issue here (can we define what the plaintext version looks like).
another option of course (other than multipart) is to do what Notifications does; which allows user to select the format they want and then snews will send the email with text fields to text users and the email again with html fields to html users. But multipart seems like a better solution.
i can do the code to "fix" this; just not sure yet what is there or is required/preferred - maybe the patches here do the right thing?
Comment #19
liquidcms commentedlooking at patch from #13, looks like the right way to go; but patch fails on 6.x-2.0-alpha2 rev
i'll apply manually and see how it works.
Comment #20
liquidcms commentedyes, i agree that defining the field per node is overkill. should be per type.
no luck yet with manually patching as current code is missing part in simplenews.module which are being patched. looking deeper.
Comment #21
liquidcms commentedattached patch takes the per type approach.
it allows designating a cck field in the node as the plain text version of the newsletter to be added to the mimemail mulitpart msg.
i still have a few issues/questions with what i did here:
i mostly tried to follow the logic that the earlier (per node) patch was using but either i followed it wrong; or the logic is just wrong.
1. i think the text_alternative parameter should be set to either the ptext cck field if it exists and is not empty or to simplenews_html_to_text(body field) - does that seem correct. currently it is only set to the field designated as the plain text field.
2. i am not too sure the mail format selector makes any sense, why would we want to ever send plain text and should html not really say multipart? but maybe i am still missing something here.
i did a quick test (selecting html mail format, which is really multipart) and sure enough (once i found a text mail reader, because setting Outlook to read as plain text simply converts the html part of the multipart to text) then i do see my cck plain field as the msg and if i read in an html mail reader i get the body field in the mail. But, issue with plain text version is the footer is lost - why is that?
btw - the patch applies to latest -dev version of simplenews.
Comment #22
liquidcms commentedok, since it is drupal_mail that tacks on the footer to the body i think best is for snews to do the same for alternative text (i.e. plain text part of multipart). so this patch adds this and with this i now get this:
node type edit form: http://screencast.com/t/64gW836trIVv
newsletter issue edit: http://screencast.com/t/cX6FdDjn
plain text result email: http://screencast.com/t/MRscROTuu7
html version of email: http://screencast.com/t/evFYFTblJUL
@todo:
- still not sure if my cck field is undefined or empty i should be putting simplenews_html_to_text(body field) in as text_alternative - but maybe no need as the mail client will just do its best with the html version
- i guess cck plain textfield should have a token replace performed - yes, obvious.. so will add patch with that in a minute.
Comment #23
liquidcms commentedpatch to match with #22, but still i see issues..
i think text alternative field is only valid for mimemail (is this true?) so it should likely be wrapped in a if mimemail exists.
Comment #24
liquidcms commentedComment #25
liquidcms commentedyes, i need to insert cleaned body if my custom cck field is empty... or i get nothing in plain text mail client.
Comment #26
liquidcms commentedi still think might be some issues with the order i do things for token handling.. but maybe someone else can take a look. this works pretty good now for my needs.
Comment #27
miro_dietikerWe have discussed this need here. In order to have a clean setup, we decided to
- Use a field to (optionally) store plaintext node replacement
- Define a widget for this textfield to allow automated plaintext creation as a template
-- We still stay with simplenews view modes plaintext and html
-- The plaintext view mode is used for plaintext suggestion
- When sending out, the optional plaintext field overrides the plaintext variant.
Comment #28
miro_dietikerChanging assignment. :-)
Comment #29
miro_dietikerComment #30
s_leu commented@Berdir
Here's the patch. I diffed it from you commit f986e02c747c0b2742a02f6feb539f1da37880d3 "Issue #805114 by Berdir: Added missing multi signup block template." cause i was not able to diff from origin/7.x-1.x .
I could not load the JS in simplenews_plaintext using #attached. It's loaded in a preprocess_page hook at the moment which is obviously wrong. But it was the only way i could get the JS to run and i needed the JS to see a result to develop other parts of the module.
Please review/improve.
Comment #31
s_leu commentedPatch:
Comment #32
berdirUploading the patch without the # to see if it applies. Will do a review in the next post.
Comment #34
berdirAnd here is the same patch against the most recent 7.x-1.x.
I had a very weird issue when trying to apply the patch with git apply, only patch worked.
Comment #36
berdirBoth a review and thinking out loud about some parts below... We'll see next week who has time to continue working on this one.
Maybe I'll find time this weekend to start working on the cache issue, might make this a bit easier to handle, although it would require quite a re-roll probably.
Just a space changed and even the wrong way round...
Not convinced about this. If the plaintext module is an optional feature in a sub-module, why automatically enable it?
Not sure about adding another fieldset. It made sense when we had a second option, but adding a fieldset for just a single option is a but too much I think.
Maybe open a different issue where it can be discussed separatly if you like this change.
This part is commented out, what's it supposed to do?
field_get_items() should be used here instead of the hardcoded 'und'.
Looks like this part can be removed.
It would probably be nice to make that function return an array of fields and then loop over them.
Quite a few trailing whitespaces. I suggest to configure your editor to remove them. Netbeans has an option to only do it on changed lines, not sure about Eclipse.
The body special case is probably a left-over from D6 where body wasn't a field. It's quite pointless now. Also, this should probably use field_view_field or something like that. Given that, not sure if we actually need a theme function anymore.
First line of a function docblock should be a single line and shorter.
Maybe something like "Checks if a html mail transmitter module is enabled."
Should also contain @return, something like:
@return
TRUE if html mails can be sent, FALSE if not.
maybe rename the function to something like "simplenews_html_mails_supported()" or something like that?
Yeah, what I said above :)
Always use curly braces for conditions.
Missing newline at end of file, the commented out files declaration should be removed or tests added :)
Tabs.
Comments should be wrapped at 80 characters.
Would probably be good to use the module name in the widget name for proper namespacing.
Will need to look into this.
Maybe "Generated plain text" or "Fetch generated plain text"?
bar just measures the time until the sending is finished, which is e.g. useful when uploading large files. I doubt that text is actually even visible long enough to read it under normal instances.
Will need to check this. Would be nice if node_view() would work, the code below at least needs to be reworked to use the correct language..
Comments should start with a upper case and end with a "."
Comment #37
miro_dietikerAssigning to Berdir. Can you please make a suggestion?
We possibly postpone this to AFTER beta / stable.
Comment #38
miro_dietikerPromoting this to 8.x
People learned to live without it... and one might claim this feature is far from critical...
However, bad quality alternative fallback mails are bad and in D8 we tried to push newsletter quality.
Previewing the alternative text and content awareness of what a user sends (or recipients might see) is still of the goal list.
Comment #39
miro_dietikerSetting to active as i guess we need to start over again.